diff options
author | Emanuele Caruso <emanuele.caruso@gmail.com> | 2011-03-26 16:48:50 +0100 |
---|---|---|
committer | Emanuele Caruso <emanuele.caruso@gmail.com> | 2011-03-26 16:48:50 +0100 |
commit | 6d4dae1115cebc5e0ec986edd5f6f795e24b729c (patch) | |
tree | ec0f1a58f179f625de27b568d4f6a0820209bb24 | |
parent | cc6260bd71a2d33c04ec5e741b94a673d78c36e5 (diff) |
Added support for a heated bed thermistor that can be different from the hot-end thermistor
-rw-r--r-- | Tonokip_Firmware/BedThermistorTable.h | 33 | ||||
-rw-r--r-- | Tonokip_Firmware/Tonokip_Firmware.pde | 68 |
2 files changed, 98 insertions, 3 deletions
diff --git a/Tonokip_Firmware/BedThermistorTable.h b/Tonokip_Firmware/BedThermistorTable.h new file mode 100644 index 0000000..75ba458 --- /dev/null +++ b/Tonokip_Firmware/BedThermistorTable.h @@ -0,0 +1,33 @@ +// Thermistor lookup table for RepRap Temperature Sensor Boards (http://make.rrrf.org/ts) +// Made with createTemperatureLookup.py (http://svn.reprap.org/trunk/reprap/firmware/Arduino/utilities/createTemperatureLookup.py) +// ./createTemperatureLookup.py --r0=10000 --t0=25 --r1=0 --r2=4700 --beta=3977 --max-adc=1023 +// r0: 10000 +// t0: 25 +// r1: 0 +// r2: 4700 +// beta: 3977 +// max adc: 1023 +#define NUMTEMPS 20 +short bedtemptable[NUMTEMPS][2] = { + {1, 430}, + {54, 137}, + {107, 107}, + {160, 91}, + {213, 80}, + {266, 71}, + {319, 64}, + {372, 57}, + {425, 51}, + {478, 46}, + {531, 41}, + {584, 35}, + {637, 30}, + {690, 25}, + {743, 20}, + {796, 14}, + {849, 7}, + {902, 0}, + {955, -11}, + {1008, -35} +}; + diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index fc106b6..27e552f 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -4,6 +4,7 @@ #include "configuration.h" #include "pins.h" #include "ThermistorTable.h" +#include "BedThermistorTable.h" #ifdef SDSUPPORT #include "SdFat.h" #endif @@ -504,13 +505,13 @@ inline void process_commands() if (code_seen('S')) target_raw = temp2analog(code_value()); break; case 140: // M140 set bed temp - if (code_seen('S')) target_bed_raw = temp2analog(code_value()); + if (code_seen('S')) target_bed_raw = temp2analogBed(code_value()); break; case 105: // M105 Serial.print("T:"); Serial.println( analog2temp(analogRead(TEMP_0_PIN)) ); Serial.print("Bed:"); - Serial.println( analog2temp(analogRead(TEMP_1_PIN)) ); + Serial.println( analog2tempBed(analogRead(TEMP_1_PIN)) ); if(!code_seen('N')) { return; // If M105 is sent from generated gcode, then it needs a response. } @@ -776,7 +777,7 @@ inline void manage_heater() } } -// Takes temperature value as input and returns corresponding analog value from RepRap thermistor temp table. +// Takes hot end 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) { @@ -806,7 +807,38 @@ float temp2analog(int celsius) { } } +// Takes bed 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 temp2analogBed(int celsius) { + if(USE_THERMISTOR) { + int raw = 0; + byte i; + + for (i=1; i<NUMTEMPS; i++) + { + if (bedtemptable[i][1] < celsius) + { + raw = bedtemptable[i-1][0] + + (celsius - bedtemptable[i-1][1]) * + (bedtemptable[i][0] - bedtemptable[i-1][0]) / + (bedtemptable[i][1] - bedtemptable[i-1][1]); + + break; + } + } + + // Overflow: Set to last value in the table + if (i == NUMTEMPS) raw = bedtemptable[i-1][0]; + + return 1023 - raw; + } else { + return celsius * (1024.0/(5.0*100.0)); + } +} + // Derived from RepRap FiveD extruder::getTemperature() +// For hot end thermistor. float analog2temp(int raw) { if(USE_THERMISTOR) { int celsius = 0; @@ -835,6 +867,36 @@ float analog2temp(int raw) { } } +// Derived from RepRap FiveD extruder::getTemperature() +// For bed thermistor. +float analog2tempBed(int raw) { + if(USE_THERMISTOR) { + int celsius = 0; + byte i; + + for (i=1; i<NUMTEMPS; i++) + { + if (bedtemptable[i][0] > raw) + { + celsius = bedtemptable[i-1][1] + + (raw - bedtemptable[i-1][0]) * + (bedtemptable[i][1] - bedtemptable[i-1][1]) / + (bedtemptable[i][0] - bedtemptable[i-1][0]); + + break; + } + } + + // Overflow: Set to last value in the table + if (i == NUMTEMPS) celsius = bedtemptable[i-1][1]; + + return celsius; + + } else { + return raw * ((5.0*100.0)/1024.0); + } +} + inline void kill(byte debug) { if(HEATER_0_PIN > -1) digitalWrite(HEATER_0_PIN,LOW); |