2020-06-22 03:11 AM
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...
2020-06-22 03:45 AM
Can you route the signal to the external input ETR of a counter? Then you do not need an interrupt!
2020-06-25 03:03 AM
Thanks for ur reply.. i have enabled the pulse as external interrupt and counted the pulse..