cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to frequently read motor hall sensor in XOR ON / Hall Sensor Mode

Gladson
Associate III

I am designing a BLDC motor controller using STM32F103C8T6. I am using "XOR ON / Hall Sensor Mode" for reading the motor's hall sensor. But if the motor is rotated quickly, the hall sensor value does not update. The hall sensor value updates properly if motor is rotated very slowly. I have removed all other parts from the code, The only code in the program is of reading hall sensor pins.

 

 

void TIM4_IRQHandler(void)
{
  /* USER CODE BEGIN TIM4_IRQn 0 */
	hallPosx =
			((HAL_GPIO_ReadPin( HW_GPIO_Port, HW_Pin ) << 2)
			|(HAL_GPIO_ReadPin( HV_GPIO_Port, HV_Pin ) << 1)
			| HAL_GPIO_ReadPin( HU_GPIO_Port, HU_Pin ) );
 );
	if (0U == LL_TIM_IsActiveFlag_UPDATE(TIM4))
	{
		/* Nothing to do */
	}
	else
	{
		LL_TIM_ClearFlag_UPDATE(TIM4);
	}
	if (LL_TIM_IsActiveFlag_CC1 (TIM4) != 0U)
	{
		LL_TIM_ClearFlag_CC1(TIM4);
	}
	else
	{
		/* Nothing to do */
	}


  /* USER CODE END TIM4_IRQn 0 */
  /* USER CODE BEGIN TIM4_IRQn 1 */

  /* USER CODE END TIM4_IRQn 1 */
}

 

 


This is the configuration.

Gladson_0-1708437766884.png

 

3 REPLIES 3

> But if the motor is rotated quickly, the hall sensor value does not update.

How do you know?

What does it mean "quickly"? Quantify.

What's the mcu clock setup?

Also, read out and post TIM4 registers content.

JW

PS. Don't tag the post "STM32F0" if you use STM32F1.

 

How do you know?


I am using the "live expressions" to watch the variable (hallPosx) in which I am storing the hall sensor value. but if I rotate the motor such that the hall sensor state changes faster than about half a second, then the variable (hallPosx) does not update. Then when the motor stops rotating, the variable is updated.

If I rotate the motor very slowly, such that the hall sensor states change slower than 1 second, then the values update properly.

This is the mcu clock setup.

Gladson_0-1708483355677.png

 

PS. Thank you for pointing out the mistake in tags, I have updated it
 

64MHz system clock should be enough even with the pathetic Cube/HAL interrupt handling to capture something like a 1kHz signal. Try incrementing a variable qualified as volatile.

Also, read out and post TIM4 registers content.

JW