Hi Adrian,
Finally managed to configure the timers to get the range reading.
code is
void GetRange (void){
PWM1_SetDutyUS(PWM1Ptr, 35u);
PWM1_Enable(PWM1Ptr);
Index = 0;
Error = TU1_ResetCounter(MyTU1Ptr); /* Start new measuring */
Overflow = FALSE;
Done = FALSE;
do {} while (!Done && !Overflow) ; /* Wait for end of measurements or time-out */
if (Overflow) {
/* Time out. Period of measured signal is too long */
Bit2_PutVal(Bit2Ptr, 0);
}
else {
/* TU1_CNT_INP_FREQ_R_0 is a counter input frequency in Hz - see header file */
Period = (Ticks[1] - Ticks[0]) / TU1_CNT_INP_FREQ_R_0; /* Period of the signal in seconds */
}
PWM1_Disable(PWM1Ptr);
}
int j=0;
for(;;){
GetRange();
Range = Period * 34000/5;
for(j= 1; j<= 10000; j++){
Bit1_PutVal (Bit1Ptr,Range< 10);
}
}
On the events
void TU1_OnChannel0(LDD_TUserData *UserDataPtr)
{
/* Write your code here ... */
Error = TU1_GetCaptureValue(MyTU1Ptr,CHANNEL,&Ticks[Index]); /* Store captured value to array Ticks */
Index++;
if (Index >= NUMBER_OF_MEASUREMENTS) {
Done = TRUE;
}
But the measurement is not 100% accurate.
Kesara De Costa