I am attempting to setup a PWM signal on Pin 12 (GPIO #18) using a Raspberry Pi 3. I am capable of sending a PWM signal, however it is quite off from the target frequency. I have an o-scope that I have been using to measure the signals in order to ensure that it is operating correctly. Here is my code:
import spidev
import time
import RPi.GPIO as GPIO
# Choose pins here (in reference to BOARD) and frequencies FROM DATASHEET
FCLK_pin = 12
EN_pin = 29
FCLK_freq = 500 # Recommended LPF Cutoff
duty = 50.0
def GPIO_setup():
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(EN_pin, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(FCLK_pin, GPIO.OUT, initial=GPIO.LOW)
pwm = GPIO.PWM(FCLK_pin, FCLK_freq*60)
return pwm;
fclk_pwm = GPIO_setup()
fclk_pwm.start(duty)
time.sleep(1)
GPIO.output(EN_pin, GPIO.HIGH)
time.sleep(5)
fclk_pwm.close()
GPIO.cleanup()
The desired frequency is 500*60Hz, or 30kHz. Here is what I get back on the o-scope when I replace FCLK_freq*60 to a solid 1000 (so expecting 1000Hz):
Here is the readout when set to 30000 (so expecting 30kHz):
Am I going about this the wrong way? Any advice / help is appreciated!