From a80a738acc247fdb5a37c79b3b9cf90aa7c81505 Mon Sep 17 00:00:00 2001 From: Michel Pollet Date: Thu, 5 Apr 2012 17:45:34 +0100 Subject: [PATCH] thermistor: Now works Return millivolts, not ADC values Signed-off-by: Michel Pollet --- examples/board_reprap/reprap.c | 11 +++++++---- examples/board_reprap/thermistor.c | 12 +++++++----- 2 files changed, 14 insertions(+), 9 deletions(-) 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; } } -- 2.20.1