Merge branch 'master' of ghostdub.de:cupwarmer

Conflicts:
	firmware/cup.c
master
Nidan 13 years ago
commit dc3fb2b610

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

@ -16,8 +16,8 @@
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; #define TARGET_TEMP_MIN 300
const uint16_t TARGET_TEMP_MAX = 1520; #define TARGET_TEMP_MAX 1520
uint8_t setting_timeout = 0; uint8_t setting_timeout = 0;
@ -80,7 +80,7 @@ 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 << 4; target += change * 10; // 1 celsius per step
if(target < TARGET_TEMP_MIN) {target = TARGET_TEMP_MIN;} if(target < TARGET_TEMP_MIN) {target = TARGET_TEMP_MIN;}
else if(target > TARGET_TEMP_MAX) {target = TARGET_TEMP_MAX;} else if(target > TARGET_TEMP_MAX) {target = TARGET_TEMP_MAX;}
setting_timeout = TIMEOUT; setting_timeout = TIMEOUT;
@ -128,14 +128,20 @@ inline uint16_t linearize_temp(uint16_t temp_in)
59911, 1300, 59911, 1300,
62902, 1400, 62902, 1400,
65474, 1500, // 150 celsius 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; uint8_t i=2;
for(; i < sizeof(coeffs) / sizeof(coeffs[0]); i += 2) for(; i < sizeof(coeffs) / sizeof(coeffs[0]); i += 2)
{ {
if(temp_in < pgm_read_word(&coeffs[i])) 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; break;
} }
} }
@ -160,14 +166,16 @@ inline void led_init(void)
inline void led_set(uint16_t value) inline void led_set(uint16_t value)
{ {
if (LED_GREEN_TEMP < value && value < LED_RED_TEMP) { uint8_t pwmval;
value = ((uint32_t) (value-LED_GREEN_TEMP) * 255)/(LED_RED_TEMP-LED_GREEN_TEMP); if (LED_GREEN_TEMP <= value && value < LED_RED_TEMP) {
} else if (value < LED_GREEN_TEMP) { pwmval = ((uint32_t) (value-LED_GREEN_TEMP) * 255)/(LED_RED_TEMP-LED_GREEN_TEMP);
value = 0; } else if (value <= LED_GREEN_TEMP) {
pwmval = 0;
} else { } else {
value = 255; pwmval = 255;
} }
OCR0A = OCR0B = (uint8_t)value; OCR0A = pwmval;
OCR0B = pwmval;
} }
inline void led_off(void) inline void led_off(void)

Loading…
Cancel
Save