create_speed_lookuptable.py

Sat, 07 Nov 2015 13:23:07 +0100

author
mbayer
date
Sat, 07 Nov 2015 13:23:07 +0100
changeset 0
2c8ba1964db7
permissions
-rw-r--r--

Initial code from reprappro Marlin repository

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

mercurial