From ba64d2a6836ce4fbb39ce1d032a6bbb0d48668d1 Mon Sep 17 00:00:00 2001 From: optixx Date: Wed, 23 Sep 2009 18:55:31 +0200 Subject: [PATCH] add sinegen script --- scripts/sinegen.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 scripts/sinegen.py diff --git a/scripts/sinegen.py b/scripts/sinegen.py new file mode 100644 index 0000000..a1df00e --- /dev/null +++ b/scripts/sinegen.py @@ -0,0 +1,38 @@ +import string +import math +import sys + +M_PI = 3.14159265358979323846 + + + +def sine(val,r,scale,stepping): + global M_PI,flip + re = int(math.sin(val*(M_PI*scale)/r)*r) + r + re = re & 0xff + re = re * stepping + return re + + +def main(): + cnt = 64 + stepping = 1 + upper = 0xff + + s = "#define PWM_SINE_MAX %i\nuint8_t pwm_sine_table[] = {\n" % cnt + for i in range(0,cnt): + if i > 0 and i%16==0: + s+="\n" + s +="0x%02x," % sine(i,upper/2,(float(upper)/cnt),stepping) + s=s[:-1] + s+="\n};\n" + print s + +main() + + + + + + +