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 | ||
---|---|---|
17 | 17 | |
18 | 18 | #include <avr/io.h> |
19 | 19 | #include <avr/interrupt.h> |
20 | #define F_CPU 8000000UL | |
21 | #include <util/delay.h> | |
20 | 22 | |
21 | 23 | #include "io.h" |
22 | 24 | #include "accel.h" |
... | ... | |
50 | 52 | } |
51 | 53 | |
52 | 54 | |
53 | uint16_t measure_ref(bool gnd) | |
55 | uint16_t measure_ref(void) | |
54 | 56 | { |
55 | 57 | while (ADCSRA & (1 << ADSC)); |
56 | 58 | adcsra(0); |
57 | 59 | ADMUX = |
58 | 60 | 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); | |
60 | 63 | adcsra(1); |
61 | 64 | while (ADCSRA & (1 << ADSC)); |
62 | 65 | return ADC; |
fw/accel.h | ||
---|---|---|
21 | 21 | extern void (*sample)(bool x, uint16_t v); |
22 | 22 | |
23 | 23 | |
24 | uint16_t measure_ref(bool gnd); | |
24 | uint16_t measure_ref(void); | |
25 | 25 | void accel_start(void); |
26 | 26 | |
27 | 27 | #endif /* !ACCEL_H */ |
fw/diag.c | ||
---|---|---|
35 | 35 | |
36 | 36 | static void do_diag(void) |
37 | 37 | { |
38 | uint8_t pkg[3+4*DIAG_SAMPLES] = { DIAG_ACK, 4, 0, }; | |
38 | uint8_t pkg[3+2*DIAG_SAMPLES] = { DIAG_ACK, 4, 0, }; | |
39 | 39 | uint8_t *p = pkg+3; |
40 | 40 | uint16_t v; |
41 | 41 | uint8_t i; |
42 | 42 | |
43 | 43 | cli(); |
44 | 44 | set_line(localize_line(tmp[0], tmp[1])); |
45 | _delay_ms(100); | |
45 | _delay_ms(50); | |
46 | 46 | 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(); | |
51 | 48 | *p++ = v; |
52 | 49 | *p++ = v >> 8; |
53 | 50 | } |
54 | 51 | 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 | */ | |
56 | 58 | rf_send(pkg, sizeof(pkg)); |
57 | 59 | } |
58 | 60 |
tools/ant-cl/ant-cl.c | ||
---|---|---|
517 | 517 | /* ----- Diagnostics ------------------------------------------------------- */ |
518 | 518 | |
519 | 519 | |
520 | static void send_diag(struct atrf_dsc *dsc, uint16_t pattern, | |
521 | uint16_t *gnd, uint16_t *v_bg) | |
520 | static void send_diag(struct atrf_dsc *dsc, uint16_t pattern, uint16_t *v_bg) | |
522 | 521 | { |
523 | 522 | uint8_t payload[PAYLOAD]; |
524 | 523 | int got, i; |
... | ... | |
553 | 552 | } |
554 | 553 | if (verbose) |
555 | 554 | 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; | |
560 | 557 | } |
561 | 558 | |
562 | 559 | |
563 | 560 | static void diag_1(struct atrf_dsc *dsc, uint16_t pattern) |
564 | 561 | { |
565 | uint16_t gnd[DIAG_SAMPLES], v_bg[DIAG_SAMPLES]; | |
562 | uint16_t v_bg[DIAG_SAMPLES]; | |
566 | 563 | int i; |
567 | 564 | |
568 | send_diag(dsc, pattern, gnd, v_bg); | |
565 | send_diag(dsc, pattern, v_bg); | |
569 | 566 | printf("%d", pattern); |
570 | 567 | 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]); | |
572 | 569 | printf("\n"); |
573 | 570 | fflush(stdout); |
574 | 571 | } |
Branches:
master
tornado-v1