From ef8099b6dd474a5630bfec49538c88c8b05e97e1 Mon Sep 17 00:00:00 2001 From: kliment Date: Wed, 27 Apr 2011 23:30:58 +0200 Subject: Added PWM control to fan pin, added smoothing code for erratic gen6 temp readings --- Tonokip_Firmware/Tonokip_Firmware.pde | 19 +++++++++++++++++-- Tonokip_Firmware/configuration.h | 4 ++++ 2 files changed, 21 insertions(+), 2 deletions(-) (limited to 'Tonokip_Firmware') diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index d838d7a..a7c748f 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -103,6 +103,10 @@ 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); +#endif + //Inactivity shutdown variables @@ -653,9 +657,15 @@ inline void process_commands() } break; case 106: //M106 Fan On - digitalWrite(FAN_PIN, HIGH); + if (code_seen('S')) + digitalWrite(FAN_PIN, HIGH); + analogWrite(FAN_PIN,constrain(code_value(),0,255)); + else + digitalWrite(FAN_PIN, HIGH); break; case 107: //M107 Fan Off + analogWrite(FAN_PIN, 0); + digitalWrite(FAN_PIN, LOW); break; case 80: // M81 - ATX Power On @@ -1049,6 +1059,8 @@ inline int read_max6675() return max6675_temp; } #endif + + inline void manage_heater() { #ifdef HEATER_USES_THERMISTOR @@ -1061,7 +1073,10 @@ inline void manage_heater() #elif defined HEATER_USES_MAX6675 current_raw = read_max6675(); #endif - + #ifdef SMOOTHING + nma=(nma+current_raw)-(nma/SMOOTHFACTOR); + current_raw=nma/SMOOTHFACTOR; + #endif #if (TEMP_0_PIN > -1) || defined (HEATER_USES_MAX66675) #ifdef PIDTEMP error = target_raw - current_raw; diff --git a/Tonokip_Firmware/configuration.h b/Tonokip_Firmware/configuration.h index 819c2c3..8f8dbb0 100644 --- a/Tonokip_Firmware/configuration.h +++ b/Tonokip_Firmware/configuration.h @@ -26,6 +26,10 @@ float min_constant_speed_units = 0.6; // the minimum units of an accelerated mov #define PID_DGAIN 100 //100 is 1.0 #endif +//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 + // Select one of these only to define how the nozzle temp is read. #define HEATER_USES_THERMISTOR //#define HEATER_USES_AD595 -- cgit v1.2.1