cancel
Showing results for 
Search instead for 
Did you mean: 

Need to count the pulses from a device using Interrupt in STM32H750VB

nanotronicsnss
Associate II

Hi,

I need to count the number of pulses from a device which is connected to STM32 IC. For counting pulses i have activated the interrupt using Timer 2 and i have used channel 1 (PA0).The parameter setting for enabling and using Timer2 in CUBEMX is given as an Image File(settings CUBE).Now for activating the interrupt HAL_TIM_OC_Start_IT(&htim2); command is used and whenever the line

count=__HAL_TIM_GET_COUNTER(&htim2);

is used inside the while loop the pulses is counted i.e., count value is incremented but when i use the same line inside interrupt call i.e., void TIM2_IRQHandler(void) {} the count value is not incrementing..I dont know where i have done mistake..Kindly correct me if i have done any mistake in the coding..

Interrupt call Coding:

void TIM2_IRQHandler(void)

{

 /* USER CODE BEGIN TIM2_IRQn 0 */

 /* USER CODE END TIM2_IRQn 0 */

 HAL_TIM_IRQHandler(&htim2);

 /* USER CODE BEGIN TIM2_IRQn 1 */

 count=__HAL_TIM_GET_COUNTER(&htim2);

// HAL_GPIO_TogglePin(PROCESS_LED_GPIO_Port,PROCESS_LED_Pin);

 /* USER CODE END TIM2_IRQn 1 */

}

 

i have also tried with

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim2)

{

  count=__HAL_TIM_GET_COUNTER(&htim2);

}

but still the count value is not incremented...

2 REPLIES 2
Uwe Bonnes
Principal II

Can you route the signal to the external input ETR of a counter? Then you do not need an interrupt!

Thanks for ur reply.. i have enabled the pulse as external interrupt and counted the pulse..