cancel
Showing results for 
Search instead for 
Did you mean: 

Timer 2 Input Capture issue.

PSzcz.2
Associate II

Hello there,

I've been messing around with a development board I've recently bought, STEVAL-SPIN3204, and I've been attempting to produce a RPM measurement using one hall effect sensor input attached to the PA5 pin, which with can be set to TIM2_Channel1. Using STM32CubeIDE.

I've been following many examples that I've found online on how to set up Timer Input Capture interrupt and time and time again it didn't seem to be working out for me.

I'm still new to STM32 programming but following examples I learn quite a lot, although I'm stuck on this one problem I cannot seem to go over.

Here's some attachments that I feel should go along with this question.

Code Snip of input capture callback:

/* USER CODE BEGIN 4 */
 
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
	if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1)  // if interrput source is channel 1
	{
		if (Is_First_Captured==0)  // is the first value captured ?
		{
			IC_Value1 = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1);  // capture the first value
			Is_First_Captured =1;  // set the first value captured as true
		}
 
		else if (Is_First_Captured)  // if the first is captured
		{
			IC_Value2 = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1);  // capture second value
 
			if (IC_Value2 > IC_Value1)
			{
				Difference = IC_Value2-IC_Value1;   // calculate the difference
			}
		}
	}
}
 
/* USER CODE END 4 */

Also the timer setup code snip:

  /* USER CODE BEGIN 2 */
 
  HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_1);
 
  /* USER CODE END 2 */

And snips from the STM32CubeIDE:

0693W00000DmnLQQAZ.png0693W00000DmnMEQAZ.png 

I've tried this with toggling LEDs upon an interrupt, just to test the interrupt function, no luck in that either. I'm using "Expressions" to monitor the value of the 'Diffrence' variable that should be the difference between two timer events. But that's not even working or is stuck at a constant 0.

Any assistance would be appreciated, thank you. :)

1 REPLY 1

Read out and check/post TIM and relevant GPIO registers' content.

Some generic "interrupts don't work" hints here.

JW