I have a simple Python program running on a Pi 2. I can't seem to figure out why the output frequency is way off. I have it programmed for 2000hz. I measure the output two ways and both yield 1530 Hz.
Since I use pin 18, I believe I should be using the hardware PWM. Any suggestions, what am I missing.
Here's the code
import time
import sys
import datetime
import RPi.GPIO as GPIO
def tonet(hz,s):
pt = GPIO.PWM(tone,hz)
pt.start(50) # duty cycle
time.sleep(s)
pt.stop
GPIO.output(tone, GPIO.LOW) # good house keeping
return
# Pin Definitons:
tone = 18 #
# Pin Setup:
GPIO.setmode(GPIO.BCM) # Broadcom pin-numbering scheme
GPIO.setup(tone, GPIO.OUT) # pin set as output
GPIO.output(tone, GPIO.HIGH)
pause = raw_input('high press a key')
GPIO.output(tone, GPIO.LOW)
pause = raw_input('low press a key....')
print 'start pwm'
tonet(2000, 20)
GPIO.cleanup()