1

I want four pwm signals and same duty cycle (%50) and same frequency (100kHz) . And ı want this signals phase shift (for ex:45 degrees)

Bjorn
  • 11
  • 3

2 Answers2

1

That goal is possible using an Arduino 2560 and its 4 16-bit timers.

Timer-1 would have its OCR registers set for 20, 40 and 60 (this just happens to work for 100 kHz and 12.5 degree steps). T1's COMP_abc ISR's would start Timers 3, 4, and 5. COMP_c ISR would clear TIMSK1 stopping further Interrupts (then set OCRa to 80-value for 50% duty requirement). All outputs from A channels.

All Timers would use Fast PWM and have the frequency of 100 kHz, all ICRs = 160.

But this use-case is not great to adjust phase. The ICR is only 160 value and what you need for decent phase resolution is an ICR value of 360 or greater. 44.4 kHz frequency (or below) gets you an ICR of 360 with Arduino anyway.

I do something similar at 1 kHz for phase-shifted PWM using Arduino 2560.

stockvu

stockvu
  • 11
  • 2
0

You will have to use timers in master/slave configuration.

You will have to setup timers in slave configuration in such a way, that they receive input from other timers, when it reaches certain value.

Abstract example:

Timer1 is a master and has PWM output on some pin (via capture/compare). It also has a second capture/compare (compare in this case) value set to 1/4 period (ARR/4-1), which triggers TRGO trigger output, which will fire the next timer.

Timer2 is a slave timer and it has a PWM output and it also has TRGI trigger input configured to Timer1 in a mode that starts the counter when it receives TRGI. It also has a TRGO trigger output via another compare value to start the next timer.

Timer3 is the same as Timer2, just started by Timer2 TRGO and outputs TRGI as well.

Timer4 is the same as Timer3, but doesn't have TRGO since it doesn't need to trigger anything.


Timer numbers in the example are purely abstract. In reality you will have to check what timers connect to what. It could very easily be like TIM3 activates TIM5 activates TIM8 activates TIM12. One times can't activate a random other timer, they are wired to one another in a specific way, covered in reference manual of the MCU. You can find it in the document if you search "ITR0" there, you'll see a table for every timer or set of timers with possible connections between the timers.

It should be possible to do it with STM32CubeIDE, although I haven't tried it there.

Ilya
  • 992
  • 7
  • 14
  • If you're interested in figuring out in how to do that on registers, I can suggest you to peek at the github demo of mine that chains timers. Purely registers, heavily commented. It's for different MCU, but timers on STM32 are generally the same or at least very similar across MCU if they have the same number (like TIM1 is identical or nearly identical, TIM8 is identical or nearly identical). Link https://github.com/ellectroid/STM32F746-CMSIS-Chained-Timers-Demo – Ilya May 15 '22 at 20:01