Other Parts Discussed in Thread: CC2652RB
Hi all,
I am connecting my Launchpad CC2652RB with an Ultrasonic HC-SR04 sensor. I am using Sensor Controller Studio for the code. The code I've used is below:
// sending the 10us trigger signal
timer0Start(TIMER0_MODE_SINGLE, 240,0);
gpioSetOutput(AUXIO_O_TRIGGER_PIN);
timer0Wait();
gpioClearOutput(AUXIO_O_TRIGGER_PIN);
//starting a 0.15s timer
timer0Start(TIMER0_MODE_SINGLE,367,12);
tdcSetCntSource(TDC_CNTSRC_96M_RCOSC);
tdcSetTriggers(TDC_STARTTRIG_AUXIO_HIGH_BASE + AUXIO_I_ECHO_PIN, TDC_STOPTRIG_AUXIO_LOW_BASE + AUXIO_I_ECHO_PIN,0);
tdcEnable();
tdcArm(TDC_START_ASYNC);
do {
U16 timerIsRunning;
timer0CheckState(timerIsRunning);
U16 timeout = timerIsRunning ^0x0001;
U16 checkEV;
tdcCheckDoneEv(checkEV);
U16 done = checkEV|timeout;
} while(done==0);
timer0Stop();
tdcGetValue(output.valueHigh, output.valueLow);
tdcDisable();
I am fairly certain that the first part of the code works (the 10ms trigger pin signal), because I am actually getting periodical readings from the sensor. However, I am not getting the readings I expect from the tdcGetValue procedure.
The Echo pin goes high when the bounce back ultrasound signal is received after it is triggered by the Trigger Pin. The time period for which it goes high is the time the ultrasound has travelled. Hence, I would like to read the duration of the Echo pin high signal with tdcSetTriggers. The output values for the high and low value for tdcGetValue are very inconsistent though. I can point the sensor around the room and it will stay around 7000, for example. At other times I can move an object very close and it will jump to 40000. Even if I cover both signals completely with my hand, which should result in a timeout, I get readings.
I can't find the mistake in my code so if anyone is able to point me to it, I would appreciate all the help!
Thanks!