]> git.gag.com Git - fw/openalt/commitdiff
v0.1 board believed to be reading Vbat, Pressure, and X/Y/Z correctly now,
authorBdale Garbee <bdale@gag.com>
Fri, 15 Feb 2008 07:27:05 +0000 (00:27 -0700)
committerBdale Garbee <bdale@gag.com>
Fri, 15 Feb 2008 07:27:05 +0000 (00:27 -0700)
though with no accelerometer loaded I can't be completely sure

adc/adc.c
adc/adc.h
sensors/sensors.c

index a1a08d56d7618f76bd12536621eb7eee7f89d3d1..b34dcf121c5f247989b71444b1c2786eda7ce72a 100644 (file)
--- 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);
 }
index 161185a6101a5f38988db6944f5e1f1afcc51dbd..8527077c7ee6ff9c39c4ff49d7588a2716ab5544 100644 (file)
--- 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
index 272b291b5454bb15d7a2223910754100b7c549c0..87fe18ab8358b0694872eeecb2259abc4e6d1c44 100644 (file)
@@ -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());
 
   }
 }