LCA 2008 Z-axis accelerometer demo
authorBdale Garbee <bdale@gag.com>
Wed, 6 Feb 2008 06:14:29 +0000 (23:14 -0700)
committerBdale Garbee <bdale@gag.com>
Wed, 6 Feb 2008 06:14:29 +0000 (23:14 -0700)
Makefile
adc/adc.c
adc/adc.h
lpc210x.h
main.c
openocd-debug.cfg
openocd-flash.cfg
sensors/sensors.c

index 11bd29d5aefc37e2efbd027481722fc15e053eb2..7932b1d3c630cf87c49f360d3ebe9b8f23e8470e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -82,7 +82,7 @@ tags :
 clean :
        find . -name \*.o -exec rm -f {} \;
        find . -name .depend -exec rm -f {} \;
-       rm -f *.map *.lst *.elf *.hex .depend $(COMMON)/common.a
+       rm -f *.map *.lst *.elf *.hex *.bin .depend $(COMMON)/common.a
 
 #
 #
index 21d8572b4252efa3e97eb8237ec6a73c44ac6e2f..cc7158eff2fa0e684b6c2a926f383ba3ea7dbcfd 100644 (file)
--- a/adc/adc.c
+++ b/adc/adc.c
@@ -7,13 +7,14 @@
 //
 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;
+//  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))
-    ;
+//  while (!(AD0_DR3 & AD_DR_DONE))
+//    ;
 
-  return ((AD0_DR3 & AD_DR_RESULTMASK) >> AD_DR_RESULTSHIFT);
+//  return ((AD0_DR3 & AD_DR_RESULTMASK) >> AD_DR_RESULTSHIFT);
+    return (0);
 }
 
 //
@@ -21,9 +22,53 @@ int adcRead0_3 (void)
 //
 void adcInit (void)
 {
-  SCB_PCONP |= SCB_PCONP_PCAD0;
+//  SCB_PCONP |= SCB_PCONP_PCAD0;
+  SCB_PCONP |= SCB_PCONP_PCAD1;
 
-  PCB_PINSEL1 |= PCB_PINSEL1_P030_AD03;
+//  PCB_PINSEL1 |= PCB_PINSEL1_P030_AD03;
 
-  AD0_CR = AD_CR_CLKS10 | AD_CR_PDN | ((11 - 1) << AD_CR_CLKDIVSHIFT) | AD_CR_SEL3;
+  PCB_PINSEL0 |= PCB_PINSEL0_P012_AD13;
+  PCB_PINSEL0 |= PCB_PINSEL0_P013_AD14;
+  PCB_PINSEL1 |= PCB_PINSEL1_P021_AD16;
+
+}
+
+void adcStartXYZ (void)
+{
+//  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;
+//  AD1_CR = AD_CR_CLKS10 | AD_CR_PDN | ((11 - 1) << AD_CR_CLKDIVSHIFT) | AD_CR_SEL3 | AD_CR_BURST;
+  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))
+//    ;
+
+}
+
+//
+//  Read and return X accelerometer value
+//
+int adcReadX (void)
+{
+//  while (!(AD1_DR3 & AD_DR_DONE)) ;
+  return ((AD1_DR3 & AD_DR_RESULTMASK) >> AD_DR_RESULTSHIFT);
+}
+
+//
+//  Read and return Y accelerometer value
+//
+int adcReadY (void)
+{
+//  while (!(AD1_DR4 & AD_DR_DONE)) ;
+  return ((AD1_DR4 & AD_DR_RESULTMASK) >> AD_DR_RESULTSHIFT);
+}
+
+//
+//  Read and return Z accelerometer value
+//
+int adcReadZ (void)
+{
+  while (!(AD1_DR6 & AD_DR_DONE)) ;
+  return ((AD1_DR6 & AD_DR_RESULTMASK) >> AD_DR_RESULTSHIFT);
 }
index 5765e5ffdcb3e9bb51a55ee289fc0ed8e5dffe5b..161185a6101a5f38988db6944f5e1f1afcc51dbd 100644 (file)
--- a/adc/adc.h
+++ b/adc/adc.h
@@ -5,4 +5,9 @@ int adcRead0_3 (void);
 int adcRead0_7 (void);
 void adcInit (void);
 
+void adcStartXYZ (void);
+int adcReadX (void);
+int adcReadY (void);
+int adcReadZ (void);
+
 #endif
index f740f73ef6a1512e27f147a3516492d0fe5cbc87..d78580d16e3158de32282704eac3ee489989b8d4 100644 (file)
--- a/lpc210x.h
+++ b/lpc210x.h
 #define AD0_DR6             (*(pREG32 (0xe0034028)))
 #define AD0_DR7             (*(pREG32 (0xe003402c)))
 
-#define AD1_CR              (*(pREG32 (0xe0064000)))
-#define AD1_GDR             (*(pREG32 (0xe0064004)))
-#define AD1_STAT            (*(pREG32 (0xe0064030)))
-#define AD1_GSR             (*(pREG32 (0xe0034008)))
-#define AD1_INTEN           (*(pREG32 (0xe006400c)))
-#define AD1_DR0             (*(pREG32 (0xe0064010)))
-#define AD1_DR1             (*(pREG32 (0xe0064014)))
-#define AD1_DR2             (*(pREG32 (0xe0064018)))
-#define AD1_DR3             (*(pREG32 (0xe006401c)))
-#define AD1_DR4             (*(pREG32 (0xe0064020)))
-#define AD1_DR5             (*(pREG32 (0xe0064024)))
-#define AD1_DR6             (*(pREG32 (0xe0064028)))
-#define AD1_DR7             (*(pREG32 (0xe006402c)))
+#define AD1_CR              (*(pREG32 (0xe0060000)))
+#define AD1_GDR             (*(pREG32 (0xe0060004)))
+#define AD1_STAT            (*(pREG32 (0xe0060030)))
+#define AD1_GSR             (*(pREG32 (0xe0030008)))
+#define AD1_INTEN           (*(pREG32 (0xe006000c)))
+#define AD1_DR0             (*(pREG32 (0xe0060010)))
+#define AD1_DR1             (*(pREG32 (0xe0060014)))
+#define AD1_DR2             (*(pREG32 (0xe0060018)))
+#define AD1_DR3             (*(pREG32 (0xe006001c)))
+#define AD1_DR4             (*(pREG32 (0xe0060020)))
+#define AD1_DR5             (*(pREG32 (0xe0060024)))
+#define AD1_DR6             (*(pREG32 (0xe0060028)))
+#define AD1_DR7             (*(pREG32 (0xe006002c)))
 
 #define AD_CR_SEL0          (0x00000001)
 #define AD_CR_SEL1          (0x00000002)
diff --git a/main.c b/main.c
index 7a7fe8c538041627469f20b89560033cfa23bf93..92ab8dc1f75333487f99aada962c73fd42954f15 100644 (file)
--- a/main.c
+++ b/main.c
@@ -58,39 +58,29 @@ xTaskHandle taskHandles [TASKHANDLE_LAST];
 int main (void)
 {
   cpuSetupHardware ();
-//#ifndef BDALE
   uartInit (0, BAUD_UART0, 64);
   uartInit (1, BAUD_UART1, 64);
-//#endif
 #ifndef CFG_USB_MSC
   usbserInit ();
 #else
   usbmassInit ();
 #endif
-//#ifndef BDALE
   rtcInit ();
   adcInit ();
   dacInit ();
-//#endif
   i2cInit ();
-//#ifndef BDALE
   eintsInit ();
   fiqInit ();
   iapInit ();
-//#endif
 
   memset (taskHandles, 0, sizeof (taskHandles));
 
-  xTaskCreate (vSensorsTask,  (const signed portCHAR * const) "Sensors",  512,                      NULL, (configMAX_PRIORITIES - 2), &taskHandles [TASKHANDLE_SENSORS]);
-//#ifndef BDALE
+  xTaskCreate (vSensorsTask,  (const signed portCHAR * const) "Sensors",  1024,                      NULL, (configMAX_PRIORITIES - 2), &taskHandles [TASKHANDLE_SENSORS]);
 #ifndef CFG_CONSOLE_UART1
   xTaskCreate (vGPSTask,      (const signed portCHAR * const) "GPS",      768,                      NULL, (tskIDLE_PRIORITY + 1),     &taskHandles [TASKHANDLE_GPS]);
 #endif
-//#endif
   xTaskCreate (vMonitorTask,  (const signed portCHAR * const) "Monitor",  1024,                     NULL, (tskIDLE_PRIORITY + 1),     &taskHandles [TASKHANDLE_MONITOR]);
-//#ifndef BDALE
   xTaskCreate (vLEDFlashTask, (const signed portCHAR * const) "LEDx",     configMINIMAL_STACK_SIZE, NULL, (tskIDLE_PRIORITY + 1),     &taskHandles [TASKHANDLE_LED]);
-//#endif
   vTaskStartScheduler ();
 
   return 0;
index 1fafcc95c42ca8dc5f6031df3ea2920c6a9ab611..309ff77f09a61d67ced4460df08dba447b30df6b 100644 (file)
@@ -8,8 +8,8 @@ ft2232_layout "olimex-jtag"
 ft2232_vid_pid 0x15BA 0x0003
 jtag_speed 3
 #use combined on interfaces or targets that can't set TRST/SRST separately
-#reset_config trst_and_srst separate
-reset_config trst_and_srst srst_pulls_trst
+reset_config trst_and_srst separate
+#reset_config trst_and_srst srst_pulls_trst
 #jtag scan chain
 #format L IRC IRCM IDCODE (Length, IR Capture, IR Capture Mask, IDCODE)
 jtag_device 4 0x1 0xf 0xe
index 26131e9069c33025f32316edefe7ed54e34e4da8..22a566abe1b0f41c4e179e7d0d5cc7199badc4b7 100644 (file)
@@ -8,8 +8,8 @@ ft2232_layout "olimex-jtag"
 ft2232_vid_pid 0x15BA 0x0003
 jtag_speed 3
 #use combined on interfaces or targets that can't set TRST/SRST separately
-#reset_config trst_and_srst separate
-reset_config trst_and_srst srst_pulls_trst
+reset_config trst_and_srst separate
+#reset_config trst_and_srst srst_pulls_trst
 #jtag scan chain
 #format L IRC IRCM IDCODE (Length, IR Capture, IR Capture Mask, IDCODE)
 jtag_device 4 0x1 0xf 0xe
index 86fb39c8b2c00375592dceb047f4aa89111046c0..1f69a3647d3d82d11bb3143d54e39ff0441e7dfb 100644 (file)
@@ -56,10 +56,14 @@ portTASK_FUNCTION (vSensorsTask, pvParameters __attribute__ ((unused)))
 
   xTickCount = xTaskGetTickCount ();
 
+  adcStartXYZ();
+
   for (;;)
   {
     vTaskDelayUntil (&xTickCount, 100 / portTICK_RATE_MS);
 
+    printf("tick\n");
+
     //
     //  Adjust the DAC value so we output a slow sine wave
     //
@@ -90,5 +94,12 @@ portTASK_FUNCTION (vSensorsTask, pvParameters __attribute__ ((unused)))
 
       xSemaphoreGive (semaphore);
     }
+
+    //
+    //  get and display last X, Y, and Z accelerometer readings,
+    //  the start another conversion
+    //
+    printf("%04x %04x %04x\n", adcReadX(), adcReadY(), adcReadZ());
+
   }
 }