From 0fcd6537ec5dcbabfb35afde7507a49dd6255755 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Sat, 13 Jan 2018 15:07:27 +0100 Subject: [PATCH] bus_pirate: Fix pwm calculation --- bus_pirate.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bus_pirate.py b/bus_pirate.py index 52a1c5c..cdd259f 100644 --- a/bus_pirate.py +++ b/bus_pirate.py @@ -65,7 +65,7 @@ class BP: return v[0]/1024.0*6.6 # http://codepad.org/qtYpZmIF - def pwm(self, freq, duty_cycle): + def pwm(self, freq, duty_cycle_percent): lPrescaler = {0:1, 1:8 , 2:64, 3:256} Fosc = 32e6 Tcy = 2.0 / Fosc @@ -77,12 +77,12 @@ class BP: prescaler = lPrescaler[i] PRy = period * 1.0 / (Tcy * prescaler) PRy = int(PRy - 1) - OCR = int(PRy * duty_cycle) + OCR = int(PRy * duty_cycle_percent) if PRy < (2 ** 16 - 1): break # valid value for PRy, keep values - cmd = struct.pack(">BBHH", 0b00010010, prescaler, duty_cycle, period) + cmd = struct.pack(">BBHH", 0b00010010, i, OCR, PRy) ret = self.command(cmd, 1) if ord(ret) != 0x1: raise Exception() -- 2.39.5