]> defiant.homedns.org Git - pyshared.git/commitdiff
bus_pirate: Fix pwm calculation
authorErik Andresen <erik@vontaene.de>
Sat, 13 Jan 2018 14:07:27 +0000 (15:07 +0100)
committerErik Andresen <erik@vontaene.de>
Sat, 13 Jan 2018 14:07:27 +0000 (15:07 +0100)
bus_pirate.py

index 52a1c5c1b759fc2f8f20fd633b0fbbbc9ec4f3f9..cdd259fa7581ee42dba23da879fbf10b3aa4d287 100644 (file)
@@ -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()