From 1be433e65f6aa8e8636e1bc372635d2d291047c4 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sun, 1 Jul 2012 10:35:29 -0300 Subject: [PATCH] fw/accel.c (measure_ref): GND and Vbg measurement function (for diagnostics) --- fw/accel.c | 13 +++++++++++++ fw/accel.h | 1 + 2 files changed, 14 insertions(+) diff --git a/fw/accel.c b/fw/accel.c index 1f45d66..018df41 100644 --- a/fw/accel.c +++ b/fw/accel.c @@ -50,6 +50,19 @@ static inline void adcsra(bool start) } +uint16_t measure_ref(bool gnd) +{ + while (ADCSRA & (1 << ADSC)); + adcsra(0); + ADMUX = + 1 << REFS0 | /* Vref is AVcc */ + (gnd ? 15 : 14); /* GND (0 V) or Vbg (1.1 V) */ + adcsra(1); + while (ADCSRA & (1 << ADSC)); + return ADC; +} + + ISR(ADC_vect) { uint16_t v; diff --git a/fw/accel.h b/fw/accel.h index e5c22bc..06c8f0d 100644 --- a/fw/accel.h +++ b/fw/accel.h @@ -21,6 +21,7 @@ extern void (*sample)(bool x, uint16_t v); +uint16_t measure_ref(bool gnd); void accel_start(void); #endif /* !ACCEL_H */