From 5c3c839e7349367eb9c6f4102506f6a276114e5b Mon Sep 17 00:00:00 2001 From: Nidan Date: Sun, 24 Feb 2013 21:12:00 +0100 Subject: [PATCH] things --- firmware/cup.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/firmware/cup.c b/firmware/cup.c index 69a4908..1858121 100644 --- a/firmware/cup.c +++ b/firmware/cup.c @@ -14,7 +14,7 @@ #define TIMEOUT 51 /* 2 seconds */ const uint16_t LED_GREEN_TEMP = 300; -const uint16_t LED_RED_TEMP = 1200; +const uint16_t LED_RED_TEMP = 1000; #define TARGET_TEMP_MIN 300 #define TARGET_TEMP_MAX 1520 @@ -62,16 +62,20 @@ ISR(TIM1_OVF_vect) /* incremtening softpwm, toggling output if needed */ heat_pwm++; - if(heat_pwm <= heat_power) - { - PORTB |= (1 << FET0_PIN); - } else { + if(heat_pwm == 0 && heat_power > 0) + { + PORTB |= (1 << FET0_PIN); + } + else if(heat_pwm > heat_power) + { PORTB &= ~(1 << FET0_PIN); } - if( ((heat_pwm + 128)&0xff) <= heat_power ) - { - PORTB |= (1 << FET1_PIN); - } else { + if(heat_pwm == 128 && heat_power > 0) + { + PORTB |= (1 << FET1_PIN); + } + else if( ((heat_pwm + 128) & 0xff) > heat_power ) + { PORTB &= ~(1 << FET1_PIN); } @@ -113,11 +117,11 @@ inline uint8_t control_output(void) } else if(temperature + 100 > target) { - return (target - temperature) * 255 / 100; + return (target - temperature) * 192 / 100; } else { - return 255; + return 192; //return (uint8_t)((uint16_t)((uint32_t)((uint32_t)255*target)/temperature)/TARGET_TEMP_MAX); } } @@ -256,25 +260,27 @@ int main(void) adc_sum += ADC; if(++adc_pos == 64) { - //adc_sum = 47000; temperature = linearize_temp(adc_sum); - //temperature = 1100; + if(temperature < 400) + { + startup = 2 * TEN_SECONDS; + } adc_sum = 0; adc_pos = 0; - if(1)//dev_state) + if(dev_state) { heat_power = control_output(); if(startup && heat_power > 96) {heat_power = 96;} } - /*else + else { heat_power = 0; - }*/ + } } } - /*if(!dev_state) {led_off();} - else */if(setting_timeout) {led_set(target);} + if(!dev_state) {led_off();} + else if(setting_timeout) {led_set(target);} else {led_set(temperature);} if(eeprom_write && dev_state)