v0idv0id / stm32-scaler Goto Github PK
View Code? Open in Web Editor NEWA simple timer PSC, ARR and CCRx calculator for STM32 MCUs
License: MIT License
A simple timer PSC, ARR and CCRx calculator for STM32 MCUs
License: MIT License
Nice script! I have a small improvement.
Line 108 in 4671486
If you replace d = int(arr/(100.0/DUTY))
by d = int(arr/(100.0/DUTY)+0.5)
the error in the duty cycle could get smaller :)
And than you have to do minus 1 probably, never mind. I think it's good after all.
Hi, didn't quite understand why you would require the chips frequency to be divisible by the prescaler when there can't be a perfect solution anyways and we have to accept an error. From what I understood a prescaler value of N basically results in the counter being counted ( and reset/triggered on ARR) only every Nth cycle, so what we really are looking for is a good PSC*ARR combination for the desired amount of cycles.
I compared the output of this script with some others and found that for
timescale.py -t 0.007777 -c 22180400 -e 0.1
only when I change the if to
if ( (TIM_BASE_CLOCK % (psc+1) == 0) or (psc==2) ) and x <= TARGET_ARR_MAX[bit]:
I will get a near perfect match of
PSC: 2 ARR: 57498 => FREQ: 128.58426523359827 [Hz] ERROR: 1.6927833490498756e-05 [%] - CRRx[ 50.0 %]: 28749
PSC: 3 ARR: 43123 => FREQ: 128.585010666914 [Hz] ERROR: 0.000562792491631825 [%] - CRRx[ 50.0 %]: 21561
which results in the desired frequncy to only have a tiny bit of error to the clock frequency (357499128.5842870001286 = 22180403.75) whereas the next best only gets near to 22180275 ... probably not relevant in realy life applications but I was wondering if there might be cases where this would miss really much better ones...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.