From 3c1462cf842e20d27dab894e069e75a474536a4f Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Fri, 15 Feb 2008 00:27:05 -0700 Subject: [PATCH] v0.1 board believed to be reading Vbat, Pressure, and X/Y/Z correctly now, though with no accelerometer loaded I can't be completely sure --- adc/adc.c | 67 ++++++++++++++++++++--------------------------- adc/adc.h | 6 ++--- sensors/sensors.c | 7 ++--- 3 files changed, 35 insertions(+), 45 deletions(-) diff --git a/adc/adc.c b/adc/adc.c index a1a08d5..b34dcf1 100644 --- a/adc/adc.c +++ b/adc/adc.c @@ -2,40 +2,21 @@ #include "adc.h" -// -// -// -int adcRead0_3 (void) -{ -// AD0_CR = AD_CR_CLKS10 | AD_CR_PDN | ((11 - 1) << AD_CR_CLKDIVSHIFT) | AD_CR_SEL3; -// AD0_CR |= AD_CR_START_NOW; - -// while (!(AD0_DR3 & AD_DR_DONE)) -// ; - -// return ((AD0_DR3 & AD_DR_RESULTMASK) >> AD_DR_RESULTSHIFT); - return (0); -} - // // Assumes PCLK == 48Mhz // void adcInit (void) { -// SCB_PCONP |= SCB_PCONP_PCAD0; - SCB_PCONP |= SCB_PCONP_PCAD1; + unsigned portLONG ulCompareMatch; -// PCB_PINSEL1 |= PCB_PINSEL1_P030_AD03; + SCB_PCONP |= SCB_PCONP_PCAD0; + SCB_PCONP |= SCB_PCONP_PCAD1; + PCB_PINSEL0 |= PCB_PINSEL0_P06_AD10; + PCB_PINSEL0 |= PCB_PINSEL0_P010_AD12; PCB_PINSEL0 |= PCB_PINSEL0_P012_AD13; PCB_PINSEL0 |= PCB_PINSEL0_P013_AD14; - PCB_PINSEL1 |= PCB_PINSEL1_P021_AD16; - -} - -void adcStartXYZ (void) -{ - unsigned portLONG ulCompareMatch; + PCB_PINSEL0 |= PCB_PINSEL0_P015_AD15; // configure MAT0.1 ... assumes TIMER0 already initialized and running @@ -50,18 +31,10 @@ void adcStartXYZ (void) #endif T0_MR1 = ulCompareMatch; - // burst sample 3 channels of accelerometer triggering on MAT0.1 - AD1_CR = AD_CR_CLKS10 | AD_CR_PDN | ((11 - 1) << AD_CR_CLKDIVSHIFT) | AD_CR_SEL3 | AD_CR_SEL4 | AD_CR_SEL6 | AD_CR_BURST; + // burst sample desired inputs triggering on MAT0.1 + AD1_CR = AD_CR_CLKS10 | AD_CR_PDN | ((11 - 1) << AD_CR_CLKDIVSHIFT); + AD1_CR |= AD_CR_SEL0 | AD_CR_SEL2 | AD_CR_SEL3 | AD_CR_SEL4 | AD_CR_SEL5 | AD_CR_BURST; AD1_CR |= AD_CR_START_MAT01; - -// following works for one channel repeated sampling -// AD1_CR = AD_CR_CLKS10 | AD_CR_PDN | ((11 - 1) << AD_CR_CLKDIVSHIFT) | AD_CR_SEL6 | AD_CR_BURST; -// AD1_CR |= AD_CR_START_NOW; - -// wait for conversion to complete -// while (!(AD1_DR3 & AD_DR_DONE)) -// ; - } // @@ -87,6 +60,24 @@ int adcReadY (void) // int adcReadZ (void) { - while (!(AD1_DR6 & AD_DR_DONE)) ; - return ((AD1_DR6 & AD_DR_RESULTMASK) >> AD_DR_RESULTSHIFT); + while (!(AD1_DR5 & AD_DR_DONE)) ; + return ((AD1_DR5 & AD_DR_RESULTMASK) >> AD_DR_RESULTSHIFT); +} + +// +// Read and return battery voltage +// +int adcReadVbat (void) +{ + while (!(AD1_DR0 & AD_DR_DONE)) ; + return ((AD1_DR0 & AD_DR_RESULTMASK) >> AD_DR_RESULTSHIFT); +} + +// +// Read and return barometric pressure +// +int adcReadPres (void) +{ + while (!(AD1_DR2 & AD_DR_DONE)) ; + return ((AD1_DR2 & AD_DR_RESULTMASK) >> AD_DR_RESULTSHIFT); } diff --git a/adc/adc.h b/adc/adc.h index 161185a..8527077 100644 --- a/adc/adc.h +++ b/adc/adc.h @@ -1,13 +1,11 @@ #ifndef _ADC_H_ #define _ADC_H_ -int adcRead0_3 (void); -int adcRead0_7 (void); void adcInit (void); - -void adcStartXYZ (void); int adcReadX (void); int adcReadY (void); int adcReadZ (void); +int adcReadVbat (void); +int adcReadPres (void); #endif diff --git a/sensors/sensors.c b/sensors/sensors.c index 272b291..87fe18a 100644 --- a/sensors/sensors.c +++ b/sensors/sensors.c @@ -56,14 +56,13 @@ portTASK_FUNCTION (vSensorsTask, pvParameters __attribute__ ((unused))) xTickCount = xTaskGetTickCount (); - adcStartXYZ(); - for (;;) { vTaskDelayUntil (&xTickCount, 100 / portTICK_RATE_MS); // printf("tick\n"); +#ifndef BDALE // // Adjust the DAC value so we output a slow sine wave // @@ -94,12 +93,14 @@ portTASK_FUNCTION (vSensorsTask, pvParameters __attribute__ ((unused))) xSemaphoreGive (semaphore); } +#endif // // get and display last X, Y, and Z accelerometer readings, // the start another conversion // - printf("%04x %04x %04x\n", adcReadX(), adcReadY(), adcReadZ()); + printf("Vbat %04x Pres %04x X %04x Y %04x Z %04x\n", + adcReadVbat(), adcReadPres(), adcReadX(), adcReadY(), adcReadZ()); } } -- 2.30.2