Advertisement
Guest User

AphoticJezter

a guest
Jan 13th, 2011
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 20.94 KB | None | 0 0
  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                          315.000
  56. #define STEPS_PER_MM_Y                          315.000
  57. #define STEPS_PER_MM_Z                          315.000
  58.  
  59. // http://blog.arcol.hu/?p=157 may help with this next one
  60. #define STEPS_PER_MM_E                          7.3504
  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              1200
  72. #define MAXIMUM_FEEDRATE_Y              1200
  73. #define MAXIMUM_FEEDRATE_Z              400
  74. #define MAXIMUM_FEEDRATE_E              6000
  75.  
  76. // used when searching endstops and as default feedrate
  77. #define SEARCH_FEEDRATE_X                       100
  78. #define SEARCH_FEEDRATE_Y                       100
  79. #define SEARCH_FEEDRATE_Z                       100
  80. #define SEARCH_FEEDRATE_E                       100
  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                       0
  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  50000
  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              AIO5
  155.         #define X_DIR_PIN               DIO2
  156.         #define X_MIN_PIN               DIO12
  157.  
  158.         #define Y_STEP_PIN              DIO4
  159.         #define Y_DIR_PIN               DIO5
  160.         #define Y_MIN_PIN               DIO11
  161.  
  162.         #define Z_STEP_PIN              DIO6
  163.         #define Z_DIR_PIN               DIO7
  164.         #define Z_MIN_PIN               DIO10
  165.  
  166.         #define E_STEP_PIN              DIO7
  167.         #define E_DIR_PIN               DIO8
  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. #define X_INVERT_MIN            1
  203. #define Y_INVERT_MIN            1
  204. #define Z_INVERT_MIN            1
  205.  
  206.  
  207. /***************************************************************************\
  208. *                                                                           *
  209. * 4. TEMPERATURE SENSORS                                                    *
  210. *                                                                           *
  211. \***************************************************************************/
  212.  
  213. /*
  214.         TEMP_HYSTERESIS: actual temperature must be target +/- hysteresis before target temperature can be achieved.
  215.           NOTE: format is 30.2 fixed point, so value of 20 actually means +/- 5 degrees
  216.  
  217.         TEMP_RESIDENCY_TIME: actual temperature must be close to target for this long before target is achieved
  218.  
  219.         temperature is "achieved" for purposes of M109 and friends when actual temperature is within [hysteresis] of target for [residency] seconds
  220. */
  221. #define TEMP_HYSTERESIS                         20
  222. #define TEMP_RESIDENCY_TIME             10
  223.  
  224. // which temperature sensors are you using? (intercom is the gen3-style separate extruder board)
  225. // #define      TEMP_MAX6675
  226. #define TEMP_THERMISTOR
  227. // #define      TEMP_AD595
  228. // #define      TEMP_PT100
  229. // #define      TEMP_INTERCOM
  230.  
  231. // if you selected thermistor or AD595, what pin is it on? (this value only used to fill ANALOG_MASK for you)
  232. #define TEMP_PIN_CHANNEL        AIO0_PIN
  233.  
  234. // 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
  235. #define ANALOG_MASK                             MASK(TEMP_PIN_CHANNEL)
  236.  
  237. // how many temperature sensors do you have?
  238. #define NUM_TEMP_SENSORS        1
  239.  
  240. /***************************************************************************\
  241. *                                                                           *
  242. * Fill in the following struct according to your hardware                   *
  243. *                                                                           *
  244. * If your temperature sensor has no associated heater, enter '255' as the   *
  245. *   heater index. Unassociated temperature sensors are still read, but they *
  246. *   do not affect firmware operation                                        *
  247. *                                                                           *
  248. * for GEN3 set temp_type to TT_INTERCOM, temp_pin to 0 and heater index to  *
  249. *   255 - the extruder manages the heater for us                            *
  250. *                                                                           *
  251. * Types are same as TEMP_ list above- TT_MAX6675, TT_THERMISTOR, TT_AD595,  *
  252. *   TT_PT100, TT_INTERCOM. See list in temp.c.                              *
  253. *                                                                           *
  254. \***************************************************************************/
  255.  
  256. #ifdef  TEMP_C
  257. struct {
  258.         uint8_t                                         temp_type;
  259.         uint8_t                                         temp_pin;
  260.  
  261.         uint8_t                                         heater_index;
  262. } temp_sensors[NUM_TEMP_SENSORS] =
  263. {
  264.         // type         pin heater
  265.         { TT_THERMISTOR,  0,  0 }
  266. };
  267. #endif
  268.  
  269.  
  270.  
  271. /***************************************************************************\
  272. *                                                                           *
  273. * 5. HEATERS                                                                *
  274. *                                                                           *
  275. \***************************************************************************/
  276.  
  277. // number of heaters- for GEN3, set to zero as extruder manages the heater by itself
  278. #define NUM_HEATERS                             1
  279.  
  280. // check if heater responds to changes in target temperature, disable and spit errors if not
  281. // #define      HEATER_SANITY_CHECK
  282.  
  283. /***************************************************************************\
  284. *                                                                           *
  285. * Fill in the following struct according to your hardware                   *
  286. *                                                                           *
  287. * If your heater isn't on a PWM-able pin, set heater_pwm to zero and we'll  *
  288. *   use bang-bang output. Note that PID will still be used                  *
  289. *                                                                           *
  290. * If a heater isn't attached to a temperature sensor above, it can still be *
  291. *   controlled by host but otherwise is ignored by firmware                 *
  292. *                                                                           *
  293. \***************************************************************************/
  294.  
  295. #ifdef  HEATER_C
  296. struct {
  297.         volatile uint8_t        *heater_port;
  298.         uint8_t                                         heater_pin;
  299.         volatile uint8_t        *heater_pwm;
  300. } heaters[NUM_HEATERS] =
  301. {
  302.         // port   pin    pwm
  303.         { &DIO3_WPORT, DIO3_PIN, &OCR2B }       // 328
  304. //      { &DIO3_WPORT, DIO3_PIN, &OCR3C }       // Mega
  305. };
  306. #endif
  307.  
  308.  
  309.  
  310. /***************************************************************************\
  311. *                                                                           *
  312. * 6. COMMUNICATION OPTIONS                                                  *
  313. *                                                                           *
  314. \***************************************************************************/
  315.  
  316. /*
  317.         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.
  318.         See the discussion on the reprap-dev mailing list from 11 Oct. 2010.
  319.  
  320.         Undefine it for best human readability, set it to an old date for compatibility with hosts before August 2010
  321. */
  322. // #define REPRAP_HOST_COMPATIBILITY 19750101
  323. #define REPRAP_HOST_COMPATIBILITY 20100806
  324. // #define REPRAP_HOST_COMPATIBILITY <date of next RepRap Host compatibility break>
  325.  
  326. /*
  327.         Xon/Xoff flow control.
  328.                 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).
  329.                 Can also be set in Makefile
  330. */
  331. // #define      XONXOFF
  332.  
  333.  
  334.  
  335. /***************************************************************************\
  336. *                                                                           *
  337. * 7. MISCELLANEOUS OPTIONS                                                  *
  338. *                                                                           *
  339. \***************************************************************************/
  340.  
  341. /*
  342.         DEBUG
  343.                 enables /heaps/ of extra output, and some extra M-codes.
  344.                 WARNING: this WILL break most host-side talkers that expect particular responses from firmware such as reprap host and replicatorG
  345.                 use with serial terminal or other suitable talker only.
  346. */
  347. #define DEBUG
  348.  
  349. /*
  350.         move buffer size, in number of moves
  351.                 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.
  352.                 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
  353. */
  354. #define MOVEBUFFER_SIZE 8
  355.  
  356. /*
  357.         DC extruder
  358.                 If you have a DC motor extruder, configure it as a "heater" above and define this value as the index.
  359. */
  360. // #define      DC_EXTRUDER 1
  361. // #define      DC_EXTRUDER_PWM 180
  362.  
  363. /*
  364.         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.
  365. */
  366. // #define USE_WATCHDOG
  367.  
  368. /*
  369.         analog subsystem stuff
  370.         REFERENCE - which analog reference to use. see analog.h for choices
  371. */
  372. #define REFERENCE                       REFERENCE_AVCC
  373.  
  374. /*
  375.         this option makes the step interrupt interruptible (nested).
  376.         this should help immensely with dropped serial characters, but may also make debugging infuriating due to the complexities arising from nested interrupts
  377. */
  378. #define         STEP_INTERRUPT_INTERRUPTIBLE    1
  379.  
  380. /*
  381.         how often we overflow and update our clock; with F_CPU=16MHz, max is < 4.096ms (TICK_TIME = 65535)
  382. */
  383. #define         TICK_TIME                       2 MS
  384. #define         TICK_TIME_MS    (TICK_TIME / (F_CPU / 1000))
  385.  
  386. /*
  387.         temperature history count. This is how many temperature readings to keep in order to calculate derivative in PID loop
  388.         higher values make PID derivative term more stable at the expense of reaction time
  389. */
  390. #define TH_COUNT                                        8
  391.  
  392. // this is the scaling of internally stored PID values. 1024L is a good value
  393. #define PID_SCALE                                               1024L
  394.  
  395.  
  396.  
  397. /***************************************************************************\
  398. *                                                                           *
  399. * 8. APPENDIX A - PWMABLE PINS AND MAPPINGS                                 *
  400. *                                                                           *
  401. *                                                                           *
  402. * list of PWM-able pins and corresponding timers                            *
  403. * timer1 is used for step timing so don't use OC1A/OC1B                     *
  404. * they are omitted from this listing for that reason                        *
  405. *                                                                           *
  406. * For the atmega168/328, timer/pin mappings are as follows                  *
  407. *                                                                           *
  408. * OCR0A - PD6                                                               *
  409. * OCR0B - PD5                                                               *
  410. * OCR2A - PB3                                                               *
  411. * OCR2B - PD3                                                               *
  412. *                                                                           *
  413. * For the atmega644, timer/pin mappings are as follows                      *
  414. *                                                                           *
  415. * OCR0A - PB3                                                               *
  416. * OCR0B - PB4                                                               *
  417. * OCR2A - PD7                                                               *
  418. * OCR2B - PD6                                                               *
  419. *                                                                           *
  420. * For the atmega1280, timer/pin mappings are as follows                     *
  421. *                                                                           *
  422. * OC0A - PB7                                                                *
  423. * OC0B - PG5                                                                *
  424. * OC2A - PB4                                                                *
  425. * OC2B - PH6                                                                *
  426. * OC3A - PE3                                                                *
  427. * OC3B - PE4                                                                *
  428. * OC3C - PE5                                                                *
  429. * OC4A - PH3                                                                *
  430. * OC4B - PH4                                                                *
  431. * OC4C - PH5                                                                *
  432. * OC5A - PL3                                                                *
  433. * OC5B - PL4                                                                *
  434. * OC5C - PL5                                                                *
  435. *                                                                           *
  436. \***************************************************************************/
  437.  
  438. #endif  /* _CONFIG_H */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement