We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi,
I'm using LPC2148 controller and interfacing accelerometer sensor, I need to enable this
sensor all the time and with the counter set in the ISR it should come out of the loop, below is
the code.
#include "adc.h" #include "lcd.h" #include "lcd1.h" #include "systemInit.h" #include "delay.h" #include <stdio.h> #include "string.h" //#include "uart.h" #include "config.h" #include "stdlib.h" #define BUZZER (1 << 25) #define BUZZER_DIR IO1DIR #define BUZZER_SET IO1SET #define BUZZER_CLR IO1CLR #define TIMER_TICK_1_MS (59999) /* VPB at 60 MHz clock */ static unsigned int ms_count; void delay2(int count); void TimerInit(void); unsigned char buf[16] = {0}; int adcValue;//x int adcValue1;//y int adcValue2;//z int adcValue3;//for X difference int adcValue4;//for Y difference int adcValue5;//for Z difference int delta_x; int delta_y; int delta_z; int thx_x = 10; int thx_y = 10; int thx_z = 10; int a,b; float temp; unsigned int sensor_detect(); void delayMS(unsigned int milliseconds) { /*Assuming that PLL0 has been setup with CCLK = 60Mhz and PCLK also = 60Mhz.*/ T0CTCR = 0; T0PR = 60000; //60000 clock cycles = 1 mS @ 60Mhz T0TCR = 0x02; //Reset Timer T0TC = 0; T0TCR = 0x01; //Enable timer while(T0TC < milliseconds); //wait until timer counter reaches the desired delay T0TCR = 0x00; //Disable timer } void Timer_ISR(void) __irq { ms_count++; ///* Count increments for every 1MSec */ if(ms_count == 10) { sensor_detect(); } ms_count = 0; T1IR = 0x01; VICVectAddr = 0x00; } void TimerInit(void) { T1TCR = 0x00; /* ensure timer 1 is off */ /* set timer counter and prescale counter */ T1TC = 0x0; T1PC = 0x0; /* set prescale and match values to give 1 ms "tick" */ T1PR = 0x0; T1MR0 = TIMER_TICK_1_MS; /* set control to interrupt on MR0 match, and reset to 0 (i.e. "tick") */ T1MCR = 0x3; /* vector TIMER 1 as mid-level priority and enabled */ VICVectCntl11 = 0x25; /* vector TIMER 1 interrupt address */ VICVectAddr11 = (unsigned int) Timer_ISR; /* enable TIMER 1 in VIC */ VICIntEnable = 0x0020; /* go start timer 1... */ T1TCR = 0x1; } int main() { ADC_Init(); init_lcd(); TimerInit(); //Timer initialisation lcd_clear(); // clear display while(1) { sprintf((char *)buf, "a:%d ",a);//need to print the sensor values 0 and 1 here lcd_putstring(0, (char *)buf); } } unsigned int sensor_detect() { ADC_Init(); adcValue = ADC_GetAdcValue(AD0_1);//x // Read the ADC value of channel zero where the temperature sensor(LM35) is connected adcValue1 = ADC_GetAdcValue(AD0_2);//y adcValue2 = ADC_GetAdcValue(AD0_4);//z sprintf((char *)buf," X=%4d",adcValue-804); // lcd_putstring(0, (char *)buf); sprintf((char *)buf," Y=%4d",adcValue1-813); // lcd_putstring(0, (char *)buf); sprintf((char *)buf," Z=%4d",adcValue2-601); // lcd_putstring(1, (char *)buf); delayMS(50); adcValue3 = ADC_GetAdcValue(AD0_1); //X AXIS delta_x = adcValue - adcValue3; if (delta_x > thx_x) { BUZZER_DIR |= BUZZER; BUZZER_SET |= BUZZER; a=1;//need to print this value in main function sprintf((char *)buf, "a:%d ",a); lcd_putstring(0, (char *)buf); } ////////////////////////////////////// adcValue4 = ADC_GetAdcValue(AD0_2); //Y AXIS delta_y = adcValue1 - adcValue4; if (delta_y > thx_y) { BUZZER_DIR |= BUZZER; BUZZER_SET |= BUZZER; a=2;//need to print this value in main function sprintf((char *)buf, "a:%d ",a); lcd_putstring(0, (char *)buf); } ///////////////////////////////////////// adcValue5 = ADC_GetAdcValue(AD0_4); //Z AXIS delta_z = adcValue2 - adcValue5; if (delta_z > thx_z) { BUZZER_DIR |= BUZZER; BUZZER_SET |= BUZZER; a=3;//need to print this value in main function sprintf((char *)buf, "a:%d ",a); lcd_putstring(0, (char *)buf); } return a; }
Regards,
Aakansha