hrishikesh23
Junior Member level 1
- Joined
- May 23, 2011
- Messages
- 17
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- Banglore
- Activity points
- 1,449
Hi Everybody!
I am newbie to LPC family , I am engaged in a project in which I am transmitting 38khz square wave and after deflaction from an obstacle the receiver receives the frequency on CAP0[1] pin of LPC2364. I have managed to generate the 38k square wave but not able to capture the square wave. can any body just correct the below written code to capture the square wave..as my intention is to calculate the time required for the wave to travel and come back.
with this delay i can calculate the distance at which the object is kept.
U8 ConfCaptMode() //CONFIGURE THE PIN1.27 TO CAPTURE THE TIMER COUNTER 0 VALUE ON RISING EDGE
{
PINSEL3 = 0x00D00000; //SELECT CAP0[1] FUNCTIONALITY FOR 11 ACT AS GPIO[23 22].
EnableFastGPIO(GPIO_PORT1,27); //Enable GPIO_PORT1 PIN NUM 20
WriteFastGPIODirection(1,27,0); //PORT NUM 1,PIN NUM 27,DIRECTION INPUT.FAST IO
T0CCR = 0X01 ; //CAPTURE CONTROL REGISTER THE SEQUENCE 0-1 WILL CAUSE THE REGISTER TO LOAD WITH TC VALUE
return(0);
}
UL32 InitTxRx()
{
U8 b_ReadFlag =0; //READ THE STATUS OF RECEIVER PIN
U8 b_Count = 0; //TRANSMIT THE WAVE FOR B_COUNT TIMES
//TO CALCULATE THE AVERAGE DISTANCE
UL32 TempArray[AVG_VAL]={'\0'}; //TEMP ARRAY TO STORE AVERAGE DELAY
for(b_Count = 0 ; b_Count <= AVG_VAL ; b_Count++) //LOOP TO TRANSMIT AND RECEIVE THE FREQ AVG NUM OF TIMES
{
EnableTimer(0); //ENABLE TIMER I.E START TIMER
WriteFastGPIO(GPIO_PORT0,26,HIGH); //MAKE THE TX PIN HIGH FOR TRANSMITTER
DelayUs(0,13);
WriteFastGPIO(GPIO_PORT0,26,HIGH);
DelayUs(0,13);
while(b_ReadFlag != 1) //READ THE PIN STATUS
{
b_ReadFlag=ReadFastGPIO(GPIO_PORT1,27); //READ FAST GPIO
}
ul_TCVal = T0CR0 ; //COPY CAPTURE VALUE TO STORE IN GLOBAL DELAY VARIABLE
ul_StoreDelay[b_Count] = ul_TCVal ; //STORE THE DELAY IN GLOBAL ARRAY POSITION WISE
WriteFastGPIO(GPIO_PORT0,26,LOW); //TURN OFF THE TRANSMITTER
T0TCR = 0x02; //RESET TIMER
disable_timer(0); //DISABLE TIMER
}
for(b_Count=0 ; b_Count <= AVG_VAL ; b_Count++) //CALCULATE THE AVERAGE VALUE
{
TempArray[b_Count] = TempArray[b_Count] + ul_StoreDelay[b_Count];
ul_TCVal = (TempArray[b_Count]/AVG_VAL);
}
return(ul_TCVal);
}
if anybody can give idea through algorithm will also be helpful?
Basically how to capture a square wave and calculate the travelling time.
I am newbie to LPC family , I am engaged in a project in which I am transmitting 38khz square wave and after deflaction from an obstacle the receiver receives the frequency on CAP0[1] pin of LPC2364. I have managed to generate the 38k square wave but not able to capture the square wave. can any body just correct the below written code to capture the square wave..as my intention is to calculate the time required for the wave to travel and come back.
with this delay i can calculate the distance at which the object is kept.
U8 ConfCaptMode() //CONFIGURE THE PIN1.27 TO CAPTURE THE TIMER COUNTER 0 VALUE ON RISING EDGE
{
PINSEL3 = 0x00D00000; //SELECT CAP0[1] FUNCTIONALITY FOR 11 ACT AS GPIO[23 22].
EnableFastGPIO(GPIO_PORT1,27); //Enable GPIO_PORT1 PIN NUM 20
WriteFastGPIODirection(1,27,0); //PORT NUM 1,PIN NUM 27,DIRECTION INPUT.FAST IO
T0CCR = 0X01 ; //CAPTURE CONTROL REGISTER THE SEQUENCE 0-1 WILL CAUSE THE REGISTER TO LOAD WITH TC VALUE
return(0);
}
UL32 InitTxRx()
{
U8 b_ReadFlag =0; //READ THE STATUS OF RECEIVER PIN
U8 b_Count = 0; //TRANSMIT THE WAVE FOR B_COUNT TIMES
//TO CALCULATE THE AVERAGE DISTANCE
UL32 TempArray[AVG_VAL]={'\0'}; //TEMP ARRAY TO STORE AVERAGE DELAY
for(b_Count = 0 ; b_Count <= AVG_VAL ; b_Count++) //LOOP TO TRANSMIT AND RECEIVE THE FREQ AVG NUM OF TIMES
{
EnableTimer(0); //ENABLE TIMER I.E START TIMER
WriteFastGPIO(GPIO_PORT0,26,HIGH); //MAKE THE TX PIN HIGH FOR TRANSMITTER
DelayUs(0,13);
WriteFastGPIO(GPIO_PORT0,26,HIGH);
DelayUs(0,13);
while(b_ReadFlag != 1) //READ THE PIN STATUS
{
b_ReadFlag=ReadFastGPIO(GPIO_PORT1,27); //READ FAST GPIO
}
ul_TCVal = T0CR0 ; //COPY CAPTURE VALUE TO STORE IN GLOBAL DELAY VARIABLE
ul_StoreDelay[b_Count] = ul_TCVal ; //STORE THE DELAY IN GLOBAL ARRAY POSITION WISE
WriteFastGPIO(GPIO_PORT0,26,LOW); //TURN OFF THE TRANSMITTER
T0TCR = 0x02; //RESET TIMER
disable_timer(0); //DISABLE TIMER
}
for(b_Count=0 ; b_Count <= AVG_VAL ; b_Count++) //CALCULATE THE AVERAGE VALUE
{
TempArray[b_Count] = TempArray[b_Count] + ul_StoreDelay[b_Count];
ul_TCVal = (TempArray[b_Count]/AVG_VAL);
}
return(ul_TCVal);
}
if anybody can give idea through algorithm will also be helpful?
Basically how to capture a square wave and calculate the travelling time.