Hello guys, I'm trying to use the Icu to interface an HC-SR04 sensor.
Here's my pin mapping so far:
Vcc - 5V pin,
Echo - PTB2 (FTM1_CH0)/ Input
Trig - PTB3 (GPIO)/ Output
I'll try to show you all the configurations I've done in Eb Tresos :
here's the port configuration :
here's the Icu configuration :
and I'm thinking this is all it takes for the Mcu Configuration:
here's my code:
Icu_ValueType highTimeValue;
int main()
{
Mcu_Init(&Mcu_Config);
(void)Mcu_InitClock(McuClockSettingConfig_0);
Port_Init(&Port_Config);
Icu_Init(&Icu_Config);
Icu_StartSignalMeasurement(IcuConf_IcuChannel_IcuChannel_0);
while( 1 )
{
// Output 10us HIGH on TRIG pin
Dio_WriteChannel(DioConf_DioChannel_TRIG_PIN, STD_HIGH);
uS10_Delay(1);
Dio_WriteChannel(DioConf_DioChannel_TRIG_PIN, STD_LOW);
while(Icu_GetInputState(IcuConf_IcuChannel_IcuChannel_0) == ICU_IDLE);
if(Icu_GetInputState(IcuConf_IcuChannel_IcuChannel_0) == ICU_ACTIVE)
{
highTimeValue = Icu_GetTimeElapsed(IcuConf_IcuChannel_IcuChannel_0);
}
uS10_Delay(100000);
}
}
Idk why but my code can't enter this if statement:
if(Icu_GetInputState(IcuConf_IcuChannel_IcuChannel_0) == ICU_ACTIVE)
I've tried using Dio_ReadChannel for that pin and it does say HIGH;
and when I use an IcuMeasurementMode of ICU_MODE_EDGE_COUNTER, it works.
can someone please help me...
@namnguyenviet
Hi @cabz,
The Icu_GetInputState only support for ICU_MODE_SIGNAL_EDGE_DETECT and didn't support for other modes.
In the ICU_MODE_EDGE_COUNTER, this function will return ICU_ACTIVE if occur the situation if (ICU_CHANNEL_STATE_IDLE == Icu_GetBitChState).
Best regards,
Dan