Skip to main content
Paolo Chiantore
Associate II
Jun 19, 2017 1:26 PM UTC
Solved

HTIM UIF clear from capture callback

Posted on June 19, 2017 at 15:26

On a STM32 F777 I am configuring TIM4 to read Hall sensors (HAL_TIMEx_HallSensor_Init).

I have enabled capture interrupt and in capture callback  (which is triggered at every Hall event as expected) I am clearing UIF flag (i.e. timer overflow flag).

The issue is that everytime the capture callback is triggered UIF flag is always found to be one even if I measure Hall events faster than timer overflow (which is expected every 32.7 ms). With reference to the attached figure: code never breaks in line 282.

Any hint appreciated.

#callback #tim #clear #uif
This topic has been closed for replies.
waclawek.jan
waclawek.janBest answer
Super User
Jun 19, 2017 4:09 PM UTC
Posted on June 19, 2017 at 18:09

HAL_TIMEx_HallSensor_Init sets SMS to Reset on every edge

  /* Use the TIM_TS_TI1F_ED signal to reset the TIM counter each edge detection */  

  htim->Instance->SMCR &= ~TIM_SMCR_SMS;

  htim->Instance->SMCR |= TIM_SLAVEMODE_RESET;

Slave reset causes the update flag to be set:

100: Reset Mode - Rising edge of the selected trigger input (TRGI) reinitializes the counter

and generates an update of the registers.

JW

2 replies

waclawek.jan
waclawek.janBest answer
Super User
Jun 19, 2017 4:09 PM UTC
Posted on June 19, 2017 at 18:09

HAL_TIMEx_HallSensor_Init sets SMS to Reset on every edge

  /* Use the TIM_TS_TI1F_ED signal to reset the TIM counter each edge detection */  

  htim->Instance->SMCR &= ~TIM_SMCR_SMS;

  htim->Instance->SMCR |= TIM_SLAVEMODE_RESET;

Slave reset causes the update flag to be set:

100: Reset Mode - Rising edge of the selected trigger input (TRGI) reinitializes the counter

and generates an update of the registers.

JW

Paolo Chiantore
Associate II
Jun 20, 2017 9:21 AM UTC
Posted on June 20, 2017 at 09:21

Thank you Jan, you are right.

The solution in my use case is to set TIM4_CR1.URS bit so that UIF flag is set just by overflow events,  while slave generated update events will be ignored.