How to make the Icu of s32k144 work with MCAL Apis?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How to make the Icu of s32k144 work with MCAL Apis?

603件の閲覧回数
cabz
Contributor II

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 :

AllenGlen_1-1677968635984.png

here's the Icu configuration :

AllenGlen_3-1677968840422.png

AllenGlen_2-1677968818818.png

 

AllenGlen_0-1677968407440.png

and I'm thinking this is all it takes for the Mcu Configuration:

AllenGlen_4-1677968959369.png


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

タグ(3)
0 件の賞賛
返信
1 返信

548件の閲覧回数
nxf78987
NXP Employee
NXP Employee

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).

if (ICU_CHANNEL_STATE_IDLE == Icu_GetBitChState(Channel, ICU_CHANNEL_STATE_IDLE))
{
          tempState = ICU_ACTIVE;
          Icu_ClearBitChState(Channel, ICU_CHANNEL_STATE_IDLE);
}
else if (ICU_MODE_SIGNAL_EDGE_DETECT == \
                 ((*Icu_pCfgPtr[u32CoreId]->Icu_ChannelConfigPtr)[ChannelIndex]).Icu_ChannelMode)
{
          tempState = Icu_Ipw_GetInputState(ChannelConfig) ? ICU_ACTIVE : ICU_IDLE;
}
else
{
          /* Do nothing. */
}
 

Best regards,

Dan

0 件の賞賛
返信