jamieboyd wrote:Thanks to the info on this page, I got RPIO.PWM working on the Pi 2. One thing I noticed is that the timing is a bit off. With the 20000 microseconds default period, I should get 50 Hz, but I get 44.45 Hz, the period is off by a factor of 1.25. Similarly, the pulse widths are a little longer than they should be. Is the timing with RPIO.PWM more accurate on the Pi1?
Using the hardware PWM with Gordon's WiringPi, I can choose the clock divider to get a frequency of 49.867Hz and pulse widths are much more accurate, but you have to know the pi clock rate (19.2e6 for pi 2) to calculate it. Looking through pwm.c I see that PRIO.PWM uses the 500MHz PLLD clock as source - is there a difference in PLLD between pi1 and 2 that might account for the 1.25X period length difference?
Replying to my own post, I know, but I changed the clock divisor in ppm.c from 50 to 45, and re-installed. 49.38 Hz, and pulse timing is much more accurate. To do this yourself, look in pwm.c for:
clk_reg[PWMCLCK_DIV]=0x5A000000 | (50<<12); //set pwm div to 50, giving 10 MHz
and change the 50 to 45.
I think the problem is the line above that:
clk_reg[PWM_CLCK_CNTL] = 0x5A000006; // source = PLLD (500 MHZ)
and the constant referred to has changed between Pi versions, so that is selecting a different frequency than previously. The better fix would be to change the 0x5A000006 to actually select 500Mhz, but where that info is, I don't know.
I've heard about PIGPIO, but have not tested it yet.