added correction factor
This commit is contained in:
@@ -83,7 +83,7 @@ class PCA9685(object):
|
||||
self._device.write8(MODE1, mode1)
|
||||
time.sleep(0.005) # wait for oscillator
|
||||
|
||||
def set_pwm_freq(self, freq_hz):
|
||||
def set_pwm_freq(self, freq_hz, correctionFactor=1.0):
|
||||
"""Set the PWM frequency to the provided value in hertz."""
|
||||
prescaleval = 25000000.0 # 25MHz
|
||||
prescaleval /= 4096.0 # 12-bit
|
||||
@@ -91,7 +91,7 @@ class PCA9685(object):
|
||||
prescaleval -= 1.0
|
||||
logger.debug('Setting PWM frequency to {0} Hz'.format(freq_hz))
|
||||
logger.debug('Estimated pre-scale: {0}'.format(prescaleval))
|
||||
prescale = int(math.floor(prescaleval + 0.5))
|
||||
prescale = round(prescaleval * correctionFactor + 0.5)
|
||||
logger.debug('Final pre-scale: {0}'.format(prescale))
|
||||
oldmode = self._device.readU8(MODE1);
|
||||
newmode = (oldmode & 0x7F) | 0x10 # sleep
|
||||
|
||||
Reference in New Issue
Block a user