Skip to main content
BTrem.1
Senior
May 19, 2021
Solved

Can a Timer Capture Compare be skipped if needed?

  • May 19, 2021
  • 2 replies
  • 806 views

I'm using a Timer (TIM8) in a capture compare application for measuring timing between signals. In some cases I don't need the value so I have been skipping the read of the CCRx register. I'm using a HAL command as the code below shows:

The HAL_TIM_ReadCapturedValue() simply reads the CCRx register.

I'm counting on the Timer to continue running and the next IRQ will capture a timer value that would be the same whether or not the previous IRQ occurred. Is this a valid assumption?

I realize the overflow flag will likely be set when I skip a read of the CCRx register but does this have any unforeseen consequences?

	if( htim->Instance == TIM8)
	{
		if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1)
		{
			// toggle ref for viewing in ST GUI
			g_nFrefSignal = !g_nFrefSignal ;
 
			// received REF edge which is 'PU', update state machine,
			switch (p_mPFD->State)
			{
				case COAST:
					p_mPFD->State = ACCEL;
					buffer1[0] = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1) ;
					(p_mPFD->pu_cnt)++;
					break;
				case DECEL:
					p_mPFD->State = COAST;
					buffer1[0] = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1) ;
					(p_mPFD->pu_cnt)++;
					break;
				case ACCEL:
					p_mPFD->State = ACCEL;
					p_mPFD->pu_cnt = 0;
					break;
				default:
					p_mPFD->State = COAST; // should never get here
			}
 // capture Fref period for FRF command
			TIM8_Current++;
		}

Thanks,

Brian

This topic has been closed for replies.
Best answer by TDK

The flag is cleared within HAL_TIM_IRQHandler, so you don't need to read the value in order to clear the interrupt flag. Not reading the value shouldn't cause any issues.

Note this assumes you're using the HAL generated interrupt code. If you're doing your own thing, you need to clear the flag or read the counter in order to clear the flag, otherwise the interrupt will fire continuously.

2 replies

TDK
TDKBest answer
May 19, 2021

The flag is cleared within HAL_TIM_IRQHandler, so you don't need to read the value in order to clear the interrupt flag. Not reading the value shouldn't cause any issues.

Note this assumes you're using the HAL generated interrupt code. If you're doing your own thing, you need to clear the flag or read the counter in order to clear the flag, otherwise the interrupt will fire continuously.

"If you feel a post has answered your question, please click ""Accept as Solution""."
BTrem.1
BTrem.1Author
Senior
May 20, 2021

Thanks TDK,

My code Interrupt handler calls  HAL_TIM_IRQHandler(&htim8), and the code snippet I showed above is in the HAL_TIM_IC_CaptureCallback callback function.

Regards,

Brian