From 484b3b087e5070604efd731c6533fa960fe442fe Mon Sep 17 00:00:00 2001 From: kliment Date: Sun, 15 May 2011 14:08:04 +0200 Subject: Make temperature check interval constant regardless of whether a move is happening or not - this improved PID performance Make temp check interval configurable. Make temp tables static to save RAM. --- Tonokip_Firmware/BedThermistorTable_100k.h | 2 +- Tonokip_Firmware/BedThermistorTable_200k.h | 2 +- Tonokip_Firmware/ThermistorTable_100k.h | 2 +- Tonokip_Firmware/ThermistorTable_200k.h | 2 +- Tonokip_Firmware/ThermistorTable_mendelparts.h | 63 ++++++++++++++++---------- Tonokip_Firmware/Tonokip_Firmware.pde | 48 +++++++++++++------- Tonokip_Firmware/configuration.h | 3 ++ 7 files changed, 76 insertions(+), 46 deletions(-) diff --git a/Tonokip_Firmware/BedThermistorTable_100k.h b/Tonokip_Firmware/BedThermistorTable_100k.h index f607f4e..84bc607 100644 --- a/Tonokip_Firmware/BedThermistorTable_100k.h +++ b/Tonokip_Firmware/BedThermistorTable_100k.h @@ -15,7 +15,7 @@ // max adc: 1023 #define BNUMTEMPS 61 -short bedtemptable[BNUMTEMPS][2] = { +const short bedtemptable[BNUMTEMPS][2] = { { 23 , 300 }, { 25 , 295 }, { 27 , 290 }, diff --git a/Tonokip_Firmware/BedThermistorTable_200k.h b/Tonokip_Firmware/BedThermistorTable_200k.h index 79c9ea4..3d96aa3 100644 --- a/Tonokip_Firmware/BedThermistorTable_200k.h +++ b/Tonokip_Firmware/BedThermistorTable_200k.h @@ -15,7 +15,7 @@ // max adc: 1023 #define BNUMTEMPS 20 -short bedtemptable[BNUMTEMPS][2] = { +const short bedtemptable[BNUMTEMPS][2] = { {1, 848}, {54, 275}, {107, 228}, diff --git a/Tonokip_Firmware/ThermistorTable_100k.h b/Tonokip_Firmware/ThermistorTable_100k.h index 3762b6a..d0698b2 100644 --- a/Tonokip_Firmware/ThermistorTable_100k.h +++ b/Tonokip_Firmware/ThermistorTable_100k.h @@ -15,7 +15,7 @@ // max adc: 1023 #define NUMTEMPS 61 -short temptable[NUMTEMPS][2] = { +const short temptable[NUMTEMPS][2] = { { 23 , 300 }, { 25 , 295 }, { 27 , 290 }, diff --git a/Tonokip_Firmware/ThermistorTable_200k.h b/Tonokip_Firmware/ThermistorTable_200k.h index ef68b5f..4142eb2 100644 --- a/Tonokip_Firmware/ThermistorTable_200k.h +++ b/Tonokip_Firmware/ThermistorTable_200k.h @@ -15,7 +15,7 @@ // max adc: 1023 #define NUMTEMPS 20 -short temptable[NUMTEMPS][2] = { +const short temptable[NUMTEMPS][2] = { {1, 848}, {54, 275}, {107, 228}, diff --git a/Tonokip_Firmware/ThermistorTable_mendelparts.h b/Tonokip_Firmware/ThermistorTable_mendelparts.h index 68766ad..9e65b85 100644 --- a/Tonokip_Firmware/ThermistorTable_mendelparts.h +++ b/Tonokip_Firmware/ThermistorTable_mendelparts.h @@ -2,31 +2,44 @@ #define THERMISTORTABLE_H_ //thermistor table for mendel-parts thermistor - -#define NUMTEMPS 20 -short temptable[NUMTEMPS][2] = { - {1, 827}, - {54, 253}, - {107, 207}, - {160, 182}, - {213, 165}, - {266, 152}, - {319, 141}, - {372, 132}, - {425, 123}, - {478, 115}, - {531, 107}, - {584, 100}, - {637, 93}, - {690, 86}, - {743, 78}, - {796, 70}, - {849, 61}, - {902, 49}, - {955, 34}, - {1008, 3} -}; +// Standardized R/T characteristic no. 8404 + // RS thermistor 484-0183; EPCOS NTC + // Mendel-Parts thermistor G540 / G550 + // Optimized for 100...300C working range. + // Max range: -20...300C + // Max reading error on Gen 6 electronics: ~+5%, -3% in 100 - 300C range. + +#define NUMTEMPS 28 +const short temptable[NUMTEMPS][2] = { + {1,864}, + {21,300}, + {25,290}, + {29,280}, + {33,270}, + {39,260}, + {46,250}, + {54,240}, + {64,230}, + {75,220}, + {90,210}, + {107,200}, + {128,190}, + {154,180}, + {184,170}, + {221,160}, + {265,150}, + {316,140}, + {375,130}, + {441,120}, + {513,110}, + {588,100}, + {734,80}, + {856,60}, + {938,40}, + {986,20}, + {1008,0}, + {1018,-20} + }; #endif - diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index 4fa24a9..70a4ac9 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -297,11 +297,14 @@ void loop() buflen = (buflen-1); bufindr = (bufindr + 1)%BUFSIZE; } - - manage_heater(); - - manage_inactivity(1); //shutdown if not receiving any new commands -} + //check heater every n milliseconds + if((millis() - previous_millis_heater) >= HEATER_CHECK_INTERVAL ) { + manage_heater(); + previous_millis_heater = millis(); + + manage_inactivity(1); + } + } inline void get_command() @@ -462,8 +465,13 @@ inline void process_commands() 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 + codenum += millis(); // keep track of when we started waiting + while(millis() < codenum ){ + if((millis() - previous_millis_heater) >= HEATER_CHECK_INTERVAL ) { + manage_heater(); + previous_millis_heater = millis(); + } + } break; case 28: //G28 Home all Axis one at a time saved_feedrate = feedrate; @@ -691,23 +699,26 @@ inline void process_commands() watchmillis = 0; } #endif - previous_millis_heater = millis(); + codenum = millis(); while(current_raw < target_raw) { - if( (millis() - previous_millis_heater) > 1000 ) //Print Temp Reading every 1 second while heating up. + if( (millis() - codenum) > 1000 ) //Print Temp Reading every 1 second while heating up. { Serial.print("T:"); Serial.println( analog2temp(current_raw) ); - previous_millis_heater = millis(); + codenum = millis(); + } + if((millis() - previous_millis_heater) >= HEATER_CHECK_INTERVAL ) { + manage_heater(); + previous_millis_heater = millis(); } - manage_heater(); } break; case 190: // M190 - Wait bed for heater to reach target. #if TEMP_1_PIN > -1 if (code_seen('S')) target_bed_raw = temp2analog(code_value()); - previous_millis_heater = millis(); + codenum = millis(); while(current_bed_raw < target_bed_raw) { - if( (millis()-previous_millis_heater) > 1000 ) //Print Temp Reading every 1 second while heating up. + if( (millis()-codenum) > 1000 ) //Print Temp Reading every 1 second while heating up. { tt=analog2temp(current_raw); Serial.print("T:"); @@ -716,9 +727,12 @@ inline void process_commands() Serial.print( tt ); Serial.print(" B:"); Serial.println( analog2temp(current_bed_raw) ); - previous_millis_heater = millis(); + codenum = millis(); + } + if((millis() - previous_millis_heater) >= HEATER_CHECK_INTERVAL ) { + manage_heater(); + previous_millis_heater = millis(); } - manage_heater(); } #endif break; @@ -1069,8 +1083,8 @@ void linear_move(unsigned long x_steps_remaining, unsigned long y_steps_remainin //move until no more steps remain while(x_steps_remaining + y_steps_remaining + z_steps_remaining + e_steps_remaining > 0) { - //If more that 50ms have passed since previous heating check, adjust temp - if((millis() - previous_millis_heater) >= 50 ) { + //If more that HEATER_CHECK_INTERVAL ms have passed since previous heating check, adjust temp + if((millis() - previous_millis_heater) >= HEATER_CHECK_INTERVAL ) { manage_heater(); previous_millis_heater = millis(); diff --git a/Tonokip_Firmware/configuration.h b/Tonokip_Firmware/configuration.h index 47466ae..8ef28e4 100644 --- a/Tonokip_Firmware/configuration.h +++ b/Tonokip_Firmware/configuration.h @@ -50,6 +50,9 @@ float min_constant_speed_units = 2; // the minimum units of an accelerated move #define PID_DGAIN 100 //100 is 1.0 #endif +//How often should the heater check for new temp readings, in milliseconds +#define HEATER_CHECK_INTERVAL 50 + //Experimental temperature smoothing - only uncomment this if your temp readings are noisy //#define SMOOTHING 1 //#define SMOOTHFACTOR 16 //best to use a power of two here - determines how many values are averaged together by the smoothing algorithm -- cgit v1.2.1