1
0
mirror of git://projects.qi-hardware.com/antorcha.git synced 2025-04-21 12:27:27 +03: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));
}