i have this code built as i am not much used to programming with ADC's so plz suggest changes in code required. i want to get led glowing for 3 seconds wen it detects motion then should go off.
i have this code built as i am not much used to programming with ADC's so plz suggest changes in code required. i want to get led glowing for 3 seconds wen it detects motion then should go off.
Answer : You have forgotten to include delay!!! and who is going to switch off? two thins you didnt do.. a infinte while loop is missing and also why is P1 port u r using it as interrupt? that to as external one!!! do recheck the code and see whether their is syntax errors.
i have this availiable device its p1.1 is attached with o/p of the PIR sensor. so hav to make it as an input.
where to put delay? at start? can i use WDT for delay
Oki.. are you using launch pad? first of all, TH EPIR output should be given to input pin. that means if pin1.1 is connected then the change the direction to input direction. Now if any of your embedded project has o work then u should hav an infinite loop. run this one in infinte loop
unsigned int result_new;
while(1){
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
result_new = ADC10MEM;
if (result_new > result_old) // Get difference between samples
result_old = result_new - result_old;
else
result_old = result_old - result_new;
if (result_old > THRESHOLD) // If motion detected...
P1OUT |= BIT6; // Turn LED on
result_old = ADC10MEM; // Save last conversion
// give delay here. it can be hardware delay or software delay. u wil hav to find amount of iteractions u req to do to get that delay.
//switch off the led here. it wil help u rerun infinite times.
}
sir,
thankx...
but, after reciving sample i have to start conversion, so can i put an interrupt for reciving signal, then starting the conversion in ISR
- - - Updated - - -
and is the configuration for adc done right for continous sampling.
m not using launchpad, its a prototype device for motion sensing
have you downloaded sample codes? use single channel continous mode for fetching the input from the device. default sampling rate would do the job. dont give any reference for ADC. I guess G2131 has 10 bit adc. So the sampled output will be in ADC10MEM0. collect the data from there. and write the code.
m trying that...i got it configured right...still its not working..i want sampling to start when ip comes to pin1.1..so can i use port interrupts with adc interrupt
configure pin1.1 as interrupt pin. u can do it.. initialise adc in main function. after that when interrupt occurs, just enable the adc inside the interrupt. it wil work. however i would like to ask one question, why do u want the sampling to start after input is reached? cant it be before? this question i m asking bcoz, for first few samples the adc converted data will be garbage. so u will get error results. the stability and performance of whole system wil be deteriorated. so i suggest u to rethink of the logic.