Hello everyone,
I'm used to use fast pwm with avr's, but I can't figure it out how it works on the pi.
You have the clock frequency of 19,2 MHz, you use a prescaler of 32 What gives 600 KHz.
I suppose this is a counter tick, but what with the range? It doesn't work like what I'm used to, the frequency is variable and can't find the solution.
Who can explain the pwm signal generating.
Thanks
-
- Posts: 75
- Joined: Thu Mar 15, 2012 7:27 pm
Re: How the pwm works (in theory)
Right. Then for 10 bits of precision, say, you set a range of 0x400 = 1024. Each full output period lasts 1024 of the 600kHz ticks, or 1.706667ms. The valid data values are 0..1024. The selected number of output ticks are high, and the rest are low. So the average voltage is (data/1024) * 3.3V.honda4life wrote:You have the clock frequency of 19,2 MHz, you use a prescaler of 32 What gives 600 KHz.
I suppose this is a counter tick, but what with the range?
Now, in a traditional PWM implementation each output period consists of one contiguous run of high ticks and one run of low ticks. So an external frequency counter or scope will tell you that the output frequency is always 585.9375Hz and only the duty cycle varies from 0 to 100%. The BCM2835 supports this mode, which it calls mark-space, if you set MSEN=1 in the PWM CTL register.
But the default MSEN=0 mode is Pulse Density Modulation. This spreads the high and low ticks out as evenly as possible throughout the output period. For an output of 512/1024 it gives a pattern of 01010101..., which has frequency 300kHz. For an output of 409/1024 it gives 001001010010100101..., which is alternating between 200kHz 33% duty and 300kHz 50% duty.
PDM has the property that every substring of the output sequence is within one bit of the correct average value. So it is much smoother than traditional PWM (except for outputs at the extreme ends of the range, where it is the same).
-
- Posts: 75
- Joined: Thu Mar 15, 2012 7:27 pm
Re: How the pwm works (in theory)
Now I understand.
I've read about MSEN but it wasn't clear to me
Thank you very much
I've read about MSEN but it wasn't clear to me

Thank you very much

Re: How the pwm works (in theory)
Hello, thank you for the useful information about the MSENi bit.
I have some more questions. In the BCM2835-Arm-Peripherals at page 141 it says: "PWM clock source and frequency is controlled in CPRMAN" . Can someone explain what does it means?
(So the pwm clock is used to define the period which will then be multiplied by the RNGi Register value and give the output period. Am i correct?)
I didn't also understand what happens when the RNGi Register has a value below 32 ?
Sorry for posting in such an old topic, but i also have theory questions so i thought it would be ok here.
I have some more questions. In the BCM2835-Arm-Peripherals at page 141 it says: "PWM clock source and frequency is controlled in CPRMAN" . Can someone explain what does it means?
(So the pwm clock is used to define the period which will then be multiplied by the RNGi Register value and give the output period. Am i correct?)
I didn't also understand what happens when the RNGi Register has a value below 32 ?
Sorry for posting in such an old topic, but i also have theory questions so i thought it would be ok here.
- Gert van Loo
- Posts: 2487
- Joined: Tue Aug 02, 2011 7:27 am
- Contact: Website
Re: How the pwm works (in theory)
As for CPRMAN: CPRMAN stands for Clock Power Reset MANager.
In the BCM2835 all the clocks and power and reset are controlled by this one central block.
(But in the datasheet you will find that the clock section is described separate from the power/reset manager.)
In the BCM2835 all the clocks and power and reset are controlled by this one central block.
(But in the datasheet you will find that the clock section is described separate from the power/reset manager.)
Re: How the pwm works (in theory)
I see, thank you.
Re: How the pwm works (in theory)
I've no idea what RNG is meant to do either. I do not understand what the documentation is saying. I just find a setting which seems to work and then leave it alone.
Re: How the pwm works (in theory)
(Yes.) In PWM/PDM modes there is nothing special about range values smaller or larger than 32. Obviously the choice of output values becomes very limited at short ranges. A range of 255 or 1024 would be typical.makbut wrote:(So the pwm clock is used to define the period which will then be multiplied by the RNGi Register value and give the output period. Am i correct?)
I didn't also understand what happens when the RNGi Register has a value below 32 ?
The references to 32 are for when the peripheral is in serialiser mode, CTL.MODEi=1. Instead of DATi setting the number of high ticks during each full output period, it sets the actual pattern of ones and zeros to be sent. Because the DATi register is 32 bits wide, if RNGi<32 not all of its bits are sent, and if RNGi>32 the extra ticks are padded as zeros.
Re: How the pwm works (in theory)
Now it makes perfect sense. Thank you very much!