cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G031G8Ux Timer as pulse counter did not work properly - very frustrating

ABucs
Associate II

Hi All,

I'm getting very frustrated about a weird behavior of STM32G0 microcontroller; why? because I did similar projects with members from different families and all work. So I don't know. Maybe I'm doing something wrong with this one.

The application is to count a number of rise and fall transitions between 2 timers events; for this reason I have Timer3 configure as PWM output, and I use 2 channels (2 and 3) to set the window where I need to count. Timer 3 generates interrupts and Timer 1 is used as transitions counter; PA11 is mapped as PA9 and the timer use CH2 (TI2FP2) to trigger the counter.

I initialize both timers 1 and 3 and then I start them with:

HAL_TIM_PWM_Start_IT(&htim3, TIM_CHANNEL_2);
HAL_TIM_PWM_Start_IT(&htim3, TIM_CHANNEL_3); and
 
HAL_TIM_Base_Start(&htim1);
 
on PulseFinishCallback event I reset the counter then read-it as follows:
void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)  
{
    if (htim->Instance==TIM3) // check if the interrupt comes from TIM3
      {
if (htim->Channel==HAL_TIM_ACTIVE_CHANNEL_2)// consider a window between channel 2 and channel 3 autoreload (the window is in the middle of ch1 PWM low state)
{ __HAL_TIM_SET_COUNTER(&htim1, 0);// reset the timer counter at the end of PWM cycle (under low state)
......
}
if (htim->Channel==HAL_TIM_ACTIVE_CHANNEL_3)
{
cmp = __HAL_TIM_GET_COUNTER(&htim1); // read the counter when TIM3 CH3 reload
}
 
The problem is that cmp remains 0 even if I have pulses at PA9 input. TIM3 CH2 had auto reload value smaller than CH3. I've test and both TIM3 events are happened. A similar application was working on STM32F0.
 
What do I miss ...some initialization/ hidden setting? there is a known bug in HAL package or CubeMX? For both I use the latest versions (V6.13.0/ G0 FW 1.6.2)).
 
Any feedback is welcomed... 
 
Thanks,
-an

 

0 REPLIES 0