Created
December 14, 2020 20:01
-
-
Save rogersguedes/23a4c2297177af807763b10a36f00a1d to your computer and use it in GitHub Desktop.
STM32 G.P. Timer Prescaler and Period Calc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
timerBusClkFreq=216000000 | |
timerDesiredIntFreq=5000 | |
#counts=43200 | |
counts=timerBusClkFreq/timerDesiredIntFreq | |
prescaler=0 | |
period=0 | |
#counts = (prescaler + 1)*(period + 1) | |
prescalerMax = counts - 1 | |
periodMax = counts - 1 | |
print "prescalerMax: ", prescalerMax | |
print "periodMax: ", periodMax | |
minDiffDelta=prescalerMax | |
for prescaler in range(0, counts): | |
for period in range(0, counts): | |
curCount = (prescaler + 1)*(period + 1) | |
delta = abs(prescaler - period) | |
if curCount > counts: | |
break | |
if curCount == counts: | |
print "prescaler: ", prescaler, | |
print "period: ", period, | |
print "delta: ", delta, | |
if delta < minDiffDelta: | |
minDiffDelta = delta | |
print "<" | |
else: | |
print "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment