Multi-channel High Frequency PWM with registers and phase shift capabilities

Hi antodom,

I looked into Rasperry Pi Zero PWM more closely now and did test your pwm_capture_test. PWM0 is on GPIO pin 18, so I connected that to Due D2, and GND to GND.

The formula for Raspberry Pi Zero PWM frequency is "19.2MHz / pwmClock / pwmRange".

As a first test I started with 10KHz because that is what I can verify with my small USB oscilloscope.
These are the Pi Zero GPIO commands:

pi@raspberrypi01:~ $ gpio -g mode 18 pwm
pi@raspberrypi01:~ $ gpio -g pwm-ms
pi@raspberrypi01:~ $ gpio -g pwmc 960
pi@raspberrypi01:~ $ gpio -g pwmr 2
pi@raspberrypi01:~ $ gpio -g pwm 18 1
pi@raspberrypi01:~ $
pi@raspberrypi01:~ $ bc -lq
19200000/960/2
10000.00000000000000000000

And here is photo of oscilloscope verifying the 10KHz:

I added the output of period in ticks and ticks per us to your programs output line.
For pwmc=48 (corresponds to 19.2/48/2=200KHz) this is the line from pwm_capture_test, and 210 ticks @42MHz are exactly 5us:

[PIN 35 -> PIN 2] duty: 2.500 usecs. period: 5.000 usecs. period2: 210.00 ticks: 42.00[overrun][stopped]

Since 6 is a divisor of 210 I tried pwmc=8 next (corresponds to 19.2/8/2=1.2MHz) and period2=35 matches that:

[PIN 35 -> PIN 2] duty: 0.405 usecs. period: 0.833 usecs. period2: 35.00 ticks: 42.00[overrun][stopped]

Finally I set pwmc=2 (corresponds to 19.2/2/2=4.8MHz) and the output are lines with period2 being 8 or 9. From 17 samples 4 were 8, and the average measured frequency is 1/((139+48 )/17/42) = 4.79MHz!

[PIN 35 -> PIN 2] duty: 0.071 usecs. period: 0.190 usecs. period2: 8.00 ticks: 42.00[overrun][stopped]
=======================================================================
=======================================================================
[PIN 35 -> PIN 2] duty: 0.119 usecs. period: 0.214 usecs. period2: 9.00 ticks: 42.00[overrun][stopped]

For some reason setting clock divider to 1 does not work with pwm_capture_test. So either 19.2/1/2=9.6MHz is a tainted frequency for pwm_capture_test, or the Pi Zero PWM documentation is wrong wrt pwmc=1 being allowed.

Hermann.