Poll
Question: Which type of pulse width modulation is important to you?
Fast PWM - 3 (17.6%)
Phase-correct PWM - 2 (11.8%)
Some other type - 0 (0%)
Don't care - 3 (17.6%)
Huh?  There's different kinds of PWM? - 9 (52.9%)
Total Voters: 11

Pages: [1]   Go Down
Author Topic: PWM Flavor  (Read 1247 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12283
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Arduinos have two kinds of pulse width modulation: fast and phase-correct.  Which is important to you?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 21
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you explain the difference between the two? What is the benefit of using phase correct PWM? Thanks
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12283
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


That's a very good question.  Unfortunately, I'm not going to be much help answering it.  My only experience with PWM is dimming LEDs.

What I've read and a little bit I know...

- Fast is good for power regulation.  I assume this would be for something like a "switching power supply".  A quote from the '85 datasheet: "This high frequency makes the fast PWM mode well suited for power regulation, rectification, and DAC applications.  High frequency allows physically small sized external components (coils, capacitors), and therefore reduces total system cost."

- Phase-correct works well for motor control.  A quote from the '85 datasheet: "However, due to the symmetric feature of the dual-slope PWM modes, these modes are preferred for motor control applications."

- The maximum phase-correct frequency is half the maximum fast frequency.

- I believe the frequency for fast PWM on a 16 MHz Arduino is 16000000 / (64 * 256) = ~976 Hz.  The frequency is half that for 8 MHz Arduinos.

- I believe the frequency for phase-correct PWM on a 16 MHz Arduino is 16000000 / (64 * 510) = ~490 Hz.  The frequnecy is half that for 8 MHz Arduinos.

Hopefully, someone else can provide something more informative.

This helped me understand the difference...
http://www.societyofrobots.com/member_tutorials/node/230
« Last Edit: November 14, 2010, 10:10:38 pm by bcook » Logged

0
Offline Offline
God Member
*****
Karma: 0
Posts: 594
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I use whatever suits my application, however I do find that phase-correct looks nicer on the logic analyzer I use to debug
Logged

Freelance engineer, consultant, contractor. Graduated from UW in 2013.

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6373
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have never understood how the difference would be relevant, especially at the relatively low speed used for PWM outputs on Arduino...
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12283
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


My motivation for asking is the ATtiny85 processor.  It has two timers (0 and 1) each with two PWM channels (A and B).  One channel from each timer is connected to a single pin (PB1 is connected to Timer 0 Channel B and Timer 1 Channel A).  I'm in the process of filling-out the '85 core files and I need to decide if this pin should be fast or phase-correct.
« Last Edit: November 15, 2010, 02:19:35 am by bcook » Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6373
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I believe that on a standard arduino, four of the PWM pins run phase-correct, and two run "fast" (because the timer is shared with the 1ms interrupt.)  Most of the time, no one notices...  
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The ATMega328 datasheet will explain the differences in these two flavors of PWM quite well.

But basically fast PWM uses the counter in a "count up and reset" mode while phase correct mode uses the counter in a "count up and then back down mode".

The result is that in fast mode the PWM duty cycle changes the mid-point of the signal based on its width.  Thus the phase of the signal varies.

In phase correct mode the center of the on-time of the PWM signal is always centered around the "top" point of the count because the counter counts up and then back down to zero.  Thus the on time is always centered around the max count i.e. the phase doesn't change with duty cycle.

There are two other results.  One is that the fast mode is twice the frequency of the phase correct mode.  The other result is that the fast mode can never turn fully off.  The count compare always matches for at least one count when the duty cycle is commanded to zero.  This makes it problematic for motor control.

From what I've seen the counters use phase-correct mode for the AnalogWrite() command in the 328-based and I assume 1280/2560-based Arduinos.  I haven't measured them all but the basic frequency is 490Hz for Timer1 and Timer2 at least.

/me
« Last Edit: November 16, 2010, 01:38:19 pm by RobotPower » Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12283
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


@RobotPower: Thank you for the post.

Quote
From what I've seen the counters use phase-correct mode for the AnalogWrite() command in the 328-based and I assume 1280/2560-based Arduinos.
The two pins connected to Timer 0 (the millis timer) are fast PWM.  All the others are phase-correct.

Did you vote?  Which flavor is more important to you?
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6373
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The result is that in fast mode the PWM duty cycle changes the mid-point of the signal based on its width.  Thus the phase of the signal varies.
Excellent explanation!  I had read (well, "looked at") the datasheet and understood the count up vs up&down thing, but I never understood why it was relevant, or how the latter was better for motors...
Logged

Pages: [1]   Go Up
Jump to: