cancel
Showing results for 
Search instead for 
Did you mean: 

Interrupt value does not get reset

Tejashree
Associate III

I am using timer 4 in STM32G431 to read hall sensor input and trigger interrupt when high .

0693W00000Hof0yQAB.png0693W00000Hof1XQAR.png0693W00000Hof27QAB.png.

Above is my setting.

void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)

{

if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1)

{

_hallA = HAL_TIM_ReadCapturedValue(htim,TIM_CHANNEL_1);

    if(_hallA != 0x00U)

{

TIM1->CCR2 = 40000;

}

    else

    {

      TIM1->CCR2 = 10000;

   }

 }

I check for if my hallA is equal to 1.The interrupt gets triggered and sets CCR2 value to 40000.

but when i change my hallA value to 0,it does not change the value of CCR2(CRR2 has contant value of 40000,whether hallA is 1 or 0)

I want to change the value of CCR2 ,depending upon the hallA value.

I don't understand what setting is wrong?

3 REPLIES 3
TDK
Guru

How do you know this code has _hallA = 0 or 1? This value is read from CCR1, not set. How are you "changing" that value?

"If" statements work correctly.

If you feel a post has answered your question, please click "Accept as Solution".
Tejashree
Associate III

void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)

{

if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1)

{

_hallA = HAL_TIM_ReadCapturedValue(htim,TIM_CHANNEL_1);

    if(_hallA != 0x00U) -----here i check hall is 1

{

TIM1->CCR2 = 40000; ------ this is the value for Timer 1 CCR1

}

    else

    {

    TIM1->CCR2 = 10000;

  }

 }

This value is read from CCR1, not set. How are you "changing" that value?

-> Do you mean I should check CCR1 value of timer 4 instead of hallA value?

TDK
Guru

Yes, I can see the check is in your code. Your logic in the if statement matches what you want to happen. However, the value used for that check (_hallA) comes from this statement:

> _hallA = HAL_TIM_ReadCapturedValue(htim,TIM_CHANNEL_1);

How do you know that function is returning 0 or 1?

If you feel a post has answered your question, please click "Accept as Solution".