summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ao.h8
-rw-r--r--src/ao_adc.c28
-rw-r--r--src/ao_pins.h3
3 files changed, 33 insertions, 6 deletions
diff --git a/src/ao.h b/src/ao.h
index abac22a3..cef20e61 100644
--- a/src/ao.h
+++ b/src/ao.h
@@ -163,6 +163,11 @@ struct ao_adc {
#endif
#if HAS_ADC
+
+#ifndef HAS_ACCEL_REF
+#error Please define HAS_ACCEL_REF
+#endif
+
/*
* ao_adc.c
*/
@@ -178,6 +183,9 @@ struct ao_adc {
*/
extern volatile __xdata struct ao_adc ao_adc_ring[AO_ADC_RING];
extern volatile __data uint8_t ao_adc_head;
+#if HAS_ACCEL_REF
+extern volatile __xdata uint16_t ao_accel_ref[AO_ADC_RING];
+#endif
/* Trigger a conversion sequence (called from the timer interrupt) */
void
diff --git a/src/ao_adc.c b/src/ao_adc.c
index f577b458..3adf9b2e 100644
--- a/src/ao_adc.c
+++ b/src/ao_adc.c
@@ -19,12 +19,19 @@
#include "ao_pins.h"
volatile __xdata struct ao_adc ao_adc_ring[AO_ADC_RING];
+#if HAS_ACCEL_REF
+volatile __xdata uint16_t ao_accel_ref[AO_ADC_RING];
+#endif
volatile __data uint8_t ao_adc_head;
void
ao_adc_poll(void)
{
+#if HAS_ACCEL_REF
+ ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | 2;
+#else
ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | 0;
+#endif
}
void
@@ -41,20 +48,29 @@ ao_adc_isr(void) __interrupt 1
uint8_t __xdata *a;
sequence = (ADCCON2 & ADCCON2_SCH_MASK) >> ADCCON2_SCH_SHIFT;
- if (sequence == ADCCON3_ECH_TEMP)
- sequence = 2;
- a = (uint8_t __xdata *) (&ao_adc_ring[ao_adc_head].accel + sequence);
+#if HAS_ACCEL_REF
+ if (sequence == 2) {
+ a = (uint8_t __xdata *) (&ao_accel_ref[ao_adc_head]);
+ sequence = 0;
+ } else
+#endif
+ {
+ if (sequence == ADCCON3_ECH_TEMP)
+ sequence = 2;
+ a = (uint8_t __xdata *) (&ao_adc_ring[ao_adc_head].accel + sequence);
+ sequence++;
+ }
a[0] = ADCL;
a[1] = ADCH;
- if (sequence < 5) {
+ if (sequence < 6) {
#if HAS_EXTERNAL_TEMP == 0
/* start next channel conversion */
/* v0.2 replaces external temp sensor with internal one */
- if (sequence == 1)
+ if (sequence == 2)
ADCCON3 = ADCCON3_EREF_1_25 | ADCCON3_EDIV_512 | ADCCON3_ECH_TEMP;
else
#endif
- ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | (sequence + 1);
+ ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | sequence;
} else {
/* record this conversion series */
ao_adc_ring[ao_adc_head].tick = ao_time();
diff --git a/src/ao_pins.h b/src/ao_pins.h
index 9446964e..2c5b9db5 100644
--- a/src/ao_pins.h
+++ b/src/ao_pins.h
@@ -31,6 +31,7 @@
#define AO_LED_RED 1
#define LEDS_AVAILABLE (AO_LED_RED)
#define HAS_EXTERNAL_TEMP 0
+ #define HAS_ACCEL_REF 0
#endif
#if defined(TELEMETRUM_V_1_1)
@@ -46,6 +47,7 @@
#define AO_LED_RED 1
#define LEDS_AVAILABLE (AO_LED_RED)
#define HAS_EXTERNAL_TEMP 0
+ #define HAS_ACCEL_REF 1
#define SPI_CS_ON_P1 1
#define SPI_CS_ON_P0 0
#define M25_CS_MASK 0x02 /* CS0 is P1_1 */
@@ -81,6 +83,7 @@
#define AO_LED_GREEN 1
#define LEDS_AVAILABLE (AO_LED_RED|AO_LED_GREEN)
#define HAS_EXTERNAL_TEMP 1
+ #define HAS_ACCEL_REF 0
#define SPI_CS_ON_P1 1
#define SPI_CS_ON_P0 0
#endif