## PWM PULSE WITH MEGA8A??

17 posts / 0 new
Author
Message

HI

can I produce a pwm pulse with mega8 that 5us=on & 10ms=off?

Depends on your skill level, but for those skilled in the art, your requirements are easy to achieve. Sounds like you want to control a RC servo. If so, there are plenty of examples on the interwebs.

I want to apply this pulse to a meg16.

mostafa147 wrote:

can I produce a pwm pulse with mega8 that 5us=on & 10ms=off?

Yes.

'This forum helps those who help themselves.'

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

Thanks

To my knowledge, in case of ATmega8, the best resolution of PWM is 1/1024 [10 bits]. The ratio 5us/10,000us is 1/2000. So, to me in the least, the answer to your question is no if ATmega8 is used... though I wish I am wrong.

KerimF wrote:

To my knowledge, in case of ATmega8, the best resolution of PWM is 1/1024 [10 bits]. The ratio 5us/10,000us is 1/2000. So, to me in the least, the answer to your question is no if ATmega8 is used... though I wish I am wrong.

And yet my screen grab above, and this one below, would appear to say otherwise...

'This forum helps those who help themselves.'

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

Same 10ms repeat rate, here I've set a wider pulse width...

'This forum helps those who help themselves.'

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

KerimF wrote:

To my knowledge, in case of ATmega8, the best resolution of PWM is 1/1024 [10 bits]. The ratio 5us/10,000us is 1/2000. So, to me in the least, the answer to your question is no if ATmega8 is used... though I wish I am wrong.

Yes you are wrong. Yes, there is at least one canned 10-bit mode. But there is also at least one canned 16-bit mode.
See the

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

theusch wrote:

KerimF wrote:

To my knowledge, in case of ATmega8, the best resolution of PWM is 1/1024 [10 bits]. The ratio 5us/10,000us is 1/2000. So, to me in the least, the answer to your question is no if ATmega8 is used... though I wish I am wrong.

Yes you are wrong. Yes, there is at least one canned 10-bit mode. But there is also at least one canned 16-bit mode.
See the

Thank you for pointing out that there is a 16-bit mode when using PWM of ATmega8 (the only MCU I have for my various projects).

Would you please let me know on which table on its datasheet this mode is shown (I write my codes in assembly only).

Thank you in advance for your time.

Last Edited: Tue. Oct 31, 2017 - 12:02 PM

theusch wrote:
See the

Don't you just love a cliffhanger!

KerimF wrote:

Would you please let me know on which table on its datasheet this mode is shown ...

Table 39 (or at least it is in the version of the datasheet I have downloaded.)

'This forum helps those who help themselves.'

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

Thank you Brian for your fast reply.

Yes, it is on table 39; titled 'Waveform Generation Mode Bit Description'.

It seems I am getting old faster than I was expecting ;)

Only now I noticed that by using the 'Phase Correct PWM Mode' or 'Phase and Frequency Correct PWM Mode', a 16-bit PWM could be generated.

I used skipping these two modes because it happens that I didn't need better than 10-bit PWM in my projects.

So, thanks to you and theusch for opening my eyes on this.

Last Edited: Tue. Oct 31, 2017 - 01:18 PM

awneil wrote:
Don't you just love a cliffhanger!
Not a cliffhanger, it's a leehanger.

David (aka frog_jr)

I wondered if anyone else would spot that!

KerimF wrote:
Only now I noticed that by using the 'Phase Correct PWM Mode' or 'Phase and Frequency Correct PWM Mode', a 16-bit PWM could be generated.

I used skipping these two modes

But it's not only that two modes. There are also 16 bit Fast PWM modes (mode 14 and 15).

Stefan Ernst

sternst wrote:

KerimF wrote:

Only now I noticed that by using the 'Phase Correct PWM Mode' or 'Phase and Frequency Correct PWM Mode', a 16-bit PWM could be generated.

I used skipping these two modes

But it's not only that two modes. There are also 16 bit Fast PWM modes (mode 14 and 15).

Yes, you are right. In Fast PWM mode, OCR1A\B or ICR1 is also used.

Thank you for your remark.

Last Edited: Tue. Oct 31, 2017 - 02:00 PM