Browse Source

Merge pull request #106 from bgamari/Marlin_v1

Make F_CPU dependence of stepper.cpp more explicit
ErikZalm 12 years ago
parent
commit
7cefad3744
3 changed files with 65 additions and 2 deletions
  1. 5
    1
      Marlin/Makefile
  2. 53
    0
      Marlin/create_speed_lookuptable.py
  3. 7
    1
      Marlin/stepper.cpp

+ 5
- 1
Marlin/Makefile View File

@@ -23,7 +23,9 @@
23 23
 #  3. Set the line containing "MCU" to match your board's processor. 
24 24
 #     Older one's are atmega8 based, newer ones like Arduino Mini, Bluetooth
25 25
 #     or Diecimila have the atmega168.  If you're using a LilyPad Arduino,
26
-#     change F_CPU to 8000000.
26
+#     change F_CPU to 8000000. If you are using Gen7 electronics, you
27
+#     probably need to use 20000000. Either way, you must regenerate
28
+#     the speed lookup table with create_speed_lookuptable.py.
27 29
 #
28 30
 #  4. Type "make" and press enter to compile/verify your program.
29 31
 #
@@ -42,6 +44,8 @@ MCU = atmega1280
42 44
 #Arduino install directory
43 45
 INSTALL_DIR = ../../arduino-0022/
44 46
 
47
+# Be sure to regenerate speed_lookuptable.h with create_speed_lookuptable.py
48
+# if you are setting this to something other than 16MHz
45 49
 F_CPU = 16000000
46 50
 
47 51
 UPLOAD_RATE = 115200

+ 53
- 0
Marlin/create_speed_lookuptable.py View File

@@ -0,0 +1,53 @@
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
+# Based on timer calculations of 'RepRap cartesian firmware' by Zack
26
+# Smith and Philip Tiefenbacher.
27
+
28
+print "const uint16_t speed_lookuptable_fast[256][2] PROGMEM = {"
29
+a = [ timer_freq / ((i*256)+32) for i in range(256) ]
30
+b = [ a[i] - a[i+1] for i in range(255) ]
31
+b.append(b[-1])
32
+for i in range(32):
33
+    print "  ",
34
+    for j in range(8):
35
+        print "{%d, %d}," % (a[8*i+j], b[8*i+j]),
36
+    print 
37
+print "};"
38
+print
39
+
40
+print "const uint16_t speed_lookuptable_slow[256][2] PROGMEM = {"
41
+a = [ timer_freq / ((i*8)+32) for i in range(256) ]
42
+b = [ a[i] - a[i+1] for i in range(255) ]
43
+b.append(b[-1])
44
+for i in range(32):
45
+    print "  ",
46
+    for j in range(8):
47
+        print "{%d, %d}," % (a[8*i+j], b[8*i+j]),
48
+    print 
49
+print "};"
50
+print
51
+
52
+print "#endif"
53
+

+ 7
- 1
Marlin/stepper.cpp View File

@@ -750,7 +750,13 @@ void st_init()
750 750
   // output mode = 00 (disconnected)
751 751
   TCCR1A &= ~(3<<COM1A0); 
752 752
   TCCR1A &= ~(3<<COM1B0); 
753
-  TCCR1B = (TCCR1B & ~(0x07<<CS10)) | (2<<CS10); // 2MHz timer
753
+  
754
+  // Set the timer pre-scaler
755
+  // Generally we use a divider of 8, resulting in a 2MHz timer
756
+  // frequency on a 16MHz MCU. If you are going to change this, be
757
+  // sure to regenerate speed_lookuptable.h with
758
+  // create_speed_lookuptable.py
759
+  TCCR1B = (TCCR1B & ~(0x07<<CS10)) | (2<<CS10);
754 760
 
755 761
   OCR1A = 0x4000;
756 762
   TCNT1 = 0;

Loading…
Cancel
Save