I want to make a 120kHz PWM signal from my raspberry pi 3. Since it uses a 1,2gHz CPU. I tried using RPi.GPIO.PWM(Chanel, frequency), the max frequency I got was about 8kHz. How can I come up to 120kHz?
Asked
Active
Viewed 2,212 times
2 Answers
2
I'm not sure that you can reach 120kHz with software PWM. That would require a wakeup every 8µs or so.
Use hardware PWM, e.g. my pigpio provides http://abyz.me.uk/rpi/pigpio/python.html#hardware_PWM and http://abyz.me.uk/rpi/pigpio/python.html#hardware_clock
1
The RPi module has only software PWM, and you get 8 kHz with default priority. With something like this:
sudo chrt -f 99 python3 test_pwm.py
I got a bit more then 60 kHz. Using RPi.GPIO.output, rather then PWM, I got 264 kHz.
Notes
- at max frequency, the pulse width is stuck at 50%
- with 2 PWM signals, the max frequency is around 40 kHz and phase varies from -145° to 100°
- don't use sleep/wait for timing (it's increasing the uncertainty), make a loop with a simple instruction (e.g. var=0)
- hardware PWM is said to have the base frequency at 19.2 MHz...
Aurora0001
- 6,357
- 3
- 25
- 39
Adrian
- 11
- 1