From d024fdb1b1c30259dac6b8503bc32405ce32c0dd Mon Sep 17 00:00:00 2001 From: tonokip Date: Sat, 1 May 2010 16:52:51 -0700 Subject: rewrite --- README | 9 + Tonokip_Firmware/ThermistorTable.h | 43 +++ Tonokip_Firmware/Tonokip_Firmware.pde | 572 ++++++++++++++++++++++++++++++++++ Tonokip_Firmware/configuration.h | 45 +++ Tonokip_Firmware/pins.h | 288 +++++++++++++++++ 5 files changed, 957 insertions(+) create mode 100644 Tonokip_Firmware/ThermistorTable.h create mode 100644 Tonokip_Firmware/Tonokip_Firmware.pde create mode 100644 Tonokip_Firmware/configuration.h create mode 100644 Tonokip_Firmware/pins.h diff --git a/README b/README index e69de29..60a8b4e 100644 --- a/README +++ b/README @@ -0,0 +1,9 @@ +Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware. + +TODO: +Inactivity timer failsafe that can be enabled/disabled by using a custom Mcode. +Max Endstop support (easy). +Add support for DC Extruders. +Store internal position using steps(long int) instead of units(float). + +Test thermocouple support. \ No newline at end of file diff --git a/Tonokip_Firmware/ThermistorTable.h b/Tonokip_Firmware/ThermistorTable.h new file mode 100644 index 0000000..844b8de --- /dev/null +++ b/Tonokip_Firmware/ThermistorTable.h @@ -0,0 +1,43 @@ +#ifndef THERMISTORTABLE_H_ +#define THERMISTORTABLE_H_ + +// Thermistor lookup table for RepRap Temperature Sensor Boards (http://make.rrrf.org/ts) +// See this page: +// http://dev.www.reprap.org/bin/view/Main/Thermistor +// for details of what goes in this table. +// Made with createTemperatureLookup.py (http://svn.reprap.org/trunk/reprap/firmware/Arduino/utilities/createTemperatureLookup.py) +// ./createTemperatureLookup.py --r0=100000 --t0=25 --r1=0 --r2=4700 --beta=4066 --max-adc=1023 +// r0: 100000 +// t0: 25 +// r1: 0 +// r2: 4700 +// beta: 4066 +// max adc: 1023 + +#define NUMTEMPS 20 +short temptable[NUMTEMPS][2] = { + {1, 841}, + {54, 255}, + {107, 209}, + {160, 184}, + {213, 166}, + {266, 153}, + {319, 142}, + {372, 132}, + {425, 124}, + {478, 116}, + {531, 108}, + {584, 101}, + {637, 93}, + {690, 86}, + {743, 78}, + {796, 70}, + {849, 61}, + {902, 50}, + {955, 34}, + {1008, 3} +}; + + +#endif + diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde new file mode 100644 index 0000000..e5ee6af --- /dev/null +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -0,0 +1,572 @@ +// Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware. +// Licence: GPL + +#include "configuration.h" +#include "pins.h" +#include "ThermistorTable.h" + +// look here for descriptions of gcodes: http://linuxcnc.org/handbook/gcode/g-code.html +// http://objects.reprap.org/wiki/Mendel_User_Manual:_RepRapGCodes + +//Implemented Codes +//------------------- +// G0 -> G1 +// G1 - Coordinated Movement X Y Z E +// G4 - Dwell S or P +// G90 - Use Absolute Coordinates +// G91 - Use Relative Coordinates +// G92 - Set current position to cordinates given + +//RepRap M Codes +// M104 - Set target temp +// M105 - Read current temp +// M109 - Wait for current temp to reach target temp. + +//Custom M Codes +// M80 - Turn on Power Supply +// M81 - Turn off Power Supply +// M82 - Set E codes absolute (default) +// M83 - Set E codes relative while in Absolute Coordinates (G90) mode +// M84 - Disable steppers until next move + + +//Stepper Movement Variables +bool direction_x, direction_y, direction_z, direction_e; +unsigned long previous_micros=0, previous_micros_x=0, previous_micros_y=0, previous_micros_z=0, previous_micros_e=0, previous_millis_heater; +unsigned long x_steps_to_take, y_steps_to_take, z_steps_to_take, e_steps_to_take; +float destination_x =0.0, destination_y = 0.0, destination_z = 0.0, destination_e = 0.0; +float current_x = 0.0, current_y = 0.0, current_z = 0.0, current_e = 0.0; +float x_interval, y_interval, z_interval, e_interval; // for speed delay +float feedrate = 1500, next_feedrate; +float time_for_move; +long gcode_N, gcode_LastN; +bool relative_mode = false; //Determines Absolute or Relative Coordinates +bool relative_mode_e = false; //Determines Absolute or Relative E Codes while in Absolute Coordinates mode. E is always relative in Relative Coordinates mode. + +// comm variables +#define MAX_CMD_SIZE 256 +char cmdbuffer[MAX_CMD_SIZE]; +char serial_char; +int serial_count = 0; +boolean comment_mode = false; +char *strchr_pointer; // just a pointer to find chars in the cmd string like X, Y, Z, E, etc + +//manage heater variables +int target_raw = 0; +int current_raw; + + + +void setup() +{ + //Initialize Step Pins + if(X_STEP_PIN > -1) pinMode(X_STEP_PIN,OUTPUT); + if(Y_STEP_PIN > -1) pinMode(Y_STEP_PIN,OUTPUT); + if(Z_STEP_PIN > -1) pinMode(Z_STEP_PIN,OUTPUT); + if(E_STEP_PIN > -1) pinMode(E_STEP_PIN,OUTPUT); + + //Initialize Dir Pins + if(X_DIR_PIN > -1) pinMode(X_DIR_PIN,OUTPUT); + if(Y_DIR_PIN > -1) pinMode(Y_DIR_PIN,OUTPUT); + if(Z_DIR_PIN > -1) pinMode(Z_DIR_PIN,OUTPUT); + if(E_DIR_PIN > -1) pinMode(E_DIR_PIN,OUTPUT); + + //Steppers default to disabled. + if(X_ENABLE_PIN > -1) if(!X_ENABLE_ON) digitalWrite(X_ENABLE_PIN,HIGH); + if(Y_ENABLE_PIN > -1) if(!Y_ENABLE_ON) digitalWrite(Y_ENABLE_PIN,HIGH); + if(Z_ENABLE_PIN > -1) if(!Z_ENABLE_ON) digitalWrite(Z_ENABLE_PIN,HIGH); + if(E_ENABLE_PIN > -1) if(!E_ENABLE_ON) digitalWrite(E_ENABLE_PIN,HIGH); + + //Initialize Enable Pins + if(X_ENABLE_PIN > -1) pinMode(X_ENABLE_PIN,OUTPUT); + if(Y_ENABLE_PIN > -1) pinMode(Y_ENABLE_PIN,OUTPUT); + if(Z_ENABLE_PIN > -1) pinMode(Z_ENABLE_PIN,OUTPUT); + if(E_ENABLE_PIN > -1) pinMode(E_ENABLE_PIN,OUTPUT); + + if(HEATER_0_PIN > -1) pinMode(HEATER_0_PIN,OUTPUT); + + Serial.begin(BAUDRATE); + Serial.println("start"); +} + + +void loop() +{ + get_command(); + manage_heater(); +} + +inline void get_command() +{ + + if( Serial.available() ) { + serial_char = Serial.read(); + if(serial_char == '\n' || serial_char == '\r' || serial_char == ':' || serial_count >= (MAX_CMD_SIZE - 1) ) + { + if(!serial_count) return; //if empty line + cmdbuffer[serial_count] = 0; //terminate string + Serial.print("Echo:"); + Serial.println(&cmdbuffer[0]); + + process_commands(); + + comment_mode = false; //for new command + serial_count = 0; //clear buffer + //Serial.println("ok"); + } + else + { + if(serial_char == ';') comment_mode = true; + if(!comment_mode) cmdbuffer[serial_count++] = serial_char; + } + } +} + + +//#define code_num (strtod(&cmdbuffer[strchr_pointer - cmdbuffer + 1], NULL)) +//inline void code_search(char code) { strchr_pointer = strchr(cmdbuffer, code); } +inline float code_value() { return (strtod(&cmdbuffer[strchr_pointer - cmdbuffer + 1], NULL)); } +inline long code_value_long() { return (strtol(&cmdbuffer[strchr_pointer - cmdbuffer + 1], NULL, 10)); } +inline bool code_seen(char code_string[]) { return (strstr(cmdbuffer, code_string) != NULL); } //Return True if the string was found + +inline bool code_seen(char code) +{ + strchr_pointer = strchr(cmdbuffer, code); + return (strchr_pointer != NULL); //Return True if a character was found +} + + + +inline void process_commands() +{ + unsigned long codenum; //throw away variable + + if(code_seen('N')) + { + gcode_N = code_value_long(); + if(gcode_N != gcode_LastN+1 && (strstr(cmdbuffer, "M110") == NULL) ) { + //if(gcode_N != gcode_LastN+1 && !code_seen("M110") ) { //Hmm, compile size is different between using this vs the line above even though it should be the same thing. Keeping old method. + Serial.print("Serial Error: Line Number is not Last Line Number+1, Last Line:"); + Serial.println(gcode_LastN); + FlushSerialRequestResend(); + return; + } + + if(code_seen('*')) + { + byte checksum = 0; + byte count=0; + while(cmdbuffer[count] != '*') checksum = checksum^cmdbuffer[count++]; + + if( (int)code_value() != checksum) { + Serial.print("Error: checksum mismatch, Last Line:"); + Serial.println(gcode_LastN); + FlushSerialRequestResend(); + return; + } + //if no errors, continue parsing + } + else + { + Serial.print("Error: No Checksum with line number, Last Line:"); + Serial.println(gcode_LastN); + FlushSerialRequestResend(); + return; + } + + gcode_LastN = gcode_N; + //if no errors, continue parsing + } + else // if we don't receive 'N' but still see '*' + { + if(code_seen('*')) + { + Serial.print("Error: No Line Number with checksum, Last Line:"); + Serial.println(gcode_LastN); + return; + } + } + + //continues parsing only if we don't receive any 'N' or '*' or no errors if we do. :) + + if(code_seen('G')) + { + switch((int)code_value()) + { + case 0: // G0 -> G1 + case 1: // G1 + get_coordinates(); // For X Y Z E F + x_steps_to_take = abs(destination_x - current_x)*x_steps_per_unit; + y_steps_to_take = abs(destination_y - current_y)*y_steps_per_unit; + z_steps_to_take = abs(destination_z - current_z)*z_steps_per_unit; + e_steps_to_take = abs(destination_e - current_e)*e_steps_per_unit; + + #define X_TIME_FOR_MOVE ((float)x_steps_to_take / (x_steps_per_unit*feedrate/60000000)) + #define Y_TIME_FOR_MOVE ((float)y_steps_to_take / (y_steps_per_unit*feedrate/60000000)) + #define Z_TIME_FOR_MOVE ((float)z_steps_to_take / (z_steps_per_unit*feedrate/60000000)) + #define E_TIME_FOR_MOVE ((float)e_steps_to_take / (e_steps_per_unit*feedrate/60000000)) + + time_for_move = max(X_TIME_FOR_MOVE,Y_TIME_FOR_MOVE); + time_for_move = max(time_for_move,Z_TIME_FOR_MOVE); + //time_for_move = max(time_for_move,E_TIME_FOR_MOVE); //Commented so E axis doesn't trigger max feedrate. + + if(x_steps_to_take) x_interval = time_for_move/x_steps_to_take; + if(y_steps_to_take) y_interval = time_for_move/y_steps_to_take; + if(z_steps_to_take) z_interval = time_for_move/z_steps_to_take; + if(e_steps_to_take) e_interval = time_for_move/e_steps_to_take; + + #define DEBUGGING false + if(DEBUGGING) { + Serial.print("destination_x: "); Serial.println(destination_x); + Serial.print("current_x: "); Serial.println(current_x); + Serial.print("x_steps_to_take: "); Serial.println(x_steps_to_take); + Serial.print("X_TIME_FOR_MVE: "); Serial.println(X_TIME_FOR_MOVE); + Serial.print("x_interval: "); Serial.println(x_interval); + Serial.println(""); + Serial.print("destination_y: "); Serial.println(destination_y); + Serial.print("current_y: "); Serial.println(current_y); + Serial.print("y_steps_to_take: "); Serial.println(y_steps_to_take); + Serial.print("Y_TIME_FOR_MVE: "); Serial.println(Y_TIME_FOR_MOVE); + Serial.print("y_interval: "); Serial.println(y_interval); + Serial.println(""); + Serial.print("destination_z: "); Serial.println(destination_z); + Serial.print("current_z: "); Serial.println(current_z); + Serial.print("z_steps_to_take: "); Serial.println(z_steps_to_take); + Serial.print("Z_TIME_FOR_MVE: "); Serial.println(Z_TIME_FOR_MOVE); + Serial.print("z_interval: "); Serial.println(z_interval); + Serial.println(""); + Serial.print("destination_e: "); Serial.println(destination_e); + Serial.print("current_e: "); Serial.println(current_e); + Serial.print("e_steps_to_take: "); Serial.println(e_steps_to_take); + Serial.print("E_TIME_FOR_MVE: "); Serial.println(E_TIME_FOR_MOVE); + Serial.print("e_interval: "); Serial.println(e_interval); + Serial.println(""); + } + + linear_move(x_steps_to_take, y_steps_to_take, z_steps_to_take, e_steps_to_take); // make the move + ClearToSend(); + return; + case 4: // G4 dwell + codenum = 0; + if(code_seen('P')) codenum = code_value(); // milliseconds to wait + if(code_seen('S')) codenum = code_value()*1000; // seconds to wait + previous_millis_heater = millis(); // keep track of when we started waiting + while((millis() - previous_millis_heater) < codenum ) manage_heater(); //manage heater until time is up + break; + case 90: // G90 + relative_mode = false; + break; + case 91: // G91 + relative_mode = true; + break; + case 92: // G92 + if(code_seen('X')) current_x = code_value(); + if(code_seen('Y')) current_y = code_value(); + if(code_seen('Z')) current_z = code_value(); + if(code_seen('E')) current_e = code_value(); + break; + + } + } + + if(code_seen('M')) + { + + switch( (int)code_value() ) + { + case 104: // M104 + if (code_seen('S')) target_raw = temp2analog(code_value()); + break; + case 105: // M105 + Serial.print("T:"); + Serial.println( analog2temp(analogRead(TEMP_0_PIN)) ); + if(code_seen('N')) Serial.println("ok"); // If M105 is sent from generated gcode, then it needs a response. + return; //If RepSnapper sends the M105 then DON'T respond "ok". + break; + case 109: // M109 - Wait for heater to reach target. + if (code_seen('S')) target_raw = temp2analog(code_value()); + previous_millis_heater = millis(); + while(current_raw < target_raw) { + if( (millis()-previous_millis_heater) > 1000 ) //Print Temp Reading every 1 second while heating up. + { + Serial.print("T:"); + Serial.println( analog2temp(analogRead(TEMP_0_PIN)) ); + previous_millis_heater = millis(); + } + manage_heater(); + } + break; + case 80: // M81 - ATX Power On + if(PS_ON_PIN > -1) pinMode(PS_ON_PIN,OUTPUT); //GND + break; + case 81: // M81 - ATX Power Off + if(PS_ON_PIN > -1) pinMode(PS_ON_PIN,INPUT); //Floating + break; + case 82: + relative_mode_e = false; + break; + case 83: + relative_mode_e = true; + break; + case 84: + disable_x(); + disable_y(); + disable_z(); + disable_e(); + break; + } + + } + + ClearToSend(); +} + +inline void FlushSerialRequestResend() +{ + char cmdbuffer[100]="Resend:"; + ltoa(gcode_LastN+1, cmdbuffer+7, 10); + Serial.flush(); + Serial.println(cmdbuffer); + ClearToSend(); +} + +inline void ClearToSend() +{ + Serial.println("ok"); +} + +inline void get_coordinates() +{ + if(code_seen('X')) destination_x = (float)code_value() + relative_mode*current_x; + else destination_x = current_x; //Are these else lines really needed? + if(code_seen('Y')) destination_y = (float)code_value() + relative_mode*current_y; + else destination_y = current_y; + if(code_seen('Z')) destination_z = (float)code_value() + relative_mode*current_z; + else destination_z = current_z; + if(code_seen('E')) destination_e = (float)code_value() + (relative_mode_e || relative_mode)*current_e; + else destination_e = current_e; + if(code_seen('F')) { + next_feedrate = code_value(); + if(next_feedrate > 0.0) feedrate = next_feedrate; + } + + //Find direction + if(destination_x >= current_x) direction_x=1; + else direction_x=0; + if(destination_y >= current_y) direction_y=1; + else direction_y=0; + if(destination_z >= current_z) direction_z=1; + else direction_z=0; + if(destination_e >= current_e) direction_e=1; + else direction_e=0; + + + if (min_software_endstops) { + if (destination_x < 0) destination_x = 0.0; + if (destination_y < 0) destination_y = 0.0; + if (destination_z < 0) destination_z = 0.0; + } + + if (max_software_endstops) { + if (destination_x > X_MAX_LENGTH) destination_x = X_MAX_LENGTH; + if (destination_y > Y_MAX_LENGTH) destination_y = Y_MAX_LENGTH; + if (destination_z > Z_MAX_LENGTH) destination_z = Z_MAX_LENGTH; + } + + if(feedrate > max_feedrate) feedrate = max_feedrate; +} + +void linear_move(unsigned long x_steps_remaining, unsigned long y_steps_remaining, unsigned long z_steps_remaining, unsigned long e_steps_remaining) // make linear move with preset speeds and destinations, see G0 and G1 +{ + //Determine direction of movement + if (destination_x > current_x) digitalWrite(X_DIR_PIN,HIGH); + else digitalWrite(X_DIR_PIN,LOW); + if (destination_y > current_y) digitalWrite(Y_DIR_PIN,HIGH); + else digitalWrite(Y_DIR_PIN,LOW); + if (destination_z > current_z) digitalWrite(Z_DIR_PIN,HIGH); + else digitalWrite(Z_DIR_PIN,LOW); + if (destination_e > current_e) digitalWrite(E_DIR_PIN,HIGH); + else digitalWrite(E_DIR_PIN,LOW); + + //Only enable axis that are moving. If the axis doesn't need to move then it can stay disabled depending on configuration. + if(x_steps_remaining) enable_x(); + if(y_steps_remaining) enable_y(); + if(z_steps_remaining) enable_z(); + if(e_steps_remaining) enable_e(); + + if(X_MIN_PIN > -1) if(!direction_x) if(digitalRead(X_MIN_PIN) != ENDSTOPS_INVERTING) x_steps_remaining=0; + if(Y_MIN_PIN > -1) if(!direction_y) if(digitalRead(Y_MIN_PIN) != ENDSTOPS_INVERTING) y_steps_remaining=0; + if(Z_MIN_PIN > -1) if(!direction_z) if(digitalRead(Z_MIN_PIN) != ENDSTOPS_INVERTING) z_steps_remaining=0; + + previous_millis_heater = millis(); + + //while(x_steps_remaining > 0 || y_steps_remaining > 0 || z_steps_remaining > 0 || e_steps_remaining > 0) // move until no more steps remain + while(x_steps_remaining + y_steps_remaining + z_steps_remaining + e_steps_remaining > 0) // move until no more steps remain + { + if(x_steps_remaining) { + if ((micros()-previous_micros_x) >= x_interval) { do_x_step(); x_steps_remaining--; } + if(X_MIN_PIN > -1) if(!direction_x) if(digitalRead(X_MIN_PIN) != ENDSTOPS_INVERTING) x_steps_remaining=0; + } + + if(y_steps_remaining) { + if ((micros()-previous_micros_y) >= y_interval) { do_y_step(); y_steps_remaining--; } + if(Y_MIN_PIN > -1) if(!direction_y) if(digitalRead(Y_MIN_PIN) != ENDSTOPS_INVERTING) y_steps_remaining=0; + } + + if(z_steps_remaining) { + if ((micros()-previous_micros_z) >= z_interval) { do_z_step(); z_steps_remaining--; } + if(Z_MIN_PIN > -1) if(!direction_z) if(digitalRead(Z_MIN_PIN) != ENDSTOPS_INVERTING) z_steps_remaining=0; + } + + if(e_steps_remaining) if ((micros()-previous_micros_e) >= e_interval) { do_e_step(); e_steps_remaining--; } + + if( (millis() - previous_millis_heater) >= 500 ) { + manage_heater(); + previous_millis_heater = millis(); + } + } + + if(DISABLE_X) disable_x(); + if(DISABLE_Y) disable_y(); + if(DISABLE_Z) disable_z(); + if(DISABLE_E) disable_e(); + + // Update current position partly based on direction, we probably can combine this with the direction code above... + if (destination_x > current_x) current_x = current_x + x_steps_to_take/x_steps_per_unit; + else current_x = current_x - x_steps_to_take/x_steps_per_unit; + if (destination_y > current_y) current_y = current_y + y_steps_to_take/y_steps_per_unit; + else current_y = current_y - y_steps_to_take/y_steps_per_unit; + if (destination_z > current_z) current_z = current_z + z_steps_to_take/z_steps_per_unit; + else current_z = current_z - z_steps_to_take/z_steps_per_unit; + if (destination_e > current_e) current_e = current_e + e_steps_to_take/e_steps_per_unit; + else current_e = current_e - e_steps_to_take/e_steps_per_unit; +} + + +inline void do_x_step() +{ + digitalWrite(X_STEP_PIN, HIGH); + previous_micros_x = micros(); + //delayMicroseconds(3); + digitalWrite(X_STEP_PIN, LOW); +} + +inline void do_y_step() +{ + digitalWrite(Y_STEP_PIN, HIGH); + previous_micros_y = micros(); + //delayMicroseconds(3); + digitalWrite(Y_STEP_PIN, LOW); +} + +inline void do_z_step() +{ + digitalWrite(Z_STEP_PIN, HIGH); + previous_micros_z = micros(); + //delayMicroseconds(3); + digitalWrite(Z_STEP_PIN, LOW); +} + +inline void do_e_step() +{ + digitalWrite(E_STEP_PIN, HIGH); + previous_micros_e = micros(); + //delayMicroseconds(3); + digitalWrite(E_STEP_PIN, LOW); +} + +inline void disable_x() { if(X_ENABLE_PIN > -1) digitalWrite(X_ENABLE_PIN,!X_ENABLE_ON); } +inline void disable_y() { if(Y_ENABLE_PIN > -1) digitalWrite(Y_ENABLE_PIN,!Y_ENABLE_ON); } +inline void disable_z() { if(Z_ENABLE_PIN > -1) digitalWrite(Z_ENABLE_PIN,!Z_ENABLE_ON); } +inline void disable_e() { if(E_ENABLE_PIN > -1) digitalWrite(E_ENABLE_PIN,!E_ENABLE_ON); } +inline void enable_x() { if(X_ENABLE_PIN > -1) digitalWrite(X_ENABLE_PIN, X_ENABLE_ON); } +inline void enable_y() { if(Y_ENABLE_PIN > -1) digitalWrite(Y_ENABLE_PIN, Y_ENABLE_ON); } +inline void enable_z() { if(Z_ENABLE_PIN > -1) digitalWrite(Z_ENABLE_PIN, Z_ENABLE_ON); } +inline void enable_e() { if(E_ENABLE_PIN > -1) digitalWrite(E_ENABLE_PIN, E_ENABLE_ON); } + +inline void manage_heater() +{ + current_raw = analogRead(TEMP_0_PIN); // If using thermistor, when the heater is colder than targer temp, we get a higher analog reading than target, + if(USE_THERMISTOR) current_raw = 1023 - current_raw; // this switches it up so that the reading appears lower than target for the control logic. + + if(current_raw >= target_raw) digitalWrite(HEATER_0_PIN,LOW); + else digitalWrite(HEATER_0_PIN,HIGH); +} + +// Takes temperature value as input and returns corresponding analog value from RepRap thermistor temp table. +// This is needed because PID in hydra firmware hovers around a given analog value, not a temp value. +// This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware. +float temp2analog(int celsius) { + if(USE_THERMISTOR) { + int raw = 0; + byte i; + + for (i=1; i raw) + { + celsius = temptable[i-1][1] + + (raw - temptable[i-1][0]) * + (temptable[i][1] - temptable[i-1][1]) / + (temptable[i][0] - temptable[i-1][0]); + + break; + } + } + + // Overflow: Set to last value in the table + if (i == NUMTEMPS) celsius = temptable[i-1][1]; + + return celsius; + + } else { + return raw * ((5.0*100.0)/1024.0); + } +} + +inline void kill() +{ + if(HEATER_0_PIN > -1) digitalWrite(HEATER_0_PIN,LOW); + + disable_x; + disable_y; + disable_z; + disable_e; + + if(PS_ON_PIN > -1) pinMode(PS_ON_PIN,INPUT); + + while(1) + { + Serial.print("Fatal Exception Shutdown, Last Line: "); + Serial.println(gcode_LastN); + delay(5000); // 5 Second delay + } +} diff --git a/Tonokip_Firmware/configuration.h b/Tonokip_Firmware/configuration.h new file mode 100644 index 0000000..fec610b --- /dev/null +++ b/Tonokip_Firmware/configuration.h @@ -0,0 +1,45 @@ +#ifndef PARAMETERS_H +#define PARAMETERS_H + +// NO RS485/EXTRUDER CONTROLLER SUPPORT +// PLEASE VERIFY PIN ASSIGNMENTS FOR YOUR CONFIGURATION!!!!!!! +#define MOTHERBOARD 4 // ATMEGA168 0, SANGUINO 1, MOTHERBOARD = 2, MEGA 3, ATMEGA328 4 + +// THERMOCOUPLE SUPPORT UNTESTED... USE WITH CAUTION!!!! +const bool USE_THERMISTOR = true; //Set to false if using thermocouple + +// Calibration formulas +// e_extruded_steps_per_mm = e_feedstock_steps_per_mm * (desired_extrusion_diameter^2 / feedstock_diameter^2) +// new_axis_steps_per_mm = previous_axis_steps_per_mm * (test_distance_instructed/test_distance_traveled) +// units are in millimeters or whatever length unit you prefer: inches,football-fields,parsecs etc + +//Calibration variables +float x_steps_per_unit = 10.047; +float y_steps_per_unit = 10.047; +float z_steps_per_unit = 833.398; +float e_steps_per_unit = 0.706; +float max_feedrate = 3000; + +//For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1 +const bool X_ENABLE_ON = 0; +const bool Y_ENABLE_ON = 0; +const bool Z_ENABLE_ON = 0; +const bool E_ENABLE_ON = 0; + +//Disables axis when it's not being used. +const bool DISABLE_X = false; +const bool DISABLE_Y = false; +const bool DISABLE_Z = true; +const bool DISABLE_E = false; + +//Endstop Settings +const bool ENDSTOPS_INVERTING = true; +const bool min_software_endstops = false; //If true, axis won't move to coordinates less than zero. +const bool max_software_endstops = true; //If true, axis won't move to coordinates greater than the defined lengths below. +const int X_MAX_LENGTH = 200; +const int Y_MAX_LENGTH = 200; +const int Z_MAX_LENGTH = 120; + +#define BAUDRATE 19200 + +#endif diff --git a/Tonokip_Firmware/pins.h b/Tonokip_Firmware/pins.h new file mode 100644 index 0000000..a585233 --- /dev/null +++ b/Tonokip_Firmware/pins.h @@ -0,0 +1,288 @@ +#ifndef PINS_H +#define PINS_H + +/**************************************************************************************** +* Arduino pin assignment +* +* ATMega168 +* +-\/-+ +* PC6 1| |28 PC5 (AI 5 / D19) +* (D 0) PD0 2| |27 PC4 (AI 4 / D18) +* (D 1) PD1 3| |26 PC3 (AI 3 / D17) +* (D 2) PD2 4| |25 PC2 (AI 2 / D16) +* PWM+ (D 3) PD3 5| |24 PC1 (AI 1 / D15) +* (D 4) PD4 6| |23 PC0 (AI 0 / D14) +* VCC 7| |22 GND +* GND 8| |21 AREF +* PB6 9| |20 AVCC +* PB7 10| |19 PB5 (D 13) +* PWM+ (D 5) PD5 11| |18 PB4 (D 12) +* PWM+ (D 6) PD6 12| |17 PB3 (D 11) PWM +* (D 7) PD7 13| |16 PB2 (D 10) PWM +* (D 8) PB0 14| |15 PB1 (D 9) PWM +* +----+ +****************************************************************************************/ +#if MOTHERBOARD == 0 +#ifndef __AVR_ATmega168__ +#error Oops! Make sure you have 'Arduino Diecimila' selected from the boards menu. +#endif + +#define X_STEP_PIN (byte)2 +#define X_DIR_PIN (byte)3 +#define X_ENABLE_PIN (byte)-1 +#define X_MIN_PIN (byte)4 +#define X_MAX_PIN (byte)9 + +#define Y_STEP_PIN (byte)10 +#define Y_DIR_PIN (byte)7 +#define Y_ENABLE_PIN (byte)-1 +#define Y_MIN_PIN (byte)8 +#define Y_MAX_PIN (byte)13 + +#define Z_STEP_PIN (byte)19 +#define Z_DIR_PIN (byte)18 +#define Z_ENABLE_PIN (byte)5 +#define Z_MIN_PIN (byte)17 +#define Z_MAX_PIN (byte)16 + +#define E_STEP_PIN (byte)11 +#define E_DIR_PIN (byte)12 +#define E_ENABLE_PIN (byte)-1 + +#define LED_PIN (byte)-1 +#define FAN_PIN (byte)-1 +#define PS_ON_PIN (byte)15 +#define KILL_PIN (byte)-1 + +#define HEATER_0_PIN (byte)6 +#define TEMP_0_PIN (byte)0 // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!! + + + + + + +/**************************************************************************************** +* Sanguino/RepRap Motherboard with direct-drive extruders +* +* ATMega644P +* +* +---\/---+ +* (D 0) PB0 1| |40 PA0 (AI 0 / D31) +* (D 1) PB1 2| |39 PA1 (AI 1 / D30) +* INT2 (D 2) PB2 3| |38 PA2 (AI 2 / D29) +* PWM (D 3) PB3 4| |37 PA3 (AI 3 / D28) +* PWM (D 4) PB4 5| |36 PA4 (AI 4 / D27) +* MOSI (D 5) PB5 6| |35 PA5 (AI 5 / D26) +* MISO (D 6) PB6 7| |34 PA6 (AI 6 / D25) +* SCK (D 7) PB7 8| |33 PA7 (AI 7 / D24) +* RST 9| |32 AREF +* VCC 10| |31 GND +* GND 11| |30 AVCC +* XTAL2 12| |29 PC7 (D 23) +* XTAL1 13| |28 PC6 (D 22) +* RX0 (D 8) PD0 14| |27 PC5 (D 21) TDI +* TX0 (D 9) PD1 15| |26 PC4 (D 20) TDO +* INT0 RX1 (D 10) PD2 16| |25 PC3 (D 19) TMS +* INT1 TX1 (D 11) PD3 17| |24 PC2 (D 18) TCK +* PWM (D 12) PD4 18| |23 PC1 (D 17) SDA +* PWM (D 13) PD5 19| |22 PC0 (D 16) SCL +* PWM (D 14) PD6 20| |21 PD7 (D 15) PWM +* +--------+ +* +****************************************************************************************/ +#elif MOTHERBOARD == 1 +#ifndef __AVR_ATmega644P__ +#error Oops! Make sure you have 'Sanguino' selected from the 'Tools -> Boards' menu. +#endif + +#define X_STEP_PIN (byte)15 +#define X_DIR_PIN (byte)18 +#define X_ENABLE_PIN (byte)19 +#define X_MIN_PIN (byte)20 +#define X_MAX_PIN (byte)21 + +#define Y_STEP_PIN (byte)23 +#define Y_DIR_PIN (byte)22 +#define Y_ENABLE_PIN (byte)19 +#define Y_MIN_PIN (byte)25 +#define Y_MAX_PIN (byte)26 + +#define Z_STEP_PIN (byte)29 +#define Z_DIR_PIN (byte)30 +#define Z_ENABLE_PIN (byte)31 +#define Z_MIN_PIN (byte)2 +#define Z_MAX_PIN (byte)1 + +#define E_STEP_PIN (byte)12 +#define E_DIR_PIN (byte)16 +#define E_ENABLE_PIN (byte)3 + +#define LED_PIN (byte)0 +#define FAN_PIN (byte)-1 +#define PS_ON_PIN (byte)-1 +#define KILL_PIN (byte)-1 + +#define HEATER_0_PIN (byte)14 +#define TEMP_0_PIN (byte)4 //D27 // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!! + +/* Unused (1) (2) (3) 4 5 6 7 8 9 10 11 12 13 (14) (15) (16) 17 (18) (19) (20) (21) (22) (23) 24 (25) (26) (27) 28 (29) (30) (31) */ + + + + + + +/**************************************************************************************** +* RepRap Motherboard ****---NOOOOOO RS485/EXTRUDER CONTROLLER!!!!!!!!!!!!!!!!!---******* +* +****************************************************************************************/ +#elif MOTHERBOARD == 2 +#ifndef __AVR_ATmega644P__ +#error Oops! Make sure you have 'Sanguino' selected from the 'Tools -> Boards' menu. +#endif + +#define X_STEP_PIN 15 +#define X_DIR_PIN 18 +#define X_ENABLE_PIN 19 +#define X_MIN_PIN 20 +#define X_MAX_PIN 21 + +#define Y_STEP_PIN 23 +#define Y_DIR_PIN 22 +#define Y_ENABLE_PIN 24 +#define Y_MIN_PIN 25 +#define Y_MAX_PIN 26 + +#define Z_STEP_PINN 27 +#define Z_DIR_PINN 28 +#define Z_ENABLE_PIN 29 +#define Z_MIN_PIN 30 +#define Z_MAX_PIN 31 + +#define E_STEP_PIN 17 +#define E_DIR_PIN 16 +#define E_ENABLE_PIN (byte)-1 + +#define LED_PIN 0 + +#define SD_CARD_WRITE 2 +#define SD_CARD_DETECT 3 +#define SD_CARD_SELECT 4 + +//our RS485 pins +#define TX_ENABLE_PIN 12 +#define RX_ENABLE_PIN 13 + +//pin for controlling the PSU. +#define PS_ON_PIN 14 + +#define FAN_PIN (byte)-1 +#define KILL_PIN (byte)-1 + +#define HEATER_0_PIN (byte)-1 +#define TEMP_0_PIN (byte)-1 // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!! + + + + + + +/**************************************************************************************** +* Arduino Mega pin assignment +* +****************************************************************************************/ +#elif MOTHERBOARD == 3 +#ifndef __AVR_ATmega1280__ +#error Oops! Make sure you have 'Arduino Mega' selected from the 'Tools -> Boards' menu. +#endif + +#define X_STEP_PIN (byte)22 +#define X_DIR_PIN (byte)23 +#define X_ENABLE_PIN (byte)24 +#define X_MIN_PIN (byte)2 +#define X_MAX_PIN (byte)3 + +#define Y_STEP_PIN (byte)25 +#define Y_DIR_PIN (byte)26 +#define Y_ENABLE_PIN (byte)27 +#define Y_MIN_PIN (byte)18 +#define Y_MAX_PIN (byte)19 + +#define Z_STEP_PIN (byte)28 +#define Z_DIR_PIN (byte)29 +#define Z_ENABLE_PIN (byte)30 +#define Z_MIN_PIN (byte)20 +#define Z_MAX_PIN (byte)21 + +#define E_STEP_PIN (byte)4 +#define E_DIR_PIN (byte)31 +#define E_ENABLE_PIN (byte)-1 + +#define LED_PIN (byte)-1 +#define FAN_PIN (byte)-1 +#define PS_ON_PIN (byte)10 +#define KILL_PIN (byte)-1 + +#define HEATER_0_PIN (byte)6 +#define TEMP_0_PIN (byte)0 // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!! + + + + + + +/**************************************************************************************** +* Duemilanove w/ ATMega328P pin assignment +* +****************************************************************************************/ +#elif MOTHERBOARD == 4 +#ifndef __AVR_ATmega328P__ +#error Oops! Make sure you have 'Arduino Duemilanove w/ ATMega328' selected from the 'Tools -> Boards' menu. +#endif + +#define X_STEP_PIN (byte)19 +#define X_DIR_PIN (byte)18 +#define X_ENABLE_PIN (byte)-1 +#define X_MIN_PIN (byte)17 +#define X_MAX_PIN (byte)-1 + +#define Y_STEP_PIN (byte)10 +#define Y_DIR_PIN (byte)7 +#define Y_ENABLE_PIN (byte)-1 +#define Y_MIN_PIN (byte)8 +#define Y_MAX_PIN (byte)-1 + +#define Z_STEP_PIN (byte)13 +#define Z_DIR_PIN (byte)3 +#define Z_ENABLE_PIN (byte)2 +#define Z_MIN_PIN (byte)4 +#define Z_MAX_PIN (byte)-1 + +//#define BASE_HEATER_PIN (byte)1 +//#define POWER_SUPPLY_PIN (byte)16 + +#define E_STEP_PIN (byte)11 +#define E_DIR_PIN (byte)12 +#define E_ENABLE_PIN (byte)-1 + +#define LED_PIN (byte)-1 +#define FAN_PIN (byte)5 +#define PS_ON_PIN (byte)-1 +#define KILL_PIN (byte)-1 + +#define HEATER_0_PIN (byte)6 +#define TEMP_0_PIN (byte)0 // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!! + + + + + + +#else + +#error Unknown MOTHERBOARD value in parameters.h + +#endif + +#endif -- cgit v1.2.1