some changes, hunting for bugs

master
Paul Goeser 13 years ago
parent f723647a5d
commit 57b1e705d2

@ -1,4 +1,5 @@
CFLAGS += -Wall -Os -I. -mmcu=attiny24 -std=c99
#CFLAGS += -save-temps
DEFINES += -DF_CPU=1e6
OBJECTS = cup.o

@ -16,8 +16,8 @@
const uint16_t LED_GREEN_TEMP = 300;
const uint16_t LED_RED_TEMP = 1200;
const uint16_t TARGET_TEMP_MIN = 300;
const uint16_t TARGET_TEMP_MAX = 1520;
#define TARGET_TEMP_MIN 300
#define TARGET_TEMP_MAX 1520
uint8_t setting_timeout = 0;
@ -80,7 +80,7 @@ ISR(PCINT0_vect)
int8_t change = state_change[((input_state & 3) << 2) | (new_state & 3)];
if(change)
{
target += change << 4;
target += change * 10; // 1 celsius per step
if(target < TARGET_TEMP_MIN) {target = TARGET_TEMP_MIN;}
else if(target > TARGET_TEMP_MAX) {target = TARGET_TEMP_MAX;}
setting_timeout = TIMEOUT;
@ -128,14 +128,21 @@ inline uint16_t linearize_temp(uint16_t temp_in)
59911, 1300,
62902, 1400,
65474, 1500, // 150 celsius
65535, 1520, // made-up, not from datasheet
65535, TARGET_TEMP_MAX // 152 celsius, made-up, not from datasheet
};
uint8_t i=2;
for (; i < (sizeof(coeffs)>>1)-2; i+=2)
{
if ( temp_in < pgm_read_word(&coeffs[i]) )
{
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])));
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;
}
}
@ -160,14 +167,16 @@ inline void led_init(void)
inline void led_set(uint16_t value)
{
if (LED_GREEN_TEMP < value && value < LED_RED_TEMP) {
value = ((uint32_t) (value-LED_GREEN_TEMP) * 255)/(LED_RED_TEMP-LED_GREEN_TEMP);
} else if (value < LED_GREEN_TEMP) {
value = 0;
uint8_t pwmval;
if (LED_GREEN_TEMP <= value && value < LED_RED_TEMP) {
pwmval = ((uint32_t) (value-LED_GREEN_TEMP) * 255)/(LED_RED_TEMP-LED_GREEN_TEMP);
} else if (value <= LED_GREEN_TEMP) {
pwmval = 0;
} else {
value = 255;
pwmval = 255;
}
OCR0A = OCR0B = (uint8_t)value;
OCR0A = pwmval;
OCR0B = pwmval;
}
inline void led_off(void)

Loading…
Cancel
Save