From 69a148b0a5fce6afedb3398e277ea0c93f3b6b19 Mon Sep 17 00:00:00 2001 From: Christopher Keller Date: Sat, 7 May 2011 16:57:35 -0500 Subject: Cleaned up the MEGA1280 Added a RAMPS version #define in pins.h, so there are two clean/clear sections of pins for the RAMPS versions. Also added the Heater_1_Pin -1 to the RAMPS V1.0 section. --- Tonokip_Firmware/pins.h | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) (limited to 'Tonokip_Firmware') diff --git a/Tonokip_Firmware/pins.h b/Tonokip_Firmware/pins.h index 282961f..42845fd 100644 --- a/Tonokip_Firmware/pins.h +++ b/Tonokip_Firmware/pins.h @@ -210,51 +210,59 @@ #define X_DIR_PIN 28 #define X_ENABLE_PIN 24 #define X_MIN_PIN 3 -#define X_MAX_PIN -2 //2 +#define X_MAX_PIN -2 //2 #define Y_STEP_PIN 38 #define Y_DIR_PIN 40 #define Y_ENABLE_PIN 36 #define Y_MIN_PIN 16 -#define Y_MAX_PIN -1 //17 +#define Y_MAX_PIN -1 //17 #define Z_STEP_PIN 44 #define Z_DIR_PIN 46 #define Z_ENABLE_PIN 42 #define Z_MIN_PIN 18 -#define Z_MAX_PIN -1 //19 +#define Z_MAX_PIN -1 //19 #define E_STEP_PIN 32 #define E_DIR_PIN 34 #define E_ENABLE_PIN 30 -#define SDPOWER 48 -#define SDSS 53 +#define SDPOWER 48 +#define SDSS 53 #define LED_PIN 13 -//#define FAN_PIN 11 // UNCOMMENT THIS LINE FOR V1.0 -#define FAN_PIN 9 // THIS LINE FOR V1.1 - #define PS_ON_PIN -1 #define KILL_PIN -1 -//#define HEATER_0_PIN 12 // UNCOMMENT THIS LINE FOR V1.0 -#define HEATER_0_PIN 10 // THIS LINE FOR V1.1 -#define HEATER_1_PIN 8 // THIS LINE FOR V1.1 +// uncomment the following line for RAMPS V1.0 +// #define RAMPS_V_1_0 -#define TEMP_0_PIN 2 // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!! -#define TEMP_1_PIN 1 // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!! +#ifdef RAMPS_V_1_0 + #define HEATER_0_PIN 12 // RAMPS 1.0 + #define HEATER_1_PIN -1 // RAMPS 1.0 + #define FAN_PIN 11 // RAMPS 1.0 -#ifndef SDSUPPORT +#else // RAMPS_V_1_1 as default + #define HEATER_0_PIN 10 // RAMPS 1.1 + #define HEATER_1_PIN 8 // RAMPS 1.1 -// SPI for Max6675 Thermocouple (these pins are defined in the SD library if building with SD support). -#define SCK_PIN 52 -#define MISO_PIN 50 -#define MOSI_PIN 51 -#define MAX6675_SS 53 + #define FAN_PIN 9 // RAMPS 1.1 +#endif + +#define TEMP_0_PIN 2 // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!! +#define TEMP_1_PIN 1 // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!! + +// SPI for Max6675 Thermocouple + +#ifndef SDSUPPORT +// these pins are defined in the SD library if building with SD support #define SCK_PIN 52 + #define MISO_PIN 50 + #define MOSI_PIN 51 + #define MAX6675_SS 53 #else -#define MAX6675_SS 49 + #define MAX6675_SS 49 #endif -- cgit v1.2.1 From f2f0ebe09c10475fe30de1113e7c8fae0dab7da5 Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Wed, 11 May 2011 01:12:19 +0200 Subject: Dramatically decreased GCODE write time to SD --- Tonokip_Firmware/Tonokip_Firmware.pde | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Tonokip_Firmware') diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index 9c395f8..fa8c861 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -314,9 +314,9 @@ void loop() if(savetosd){ if(strstr(cmdbuffer[bufindr],"M29")==NULL){ write_command(cmdbuffer[bufindr]); - file.sync(); Serial.println("ok"); }else{ + file.sync(); // maybe this call is not needed file.close(); savetosd=false; Serial.println("Done saving file."); -- cgit v1.2.1 From 61cc2ef42ccdcc6edc21a0795c62bd02bd6aa4ca Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Wed, 11 May 2011 04:30:41 +0200 Subject: Added M201 and M202 to set max acceleration for respectively print and travel moves --- Tonokip_Firmware/Tonokip_Firmware.pde | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'Tonokip_Firmware') diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index fa8c861..4c645a5 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -84,7 +84,8 @@ void kill(byte debug); // M115 - Capabilities string // M140 - Set bed target temp // M190 - Wait for bed current temp to reach target temp. - +// M201 - Set max acceleration in units/s^2 for print moves (M201 X1000 Y1000) +// M202 - Set max acceleration in units/s^2 for travel moves (M202 X1000 Y1000) //Stepper Movement Variables @@ -813,6 +814,16 @@ inline void process_commands() Serial.print("E:"); Serial.println(current_e); break; + #ifdef RAMP_ACCELERATION + case 201: // M201 + if(code_seen('X')) x_steps_per_sqr_second = code_value() * x_steps_per_unit; + if(code_seen('Y')) x_steps_per_sqr_second = code_value() * y_steps_per_unit; + break; + case 202: // M202 + if(code_seen('X')) x_travel_steps_per_sqr_second = code_value() * x_steps_per_unit; + if(code_seen('Y')) x_travel_steps_per_sqr_second = code_value() * y_steps_per_unit; + break; + #endif } } -- cgit v1.2.1 From 7b44d14a539e55ec4fd6f31dac4a664e54b7ff76 Mon Sep 17 00:00:00 2001 From: Sam Ward Date: Wed, 11 May 2011 19:41:09 +0800 Subject: extra CRLF --- Tonokip_Firmware/Tonokip_Firmware.pde | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Tonokip_Firmware') diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index 9c395f8..79663fc 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -496,7 +496,8 @@ inline void process_commands() e_steps_to_take = abs(ediff)*e_steps_per_unit; if(feedrate<10) feedrate=10; - /*//experimental feedrate calc + /* + //experimental feedrate calc if(abs(xdiff)>0.1 && abs(ydiff)>0.1) d=sqrt(xdiff*xdiff+ydiff*ydiff); else if(abs(xdiff)>0.1) -- cgit v1.2.1 From ae03a834c47ace78fe11acf12b7452a08e4a787f Mon Sep 17 00:00:00 2001 From: Sam Ward Date: Wed, 11 May 2011 20:17:49 +0800 Subject: Moved function definitions into separate .h file for readability. --- Tonokip_Firmware/Tonokip_Firmware.h | 34 ++++++++++++++++++++++++++++++++++ Tonokip_Firmware/Tonokip_Firmware.pde | 34 +--------------------------------- 2 files changed, 35 insertions(+), 33 deletions(-) create mode 100644 Tonokip_Firmware/Tonokip_Firmware.h (limited to 'Tonokip_Firmware') diff --git a/Tonokip_Firmware/Tonokip_Firmware.h b/Tonokip_Firmware/Tonokip_Firmware.h new file mode 100644 index 0000000..151937c --- /dev/null +++ b/Tonokip_Firmware/Tonokip_Firmware.h @@ -0,0 +1,34 @@ +// Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware. +// Licence: GPL + +void get_command(); +void process_commands(); + +void manage_inactivity(byte debug); + +void manage_heater(); +float temp2analog(int celsius); +float temp2analogBed(int celsius); +float analog2temp(int raw); +float analog2tempBed(int raw); + +void FlushSerialRequestResend(); +void ClearToSend(); + +void get_coordinates(); +void linear_move(unsigned long x_steps_remaining, unsigned long y_steps_remaining, unsigned long z_steps_remaining, unsigned long e_steps_remaining); +void disable_x(); +void disable_y(); +void disable_z(); +void disable_e(); +void enable_x(); +void enable_y(); +void enable_z(); +void enable_e(); +void do_x_step(); +void do_y_step(); +void do_z_step(); +void do_e_step(); + +void kill(byte debug); + diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index 161f1b9..33c4297 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -1,6 +1,7 @@ // Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware. // Licence: GPL +#include "Tonokip_Firmware.h" #include "configuration.h" #include "pins.h" @@ -8,39 +9,6 @@ #include "SdFat.h" #endif -void get_command(); -void process_commands(); - -void manage_inactivity(byte debug); - -void manage_heater(); -float temp2analog(int celsius); -float temp2analogBed(int celsius); -float analog2temp(int raw); -float analog2tempBed(int raw); - -void FlushSerialRequestResend(); -void ClearToSend(); - -void get_coordinates(); -void linear_move(unsigned long x_steps_remaining, unsigned long y_steps_remaining, unsigned long z_steps_remaining, unsigned long e_steps_remaining); -void disable_x(); -void disable_y(); -void disable_z(); -void disable_e(); -void enable_x(); -void enable_y(); -void enable_z(); -void enable_e(); -void do_x_step(); -void do_y_step(); -void do_z_step(); -void do_e_step(); - -void kill(byte debug); - - - // look here for descriptions of gcodes: http://linuxcnc.org/handbook/gcode/g-code.html // http://objects.reprap.org/wiki/Mendel_User_Manual:_RepRapGCodes -- cgit v1.2.1 From 5f1c505fc9652cf2a4414efe054b435be4512108 Mon Sep 17 00:00:00 2001 From: Sam Ward Date: Wed, 11 May 2011 20:24:17 +0800 Subject: Cleaning up code formatting --- Tonokip_Firmware/Tonokip_Firmware.h | 1 + Tonokip_Firmware/Tonokip_Firmware.pde | 178 +++++++++++++++++----------------- 2 files changed, 89 insertions(+), 90 deletions(-) (limited to 'Tonokip_Firmware') diff --git a/Tonokip_Firmware/Tonokip_Firmware.h b/Tonokip_Firmware/Tonokip_Firmware.h index 151937c..65bfccd 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.h +++ b/Tonokip_Firmware/Tonokip_Firmware.h @@ -1,5 +1,6 @@ // Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware. // Licence: GPL +#include void get_command(); void process_commands(); diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index 33c4297..4dcd2aa 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -61,23 +61,23 @@ 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, previous_millis_bed_heater; unsigned long x_steps_to_take, y_steps_to_take, z_steps_to_take, e_steps_to_take; #ifdef RAMP_ACCELERATION -unsigned long max_x_interval = 100000000.0 / (min_units_per_second * x_steps_per_unit); -unsigned long max_y_interval = 100000000.0 / (min_units_per_second * y_steps_per_unit); -unsigned long max_interval; -unsigned long x_steps_per_sqr_second = max_acceleration_units_per_sq_second * x_steps_per_unit; -unsigned long y_steps_per_sqr_second = max_acceleration_units_per_sq_second * y_steps_per_unit; -unsigned long x_travel_steps_per_sqr_second = max_travel_acceleration_units_per_sq_second * x_steps_per_unit; -unsigned long y_travel_steps_per_sqr_second = max_travel_acceleration_units_per_sq_second * y_steps_per_unit; -unsigned long steps_per_sqr_second, plateau_steps; + unsigned long max_x_interval = 100000000.0 / (min_units_per_second * x_steps_per_unit); + unsigned long max_y_interval = 100000000.0 / (min_units_per_second * y_steps_per_unit); + unsigned long max_interval; + unsigned long x_steps_per_sqr_second = max_acceleration_units_per_sq_second * x_steps_per_unit; + unsigned long y_steps_per_sqr_second = max_acceleration_units_per_sq_second * y_steps_per_unit; + unsigned long x_travel_steps_per_sqr_second = max_travel_acceleration_units_per_sq_second * x_steps_per_unit; + unsigned long y_travel_steps_per_sqr_second = max_travel_acceleration_units_per_sq_second * y_steps_per_unit; + unsigned long steps_per_sqr_second, plateau_steps; #endif #ifdef EXP_ACCELERATION -unsigned long long_full_velocity_units = full_velocity_units * 100; -unsigned long long_travel_move_full_velocity_units = travel_move_full_velocity_units * 100; -unsigned long max_x_interval = 100000000.0 / (min_units_per_second * x_steps_per_unit); -unsigned long max_y_interval = 100000000.0 / (min_units_per_second * y_steps_per_unit); -unsigned long max_interval; -unsigned long x_min_constant_speed_steps = min_constant_speed_units * x_steps_per_unit, - y_min_constant_speed_steps = min_constant_speed_units * y_steps_per_unit, min_constant_speed_steps; + unsigned long long_full_velocity_units = full_velocity_units * 100; + unsigned long long_travel_move_full_velocity_units = travel_move_full_velocity_units * 100; + unsigned long max_x_interval = 100000000.0 / (min_units_per_second * x_steps_per_unit); + unsigned long max_y_interval = 100000000.0 / (min_units_per_second * y_steps_per_unit); + unsigned long max_interval; + unsigned long x_min_constant_speed_steps = min_constant_speed_units * x_steps_per_unit, + y_min_constant_speed_steps = min_constant_speed_units * y_steps_per_unit, min_constant_speed_steps; #endif boolean acceleration_enabled=false ,accelerating=false; unsigned long interval; @@ -91,7 +91,7 @@ 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. long timediff=0; #ifdef STEP_DELAY_RATIO -long long_step_delay_ratio = STEP_DELAY_RATIO * 100; + long long_step_delay_ratio = STEP_DELAY_RATIO * 100; #endif @@ -119,25 +119,25 @@ int target_bed_raw = 0; int current_bed_raw=0; float tt=0,bt=0; #ifdef PIDTEMP -int temp_iState=0; -int temp_dState=0; -int pTerm; -int iTerm; -int dTerm; - //int output; -int error; -int temp_iState_min = 100*-PID_INTEGRAL_DRIVE_MAX/PID_IGAIN; -int temp_iState_max = 100*PID_INTEGRAL_DRIVE_MAX/PID_IGAIN; + int temp_iState=0; + int temp_dState=0; + int pTerm; + int iTerm; + int dTerm; + //int output; + int error; + int temp_iState_min = 100*-PID_INTEGRAL_DRIVE_MAX/PID_IGAIN; + int temp_iState_max = 100*PID_INTEGRAL_DRIVE_MAX/PID_IGAIN; #endif #ifdef SMOOTHING -uint32_t nma=SMOOTHFACTOR*analogRead(TEMP_0_PIN); + uint32_t nma=SMOOTHFACTOR*analogRead(TEMP_0_PIN); #endif #ifdef WATCHPERIOD -int watch_raw=-1000; -unsigned long watchmillis=0; + int watch_raw=-1000; + unsigned long watchmillis=0; #endif #ifdef MINTEMP -int minttemp=temp2analog(MINTEMP); + int minttemp=temp2analog(MINTEMP); #endif //Inactivity shutdown variables @@ -146,56 +146,54 @@ unsigned long max_inactive_time = 0; unsigned long stepper_inactive_time = 0; #ifdef SDSUPPORT -Sd2Card card; -SdVolume volume; -SdFile root; -SdFile file; -uint32_t filesize=0; -uint32_t sdpos=0; -bool sdmode=false; -bool sdactive=false; -bool savetosd=false; -int16_t n; - -void initsd(){ -sdactive=false; -#if SDSS>-1 -if(root.isOpen()) - root.close(); -if (!card.init(SPI_FULL_SPEED,SDSS)){ - if (!card.init(SPI_HALF_SPEED,SDSS)) - Serial.println("SD init fail"); -} -else if (!volume.init(&card)) - Serial.println("volume.init failed"); -else if (!root.openRoot(&volume)) - Serial.println("openRoot failed"); -else - sdactive=true; -#endif -} - -inline void write_command(char *buf){ - char* begin=buf; - char* npos=0; - char* end=buf+strlen(buf)-1; - - file.writeError = false; - if((npos=strchr(buf, 'N')) != NULL){ - begin = strchr(npos,' ')+1; - end =strchr(npos, '*')-1; - } - end[1]='\r'; - end[2]='\n'; - end[3]='\0'; - //Serial.println(begin); - file.write(begin); - if (file.writeError){ - Serial.println("error writing to file"); + Sd2Card card; + SdVolume volume; + SdFile root; + SdFile file; + uint32_t filesize=0; + uint32_t sdpos=0; + bool sdmode=false; + bool sdactive=false; + bool savetosd=false; + int16_t n; + + void initsd(){ + sdactive=false; + #if SDSS>-1 + if(root.isOpen()) + root.close(); + if (!card.init(SPI_FULL_SPEED,SDSS)){ + if (!card.init(SPI_HALF_SPEED,SDSS)) + Serial.println("SD init fail"); } -} - - + else if (!volume.init(&card)) + Serial.println("volume.init failed"); + else if (!root.openRoot(&volume)) + Serial.println("openRoot failed"); + else + sdactive=true; + #endif + } + + inline void write_command(char *buf){ + char* begin=buf; + char* npos=0; + char* end=buf+strlen(buf)-1; + + file.writeError = false; + if((npos=strchr(buf, 'N')) != NULL){ + begin = strchr(npos,' ')+1; + end =strchr(npos, '*')-1; + } + end[1]='\r'; + end[2]='\n'; + end[3]='\0'; + //Serial.println(begin); + file.write(begin); + if (file.writeError){ + Serial.println("error writing to file"); + } + } #endif @@ -226,12 +224,12 @@ void setup() //endstop pullups #ifdef ENDSTOPPULLUPS - if(X_MIN_PIN > -1) { pinMode(X_MIN_PIN,INPUT); digitalWrite(X_MIN_PIN,HIGH);} - if(Y_MIN_PIN > -1) { pinMode(Y_MIN_PIN,INPUT); digitalWrite(Y_MIN_PIN,HIGH);} - if(Z_MIN_PIN > -1) { pinMode(Z_MIN_PIN,INPUT); digitalWrite(Z_MIN_PIN,HIGH);} - if(X_MAX_PIN > -1) { pinMode(X_MAX_PIN,INPUT); digitalWrite(X_MAX_PIN,HIGH);} - if(Y_MAX_PIN > -1) { pinMode(Y_MAX_PIN,INPUT); digitalWrite(Y_MAX_PIN,HIGH);} - if(Z_MAX_PIN > -1) { pinMode(Z_MAX_PIN,INPUT); digitalWrite(Z_MAX_PIN,HIGH);} + if(X_MIN_PIN > -1) { pinMode(X_MIN_PIN,INPUT); digitalWrite(X_MIN_PIN,HIGH);} + if(Y_MIN_PIN > -1) { pinMode(Y_MIN_PIN,INPUT); digitalWrite(Y_MIN_PIN,HIGH);} + if(Z_MIN_PIN > -1) { pinMode(Z_MIN_PIN,INPUT); digitalWrite(Z_MIN_PIN,HIGH);} + if(X_MAX_PIN > -1) { pinMode(X_MAX_PIN,INPUT); digitalWrite(X_MAX_PIN,HIGH);} + if(Y_MAX_PIN > -1) { pinMode(Y_MAX_PIN,INPUT); digitalWrite(Y_MAX_PIN,HIGH);} + if(Z_MAX_PIN > -1) { pinMode(Z_MAX_PIN,INPUT); digitalWrite(Z_MAX_PIN,HIGH);} #endif //Initialize Enable Pins if(X_ENABLE_PIN > -1) pinMode(X_ENABLE_PIN,OUTPUT); @@ -258,12 +256,12 @@ void setup() #ifdef SDSUPPORT -//power to SD reader -#if SDPOWER > -1 -pinMode(SDPOWER,OUTPUT); -digitalWrite(SDPOWER,HIGH); -#endif -initsd(); + //power to SD reader + #if SDPOWER > -1 + pinMode(SDPOWER,OUTPUT); + digitalWrite(SDPOWER,HIGH); + #endif + initsd(); #endif -- cgit v1.2.1