1
0
mirror of git://projects.qi-hardware.com/antorcha.git synced 2024-12-22 18:34:14 +02:00

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
This commit is contained in:
Werner Almesberger 2012-07-01 19:40:01 -03:00
parent 1b7639c53b
commit 206eb4d591
4 changed files with 21 additions and 19 deletions

View File

@ -17,6 +17,8 @@
#include <avr/io.h>
#include <avr/interrupt.h>
#define F_CPU 8000000UL
#include <util/delay.h>
#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;

View File

@ -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 */

View File

@ -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));
}

View File

@ -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);
}