From: Bdale Garbee Date: Wed, 6 Feb 2008 06:14:29 +0000 (-0700) Subject: LCA 2008 Z-axis accelerometer demo X-Git-Url: https://git.gag.com/?p=fw%2Fopenalt;a=commitdiff_plain;h=429c02df13c3f0aeb8cbd6bd17e9e01ed3ab8e9f LCA 2008 Z-axis accelerometer demo --- diff --git a/Makefile b/Makefile index 11bd29d..7932b1d 100644 --- 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 # # diff --git a/adc/adc.c b/adc/adc.c index 21d8572..cc7158e 100644 --- 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); } diff --git a/adc/adc.h b/adc/adc.h index 5765e5f..161185a 100644 --- 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 diff --git a/lpc210x.h b/lpc210x.h index f740f73..d78580d 100644 --- a/lpc210x.h +++ b/lpc210x.h @@ -883,19 +883,19 @@ #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 7a7fe8c..92ab8dc 100644 --- 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; diff --git a/openocd-debug.cfg b/openocd-debug.cfg index 1fafcc9..309ff77 100644 --- a/openocd-debug.cfg +++ b/openocd-debug.cfg @@ -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 diff --git a/openocd-flash.cfg b/openocd-flash.cfg index 26131e9..22a566a 100644 --- a/openocd-flash.cfg +++ b/openocd-flash.cfg @@ -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 diff --git a/sensors/sensors.c b/sensors/sensors.c index 86fb39c..1f69a36 100644 --- a/sensors/sensors.c +++ b/sensors/sensors.c @@ -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()); + } }