master
Nidan 13 years ago
parent 108a00275f
commit f723647a5d

@ -19,8 +19,6 @@ const uint16_t LED_RED_TEMP = 1200;
const uint16_t TARGET_TEMP_MIN = 300;
const uint16_t TARGET_TEMP_MAX = 1520;
uint8_t led_color = 0;
uint8_t setting_timeout = 0;
uint8_t adc_pos = 0;
@ -32,8 +30,8 @@ uint16_t temperature = 0;
uint8_t heat_output = 0;
uint8_t heat_pwm = 0;
uint8_t heat_on[2] = {0, 0};
uint8_t heat_off[2] = {0, 0};
uint8_t heat_on[2] = {0, 128};
uint8_t heat_off[2] = {128, 0};
uint8_t input_state = 0;
uint8_t dev_state = 0;
@ -70,7 +68,7 @@ ISR(TIM1_OVF_vect)
ISR(PCINT0_vect)
{
uint8_t new_state = (PORTA & ((1 << IMPULS1_PIN) | (1 << IMPULS0_PIN) | (1 << TAST_PIN))) >> 1;
uint8_t new_state = (PINA & ((1 << IMPULS1_PIN) | (1 << IMPULS0_PIN) | (1 << TAST_PIN))) >> 1;
uint8_t diff = new_state ^ input_state;
if(!diff) {return;}
@ -82,7 +80,7 @@ ISR(PCINT0_vect)
int8_t change = state_change[((input_state & 3) << 2) | (new_state & 3)];
if(change)
{
target += change << 7;
target += change << 4;
if(target < TARGET_TEMP_MIN) {target = TARGET_TEMP_MIN;}
else if(target > TARGET_TEMP_MAX) {target = TARGET_TEMP_MAX;}
setting_timeout = TIMEOUT;
@ -135,9 +133,9 @@ inline uint16_t linearize_temp(uint16_t temp_in)
uint8_t i=2;
for (; i < (sizeof(coeffs)>>1)-2; i+=2)
{
if ( temp_in < pgm_read_byte(&coeffs[i]) )
if ( temp_in < pgm_read_word(&coeffs[i]) )
{
temp_out = (uint16_t) ( pgm_read_byte(&coeffs[i-1]) + (uint32_t) ( (uint32_t) (temp_in - pgm_read_byte(&coeffs[i-2])) * (pgm_read_byte(&coeffs[i+1])-pgm_read_byte(&coeffs[i-1])) ) / (pgm_read_byte(&coeffs[i])-pgm_read_byte(&coeffs[i-2])));
temp_out = (uint16_t) ( pgm_read_word(&coeffs[i-1]) + (uint32_t) ( (uint32_t) (temp_in - pgm_read_word(&coeffs[i-2])) * (pgm_read_word(&coeffs[i+1])-pgm_read_word(&coeffs[i-1])) ) / (pgm_read_word(&coeffs[i])-pgm_read_word(&coeffs[i-2])));
break;
}
}
@ -150,14 +148,14 @@ inline void io_init(void)
PORTB = 0;
DDRA = (1 << PA7);/* led outputs ... */
DDRB = (1 << PB2) | (1 << FET0_PIN) | (1 << FET1_PIN);/* ... and FET output */
input_state = PORTA & ((1 << IMPULS1_PIN) | (1 << IMPULS0_PIN) | (1 << TAST_PIN));
input_state = PINA & ((1 << IMPULS1_PIN) | (1 << IMPULS0_PIN) | (1 << TAST_PIN));
}
inline void led_init(void)
{
TCCR0A = (1 << COM0A1) | (1 << COM0B1) | (1 << COM0A0) | (1 << WGM01) | (1 << WGM00);/* pwm enable: fast, A inverted, B not */
TCCR0B = (1 << CS00);/* no prescaler */
OCR0A = OCR0B = led_color;
OCR0A = OCR0B = 0;
}
inline void led_set(uint16_t value)
@ -212,8 +210,6 @@ inline void input_init(void)
int main(void)
{
/* if we store the last setting somewhere calculate led_color from it before calling led_init() */
io_init();
adc_init();
heat_init();
@ -239,8 +235,8 @@ int main(void)
if(startup && heat_output > 192) {heat_output = 192;}
heat_on[0] = 0;
heat_on[1] = 128;
heat_off[0] = 255;//heat_output;
heat_off[1] = 128;//heat_output + 128;
heat_off[0] = 128;//heat_output;
heat_off[1] = 0;//heat_output + 128;
}
/*else
{
@ -250,7 +246,7 @@ int main(void)
}
/*if(!dev_state) {led_off();}
else*/ if(setting_timeout) {led_set(target);}
else */if(setting_timeout) {led_set(target);}
else {led_set(temperature);}
if(eeprom_write && dev_state)

Loading…
Cancel
Save