## 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 that help themselves."

"How have you proved that your chip is running at xxMHz?" - Me

"If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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 that help themselves."

"How have you proved that your chip is running at xxMHz?" - Me

"If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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

"This forum helps those that help themselves."

"How have you proved that your chip is running at xxMHz?" - Me

"If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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).

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

theusch wrote:
See the

Don't you just love a cliffhanger!

Top Tips:

1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...

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 that help themselves."

"How have you proved that your chip is running at xxMHz?" - Me

"If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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!

Top Tips:

1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...

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