master
Nidan 13 years ago
parent 4f1a47f0a3
commit 108a00275f

@ -16,6 +16,7 @@
const uint16_t LED_GREEN_TEMP = 300; const uint16_t LED_GREEN_TEMP = 300;
const uint16_t LED_RED_TEMP = 1200; const uint16_t LED_RED_TEMP = 1200;
const uint16_t TARGET_TEMP_MIN = 300;
const uint16_t TARGET_TEMP_MAX = 1520; const uint16_t TARGET_TEMP_MAX = 1520;
uint8_t led_color = 0; uint8_t led_color = 0;
@ -73,7 +74,7 @@ ISR(PCINT0_vect)
uint8_t diff = new_state ^ input_state; uint8_t diff = new_state ^ input_state;
if(!diff) {return;} if(!diff) {return;}
if(diff & (1 << TAST_PIN) && new_state & (1 << TAST_PIN)) if(diff & (1 << (TAST_PIN - 1)) && new_state & (1 << (TAST_PIN - 1)))
{ {
dev_state = !dev_state; dev_state = !dev_state;
} }
@ -81,7 +82,9 @@ ISR(PCINT0_vect)
int8_t change = state_change[((input_state & 3) << 2) | (new_state & 3)]; int8_t change = state_change[((input_state & 3) << 2) | (new_state & 3)];
if(change) if(change)
{ {
target += change; target += change << 7;
if(target < TARGET_TEMP_MIN) {target = TARGET_TEMP_MIN;}
else if(target > TARGET_TEMP_MAX) {target = TARGET_TEMP_MAX;}
setting_timeout = TIMEOUT; setting_timeout = TIMEOUT;
} }
@ -152,15 +155,15 @@ inline void io_init(void)
inline void led_init(void) inline void led_init(void)
{ {
TCCR0A = (1 << COM0A1) | (1 << COM0B1) | (1 << COM0B0) | (1 << WGM01) | (1 << WGM00);/* pwm enable: fast, A not inverted, B inverted */ TCCR0A = (1 << COM0A1) | (1 << COM0B1) | (1 << COM0A0) | (1 << WGM01) | (1 << WGM00);/* pwm enable: fast, A inverted, B not */
TCCR0B = (1 << CS00);/* prescaler / 1024 */ TCCR0B = (1 << CS00);/* no prescaler */
OCR0A = OCR0B = led_color; OCR0A = OCR0B = led_color;
} }
inline void led_set(uint16_t value) inline void led_set(uint16_t value)
{ {
if (LED_GREEN_TEMP < value && value < LED_RED_TEMP) { if (LED_GREEN_TEMP < value && value < LED_RED_TEMP) {
value = (value-LED_GREEN_TEMP) * 255/(LED_RED_TEMP-LED_GREEN_TEMP); value = ((uint32_t) (value-LED_GREEN_TEMP) * 255)/(LED_RED_TEMP-LED_GREEN_TEMP);
} else if (value < LED_GREEN_TEMP) { } else if (value < LED_GREEN_TEMP) {
value = 0; value = 0;
} else { } else {
@ -186,7 +189,8 @@ inline void adc_init(void)
inline void heat_init(void) inline void heat_init(void)
{ {
TCCR1B = (1 << WGM12) | (1 << CS10);/* some mode allowing to set timer TOP, no prescaler */ TCCR1A = (1 << WGM11) | (1 << WGM10);
TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS10);/* some mode allowing to set timer TOP, no prescaler */
TIMSK1 = (1 << TOIE1);/* interupt on overflow */ TIMSK1 = (1 << TOIE1);/* interupt on overflow */
OCR1A = 39063; OCR1A = 39063;
@ -229,24 +233,24 @@ int main(void)
temperature = linearize_temp(adc_sum); temperature = linearize_temp(adc_sum);
adc_sum = 0; adc_sum = 0;
adc_pos = 0; adc_pos = 0;
if(dev_state) if(1)//dev_state)
{ {
heat_output = control_output(); heat_output = control_output();
if(startup && heat_output > 192) {heat_output = 192;} if(startup && heat_output > 192) {heat_output = 192;}
heat_on[0] = 0; heat_on[0] = 0;
heat_on[1] = 128; heat_on[1] = 128;
heat_off[0] = heat_output; heat_off[0] = 255;//heat_output;
heat_off[1] = heat_output + 128; heat_off[1] = 128;//heat_output + 128;
} }
else /*else
{ {
heat_on[0] = heat_on[1] = heat_off[0] = heat_off[1] = 0; heat_on[0] = heat_on[1] = heat_off[0] = heat_off[1] = 0;
} }*/
} }
} }
if(!dev_state) {led_off();} /*if(!dev_state) {led_off();}
else if(setting_timeout) {led_set(target);} else*/ if(setting_timeout) {led_set(target);}
else {led_set(temperature);} else {led_set(temperature);}
if(eeprom_write && dev_state) if(eeprom_write && dev_state)

Loading…
Cancel
Save