2021-12-15 01:11 AM
I am using timer 4 in STM32G431 to read hall sensor input and trigger interrupt when high .
.
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?
2021-12-15 06:09 AM
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.
2021-12-15 06:16 AM
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?
2021-12-15 06:37 AM
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?