mirror of
git://projects.qi-hardware.com/antorcha.git
synced 2024-11-25 19:10:18 +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:
parent
1b7639c53b
commit
206eb4d591
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
|
#define F_CPU 8000000UL
|
||||||
|
#include <util/delay.h>
|
||||||
|
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
#include "accel.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));
|
while (ADCSRA & (1 << ADSC));
|
||||||
adcsra(0);
|
adcsra(0);
|
||||||
ADMUX =
|
ADMUX =
|
||||||
1 << REFS0 | /* Vref is AVcc */
|
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);
|
adcsra(1);
|
||||||
while (ADCSRA & (1 << ADSC));
|
while (ADCSRA & (1 << ADSC));
|
||||||
return ADC;
|
return ADC;
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
extern void (*sample)(bool x, uint16_t v);
|
extern void (*sample)(bool x, uint16_t v);
|
||||||
|
|
||||||
|
|
||||||
uint16_t measure_ref(bool gnd);
|
uint16_t measure_ref(void);
|
||||||
void accel_start(void);
|
void accel_start(void);
|
||||||
|
|
||||||
#endif /* !ACCEL_H */
|
#endif /* !ACCEL_H */
|
||||||
|
16
fw/diag.c
16
fw/diag.c
@ -35,24 +35,26 @@ static bool failed;
|
|||||||
|
|
||||||
static void do_diag(void)
|
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;
|
uint8_t *p = pkg+3;
|
||||||
uint16_t v;
|
uint16_t v;
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
|
||||||
cli();
|
cli();
|
||||||
set_line(localize_line(tmp[0], tmp[1]));
|
set_line(localize_line(tmp[0], tmp[1]));
|
||||||
_delay_ms(100);
|
_delay_ms(50);
|
||||||
for (i = 0; i != DIAG_SAMPLES; i++) {
|
for (i = 0; i != DIAG_SAMPLES; i++) {
|
||||||
v = measure_ref(1);
|
v = measure_ref();
|
||||||
*p++ = v;
|
|
||||||
*p++ = v >> 8;
|
|
||||||
v = measure_ref(0);
|
|
||||||
*p++ = v;
|
*p++ = v;
|
||||||
*p++ = v >> 8;
|
*p++ = v >> 8;
|
||||||
}
|
}
|
||||||
set_line(localize_line(0, 0));
|
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));
|
rf_send(pkg, sizeof(pkg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -517,8 +517,7 @@ quit:
|
|||||||
/* ----- Diagnostics ------------------------------------------------------- */
|
/* ----- Diagnostics ------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
static void send_diag(struct atrf_dsc *dsc, uint16_t pattern,
|
static void send_diag(struct atrf_dsc *dsc, uint16_t pattern, uint16_t *v_bg)
|
||||||
uint16_t *gnd, uint16_t *v_bg)
|
|
||||||
{
|
{
|
||||||
uint8_t payload[PAYLOAD];
|
uint8_t payload[PAYLOAD];
|
||||||
int got, i;
|
int got, i;
|
||||||
@ -553,22 +552,20 @@ static void send_diag(struct atrf_dsc *dsc, uint16_t pattern,
|
|||||||
}
|
}
|
||||||
if (verbose)
|
if (verbose)
|
||||||
write(2, "\n", 1);
|
write(2, "\n", 1);
|
||||||
for (i = 0; i != DIAG_SAMPLES; i++) {
|
for (i = 0; i != DIAG_SAMPLES; i++)
|
||||||
gnd[i] = payload[3+4*i] | payload[4+4*i] << 8;
|
v_bg[i] = payload[3+2*i] | payload[4+2*i] << 8;
|
||||||
v_bg[i] = payload[5+4*i] | payload[6+4*i] << 8;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void diag_1(struct atrf_dsc *dsc, uint16_t pattern)
|
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;
|
int i;
|
||||||
|
|
||||||
send_diag(dsc, pattern, gnd, v_bg);
|
send_diag(dsc, pattern, v_bg);
|
||||||
printf("%d", pattern);
|
printf("%d", pattern);
|
||||||
for (i = 0; i != DIAG_SAMPLES; i++)
|
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");
|
printf("\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user