add sinegen script
This commit is contained in:
parent
65a852ebb4
commit
ba64d2a683
38
scripts/sinegen.py
Normal file
38
scripts/sinegen.py
Normal file
@ -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()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user