Skip to main content
Mike2020
Visitor II
March 26, 2020
Solved

Timer Interrupt STM32F030C6 with Tim16 and Tim17

  • March 26, 2020
  • 2 replies
  • 2098 views

Hi guys,

I'm using STM32CubeIDE with STM32F030C6 at 48Mhz.

I'm trying to generate the graph below in my application, but I only have Timer 16 and 17 available. Is this possible? Could someone give me a tip? Thanks!

This topic has been closed for replies.
Best answer by berendi

Yes, it's possible.

Using interrupts:

  • Set up the timer channel as described in the PWM mode section of the reference manual, Enable the update interrupt in DIER.
  • The interrupts will be coming fast, so don't waste much time in the interrupt handler. Clear the SR register, increment a counter, rewrite ARR and CCR1 when the counter reaches the frequency value. Don't use any HAL functions, there are too slow.

Using the other timer as a 1s timebase:

  • Set up the timer generating the PWM signal like above, but don't request interrupts.
  • Set up the other timer to generate an interrupt once every second.
  • Starting the timers is a bit tricky, because there is no hardware synchronization between them, so:

  • disable interrupts
  • start the first timer (the one doing the PWM)
  • start the other timer (which generates the interrupt)
  • enable interrupts

2 replies

waclawek.jan
Super User
March 26, 2020

Can't you generate the waveform on the output pins from some of these timer's channel, as PWM?

Frequency then can be changed in any other convenient way, e.g. using the systick interrupt.

JW

berendi
berendiBest answer
Principal
March 26, 2020

Yes, it's possible.

Using interrupts:

  • Set up the timer channel as described in the PWM mode section of the reference manual, Enable the update interrupt in DIER.
  • The interrupts will be coming fast, so don't waste much time in the interrupt handler. Clear the SR register, increment a counter, rewrite ARR and CCR1 when the counter reaches the frequency value. Don't use any HAL functions, there are too slow.

Using the other timer as a 1s timebase:

  • Set up the timer generating the PWM signal like above, but don't request interrupts.
  • Set up the other timer to generate an interrupt once every second.
  • Starting the timers is a bit tricky, because there is no hardware synchronization between them, so:

  • disable interrupts
  • start the first timer (the one doing the PWM)
  • start the other timer (which generates the interrupt)
  • enable interrupts