Yes pigpio and Broadcom drivers provide an interface, but I've been working hard to avoid anything that requires root privileges to run the resulting executables. In almost all cases the driver backends either end up using the ioctl() interface or use /dev/mem (e.g. the Broadcom driver). The Sysfs interface for hardware PWM provides a simple and reliable hardware PWM. Looking though the old WiringPi and other example libraries I've found, the source ends up using ioctl() for softPWM, but in all cases were using the old GPIO V1 ABI which is deprecated. That is what triggered the software PWM rewrite using the GPIO V2 ABI which will hopefully have more longevity.
You did point me in the right direction to investigate using DMA to generate the PWM. I'll look into that and see if DMA can provide a higher usable PWM than the interval timer approach.
Great learning. I recall reading the pluses and minuses of using 64-bit arm instead of 32-bit arm installs and included in the documentation was that 32-bit arm would run more quickly on the Zero than the 64-bit version. What was really surprising was in the interval timer/ioctl() access case, the difference is 32-bit OS runs 100% faster than 64-bit. I've noticed the same difference in many of the sample projects I've done. The CPU demand on the 64-bit OS is roughly 2X what it is on the 32-bit OS. Generating a 25KHz PWM signal with interval timers is where the 64-bit OS maxes out. By the time you get to 32KHz, one core is saturated the the signal goes haywire.
Testing with a 3-color LED, the cpu demand with PWM at 6.4KHz (64 PWM cycles per-second, 100 tick range per-cycle) CPU use is 16% on 32-bit, 26% on 64-bit. One benefit to this method as opposed to the older WiringPi, etc.. is the CPU use isn't per-GPIO dependent. Driving 20 pins or 2 doesn't change the demand due to the line-request ioctl interface using a simple array and bitmaps to determine which lines to set. There is no extra cost to using more pins.
After working on this an extra day, the ~25KHz max for 64-bit software PWM and ~50KHz max for 32-bit OS does look like the reasonable limits for interval timer generated PWM. 2KHz is more than adequate for simple LED's etc and that is less than 5% demand total on the CPU, 4KHz is about 6%. I'll have to update with a comparison for the DMA generated PWM -- but that will be the next bit of learning. To bad there isn't an easy pioasm for the Pi instead of just the Pico. Thanks for your input.
You did point me in the right direction to investigate using DMA to generate the PWM. I'll look into that and see if DMA can provide a higher usable PWM than the interval timer approach.
Great learning. I recall reading the pluses and minuses of using 64-bit arm instead of 32-bit arm installs and included in the documentation was that 32-bit arm would run more quickly on the Zero than the 64-bit version. What was really surprising was in the interval timer/ioctl() access case, the difference is 32-bit OS runs 100% faster than 64-bit. I've noticed the same difference in many of the sample projects I've done. The CPU demand on the 64-bit OS is roughly 2X what it is on the 32-bit OS. Generating a 25KHz PWM signal with interval timers is where the 64-bit OS maxes out. By the time you get to 32KHz, one core is saturated the the signal goes haywire.
Testing with a 3-color LED, the cpu demand with PWM at 6.4KHz (64 PWM cycles per-second, 100 tick range per-cycle) CPU use is 16% on 32-bit, 26% on 64-bit. One benefit to this method as opposed to the older WiringPi, etc.. is the CPU use isn't per-GPIO dependent. Driving 20 pins or 2 doesn't change the demand due to the line-request ioctl interface using a simple array and bitmaps to determine which lines to set. There is no extra cost to using more pins.
After working on this an extra day, the ~25KHz max for 64-bit software PWM and ~50KHz max for 32-bit OS does look like the reasonable limits for interval timer generated PWM. 2KHz is more than adequate for simple LED's etc and that is less than 5% demand total on the CPU, 4KHz is about 6%. I'll have to update with a comparison for the DMA generated PWM -- but that will be the next bit of learning. To bad there isn't an easy pioasm for the Pi instead of just the Pico. Thanks for your input.
Statistics: Posted by drankinatty — Sun May 05, 2024 9:28 am