diff --git a/firmware/cup.c b/firmware/cup.c index 2801074..0fff87a 100644 --- a/firmware/cup.c +++ b/firmware/cup.c @@ -36,7 +36,9 @@ uint8_t heat_off[2] = {128, 0}; uint8_t input_state = 0; uint8_t dev_state = 0; -uint8_t startup = 1; +#define TEN_SECONDS 256 +uint16_t startup = TEN_SECONDS; + uint8_t eeprom_write = 0; #define ONE_MINUTE 1536 uint16_t eeprom_clk = ONE_MINUTE; @@ -50,10 +52,10 @@ ISR(TIM1_OVF_vect) { /* timeout for displaying target temperature */ if(setting_timeout) {setting_timeout--;} + if(startup) {startup--;} if(eeprom_clk) {eeprom_clk--;} else { - startup = 0; eeprom_write = 1; eeprom_clk = ONE_MINUTE; } @@ -91,11 +93,18 @@ ISR(PCINT0_vect) inline uint8_t control_output(void) { - if (temperature > target) + if(temperature > target) { return 0; - } else { - return (uint8_t)((uint16_t)((uint32_t)((uint32_t)255*target)/temperature)/TARGET_TEMP_MAX); + } + else if(temperature + 100 > target) + { + return (target - temperature) * 255 / 100; + } + else + { + return 255; + //return (uint8_t)((uint16_t)((uint32_t)((uint32_t)255*target)/temperature)/TARGET_TEMP_MAX); } } @@ -187,8 +196,7 @@ inline void led_off(void) inline void adc_init(void) { ADMUX = (1 << REFS1) | (TEMP_PIN << MUX0);/* Vref = 1.1, pin selection */ - ADCSRA = (1 << ADEN) | (1 << ADATE);/* adc enable, triggered */ - ADCSRB = (1 << ADTS2);/* trigger on counter 0 overflow */ + ADCSRA = (1 << ADEN) | (1 << ADSC) | (1 << ADATE) | (1 << ADPS2);/* adc enable, free running mode, prescaler 16 */ DIDR0 = (1 << TEMP_PIN);/* disable digital input on adc pin */ /* result in (ADCH << 8) | ADCL, accessable as ADC */ } @@ -234,19 +242,19 @@ int main(void) adc_sum += ADC; if(++adc_pos == 64) { - adc_sum = 47000; + //adc_sum = 47000; temperature = linearize_temp(adc_sum); - temperature = 1100; + //temperature = 1100; adc_sum = 0; adc_pos = 0; if(1)//dev_state) { heat_output = control_output(); - if(startup && heat_output > 192) {heat_output = 192;} + if(startup && heat_output > 96) {heat_output = 96;} heat_on[0] = 0; heat_on[1] = 128; - heat_off[0] = 128;//heat_output; - heat_off[1] = 0;//heat_output + 128; + heat_off[0] = heat_output; + heat_off[1] = heat_output + 128; } /*else {