From 038fccd7a122c9beefc28acaf4d57b96ed143c4b Mon Sep 17 00:00:00 2001 From: Dino Del Favero Date: Tue, 6 Jan 2015 18:32:17 +0100 Subject: [PATCH] =?UTF-8?q?I=20have=20added=20some=20code=20in=20the=20"te?= =?UTF-8?q?mperature.cpp"=20for=20have=20the=20possibility=20of=20control?= =?UTF-8?q?=20the=20time=20of=20the=20states=20with=20the=20heater=20drive?= =?UTF-8?q?d=20by=20relays,=20with=20this=20feature=20now=20it=20is=20poss?= =?UTF-8?q?ible=20use=20PID=20function=20in=20conjunction=20with=20relay?= =?UTF-8?q?=20to=20control=20the=20temperature.=20I=20have=20made=20some?= =?UTF-8?q?=20tests=20and=20the=20temperature=20stay=20always=20in=20the?= =?UTF-8?q?=20range=20of=20+-1=C2=B0C=20from=20the=20setted=20temp.=20Ther?= =?UTF-8?q?e=20is=20the=20possibility=20of=20turn=20on=20this=20features?= =?UTF-8?q?=20adding=20"#define=20SLOW=5FPWM=5FHEATERS"=20in=20Configurati?= =?UTF-8?q?on.h?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/temperature.cpp | 311 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 277 insertions(+), 34 deletions(-) diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 7acc5ffd8..8bdb7647f 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -497,7 +497,7 @@ void manage_heater() SERIAL_ECHO(" iTerm "); SERIAL_ECHO(iTerm[e]); SERIAL_ECHO(" dTerm "); - SERIAL_ECHOLN(dTerm[e]); + SERIAL_ECHOLN(dTerm[e]); #endif //PID_DEBUG #else /* PID off */ pid_output = 0; @@ -1221,68 +1221,311 @@ ISR(TIMER0_COMPB_vect) static unsigned char temp_state = 10; static unsigned char pwm_count = (1 << SOFT_PWM_SCALE); static unsigned char soft_pwm_0; - #if (EXTRUDERS > 1) || defined(HEATERS_PARALLEL) +#ifdef SLOW_PWM_HEATERS + static unsigned char slow_pwm_count = 0; + static unsigned char state_heater_0 = 0; + static unsigned char state_timer_heater_0 = 0; +#endif +#if (EXTRUDERS > 1) || defined(HEATERS_PARALLEL) static unsigned char soft_pwm_1; - #endif - #if EXTRUDERS > 2 +#ifdef SLOW_PWM_HEATERS + static unsigned char state_heater_1 = 0; + static unsigned char state_timer_heater_1 = 0; +#endif +#endif +#if EXTRUDERS > 2 static unsigned char soft_pwm_2; - #endif - #if HEATER_BED_PIN > -1 +#ifdef SLOW_PWM_HEATERS + static unsigned char state_heater_2 = 0; + static unsigned char state_timer_heater_2 = 0; +#endif +#endif +#if HEATER_BED_PIN > -1 static unsigned char soft_pwm_b; - #endif +#ifdef SLOW_PWM_HEATERS + static unsigned char state_heater_b = 0; + static unsigned char state_timer_heater_b = 0; +#endif +#endif - #if defined(FILWIDTH_PIN) &&(FILWIDTH_PIN > -1) - static unsigned long raw_filwidth_value = 0; //added for filament width sensor - #endif +#if defined(FILWIDTH_PIN) &&(FILWIDTH_PIN > -1) + static unsigned long raw_filwidth_value = 0; //added for filament width sensor +#endif +#ifndef SLOW_PWM_HEATERS + /* + * standard PWM modulation + */ if(pwm_count == 0){ soft_pwm_0 = soft_pwm[0]; if(soft_pwm_0 > 0) { WRITE(HEATER_0_PIN,1); - #ifdef HEATERS_PARALLEL +#ifdef HEATERS_PARALLEL WRITE(HEATER_1_PIN,1); - #endif +#endif } else WRITE(HEATER_0_PIN,0); - - #if EXTRUDERS > 1 + +#if EXTRUDERS > 1 soft_pwm_1 = soft_pwm[1]; if(soft_pwm_1 > 0) WRITE(HEATER_1_PIN,1); else WRITE(HEATER_1_PIN,0); - #endif - #if EXTRUDERS > 2 +#endif +#if EXTRUDERS > 2 soft_pwm_2 = soft_pwm[2]; if(soft_pwm_2 > 0) WRITE(HEATER_2_PIN,1); else WRITE(HEATER_2_PIN,0); - #endif - #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 +#endif +#if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 soft_pwm_b = soft_pwm_bed; if(soft_pwm_b > 0) WRITE(HEATER_BED_PIN,1); else WRITE(HEATER_BED_PIN,0); - #endif - #ifdef FAN_SOFT_PWM +#endif +#ifdef FAN_SOFT_PWM soft_pwm_fan = fanSpeedSoftPwm / 2; if(soft_pwm_fan > 0) WRITE(FAN_PIN,1); else WRITE(FAN_PIN,0); - #endif +#endif } if(soft_pwm_0 < pwm_count) { - WRITE(HEATER_0_PIN,0); - #ifdef HEATERS_PARALLEL - WRITE(HEATER_1_PIN,0); - #endif - } - #if EXTRUDERS > 1 + WRITE(HEATER_0_PIN,0); +#ifdef HEATERS_PARALLEL + WRITE(HEATER_1_PIN,0); +#endif + } +#if EXTRUDERS > 1 if(soft_pwm_1 < pwm_count) WRITE(HEATER_1_PIN,0); - #endif - #if EXTRUDERS > 2 +#endif +#if EXTRUDERS > 2 if(soft_pwm_2 < pwm_count) WRITE(HEATER_2_PIN,0); - #endif - #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 +#endif +#if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 if(soft_pwm_b < pwm_count) WRITE(HEATER_BED_PIN,0); - #endif - #ifdef FAN_SOFT_PWM +#endif +#ifdef FAN_SOFT_PWM if(soft_pwm_fan < pwm_count) WRITE(FAN_PIN,0); - #endif +#endif + + pwm_count += (1 << SOFT_PWM_SCALE); + pwm_count &= 0x7f; + +#else //ifndef SLOW_PWM_HEATERS + /* + * SLOW PWM HEATERS + * + * for heaters drived by relay + */ +#ifndef MIN_STATE_TIME +#define MIN_STATE_TIME 16 // MIN_STATE_TIME * 65.5 = time in milliseconds +#endif + if (slow_pwm_count == 0) { + // EXTRUDER 0 + soft_pwm_0 = soft_pwm[0]; + if (soft_pwm_0 > 0) { + // turn ON heather only if the minimum time is up + if (state_timer_heater_0 == 0) { + // if change state set timer + if (state_heater_0 == 0) { + state_timer_heater_0 = MIN_STATE_TIME; + } + state_heater_0 = 1; + WRITE(HEATER_0_PIN, 1); +#ifdef HEATERS_PARALLEL + WRITE(HEATER_1_PIN, 1); +#endif + } + } else { + // turn OFF heather only if the minimum time is up + if (state_timer_heater_0 == 0) { + // if change state set timer + if (state_heater_0 == 1) { + state_timer_heater_0 = MIN_STATE_TIME; + } + state_heater_0 = 0; + WRITE(HEATER_0_PIN, 0); +#ifdef HEATERS_PARALLEL + WRITE(HEATER_1_PIN, 0); +#endif + } + } + +#if EXTRUDERS > 1 + // EXTRUDER 1 + soft_pwm_1 = soft_pwm[1]; + if (soft_pwm_1 > 0) { + // turn ON heather only if the minimum time is up + if (state_timer_heater_1 == 0) { + // if change state set timer + if (state_heater_1 == 0) { + state_timer_heater_1 = MIN_STATE_TIME; + } + state_heater_1 = 1; + WRITE(HEATER_1_PIN, 1); + } + } else { + // turn OFF heather only if the minimum time is up + if (state_timer_heater_1 == 0) { + // if change state set timer + if (state_heater_1 == 1) { + state_timer_heater_1 = MIN_STATE_TIME; + } + state_heater_1 = 0; + WRITE(HEATER_1_PIN, 0); + } + } +#endif + +#if EXTRUDERS > 2 + // EXTRUDER 2 + soft_pwm_2 = soft_pwm[2]; + if (soft_pwm_2 > 0) { + // turn ON heather only if the minimum time is up + if (state_timer_heater_2 == 0) { + // if change state set timer + if (state_heater_2 == 0) { + state_timer_heater_2 = MIN_STATE_TIME; + } + state_heater_2 = 1; + WRITE(HEATER_2_PIN, 1); + } + } else { + // turn OFF heather only if the minimum time is up + if (state_timer_heater_2 == 0) { + // if change state set timer + if (state_heater_2 == 1) { + state_timer_heater_2 = MIN_STATE_TIME; + } + state_heater_2 = 0; + WRITE(HEATER_2_PIN, 0); + } + } +#endif + +#if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 + // BED + soft_pwm_b = soft_pwm_bed; + if (soft_pwm_b > 0) { + // turn ON heather only if the minimum time is up + if (state_timer_heater_b == 0) { + // if change state set timer + if (state_heater_b == 0) { + state_timer_heater_b = MIN_STATE_TIME; + } + state_heater_b = 1; + WRITE(HEATER_BED_PIN, 1); + } + } else { + // turn OFF heather only if the minimum time is up + if (state_timer_heater_b == 0) { + // if change state set timer + if (state_heater_b == 1) { + state_timer_heater_b = MIN_STATE_TIME; + } + state_heater_b = 0; + WRITE(HEATER_BED_PIN, 0); + } + } +#endif + } // if (slow_pwm_count == 0) + + // EXTRUDER 0 + if (soft_pwm_0 < slow_pwm_count) { + // turn OFF heather only if the minimum time is up + if (state_timer_heater_0 == 0) { + // if change state set timer + if (state_heater_0 == 1) { + state_timer_heater_0 = MIN_STATE_TIME; + } + state_heater_0 = 0; + WRITE(HEATER_0_PIN, 0); +#ifdef HEATERS_PARALLEL + WRITE(HEATER_1_PIN, 0); +#endif + } + } + +#if EXTRUDERS > 1 + // EXTRUDER 1 + if (soft_pwm_1 < slow_pwm_count) { + // turn OFF heather only if the minimum time is up + if (state_timer_heater_1 == 0) { + // if change state set timer + if (state_heater_1 == 1) { + state_timer_heater_1 = MIN_STATE_TIME; + } + state_heater_1 = 0; + WRITE(HEATER_1_PIN, 0); + } + } +#endif + +#if EXTRUDERS > 2 + // EXTRUDER 2 + if (soft_pwm_2 < slow_pwm_count) { + // turn OFF heather only if the minimum time is up + if (state_timer_heater_2 == 0) { + // if change state set timer + if (state_heater_2 == 1) { + state_timer_heater_2 = MIN_STATE_TIME; + } + state_heater_2 = 0; + WRITE(HEATER_2_PIN, 0); + } + } +#endif + +#if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 + // BED + if (soft_pwm_b < slow_pwm_count) { + // turn OFF heather only if the minimum time is up + if (state_timer_heater_b == 0) { + // if change state set timer + if (state_heater_b == 1) { + state_timer_heater_b = MIN_STATE_TIME; + } + state_heater_b = 0; + WRITE(HEATER_BED_PIN, 0); + } + } +#endif + +#ifdef FAN_SOFT_PWM + if (pwm_count == 0){ + soft_pwm_fan = fanSpeedSoftPwm / 2; + if (soft_pwm_fan > 0) WRITE(FAN_PIN,1); else WRITE(FAN_PIN,0); + } + if (soft_pwm_fan < pwm_count) WRITE(FAN_PIN,0); +#endif pwm_count += (1 << SOFT_PWM_SCALE); pwm_count &= 0x7f; + // increment slow_pwm_count only every 64 pwm_count circa 65.5ms + if ((pwm_count % 64) == 0) { + slow_pwm_count++; + slow_pwm_count &= 0x7f; + + // Extruder 0 + if (state_timer_heater_0 > 0) { + state_timer_heater_0--; + } + +#if EXTRUDERS > 1 + // Extruder 1 + if (state_timer_heater_1 > 0) + state_timer_heater_1--; +#endif + +#if EXTRUDERS > 2 + // Extruder 2 + if (state_timer_heater_2 > 0) + state_timer_heater_2--; +#endif + +#if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 + // Bed + if (state_timer_heater_b > 0) + state_timer_heater_b--; +#endif + } //if ((pwm_count % 64) == 0) { + +#endif //ifndef SLOW_PWM_HEATERS + switch(temp_state) { case 0: // Prepare TEMP_0 #if defined(TEMP_0_PIN) && (TEMP_0_PIN > -1)