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()
Am I going about this the wrong way? Any advice / help is appreciated!