Date:2012-07-02 00:40:01 (11 years 8 months ago)
Author:Werner Almesberger
Commit:206eb4d59139127fa129dd7c62d29ef55490fa88
Message: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
Files: fw/accel.c (2 diffs)
fw/accel.h (1 diff)
fw/diag.c (1 diff)
tools/ant-cl/ant-cl.c (2 diffs)

Change Details

fw/accel.c
1717
1818#include <avr/io.h>
1919#include <avr/interrupt.h>
20#define F_CPU 8000000UL
21#include <util/delay.h>
2022
2123#include "io.h"
2224#include "accel.h"
...... 
5052}
5153
5254
53uint16_t measure_ref(bool gnd)
55uint16_t measure_ref(void)
5456{
5557    while (ADCSRA & (1 << ADSC));
5658    adcsra(0);
5759    ADMUX =
5860        1 << REFS0 | /* Vref is AVcc */
59        (gnd ? 15 : 14); /* GND (0 V) or Vbg (1.1 V) */
61        14; /* Vbg (1.1 V) */
62    _delay_us(100);
6063    adcsra(1);
6164    while (ADCSRA & (1 << ADSC));
6265    return ADC;
fw/accel.h
2121extern void (*sample)(bool x, uint16_t v);
2222
2323
24uint16_t measure_ref(bool gnd);
24uint16_t measure_ref(void);
2525void accel_start(void);
2626
2727#endif /* !ACCEL_H */
fw/diag.c
3535
3636static void do_diag(void)
3737{
38    uint8_t pkg[3+4*DIAG_SAMPLES] = { DIAG_ACK, 4, 0, };
38    uint8_t pkg[3+2*DIAG_SAMPLES] = { DIAG_ACK, 4, 0, };
3939    uint8_t *p = pkg+3;
4040    uint16_t v;
4141    uint8_t i;
4242
4343    cli();
4444    set_line(localize_line(tmp[0], tmp[1]));
45    _delay_ms(100);
45    _delay_ms(50);
4646    for (i = 0; i != DIAG_SAMPLES; i++) {
47        v = measure_ref(1);
48        *p++ = v;
49        *p++ = v >> 8;
50        v = measure_ref(0);
47        v = measure_ref();
5148        *p++ = v;
5249        *p++ = v >> 8;
5350    }
5451    set_line(localize_line(0, 0));
55    sei();
52    /*
53     * @@@ for some reason the firmware often hangs if we enable
54     * interrupts here
55     *
56     * sei();
57     */
5658    rf_send(pkg, sizeof(pkg));
5759}
5860
tools/ant-cl/ant-cl.c
517517/* ----- Diagnostics ------------------------------------------------------- */
518518
519519
520static void send_diag(struct atrf_dsc *dsc, uint16_t pattern,
521    uint16_t *gnd, uint16_t *v_bg)
520static void send_diag(struct atrf_dsc *dsc, uint16_t pattern, uint16_t *v_bg)
522521{
523522    uint8_t payload[PAYLOAD];
524523    int got, i;
...... 
553552    }
554553    if (verbose)
555554        write(2, "\n", 1);
556    for (i = 0; i != DIAG_SAMPLES; i++) {
557        gnd[i] = payload[3+4*i] | payload[4+4*i] << 8;
558        v_bg[i] = payload[5+4*i] | payload[6+4*i] << 8;
559    }
555    for (i = 0; i != DIAG_SAMPLES; i++)
556        v_bg[i] = payload[3+2*i] | payload[4+2*i] << 8;
560557}
561558
562559
563560static void diag_1(struct atrf_dsc *dsc, uint16_t pattern)
564561{
565    uint16_t gnd[DIAG_SAMPLES], v_bg[DIAG_SAMPLES];
562    uint16_t v_bg[DIAG_SAMPLES];
566563    int i;
567564
568    send_diag(dsc, pattern, gnd, v_bg);
565    send_diag(dsc, pattern, v_bg);
569566    printf("%d", pattern);
570567    for (i = 0; i != DIAG_SAMPLES; i++)
571        printf(" %f %f", 1.1*1024/gnd[i], 1.1*1024/v_bg[i]);
568        printf(" %f", 1.1*1024/v_bg[i]);
572569    printf("\n");
573570    fflush(stdout);
574571}

Archive Download the corresponding diff file

Branches:
master
tornado-v1



interactive