From 206eb4d59139127fa129dd7c62d29ef55490fa88 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sun, 1 Jul 2012 19:40:01 -0300 Subject: [PATCH] clean up diagnostic more and make it more robust A number of changes: - don't enable interrupts, since they often cause hangs (not sure why) - remove GND measurement - wait 100 us between AMUX setup and start of conversion, to let input settle - reduce delay between line setup and samping from 100 ms to 50 ms, for this is already sufficient --- fw/accel.c | 7 +++++-- fw/accel.h | 2 +- fw/diag.c | 16 +++++++++------- tools/ant-cl/ant-cl.c | 15 ++++++--------- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/fw/accel.c b/fw/accel.c index 018df41..99d0222 100644 --- a/fw/accel.c +++ b/fw/accel.c @@ -17,6 +17,8 @@ #include #include +#define F_CPU 8000000UL +#include #include "io.h" #include "accel.h" @@ -50,13 +52,14 @@ static inline void adcsra(bool start) } -uint16_t measure_ref(bool gnd) +uint16_t measure_ref(void) { while (ADCSRA & (1 << ADSC)); adcsra(0); ADMUX = 1 << REFS0 | /* Vref is AVcc */ - (gnd ? 15 : 14); /* GND (0 V) or Vbg (1.1 V) */ + 14; /* Vbg (1.1 V) */ + _delay_us(100); adcsra(1); while (ADCSRA & (1 << ADSC)); return ADC; diff --git a/fw/accel.h b/fw/accel.h index 06c8f0d..1813934 100644 --- a/fw/accel.h +++ b/fw/accel.h @@ -21,7 +21,7 @@ extern void (*sample)(bool x, uint16_t v); -uint16_t measure_ref(bool gnd); +uint16_t measure_ref(void); void accel_start(void); #endif /* !ACCEL_H */ diff --git a/fw/diag.c b/fw/diag.c index 30a81fb..a430f22 100644 --- a/fw/diag.c +++ b/fw/diag.c @@ -35,24 +35,26 @@ static bool failed; static void do_diag(void) { - uint8_t pkg[3+4*DIAG_SAMPLES] = { DIAG_ACK, 4, 0, }; + uint8_t pkg[3+2*DIAG_SAMPLES] = { DIAG_ACK, 4, 0, }; uint8_t *p = pkg+3; uint16_t v; uint8_t i; cli(); set_line(localize_line(tmp[0], tmp[1])); - _delay_ms(100); + _delay_ms(50); for (i = 0; i != DIAG_SAMPLES; i++) { - v = measure_ref(1); - *p++ = v; - *p++ = v >> 8; - v = measure_ref(0); + v = measure_ref(); *p++ = v; *p++ = v >> 8; } set_line(localize_line(0, 0)); - sei(); + /* + * @@@ for some reason the firmware often hangs if we enable + * interrupts here + * + * sei(); + */ rf_send(pkg, sizeof(pkg)); } diff --git a/tools/ant-cl/ant-cl.c b/tools/ant-cl/ant-cl.c index 966c975..9788425 100644 --- a/tools/ant-cl/ant-cl.c +++ b/tools/ant-cl/ant-cl.c @@ -517,8 +517,7 @@ quit: /* ----- Diagnostics ------------------------------------------------------- */ -static void send_diag(struct atrf_dsc *dsc, uint16_t pattern, - uint16_t *gnd, uint16_t *v_bg) +static void send_diag(struct atrf_dsc *dsc, uint16_t pattern, uint16_t *v_bg) { uint8_t payload[PAYLOAD]; int got, i; @@ -553,22 +552,20 @@ static void send_diag(struct atrf_dsc *dsc, uint16_t pattern, } if (verbose) write(2, "\n", 1); - for (i = 0; i != DIAG_SAMPLES; i++) { - gnd[i] = payload[3+4*i] | payload[4+4*i] << 8; - v_bg[i] = payload[5+4*i] | payload[6+4*i] << 8; - } + for (i = 0; i != DIAG_SAMPLES; i++) + v_bg[i] = payload[3+2*i] | payload[4+2*i] << 8; } static void diag_1(struct atrf_dsc *dsc, uint16_t pattern) { - uint16_t gnd[DIAG_SAMPLES], v_bg[DIAG_SAMPLES]; + uint16_t v_bg[DIAG_SAMPLES]; int i; - send_diag(dsc, pattern, gnd, v_bg); + send_diag(dsc, pattern, v_bg); printf("%d", pattern); for (i = 0; i != DIAG_SAMPLES; i++) - printf(" %f %f", 1.1*1024/gnd[i], 1.1*1024/v_bg[i]); + printf(" %f", 1.1*1024/v_bg[i]); printf("\n"); fflush(stdout); }