SHARE
TWEET

teacup_atmega168_config.h

teslas_moustache Jul 7th, 2012 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* This is a config.h file for the Teacup firmware designed to fit on an ATmega168. It was  /* created with the intention of using it for the operation of a laser cutter. Keep in mind /* that the original code was intended for a RepRap 3D printer. As a result, several         /* parameters such as temperature sensors, extruder heaters, bed heaters, and PID controls
  2. /* have been commented out.
  3.  
  4. /* Notice to developers: this file is intentionally included twice. */
  5.  
  6. /** \file
  7.         \brief Sample Configuration
  8.  
  9.         \note this sample uses AIO0 for both X_STEP and thermistor, and is intended to be an example only!
  10. */
  11.  
  12. /*
  13.         CONTENTS
  14.  
  15.         1. Mechanical/Hardware
  16.         2. Acceleration settings
  17.         3. Pinouts
  18.         4. Temperature sensors
  19.         5. Heaters
  20.         6. Communication options
  21.         7. Miscellaneous
  22.         8. Appendix A - PWMable pins and mappings
  23. */
  24.  
  25. /***************************************************************************\
  26. *                                                                           *
  27. * 1. MECHANICAL/HARDWARE                                                    *
  28. *                                                                           *
  29. \***************************************************************************/
  30.  
  31. /*
  32.         Set your microcontroller type in Makefile! atmega168/atmega328p/atmega644p/atmega1280
  33.  
  34.         If you want to port this to a new chip, start off with arduino.h and see how you go.
  35. */
  36.  
  37. /** \def F_CPU
  38.         CPU clock rate
  39. */
  40. #ifndef F_CPU
  41. #define F_CPU   16000000UL
  42. #endif
  43.  
  44. /** \def HOST
  45.         This is the motherboard, as opposed to the extruder. See extruder/ directory for GEN3 extruder firmware
  46. */
  47. #define HOST
  48.  
  49. /*
  50.         Values reflecting the gearing of your machine.
  51.                 All numbers are fixed point integers, so no more than 3 digits to the right of the decimal point, please :-)
  52. */
  53.  
  54. /** \def STEPS_PER_M
  55.         steps per meter ( = steps per mm * 1000 )
  56.  
  57.         calculate these values appropriate for your machine
  58.  
  59.         for threaded rods, this is
  60.                 (steps motor per turn) / (pitch of the thread) * 1000
  61.  
  62.         for belts, this is
  63.                 (steps per motor turn) / (number of gear teeth) / (belt module) * 1000
  64.  
  65.         half-stepping doubles the number, quarter stepping requires * 4, etc.
  66.  
  67.         valid range = 20 to 4'0960'000 (0.02 to 40960 steps/mm)
  68. */
  69. #define STEPS_PER_M_X                                   180000
  70. #define STEPS_PER_M_Y                                   1007874
  71. #define STEPS_PER_M_Z                                   320000
  72.  
  73. /// http://blog.arcol.hu/?p=157 may help with this one
  74. #define STEPS_PER_M_E                                   320000
  75.  
  76.  
  77. /*
  78.         Values depending on the capabilities of your stepper motors and other mechanics.
  79.                 All numbers are integers, no decimals allowed.
  80.  
  81.                 Units are mm/min
  82. */
  83.  
  84. /// used for G0 rapid moves and as a cap for all other feedrates
  85. #define MAXIMUM_FEEDRATE_X              200
  86. #define MAXIMUM_FEEDRATE_Y              200
  87. #define MAXIMUM_FEEDRATE_Z              100
  88. #define MAXIMUM_FEEDRATE_E              200
  89.  
  90. /// used when searching endstops and as default feedrate
  91. #define SEARCH_FEEDRATE_X                       50
  92. #define SEARCH_FEEDRATE_Y                       50
  93. #define SEARCH_FEEDRATE_Z                       50
  94. // no SEARCH_FEEDRATE_E, as E can't be searched
  95.  
  96. /** \def SLOW_HOMING
  97.         wether to search the home point slowly
  98.                 With some endstop configurations, like when probing for the surface of a PCB, you can't deal with overrunning the endstop. In such a case, uncomment this definition.
  99. */
  100. // #define      SLOW_HOMING
  101.  
  102. /// this is how many steps to suck back the filament by when we stop. set to zero to disable
  103. #define E_STARTSTOP_STEPS                       20
  104.  
  105. /**
  106.         Soft axis limits, in mm.
  107.         Define them to your machine's size relative to what your host considers to be the origin.
  108. */
  109.  
  110. //#define       X_MIN                   0.0
  111. //#define       X_MAX                   200.0
  112.  
  113. //#define       Y_MIN                   0.0
  114. //#define       Y_MAX                   200.0
  115.  
  116. //#define       Z_MIN                   0.0
  117. //#define       Z_MAX                   140.0
  118.  
  119. /**     \def E_ABSOLUTE
  120.         Some G-Code creators produce relative length commands for the extruder, others absolute ones. G-Code using absolute lengths can be recognized when there are G92 E0 commands from time to time. If you have G92 E0 in your G-Code, define this flag.
  121.  
  122.         This is the startup default and can be changed with M82/M83 while running.
  123. */
  124. // #define E_ABSOLUTE
  125.  
  126.  
  127.  
  128. /***************************************************************************\
  129. *                                                                           *
  130. * 2. ACCELERATION                                                           *
  131. *                                                                           *
  132. * IMPORTANT: choose only one! These algorithms choose when to step, trying  *
  133. *            to use more than one will have undefined and probably          *
  134. *            disastrous results!                                            *
  135. *                                                                           *
  136. \***************************************************************************/
  137.  
  138. /** \def ACCELERATION_REPRAP
  139.         acceleration, reprap style.
  140.                 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.
  141. */
  142. // #define ACCELERATION_REPRAP
  143.  
  144. /** \def ACCELERATION_RAMPING
  145.         acceleration and deceleration ramping.
  146.                 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
  147. */
  148. #define ACCELERATION_RAMPING
  149.  
  150. /** \def ACCELERATION
  151.         how fast to accelerate when using ACCELERATION_RAMPING.
  152.                 given in mm/s^2, decimal allowed, useful range 1. to 10'000. Start with 10. for milling (high precision) or 1000. for printing
  153. */
  154. #define ACCELERATION 1000.
  155.  
  156. /** \def ACCELERATION_TEMPORAL
  157.         temporal step algorithm
  158.                 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.
  159.  
  160.                 This algorithm is not a type of acceleration, and I haven't worked out how to integrate acceleration with it.
  161.                 However it does control step timing, so acceleration algorithms seemed appropriate
  162.  
  163.                 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.
  164.                 This algorithm instead calculates when a step occurs on any axis, and sets the timer to that value.
  165.  
  166.                 // TODO: figure out how to add acceleration to this algorithm
  167. */
  168. // #define ACCELERATION_TEMPORAL
  169.  
  170.  
  171.  
  172. /***************************************************************************\
  173. *                                                                           *
  174. * 3. PINOUTS                                                                *
  175. *                                                                           *
  176. \***************************************************************************/
  177.  
  178. /*
  179.         Machine Pin Definitions
  180.         - make sure to avoid duplicate usage of a pin
  181.         - comment out pins not in use, as this drops the corresponding code and makes operations faster
  182. */
  183.  
  184. #include        "arduino.h"
  185.  
  186. /** \def USE_INTERNAL_PULLUPS
  187.         internal pullup resistors
  188.                 the ATmega has internal pullup resistors on it's input pins which are counterproductive with the commonly used eletronic endstops, so they should be switched off. For other endstops, like mechanical ones, you may want to uncomment this.
  189. */
  190. //#define USE_INTERNAL_PULLUPS
  191.  
  192. /*
  193.         user defined pins
  194.         adjust to suit your electronics,
  195.         or adjust your electronics to suit this
  196. */
  197.  
  198. #define X_STEP_PIN                                              AIO0
  199. #define X_DIR_PIN                                                       AIO1
  200. #define X_MIN_PIN                                                       AIO2
  201. //#define       X_MAX_PIN                                                       xxxx
  202. //#define       X_ENABLE_PIN                                    xxxx
  203. //#define       X_INVERT_DIR
  204. //#define       X_INVERT_MIN
  205. //#define       X_INVERT_MAX
  206. //#define       X_INVERT_ENABLE
  207.  
  208. #define Y_STEP_PIN                                              AIO3
  209. #define Y_DIR_PIN                                                       AIO4
  210. #define Y_MIN_PIN                                                       AIO5
  211. //#define       Y_MAX_PIN                                                       xxxx
  212. //#define       Y_ENABLE_PIN                                    xxxx
  213. //#define       Y_INVERT_DIR
  214. //#define       Y_INVERT_MIN
  215. //#define       Y_INVERT_MAX
  216. //#define       Y_INVERT_ENABLE
  217.  
  218. #define Z_STEP_PIN                                              DIO2
  219. #define Z_DIR_PIN                                                       DIO3
  220. #define Z_MIN_PIN                                                       DIO4
  221. //#define       Z_MAX_PIN                                                       xxxx
  222. //#define       Z_ENABLE_PIN                                    xxxx
  223. //#define       Z_INVERT_DIR
  224. //#define       Z_INVERT_MIN
  225. //#define       Z_INVERT_MAX
  226. //#define       Z_INVERT_ENABLE
  227.  
  228. #define E_STEP_PIN                                              DIO7
  229. #define E_DIR_PIN                                                       DIO8
  230. //#define E_ENABLE_PIN                                  xxxx
  231. //#define       E_INVERT_DIR
  232. //#define       E_INVERT_ENABLE
  233.  
  234. #define PS_ON_PIN                                                       DIO9
  235. //#define       STEPPER_ENABLE_PIN              xxxx
  236. //#define       STEPPER_INVERT_ENABLE
  237.  
  238.  
  239.  
  240. /***************************************************************************\
  241. *                                                                           *
  242. * 4. TEMPERATURE SENSORS                                                    *
  243. *                                                                           *
  244. \***************************************************************************/
  245.  
  246. /**
  247.         TEMP_HYSTERESIS: actual temperature must be target +/- hysteresis before target temperature can be achieved.
  248.         Unit is degree Celsius.
  249. */
  250. #define TEMP_HYSTERESIS                         5
  251. /**
  252.         TEMP_RESIDENCY_TIME: actual temperature must be close to target for this long before target is achieved
  253.  
  254.         temperature is "achieved" for purposes of M109 and friends when actual temperature is within [hysteresis] of target for [residency] seconds
  255. */
  256. #define TEMP_RESIDENCY_TIME             60
  257.  
  258. /// which temperature sensors are you using? List every type of sensor you use here once, to enable the appropriate code. Intercom is the gen3-style separate extruder board.
  259. // #define      TEMP_MAX6675
  260. // #define      TEMP_THERMISTOR
  261. // #define      TEMP_AD595
  262. // #define      TEMP_PT100
  263. // #define      TEMP_INTERCOM
  264. #define TEMP_NONE
  265.  
  266. /***************************************************************************\
  267. *                                                                           *
  268. * Define your temperature sensors here. One line for each sensor, only      *
  269. * limited by the number of available ATmega pins.                           *
  270. *                                                                           *
  271. * For a GEN3 set temp_type to TT_INTERCOM and temp_pin to 0.                *
  272. *                                                                           *
  273. * Types are same as TEMP_ list above - TT_MAX6675, TT_THERMISTOR, TT_AD595, *
  274. *   TT_PT100, TT_INTERCOM, TT_NONE. See list in temp.c.                     *
  275. *                                                                           *
  276. * The "additional" field is used for TT_THERMISTOR only. It defines the     *
  277. * name of the table(s) in ThermistorTable.h to use. Typically, this is      *
  278. * THERMISTOR_EXTRUDER for the first or only table, or THERMISTOR_BED for    *
  279. * the second table. See also early in ThermistorTable.{single|double}.h.    *
  280. *                                                                           *
  281. \***************************************************************************/
  282.  
  283. #ifndef DEFINE_TEMP_SENSOR
  284.         #define DEFINE_TEMP_SENSOR(...)
  285. #endif
  286.  
  287. //                 name       type            pin        additional
  288. // DEFINE_TEMP_SENSOR(extruder,  TT_THERMISTOR,  0,         THERMISTOR_EXTRUDER)
  289. // DEFINE_TEMP_SENSOR(bed,       TT_THERMISTOR,  1,         THERMISTOR_EXTRUDER)
  290. // "noheater" is a special name for a sensor which doesn't have a heater.
  291. // Use "M105 P#" to read it, where # is a zero-based index into this list.
  292. // DEFINE_TEMP_SENSOR(noheater,  TT_THERMISTOR,  1,            0)
  293.  
  294.  
  295.  
  296. /***************************************************************************\
  297. *                                                                           *
  298. * 5. HEATERS                                                                *
  299. *                                                                           *
  300. \***************************************************************************/
  301.  
  302. /** \def HEATER_SANITY_CHECK
  303.         check if heater responds to changes in target temperature, disable and spit errors if not
  304.         largely untested, please comment in forum if this works, or doesn't work for you!
  305. */
  306. // #define      HEATER_SANITY_CHECK
  307.  
  308. /***************************************************************************\
  309. *                                                                           *
  310. * Define your heaters here                                                  *
  311. *                                                                           *
  312. * If your heater isn't on a PWM-able pin, set heater_pwm to zero and we'll  *
  313. *   use bang-bang output. Note that PID will still be used                  *
  314. *                                                                           *
  315. * See Appendix 8 at the end of this file for PWMable pin mappings           *
  316. *                                                                           *
  317. * If a heater isn't attached to a temperature sensor above, it can still be *
  318. *   controlled by host but otherwise is ignored by firmware                 *
  319. *                                                                           *
  320. * To attach a heater to a temp sensor above, simply use exactly the same    *
  321. *   name - copy+paste is your friend                                        *
  322. *                                                                           *
  323. * Some common names are 'extruder', 'bed', 'fan', 'motor'                   *
  324. *                                                                           *
  325. * A milling spindle can also be defined as a heater. Attach it to a         *
  326. * temperature sensor of TT_NONE, then you can control the spindle's rpm     *
  327. * via temperature commands. M104 S1..255 for spindle on, M104 S0 for off.   *
  328. *                                                                           *
  329. \***************************************************************************/
  330.  
  331. #ifndef DEFINE_HEATER
  332.         #define DEFINE_HEATER(...)
  333. #endif
  334.  
  335. //            name      port
  336. // DEFINE_HEATER(extruder, PB3)
  337. // DEFINE_HEATER(bed,      PB4)
  338. // DEFINE_HEATER(fan,      PINB4)
  339. // DEFINE_HEATER(chamber,  PIND7)
  340. // DEFINE_HEATER(motor,    PIND6)
  341.  
  342. /// and now because the c preprocessor isn't as smart as it could be,
  343. /// uncomment the ones you've listed above and comment the rest.
  344. /// NOTE: these are used to enable various capability-specific chunks of code, you do NOT need to create new entries unless you are adding new capabilities elsewhere in the code!
  345. /// so if you list a bed above, uncomment HEATER_BED, but if you list a chamber you do NOT need to create HEATED_CHAMBER
  346. /// I have searched high and low for a way to make the preprocessor do this for us, but so far I have not found a way.
  347.  
  348. // #define      HEATER_EXTRUDER HEATER_extruder
  349. // #define HEATER_BED HEATER_bed
  350. // #define HEATER_FAN HEATER_fan
  351. // #define HEATER_CHAMBER HEATER_chamber
  352. // #define HEATER_MOTOR HEATER_motor
  353.  
  354.  
  355.  
  356. /***************************************************************************\
  357. *                                                                           *
  358. * 6. COMMUNICATION OPTIONS                                                  *
  359. *                                                                           *
  360. \***************************************************************************/
  361.  
  362. /** \def REPRAP_HOST_COMPATIBILITY
  363.         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.
  364.         See the discussion on the reprap-dev mailing list from 11 Oct. 2010.
  365.  
  366.         Undefine it for best human readability, set it to an old date for compatibility with hosts before August 2010
  367. */
  368. // #define REPRAP_HOST_COMPATIBILITY 19750101
  369. // #define REPRAP_HOST_COMPATIBILITY 20100806
  370. // #define REPRAP_HOST_COMPATIBILITY 20110509
  371. // #define REPRAP_HOST_COMPATIBILITY <date of next RepRap Host compatibility break>
  372.  
  373. /**
  374.         Baud rate for the connection to the host. Usually 115200, other common values are 19200, 38400 or 57600.
  375. */
  376. #define BAUD    115200
  377.  
  378. /** \def XONXOFF
  379.         Xon/Xoff flow control.
  380.                 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).
  381.                 Can also be set in Makefile
  382. */
  383. // #define      XONXOFF
  384.  
  385.  
  386.  
  387. /***************************************************************************\
  388. *                                                                           *
  389. * 7. MISCELLANEOUS OPTIONS                                                  *
  390. *                                                                           *
  391. \***************************************************************************/
  392.  
  393. /** \def DEBUG
  394.         DEBUG
  395.                 enables /heaps/ of extra output, and some extra M-codes.
  396.                 WARNING: this WILL break most host-side talkers that expect particular responses from firmware such as reprap host and replicatorG
  397.                 use with serial terminal or other suitable talker only.
  398. */
  399. // #define      DEBUG
  400.  
  401. /** \def BANG_BANG
  402. BANG_BANG
  403. drops PID loop from heater control, reduces code size significantly (1300 bytes!)
  404. may allow DEBUG on '168
  405. */
  406. #define BANG_BANG
  407. /** \def BANG_BANG_ON
  408. BANG_BANG_ON
  409. PWM value for 'on'
  410. */
  411. #define BANG_BANG_ON    200
  412. /** \def BANG_BANG_OFF
  413. BANG_BANG_OFF
  414. PWM value for 'off'
  415. */
  416. #define BANG_BANG_OFF   45
  417.  
  418. /**
  419.         move buffer size, in number of moves
  420.                 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.
  421.                 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
  422. */
  423. #define MOVEBUFFER_SIZE 8
  424.  
  425. /** \def DC_EXTRUDER
  426.         DC extruder
  427.                 If you have a DC motor extruder, configure it as a "heater" above and define this value as the index or name. You probably also want to comment out E_STEP_PIN and E_DIR_PIN in the Pinouts section above.
  428. */
  429. // #define      DC_EXTRUDER HEATER_motor
  430. // #define      DC_EXTRUDER_PWM 180
  431.  
  432. /** \def USE_WATCHDOG
  433.         Teacup 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.
  434. */
  435. // #define USE_WATCHDOG
  436.  
  437. /**
  438.         analog subsystem stuff
  439.         REFERENCE - which analog reference to use. see analog.h for choices
  440. */
  441. #define REFERENCE                       REFERENCE_AVCC
  442.  
  443. /** \def STEP_INTERRUPT_INTERRUPTIBLE
  444.         this option makes the step interrupt interruptible (nested).
  445.         this should help immensely with dropped serial characters, but may also make debugging infuriating due to the complexities arising from nested interrupts
  446.         \note disable this option if you're using a '168 or for some reason your ram usage is above 90%. This option hugely increases likelihood of stack smashing.
  447. */
  448. //#define               STEP_INTERRUPT_INTERRUPTIBLE    1
  449.  
  450. /**
  451.         temperature history count. This is how many temperature readings to keep in order to calculate derivative in PID loop
  452.         higher values make PID derivative term more stable at the expense of reaction time
  453. */
  454. #define TH_COUNT                                        8
  455.  
  456. /** \def FAST_PWM
  457.         Teacup offers two PWM frequencies, 76(61) Hz and 78000(62500) Hz on a 20(16) MHz electronics. The faster one is the default, as it's what most other firmwares do. It can make the heater MOSFETs pretty hot, though.
  458.  
  459.         Comment this option out if your MOSFETs overheat. Drawback is, in a quiet environment you might notice the heaters and your power supply humming, then.
  460. */
  461. #define FAST_PWM
  462.  
  463. /// this is the scaling of internally stored PID values. 1024L is a good value
  464. #define PID_SCALE                                               1024L
  465.  
  466. /** \def ENDSTOP_STEPS
  467.         number of steps to run into the endstops intentionally
  468.                 As Endstops trigger false alarm sometimes, Teacup debounces them by counting a number of consecutive positives. Valid range is 1...255. Use 4 or less for reliable endstops, 8 or even more for flaky ones.
  469. */
  470. #define ENDSTOP_STEPS   4
  471.  
  472.  
  473.  
  474. /***************************************************************************\
  475. *                                                                           *
  476. * 8. APPENDIX A - PWMABLE PINS AND MAPPINGS                                 *
  477. *                                                                           *
  478. *                                                                           *
  479. * list of PWM-able pins and corresponding timers                            *
  480. * timer1 is used for step timing so don't use OC1A/OC1B                     *
  481. * they are omitted from this listing for that reason                        *
  482. *                                                                           *
  483. * For the atmega168/328, timer/pin mappings are as follows                  *
  484. *                                                                           *
  485. * OCR0A - PD6  - DIO6                                                       *
  486. * OCR0B - PD5  - DIO5                                                       *
  487. * OCR2A - PB3  - DIO11                                                      *
  488. * OCR2B - PD3  - DIO3                                                       *
  489. *                                                                           *
  490. * For the atmega644, timer/pin mappings are as follows                      *
  491. *                                                                           *
  492. * OCR0A - PB3  - DIO3                                                       *
  493. * OCR0B - PB4  - DIO4                                                       *
  494. * OCR2A - PD7  - DIO15                                                      *
  495. * OCR2B - PD6  - DIO14                                                      *
  496. *                                                                           *
  497. * For the atmega1280, timer/pin mappings are as follows                     *
  498. *                                                                           *
  499. * OCR0A  - PB7 - DIO13                                                      *
  500. * OCR0B  - PG5 - DIO4                                                       *
  501. * OCR2A  - PB4 - DIO10                                                      *
  502. * OCR2B  - PH6 - DIO9                                                       *
  503. * OCR3AL - PE3 - DIO5                                                       *
  504. * OCR3BL - PE4 - DIO2                                                       *
  505. * OCR3CL - PE5 - DIO3                                                       *
  506. * OCR4AL - PH3 - DIO6                                                       *
  507. * OCR4BL - PH4 - DIO7                                                       *
  508. * OCR4CL - PH5 - DIO8                                                       *
  509. * OCR5AL - PL3 - DIO46                                                      *
  510. * OCR5BL - PL4 - DIO45                                                      *
  511. * OCR5CL - PL5 - DIO44                                                      *
  512. *                                                                           *
  513. \***************************************************************************/
RAW Paste Data
Top