cancel
Showing results for 
Search instead for 
Did you mean: 

Timer Interrupt STM32F030C6 with Tim16 and Tim17

Mike2020
Associate

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!

1 ACCEPTED SOLUTION

Accepted Solutions
berendi
Principal

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

View solution in original post

2 REPLIES 2

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
Principal

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