From: Michel Pollet Date: Thu, 5 Apr 2012 16:45:34 +0000 (+0100) Subject: thermistor: Now works X-Git-Tag: v1.0b1~12 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=a80a738acc247fdb5a37c79b3b9cf90aa7c81505;p=sx%2Fsimavr.git thermistor: Now works Return millivolts, not ADC values Signed-off-by: Michel Pollet --- diff --git a/examples/board_reprap/reprap.c b/examples/board_reprap/reprap.c index 5bdc93b..b1b787d 100644 --- a/examples/board_reprap/reprap.c +++ b/examples/board_reprap/reprap.c @@ -54,6 +54,7 @@ thermistor_t therm_hotend; thermistor_t therm_hotbed; +thermistor_t therm_spare; button_t button; uart_pty_t uart_pty; int do_button_press = 0; @@ -253,10 +254,12 @@ int main(int argc, char *argv[]) uart_pty_init(avr, &uart_pty); uart_pty_connect(&uart_pty, '0'); - thermistor_init(avr, &therm_hotend, TEMP_0_PIN, - (short*)temptable_5, sizeof(temptable_5) / sizeof(short) / 2, OVERSAMPLENR, 22.5f); - thermistor_init(avr, &therm_hotbed, TEMP_BED_PIN, - (short*)temptable_5, sizeof(temptable_5) / sizeof(short) / 2, OVERSAMPLENR, 22.0f); + thermistor_init(avr, &therm_hotend, 0, + (short*)temptable_5, sizeof(temptable_5) / sizeof(short) / 2, OVERSAMPLENR, 25.0f); + thermistor_init(avr, &therm_hotbed, 2, + (short*)temptable_5, sizeof(temptable_5) / sizeof(short) / 2, OVERSAMPLENR, 30.0f); + thermistor_init(avr, &therm_spare, 1, + (short*)temptable_5, sizeof(temptable_5) / sizeof(short) / 2, OVERSAMPLENR, 10.0f); /* * OpenGL init, can be ignored diff --git a/examples/board_reprap/thermistor.c b/examples/board_reprap/thermistor.c index 8c2ddd8..9776dd2 100644 --- a/examples/board_reprap/thermistor.c +++ b/examples/board_reprap/thermistor.c @@ -31,7 +31,8 @@ #include "thermistor.h" /* - * called when a byte is send via the uart on the AVR + * called the ADC could use a new value + * The value returned is NOT in "ADC" mode, it's in millivolts */ static void thermistor_in_hook(struct avr_irq_t * irq, uint32_t value, void * param) { @@ -45,10 +46,11 @@ static void thermistor_in_hook(struct avr_irq_t * irq, uint32_t value, void * pa short *t = p->table; for (int ei = 0; ei < p->table_entries; ei++, t += 2) { - if (t[1] < p->current) { - printf("%s(%2d) %.2f matches %3dC is %d adc\n", __func__, v.src, - p->current, t[1], t[0] / p->oversampling); - avr_raise_irq(p->irq + IRQ_TERM_ADC_VALUE_OUT, t[0] / p->oversampling); + if (t[1] <= p->current) { + // printf("%s(%2d) %.2f matches %3dC is %d adc\n", __func__, v.src, + // p->current, t[1], t[0] / p->oversampling); + avr_raise_irq(p->irq + IRQ_TERM_ADC_VALUE_OUT, + ((t[0] / p->oversampling) * 5000) / 0x3ff); return; } }