1
0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2024-12-21 01:37:24 +00:00
MarlinFirmware/buildroot/share/scripts/createSpeedLookupTable.py

51 lines
1.3 KiB
Python
Raw Normal View History

2012-03-07 22:41:29 +00:00
#!/usr/bin/env python
""" Generate the stepper delay lookup table for Marlin firmware. """
import argparse
__author__ = "Ben Gamari <bgamari@gmail.com>"
__copyright__ = "Copyright 2012, Ben Gamari"
__license__ = "GPL"
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('-f', '--cpu-freq', type=int, default=16, help='CPU clockrate in MHz (default=16)')
parser.add_argument('-d', '--divider', type=int, default=8, help='Timer/counter pre-scale divider (default=8)')
args = parser.parse_args()
cpu_freq = args.cpu_freq * 1000000
timer_freq = cpu_freq / args.divider
print "#ifndef SPEED_LOOKUPTABLE_H"
print "#define SPEED_LOOKUPTABLE_H"
print
print '#include "Marlin.h"'
print
print "const uint16_t speed_lookuptable_fast[256][2] PROGMEM = {"
2012-03-11 11:25:04 +00:00
a = [ timer_freq / ((i*256)+(args.cpu_freq*2)) for i in range(256) ]
2012-03-07 22:41:29 +00:00
b = [ a[i] - a[i+1] for i in range(255) ]
b.append(b[-1])
for i in range(32):
print " ",
for j in range(8):
print "{%d, %d}," % (a[8*i+j], b[8*i+j]),
2017-04-20 22:43:19 +00:00
print
2012-03-07 22:41:29 +00:00
print "};"
print
print "const uint16_t speed_lookuptable_slow[256][2] PROGMEM = {"
2012-03-11 11:25:04 +00:00
a = [ timer_freq / ((i*8)+(args.cpu_freq*2)) for i in range(256) ]
2012-03-07 22:41:29 +00:00
b = [ a[i] - a[i+1] for i in range(255) ]
b.append(b[-1])
for i in range(32):
print " ",
for j in range(8):
print "{%d, %d}," % (a[8*i+j], b[8*i+j]),
2017-04-20 22:43:19 +00:00
print
2012-03-07 22:41:29 +00:00
print "};"
print
print "#endif"