This places the 5v reference samples in an array parallel to the basic
ADC values. It doesn't do anything with the values, just stores them.
Signed-off-by: Keith Packard <keithp@keithp.com>
+
+#ifndef HAS_ACCEL_REF
+#error Please define HAS_ACCEL_REF
+#endif
+
*/
extern volatile __xdata struct ao_adc ao_adc_ring[AO_ADC_RING];
extern volatile __data uint8_t ao_adc_head;
*/
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
/* Trigger a conversion sequence (called from the timer interrupt) */
void
#include "ao_pins.h"
volatile __xdata struct ao_adc ao_adc_ring[AO_ADC_RING];
#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)
{
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;
ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | 0;
uint8_t __xdata *a;
sequence = (ADCCON2 & ADCCON2_SCH_MASK) >> ADCCON2_SCH_SHIFT;
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;
a[0] = ADCL;
a[1] = ADCH;
#if HAS_EXTERNAL_TEMP == 0
/* start next channel conversion */
/* v0.2 replaces external temp sensor with internal one */
#if HAS_EXTERNAL_TEMP == 0
/* start next channel conversion */
/* v0.2 replaces external temp sensor with internal one */
ADCCON3 = ADCCON3_EREF_1_25 | ADCCON3_EDIV_512 | ADCCON3_ECH_TEMP;
else
#endif
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();
} else {
/* record this conversion series */
ao_adc_ring[ao_adc_head].tick = ao_time();
#define AO_LED_RED 1
#define LEDS_AVAILABLE (AO_LED_RED)
#define HAS_EXTERNAL_TEMP 0
#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)
#endif
#if defined(TELEMETRUM_V_1_1)
#define AO_LED_RED 1
#define LEDS_AVAILABLE (AO_LED_RED)
#define HAS_EXTERNAL_TEMP 0
#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 */
#define SPI_CS_ON_P1 1
#define SPI_CS_ON_P0 0
#define M25_CS_MASK 0x02 /* CS0 is P1_1 */
#define AO_LED_GREEN 1
#define LEDS_AVAILABLE (AO_LED_RED|AO_LED_GREEN)
#define HAS_EXTERNAL_TEMP 1
#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
#define SPI_CS_ON_P1 1
#define SPI_CS_ON_P0 0
#endif