create_speed_lookuptable.py

changeset 0
2c8ba1964db7
equal deleted inserted replaced
-1:000000000000 0:2c8ba1964db7
1 #!/usr/bin/env python
2
3 """ Generate the stepper delay lookup table for Marlin firmware. """
4
5 import argparse
6
7 __author__ = "Ben Gamari <bgamari@gmail.com>"
8 __copyright__ = "Copyright 2012, Ben Gamari"
9 __license__ = "GPL"
10
11 parser = argparse.ArgumentParser(description=__doc__)
12 parser.add_argument('-f', '--cpu-freq', type=int, default=16, help='CPU clockrate in MHz (default=16)')
13 parser.add_argument('-d', '--divider', type=int, default=8, help='Timer/counter pre-scale divider (default=8)')
14 args = parser.parse_args()
15
16 cpu_freq = args.cpu_freq * 1000000
17 timer_freq = cpu_freq / args.divider
18
19 print "#ifndef SPEED_LOOKUPTABLE_H"
20 print "#define SPEED_LOOKUPTABLE_H"
21 print
22 print '#include "Marlin.h"'
23 print
24
25 print "const uint16_t speed_lookuptable_fast[256][2] PROGMEM = {"
26 a = [ timer_freq / ((i*256)+(args.cpu_freq*2)) for i in range(256) ]
27 b = [ a[i] - a[i+1] for i in range(255) ]
28 b.append(b[-1])
29 for i in range(32):
30 print " ",
31 for j in range(8):
32 print "{%d, %d}," % (a[8*i+j], b[8*i+j]),
33 print
34 print "};"
35 print
36
37 print "const uint16_t speed_lookuptable_slow[256][2] PROGMEM = {"
38 a = [ timer_freq / ((i*8)+(args.cpu_freq*2)) for i in range(256) ]
39 b = [ a[i] - a[i+1] for i in range(255) ]
40 b.append(b[-1])
41 for i in range(32):
42 print " ",
43 for j in range(8):
44 print "{%d, %d}," % (a[8*i+j], b[8*i+j]),
45 print
46 print "};"
47 print
48
49 print "#endif"
50

mercurial