1. #ifndef _CONFIG_H
  2. #define _CONFIG_H
  3.  
  4. /*
  5. CONTENTS
  6.  
  7. 1. Mechanical/Hardware
  8. 2. Acceleration settings
  9. 3. Pinouts
  10. 4. Temperature sensors
  11. 5. Heaters
  12. 6. Communication options
  13. 7. Miscellaneous
  14. 8. Appendix A - PWMable pins and mappings
  15. */
  16.  
  17. /***************************************************************************\
  18. * *
  19. * 1. MECHANICAL/HARDWARE *
  20. * *
  21. \***************************************************************************/
  22.  
  23. /*
  24. Set your microcontroller type in Makefile! atmega168/atmega328p/atmega644p/atmega1280
  25.  
  26. If you want to port this to a new chip, start off with arduino.h and see how you go.
  27. */
  28.  
  29. /*
  30. CPU clock rate
  31. */
  32. #ifndef F_CPU
  33. #define F_CPU 16000000L
  34. #endif
  35.  
  36. /*
  37. Are you using the official GEN3 motherboard with separate extruder controller?
  38. */
  39. //#define GEN3
  40.  
  41. /*
  42. This is the motherboard, as opposed to the extruder. See extruder/ directory for GEN3 extruder firmware
  43. */
  44. #define HOST
  45.  
  46. /*
  47. Values reflecting the gearing of your machine.
  48. All numbers are fixed point integers, so no more than 3 digits to the right of the decimal point, please :-)
  49. */
  50.  
  51. // calculate these values appropriate for your machine
  52. // for threaded rods, this is (steps motor per turn) / (pitch of the thread)
  53. // for belts, this is (steps per motor turn) / (number of gear teeth) / (belt module)
  54. // half-stepping doubles the number, quarter stepping requires * 4, etc.
  55. #define STEPS_PER_MM_X 64.133
  56. #define STEPS_PER_MM_Y 64.133
  57. #define STEPS_PER_MM_Z 1280
  58.  
  59. // http://blog.arcol.hu/?p=157 may help with this next one
  60. #define STEPS_PER_MM_E 187
  61.  
  62.  
  63. /*
  64. Values depending on the capabilities of your stepper motors and other mechanics.
  65. All numbers are integers, no decimals allowed.
  66.  
  67. Units are mm/min
  68. */
  69.  
  70. // used for G0 rapid moves and as a cap for all other feedrates
  71. #define MAXIMUM_FEEDRATE_X 200
  72. #define MAXIMUM_FEEDRATE_Y 200
  73. #define MAXIMUM_FEEDRATE_Z 100
  74. #define MAXIMUM_FEEDRATE_E 200
  75.  
  76. // used when searching endstops and as default feedrate
  77. #define SEARCH_FEEDRATE_X 50
  78. #define SEARCH_FEEDRATE_Y 50
  79. #define SEARCH_FEEDRATE_Z 50
  80. #define SEARCH_FEEDRATE_E 50
  81.  
  82. // this is how many steps to suck back the filament by when we stop. set to zero to disable
  83. #define E_STARTSTOP_STEPS 50
  84.  
  85.  
  86.  
  87. /***************************************************************************\
  88. * *
  89. * 2. ACCELERATION *
  90. * *
  91. * IMPORTANT: choose only one! These algorithms choose when to step, trying *
  92. * to use more than one will have undefined and probably *
  93. * disastrous results! *
  94. * *
  95. \***************************************************************************/
  96.  
  97.  
  98. /*
  99. acceleration, reprap style.
  100. Each movement starts at the speed of the previous command and accelerates or decelerates linearly to reach target speed at the end of the movement.
  101. */
  102. // #define ACCELERATION_REPRAP
  103.  
  104.  
  105. /*
  106. acceleration and deceleration ramping.
  107. Each movement starts at (almost) no speed, linearly accelerates to target speed and decelerates just in time to smoothly stop at the target. alternative to ACCELERATION_REPRAP
  108. */
  109. // #define ACCELERATION_RAMPING
  110.  
  111. // how fast to accelerate when using ACCELERATION_RAMPING
  112. // smaller values give quicker acceleration
  113. // valid range = 1 to 8,000,000; 500,000 is a good starting point
  114. #define ACCELERATION_STEEPNESS 500000
  115.  
  116.  
  117. /*
  118. temporal step algorithm
  119. This algorithm causes the timer to fire when any axis needs to step, instead of synchronising to the axis with the most steps ala bresenham.
  120.  
  121. This algorithm is not a type of acceleration, and I haven't worked out how to integrate acceleration with it.
  122. However it does control step timing, so acceleration algorithms seemed appropriate
  123.  
  124. The Bresenham algorithm is great for drawing lines, but not so good for steppers - In the case where X steps 3 times to Y's two, Y experiences massive jitter as it steps in sync with X every 2 out of 3 X steps. This is a worst-case, but the problem exists for most non-45/90 degree moves. At higher speeds, the jitter /will/ cause position loss and unnecessary vibration.
  125. This algorithm instead calculates when a step occurs on any axis, and sets the timer to that value.
  126.  
  127. // TODO: figure out how to add acceleration to this algorithm
  128. */
  129. // #define ACCELERATION_TEMPORAL
  130.  
  131.  
  132.  
  133. /***************************************************************************\
  134. * *
  135. * 3. PINOUTS *
  136. * *
  137. \***************************************************************************/
  138.  
  139. /*
  140. Machine Pin Definitions
  141. - make sure to avoid duplicate usage of a pin
  142. - comment out pins not in use, as this drops the corresponding code and makes operations faster
  143. */
  144.  
  145. #include "arduino.h"
  146.  
  147. #ifndef GEN3
  148. /*
  149. user defined pins
  150. adjust to suit your electronics,
  151. or adjust your electronics to suit this
  152. */
  153.  
  154. #define X_STEP_PIN DIO22
  155. #define X_DIR_PIN DIO23
  156. #define X_MIN_PIN DIO2
  157.  
  158. #define Y_STEP_PIN DIO25
  159. #define Y_DIR_PIN DIO26
  160. #define Y_MIN_PIN DIO18
  161.  
  162. #define Z_STEP_PIN DIO28
  163. #define Z_DIR_PIN DIO29
  164. #define Z_MIN_PIN DIO20
  165.  
  166. #define E_STEP_PIN DIO4
  167. #define E_DIR_PIN DIO31
  168.  
  169. #define PS_ON_PIN DIO9
  170. #else
  171. /*
  172. this is the official gen3 reprap motherboard pinout
  173. */
  174. #define TX_ENABLE_PIN DIO12
  175. #define RX_ENABLE_PIN DIO13
  176.  
  177. #define X_STEP_PIN DIO15
  178. #define X_DIR_PIN DIO18
  179. #define X_MIN_PIN DIO20
  180. #define X_MAX_PIN DIO21
  181. #define X_ENABLE_PIN DIO19
  182.  
  183. #define Y_STEP_PIN DIO23
  184. #define Y_DIR_PIN DIO22
  185. #define Y_MIN_PIN AIO6
  186. #define Y_MAX_PIN AIO5
  187. #define Y_ENABLE_PIN DIO7
  188.  
  189. #define Z_STEP_PIN AIO4
  190. #define Z_DIR_PIN AIO3
  191. #define Z_MIN_PIN AIO1
  192. #define Z_MAX_PIN AIO0
  193. #define Z_ENABLE_PIN AIO2
  194.  
  195. #define E_STEP_PIN DIO16
  196. #define E_DIR_PIN DIO17
  197.  
  198. #define SD_CARD_DETECT DIO2
  199. #define SD_WRITE_PROTECT DIO3
  200. #endif
  201.  
  202.  
  203.  
  204. /***************************************************************************\
  205. * *
  206. * 4. TEMPERATURE SENSORS *
  207. * *
  208. \***************************************************************************/
  209.  
  210. /*
  211. TEMP_HYSTERESIS: actual temperature must be target +/- hysteresis before target temperature can be achieved.
  212. NOTE: format is 30.2 fixed point, so value of 20 actually means +/- 5 degrees
  213.  
  214. TEMP_RESIDENCY_TIME: actual temperature must be close to target for this long before target is achieved
  215.  
  216. temperature is "achieved" for purposes of M109 and friends when actual temperature is within [hysteresis] of target for [residency] seconds
  217. */
  218. #define TEMP_HYSTERESIS 20
  219. #define TEMP_RESIDENCY_TIME 60
  220.  
  221. // which temperature sensors are you using? (intercom is the gen3-style separate extruder board)
  222. // #define TEMP_MAX6675
  223. #define TEMP_THERMISTOR
  224. // #define TEMP_AD595
  225. // #define TEMP_PT100
  226. //#define TEMP_INTERCOM
  227.  
  228. // if you selected thermistor or AD595, what pin is it on? (this value only used to fill ANALOG_MASK for you)
  229. #define TEMP_PIN_CHANNEL AIO1_PIN
  230.  
  231. // ANALOG_MASK is a bitmask of all analog channels used- if you use more than one analog input (more than one temp sensor?), bitwise-or them all together
  232. #define ANALOG_MASK MASK(TEMP_PIN_CHANNEL)
  233.  
  234. // how many temperature sensors do you have?
  235. #define NUM_TEMP_SENSORS 1
  236.  
  237. /***************************************************************************\
  238. * *
  239. * Fill in the following struct according to your hardware *
  240. * *
  241. * If your temperature sensor has no associated heater, enter '255' as the *
  242. * heater index. Unassociated temperature sensors are still read, but they *
  243. * do not affect firmware operation *
  244. * *
  245. * for GEN3 set temp_type to TT_INTERCOM, temp_pin to 0 and heater index to *
  246. * 255 - the extruder manages the heater for us *
  247. * *
  248. * Types are same as TEMP_ list above- TT_MAX6675, TT_THERMISTOR, TT_AD595, *
  249. * TT_PT100, TT_INTERCOM. See list in temp.c. *
  250. * *
  251. \***************************************************************************/
  252.  
  253. #ifdef TEMP_C
  254. struct {
  255. uint8_t temp_type;
  256. uint8_t temp_pin;
  257.  
  258. uint8_t heater_index;
  259. } temp_sensors[NUM_TEMP_SENSORS] =
  260. {
  261. // type pin heater
  262. { TT_THERMISTOR, 1, 0 }
  263. };
  264. #endif
  265.  
  266.  
  267.  
  268. /***************************************************************************\
  269. * *
  270. * 5. HEATERS *
  271. * *
  272. \***************************************************************************/
  273.  
  274. // number of heaters- for GEN3, set to zero as extruder manages the heater by itself
  275. #define NUM_HEATERS 1
  276.  
  277. // check if heater responds to changes in target temperature, disable and spit errors if not
  278. // #define HEATER_SANITY_CHECK
  279.  
  280. /***************************************************************************\
  281. * *
  282. * Fill in the following struct according to your hardware *
  283. * *
  284. * If your heater isn't on a PWM-able pin, set heater_pwm to zero and we'll *
  285. * use bang-bang output. Note that PID will still be used *
  286. * *
  287. * If a heater isn't attached to a temperature sensor above, it can still be *
  288. * controlled by host but otherwise is ignored by firmware *
  289. * *
  290. \***************************************************************************/
  291.  
  292. #ifdef HEATER_C
  293. struct {
  294. volatile uint8_t *heater_port;
  295. uint8_t heater_pin;
  296. volatile uint8_t *heater_pwm;
  297. } heaters[NUM_HEATERS] =
  298. {
  299. // port pin pwm
  300. { &PORTD, PINB7, &OC0A },
  301. { &PORTD, PIND5, &OCR0B }
  302. };
  303. #endif
  304.  
  305.  
  306.  
  307. /***************************************************************************\
  308. * *
  309. * 6. COMMUNICATION OPTIONS *
  310. * *
  311. \***************************************************************************/
  312.  
  313. /*
  314. RepRap Host changes it's communications protocol from time to time and intentionally avoids backwards compatibility. Set this to the date the source code of your Host was fetched from RepRap's repository, which is likely also the build date.
  315. See the discussion on the reprap-dev mailing list from 11 Oct. 2010.
  316.  
  317. Undefine it for best human readability, set it to an old date for compatibility with hosts before August 2010
  318. */
  319. // #define REPRAP_HOST_COMPATIBILITY 19750101
  320. #define REPRAP_HOST_COMPATIBILITY 20100806
  321. // #define REPRAP_HOST_COMPATIBILITY <date of next RepRap Host compatibility break>
  322.  
  323. /*
  324. Xon/Xoff flow control.
  325. Redundant when using RepRap Host for sending GCode, but mandatory when sending GCode files with a plain terminal emulator, like GtkTerm (Linux), CoolTerm (Mac) or HyperTerminal (Windows).
  326. Can also be set in Makefile
  327. */
  328. // #define XONXOFF
  329.  
  330.  
  331.  
  332. /***************************************************************************\
  333. * *
  334. * 7. MISCELLANEOUS OPTIONS *
  335. * *
  336. \***************************************************************************/
  337.  
  338. /*
  339. DEBUG
  340. enables /heaps/ of extra output, and some extra M-codes.
  341. WARNING: this WILL break most host-side talkers that expect particular responses from firmware such as reprap host and replicatorG
  342. use with serial terminal or other suitable talker only.
  343. */
  344. // #define DEBUG
  345.  
  346. /*
  347. move buffer size, in number of moves
  348. note that each move takes a fair chunk of ram (69 bytes as of this writing) so don't make the buffer too big - a bigger serial readbuffer may help more than increasing this unless your gcodes are more than 70 characters long on average.
  349. however, a larger movebuffer will probably help with lots of short consecutive moves, as each move takes a bunch of math (hence time) to set up so a longer buffer allows more of the math to be done during preceding longer moves
  350. */
  351. #define MOVEBUFFER_SIZE 8
  352.  
  353. /*
  354. DC extruder
  355. If you have a DC motor extruder, configure it as a "heater" above and define this value as the index.
  356. */
  357. // #define DC_EXTRUDER 1
  358. // #define DC_EXTRUDER_PWM 180
  359.  
  360. /*
  361. FiveD on Arduino implements a watchdog, which has to be reset every 250ms or it will reboot the controller. As rebooting (and letting the GCode sending application trying to continue the build with a then different Home point) is probably even worse than just hanging, and there is no better restore code in place, this is disabled for now.
  362. */
  363. // #define USE_WATCHDOG
  364.  
  365. /*
  366. analog subsystem stuff
  367. REFERENCE - which analog reference to use. see analog.h for choices
  368. */
  369. #define REFERENCE REFERENCE_AVCC
  370.  
  371. /*
  372. this option makes the step interrupt interruptible (nested).
  373. this should help immensely with dropped serial characters, but may also make debugging infuriating due to the complexities arising from nested interrupts
  374. */
  375. #define STEP_INTERRUPT_INTERRUPTIBLE 1
  376.  
  377. /*
  378. how often we overflow and update our clock; with F_CPU=16MHz, max is < 4.096ms (TICK_TIME = 65535)
  379. */
  380. #define TICK_TIME 2 MS
  381. #define TICK_TIME_MS (TICK_TIME / (F_CPU / 1000))
  382.  
  383. /*
  384. temperature history count. This is how many temperature readings to keep in order to calculate derivative in PID loop
  385. higher values make PID derivative term more stable at the expense of reaction time
  386. */
  387. #define TH_COUNT 8
  388.  
  389. // this is the scaling of internally stored PID values. 1024L is a good value
  390. #define PID_SCALE 1024L
  391.  
  392.  
  393.  
  394. /***************************************************************************\
  395. * *
  396. * 8. APPENDIX A - PWMABLE PINS AND MAPPINGS *
  397. * *
  398. * *
  399. * list of PWM-able pins and corresponding timers *
  400. * timer1 is used for step timing so don't use OC1A/OC1B *
  401. * they are omitted from this listing for that reason *
  402. * *
  403. * For the atmega168/328, timer/pin mappings are as follows *
  404. * *
  405. * OCR0A - PD6 *
  406. * OCR0B - PD5 *
  407. * OCR2A - PB3 *
  408. * OCR2B - PD3 *
  409. * *
  410. * For the atmega644, timer/pin mappings are as follows *
  411. * *
  412. * OCR0A - PB3 *
  413. * OCR0B - PB4 *
  414. * OCR2A - PD7 *
  415. * OCR2B - PD6 *
  416. * *
  417. * For the atmega1280, timer/pin mappings are as follows *
  418. * *
  419. * OC0A - PB7 *
  420. * OC0B - PG5 *
  421. * OC2A - PB4 *
  422. * OC2B - PH6 *
  423. * OC3A - PE3 *
  424. * OC3B - PE4 *
  425. * OC3C - PE5 *
  426. * OC4A - PH3 *
  427. * OC4B - PH4 *
  428. * OC4C - PH5 *
  429. * OC5A - PL3 *
  430. * OC5B - PL4 *
  431. * OC5C - PL5 *
  432. * *
  433. \***************************************************************************/
  434.  
  435. #endif /* _CONFIG_H */