blob: 9f43a3fcde8cf377642e2d5f1389affced8b114b [file] [log] [blame]
Luigi Santivetti69972f92019-11-12 22:55:40 +00001/*
2 cpu_map.h - CPU and pin mapping configuration file
3 Part of Grbl
4
5 Copyright (c) 2012-2016 Sungeun K. Jeon for Gnea Research LLC
6
7 Grbl is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 Grbl is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Grbl. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21/* The cpu_map.h files serve as a central pin mapping selection file for different
22 processor types or alternative pin layouts. This version of Grbl officially supports
23 only the Arduino Mega328p. */
24
25
26#ifndef cpu_map_h
27#define cpu_map_h
28
29
30#ifdef CPU_MAP_ATMEGA328P // (Arduino Uno) Officially supported by Grbl.
31
32 // Define serial port pins and interrupt vectors.
33 #define SERIAL_RX USART_RX_vect
34 #define SERIAL_UDRE USART_UDRE_vect
35
36 // Define step pulse output pins. NOTE: All step bit pins must be on the same port.
37 #define STEP_DDR DDRD
38 #define STEP_PORT PORTD
39 #define X_STEP_BIT 2 // Uno Digital Pin 2
40 #define Y_STEP_BIT 3 // Uno Digital Pin 3
41 #define Z_STEP_BIT 4 // Uno Digital Pin 4
42 #define STEP_MASK ((1<<X_STEP_BIT)|(1<<Y_STEP_BIT)|(1<<Z_STEP_BIT)) // All step bits
43
44 // Define step direction output pins. NOTE: All direction pins must be on the same port.
45 #define DIRECTION_DDR DDRD
46 #define DIRECTION_PORT PORTD
47 #define X_DIRECTION_BIT 5 // Uno Digital Pin 5
48 #define Y_DIRECTION_BIT 6 // Uno Digital Pin 6
49 #define Z_DIRECTION_BIT 7 // Uno Digital Pin 7
50 #define DIRECTION_MASK ((1<<X_DIRECTION_BIT)|(1<<Y_DIRECTION_BIT)|(1<<Z_DIRECTION_BIT)) // All direction bits
51
52 // Define stepper driver enable/disable output pin.
53 #define STEPPERS_DISABLE_DDR DDRB
54 #define STEPPERS_DISABLE_PORT PORTB
55 #define STEPPERS_DISABLE_BIT 0 // Uno Digital Pin 8
56 #define STEPPERS_DISABLE_MASK (1<<STEPPERS_DISABLE_BIT)
57
58 // Define homing/hard limit switch input pins and limit interrupt vectors.
59 // NOTE: All limit bit pins must be on the same port, but not on a port with other input pins (CONTROL).
60 #define LIMIT_DDR DDRB
61 #define LIMIT_PIN PINB
62 #define LIMIT_PORT PORTB
63 #define X_LIMIT_BIT 1 // Uno Digital Pin 9
64 #define Y_LIMIT_BIT 2 // Uno Digital Pin 10
65 #ifdef VARIABLE_SPINDLE // Z Limit pin and spindle enabled swapped to access hardware PWM on Pin 11.
66 #define Z_LIMIT_BIT 4 // Uno Digital Pin 12
67 #else
68 #define Z_LIMIT_BIT 3 // Uno Digital Pin 11
69 #endif
70 #if !defined(ENABLE_DUAL_AXIS)
71 #define LIMIT_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)|(1<<Z_LIMIT_BIT)) // All limit bits
72 #endif
73 #define LIMIT_INT PCIE0 // Pin change interrupt enable pin
74 #define LIMIT_INT_vect PCINT0_vect
75 #define LIMIT_PCMSK PCMSK0 // Pin change interrupt register
76
77 // Define user-control controls (cycle start, reset, feed hold) input pins.
78 // NOTE: All CONTROLs pins must be on the same port and not on a port with other input pins (limits).
79 #define CONTROL_DDR DDRC
80 #define CONTROL_PIN PINC
81 #define CONTROL_PORT PORTC
82 #define CONTROL_RESET_BIT 0 // Uno Analog Pin 0
83 #define CONTROL_FEED_HOLD_BIT 1 // Uno Analog Pin 1
84 #define CONTROL_CYCLE_START_BIT 2 // Uno Analog Pin 2
85 #define CONTROL_SAFETY_DOOR_BIT 1 // Uno Analog Pin 1 NOTE: Safety door is shared with feed hold. Enabled by config define.
86 #define CONTROL_INT PCIE1 // Pin change interrupt enable pin
87 #define CONTROL_INT_vect PCINT1_vect
88 #define CONTROL_PCMSK PCMSK1 // Pin change interrupt register
89 #define CONTROL_MASK ((1<<CONTROL_RESET_BIT)|(1<<CONTROL_FEED_HOLD_BIT)|(1<<CONTROL_CYCLE_START_BIT)|(1<<CONTROL_SAFETY_DOOR_BIT))
90 #define CONTROL_INVERT_MASK CONTROL_MASK // May be re-defined to only invert certain control pins.
91
92 // Define probe switch input pin.
93 #define PROBE_DDR DDRC
94 #define PROBE_PIN PINC
95 #define PROBE_PORT PORTC
96 #define PROBE_BIT 5 // Uno Analog Pin 5
97 #define PROBE_MASK (1<<PROBE_BIT)
98
99 #if !defined(ENABLE_DUAL_AXIS)
100
101 // Define flood and mist coolant enable output pins.
102 #define COOLANT_FLOOD_DDR DDRC
103 #define COOLANT_FLOOD_PORT PORTC
104 #define COOLANT_FLOOD_BIT 3 // Uno Analog Pin 3
105 #define COOLANT_MIST_DDR DDRC
106 #define COOLANT_MIST_PORT PORTC
107 #define COOLANT_MIST_BIT 4 // Uno Analog Pin 4
108
109 // Define spindle enable and spindle direction output pins.
110 #define SPINDLE_ENABLE_DDR DDRB
111 #define SPINDLE_ENABLE_PORT PORTB
112 // Z Limit pin and spindle PWM/enable pin swapped to access hardware PWM on Pin 11.
113 #ifdef VARIABLE_SPINDLE
114 #ifdef USE_SPINDLE_DIR_AS_ENABLE_PIN
115 // If enabled, spindle direction pin now used as spindle enable, while PWM remains on D11.
116 #define SPINDLE_ENABLE_BIT 5 // Uno Digital Pin 13 (NOTE: D13 can't be pulled-high input due to LED.)
117 #else
118 #define SPINDLE_ENABLE_BIT 3 // Uno Digital Pin 11
119 #endif
120 #else
121 #define SPINDLE_ENABLE_BIT 4 // Uno Digital Pin 12
122 #endif
123 #ifndef USE_SPINDLE_DIR_AS_ENABLE_PIN
124 #define SPINDLE_DIRECTION_DDR DDRB
125 #define SPINDLE_DIRECTION_PORT PORTB
126 #define SPINDLE_DIRECTION_BIT 5 // Uno Digital Pin 13 (NOTE: D13 can't be pulled-high input due to LED.)
127 #endif
128
129 // Variable spindle configuration below. Do not change unless you know what you are doing.
130 // NOTE: Only used when variable spindle is enabled.
131 #define SPINDLE_PWM_MAX_VALUE 255 // Don't change. 328p fast PWM mode fixes top value as 255.
132 #ifndef SPINDLE_PWM_MIN_VALUE
133 #define SPINDLE_PWM_MIN_VALUE 1 // Must be greater than zero.
134 #endif
135 #define SPINDLE_PWM_OFF_VALUE 0
136 #define SPINDLE_PWM_RANGE (SPINDLE_PWM_MAX_VALUE-SPINDLE_PWM_MIN_VALUE)
137 #define SPINDLE_TCCRA_REGISTER TCCR2A
138 #define SPINDLE_TCCRB_REGISTER TCCR2B
139 #define SPINDLE_OCR_REGISTER OCR2A
140 #define SPINDLE_COMB_BIT COM2A1
141
142 // Prescaled, 8-bit Fast PWM mode.
143 #define SPINDLE_TCCRA_INIT_MASK ((1<<WGM20) | (1<<WGM21)) // Configures fast PWM mode.
144 // #define SPINDLE_TCCRB_INIT_MASK (1<<CS20) // Disable prescaler -> 62.5kHz
145 // #define SPINDLE_TCCRB_INIT_MASK (1<<CS21) // 1/8 prescaler -> 7.8kHz (Used in v0.9)
146 // #define SPINDLE_TCCRB_INIT_MASK ((1<<CS21) | (1<<CS20)) // 1/32 prescaler -> 1.96kHz
147 #define SPINDLE_TCCRB_INIT_MASK (1<<CS22) // 1/64 prescaler -> 0.98kHz (J-tech laser)
148
149 // NOTE: On the 328p, these must be the same as the SPINDLE_ENABLE settings.
150 #define SPINDLE_PWM_DDR DDRB
151 #define SPINDLE_PWM_PORT PORTB
152 #define SPINDLE_PWM_BIT 3 // Uno Digital Pin 11
153
154 #else
155
156 // Dual axis feature requires an independent step pulse pin to operate. The independent direction pin is not
157 // absolutely necessary but facilitates easy direction inverting with a Grbl $$ setting. These pins replace
158 // the spindle direction and optional coolant mist pins.
159
160 #ifdef DUAL_AXIS_CONFIG_PROTONEER_V3_51
161 // NOTE: Step pulse and direction pins may be on any port and output pin.
162 #define STEP_DDR_DUAL DDRC
163 #define STEP_PORT_DUAL PORTC
164 #define DUAL_STEP_BIT 4 // Uno Analog Pin 4
165 #define STEP_MASK_DUAL ((1<<DUAL_STEP_BIT))
166 #define DIRECTION_DDR_DUAL DDRC
167 #define DIRECTION_PORT_DUAL PORTC
168 #define DUAL_DIRECTION_BIT 3 // Uno Analog Pin 3
169 #define DIRECTION_MASK_DUAL ((1<<DUAL_DIRECTION_BIT))
170
171 // NOTE: Dual axis limit is shared with the z-axis limit pin by default. Pin used must be on the same port
172 // as other limit pins.
173 #define DUAL_LIMIT_BIT Z_LIMIT_BIT
174 #define LIMIT_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)|(1<<Z_LIMIT_BIT)|(1<<DUAL_LIMIT_BIT))
175
176 // Define coolant enable output pins.
177 // NOTE: Coolant flood moved from A3 to A4. Coolant mist not supported with dual axis feature on Arduino Uno.
178 #define COOLANT_FLOOD_DDR DDRB
179 #define COOLANT_FLOOD_PORT PORTB
180 #define COOLANT_FLOOD_BIT 5 // Uno Digital Pin 13
181
182 // Define spindle enable output pin.
183 // NOTE: Spindle enable moved from D12 to A3 (old coolant flood enable pin). Spindle direction pin is removed.
184 #define SPINDLE_ENABLE_DDR DDRB
185 #define SPINDLE_ENABLE_PORT PORTB
186 #ifdef VARIABLE_SPINDLE
187 // NOTE: USE_SPINDLE_DIR_AS_ENABLE_PIN not supported with dual axis feature.
188 #define SPINDLE_ENABLE_BIT 3 // Uno Digital Pin 11
189 #else
190 #define SPINDLE_ENABLE_BIT 4 // Uno Digital Pin 12
191 #endif
192
193 // Variable spindle configuration below. Do not change unless you know what you are doing.
194 // NOTE: Only used when variable spindle is enabled.
195 #define SPINDLE_PWM_MAX_VALUE 255 // Don't change. 328p fast PWM mode fixes top value as 255.
196 #ifndef SPINDLE_PWM_MIN_VALUE
197 #define SPINDLE_PWM_MIN_VALUE 1 // Must be greater than zero.
198 #endif
199 #define SPINDLE_PWM_OFF_VALUE 0
200 #define SPINDLE_PWM_RANGE (SPINDLE_PWM_MAX_VALUE-SPINDLE_PWM_MIN_VALUE)
201 #define SPINDLE_TCCRA_REGISTER TCCR2A
202 #define SPINDLE_TCCRB_REGISTER TCCR2B
203 #define SPINDLE_OCR_REGISTER OCR2A
204 #define SPINDLE_COMB_BIT COM2A1
205
206 // Prescaled, 8-bit Fast PWM mode.
207 #define SPINDLE_TCCRA_INIT_MASK ((1<<WGM20) | (1<<WGM21)) // Configures fast PWM mode.
208 // #define SPINDLE_TCCRB_INIT_MASK (1<<CS20) // Disable prescaler -> 62.5kHz
209 // #define SPINDLE_TCCRB_INIT_MASK (1<<CS21) // 1/8 prescaler -> 7.8kHz (Used in v0.9)
210 // #define SPINDLE_TCCRB_INIT_MASK ((1<<CS21) | (1<<CS20)) // 1/32 prescaler -> 1.96kHz
211 #define SPINDLE_TCCRB_INIT_MASK (1<<CS22) // 1/64 prescaler -> 0.98kHz (J-tech laser)
212
213 // NOTE: On the 328p, these must be the same as the SPINDLE_ENABLE settings.
214 #define SPINDLE_PWM_DDR DDRB
215 #define SPINDLE_PWM_PORT PORTB
216 #define SPINDLE_PWM_BIT 3 // Uno Digital Pin 11
217 #endif
218
219 // NOTE: Variable spindle not supported with this shield.
220 #ifdef DUAL_AXIS_CONFIG_CNC_SHIELD_CLONE
221 // NOTE: Step pulse and direction pins may be on any port and output pin.
222 #define STEP_DDR_DUAL DDRB
223 #define STEP_PORT_DUAL PORTB
224 #define DUAL_STEP_BIT 4 // Uno Digital Pin 12
225 #define STEP_MASK_DUAL ((1<<DUAL_STEP_BIT))
226 #define DIRECTION_DDR_DUAL DDRB
227 #define DIRECTION_PORT_DUAL PORTB
228 #define DUAL_DIRECTION_BIT 5 // Uno Digital Pin 13
229 #define DIRECTION_MASK_DUAL ((1<<DUAL_DIRECTION_BIT))
230
231 // NOTE: Dual axis limit is shared with the z-axis limit pin by default.
232 #define DUAL_LIMIT_BIT Z_LIMIT_BIT
233 #define LIMIT_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)|(1<<Z_LIMIT_BIT)|(1<<DUAL_LIMIT_BIT))
234
235 // Define coolant enable output pins.
236 // NOTE: Coolant flood moved from A3 to A4. Coolant mist not supported with dual axis feature on Arduino Uno.
237 #define COOLANT_FLOOD_DDR DDRC
238 #define COOLANT_FLOOD_PORT PORTC
239 #define COOLANT_FLOOD_BIT 4 // Uno Analog Pin 4
240
241 // Define spindle enable output pin.
242 // NOTE: Spindle enable moved from D12 to A3 (old coolant flood enable pin). Spindle direction pin is removed.
243 #define SPINDLE_ENABLE_DDR DDRC
244 #define SPINDLE_ENABLE_PORT PORTC
245 #define SPINDLE_ENABLE_BIT 3 // Uno Analog Pin 3
246 #endif
247
248 #endif
249
250#endif
251
252/*
253#ifdef CPU_MAP_CUSTOM_PROC
254 // For a custom pin map or different processor, copy and edit one of the available cpu
255 // map files and modify it to your needs. Make sure the defined name is also changed in
256 // the config.h file.
257#endif
258*/
259
260#endif