|
|
|
@ -14,7 +14,7 @@
|
|
|
|
#define TIMEOUT 51 /* 2 seconds */
|
|
|
|
#define TIMEOUT 51 /* 2 seconds */
|
|
|
|
|
|
|
|
|
|
|
|
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 = 1000;
|
|
|
|
|
|
|
|
|
|
|
|
#define TARGET_TEMP_MIN 300
|
|
|
|
#define TARGET_TEMP_MIN 300
|
|
|
|
#define TARGET_TEMP_MAX 1520
|
|
|
|
#define TARGET_TEMP_MAX 1520
|
|
|
|
@ -62,16 +62,20 @@ ISR(TIM1_OVF_vect)
|
|
|
|
|
|
|
|
|
|
|
|
/* incremtening softpwm, toggling output if needed */
|
|
|
|
/* incremtening softpwm, toggling output if needed */
|
|
|
|
heat_pwm++;
|
|
|
|
heat_pwm++;
|
|
|
|
if(heat_pwm <= heat_power)
|
|
|
|
if(heat_pwm == 0 && heat_power > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
PORTB |= (1 << FET0_PIN);
|
|
|
|
PORTB |= (1 << FET0_PIN);
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(heat_pwm > heat_power)
|
|
|
|
|
|
|
|
{
|
|
|
|
PORTB &= ~(1 << FET0_PIN);
|
|
|
|
PORTB &= ~(1 << FET0_PIN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( ((heat_pwm + 128)&0xff) <= heat_power )
|
|
|
|
if(heat_pwm == 128 && heat_power > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
PORTB |= (1 << FET1_PIN);
|
|
|
|
PORTB |= (1 << FET1_PIN);
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( ((heat_pwm + 128) & 0xff) > heat_power )
|
|
|
|
|
|
|
|
{
|
|
|
|
PORTB &= ~(1 << FET1_PIN);
|
|
|
|
PORTB &= ~(1 << FET1_PIN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -113,11 +117,11 @@ inline uint8_t control_output(void)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(temperature + 100 > target)
|
|
|
|
else if(temperature + 100 > target)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return (target - temperature) * 255 / 100;
|
|
|
|
return (target - temperature) * 192 / 100;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return 255;
|
|
|
|
return 192;
|
|
|
|
//return (uint8_t)((uint16_t)((uint32_t)((uint32_t)255*target)/temperature)/TARGET_TEMP_MAX);
|
|
|
|
//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;
|
|
|
|
adc_sum += ADC;
|
|
|
|
if(++adc_pos == 64)
|
|
|
|
if(++adc_pos == 64)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//adc_sum = 47000;
|
|
|
|
|
|
|
|
temperature = linearize_temp(adc_sum);
|
|
|
|
temperature = linearize_temp(adc_sum);
|
|
|
|
//temperature = 1100;
|
|
|
|
if(temperature < 400)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
startup = 2 * TEN_SECONDS;
|
|
|
|
|
|
|
|
}
|
|
|
|
adc_sum = 0;
|
|
|
|
adc_sum = 0;
|
|
|
|
adc_pos = 0;
|
|
|
|
adc_pos = 0;
|
|
|
|
if(1)//dev_state)
|
|
|
|
if(dev_state)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
heat_power = control_output();
|
|
|
|
heat_power = control_output();
|
|
|
|
if(startup && heat_power > 96) {heat_power = 96;}
|
|
|
|
if(startup && heat_power > 96) {heat_power = 96;}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
heat_power = 0;
|
|
|
|
heat_power = 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)
|
|
|
|
|