Author Topic: Having issues with using simultaneous timers [STM32]  (Read 1254 times)

0 Members and 1 Guest are viewing this topic.

Offline XaviPachecoTopic starter

  • Regular Contributor
  • *
  • Posts: 243
  • Country: do
Having issues with using simultaneous timers [STM32]
« on: October 17, 2018, 11:57:04 am »
In my nucleo L432KC, I have set Timer 1 for PWM generation, Timer 15 as a timer based interrupt and Timer 2 as PWM input mode. Timer 1 and Timer 15 works well until a point. My clock frequency is 2MHz. For example, I wanted a 50 kHz update event, so I set Timer 15 Precaler 0 and period 39. in that case While(1) loop never executes, i.e, the program hangs.

When I start timer 2 as:

HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_3);
HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_4);

My timer 1 misbehaves. The program in general misbehaves. What could be happening here? It's like Timer 15 interrupt is taking all the control? Is something related with interrupts priorities?
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8167
  • Country: fi
Re: Having issues with using simultaneous timers [STM32]
« Reply #1 on: October 17, 2018, 12:57:53 pm »
It's impossible to say with so little info.

The HAL is great as long as everything just works out, but when it doesn't, you don't have visibility, or knowledge how the timers work internally. The two first things I'd do here:
1) Read the relevant timer sections of the reference manual, so that you have an idea about they are supposed to work internally, including the status register,
2) Then I'd look up these HAL functions and bring their code - even with just copypasting - to your own program. Even though you could use a debugger to see what happens in the HAL functions, it's easier to have it in your own code base, so you can make any modifications to test things out.

When you do that, you are exposed to the status registers of the timers, can look at them in debugger on print them out any way you wish. This gives you a starting point how to investigate such issues.

If your "program hangs", there tends to be two possibilities,
1) you have an ISR which reruns infinitely because the relevant flag is not cleared, not a single cycle is available to your main program. With a debugger, just stop and see where you are. Without a debugger, turn on an LED at the beginning of the interrupt handler and turn it off at the end. You instantly see the CPU time spent in the interrupt from the LED brightness (and can look it up with a scope for precise timing).
2) some of those HAL_ functions have a while() loop which does something (polls for a status), and if never satisfied, locks the system up. IMHO, a timer start function shouldn't need such a while() loop at all, but the HAL is quite crap...ish so it's well possible.

Do you have hardfault, busfault, usagefault etc. handlers?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf