Pages: [1]   Go Down
Author Topic: Adjusting resolution of duty cycle for higher PWM frequencies  (Read 760 times)
0 Members and 1 Guest are viewing this topic.
Vancouver, Canada
Offline Offline
Full Member
***
Karma: 0
Posts: 118
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

So I was looking for how to change the PWM frequencies on the Arduino Mega 2560 and I came across this useful page: http://sobisource.com/?p=195
Now I want to know what will happen to the resolution of duty cycle at let say 31250 Hz? with what precision can I adjust the duty cycle?

Thanks
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 604
Posts: 33432
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Using the default value for any frequency will give you the full 8 bit resolution. However, if you up the comparator value to get an exact frequency then there are less steps between zero and that value. Worst case you will get no PWM capability.

For example if you set OCR2A to be 51 to give a frequency of 38.4KHz, then OCR2B can only take on a value between one and 50. So in this case you an only get 49 different values of duty cycle.
Logged

Vancouver, Canada
Offline Offline
Full Member
***
Karma: 0
Posts: 118
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the reply
But what do you mean about the default values? Do you mean these:
0×01                                  1                                31250 hz
0×02                                  8                                3926.25 hz
0×03                                 32                             976.5625 hz
0×04                                 64                             488.28125 hz
0×05                                 128                           244.140625 hz

If I set the frequency to 31250 Hz, do I have 256 resolution in duty cycle?

Thanks
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 604
Posts: 33432
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
But what do you mean about the default values? Do you mean these:
Yes, set the pre divider to any of these to get the full 255 resolution on the PWM.
Logged

Pages: [1]   Go Up
Jump to: