cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronized PWM outputs with offset?

DPaul.2
Associate II

Is it possible in the STM32 world to have two synchronized PWM - but with an offset separating the outputs?

Here's the problem in picture form:

0693W00000JMwz7QAD.pngBoth the blue and red traces are the same frequency and duty cycle, but in this case trace red is offset 50 mS from trace blue.

I managed this on another micro (NXP) where their SCTimer function allows "events" to be associated with the first/red PWM. In this case there are essentially two events tied to trace blue (an on and an off) which result in the trace blue.

Alas, nothing quite so simple appears in the STM32 world, or at least that I've been able to identify (which is probably why NXP crows so much about there SCTimer). Right now, I am thinking I can fiddle with trace red as sort of a modified inverse one shot of trace blue. Seems a little crude, however, I assume there's got to be a better way.

I guess the question has two parts: First, is the above possible and second (optional) some pointers on the requisite setup.

I admit this question was recently posted (in much more general terms). Admonishment to read the manual appeared - which is undoubtedly true in the larger sense. But I'm not ashamed to admit, however, I'm trying to piggyback on existing knowledge. Something like not re-inventing the wheel if the requisite technique is public knowledge (or cheating a bit from another perspective).

Well, thanks much if you can offer any ideas. Meanwhile I'll be rooting around in that user manual....

The target in this case is an STM32G0B1, if that matters.

doug

4 REPLIES 4
KnarfB
Principal III

Hi Doug,

can be done with "Combined PWM Mode" for some timers in some series, like TIM1 on G0.

For example, set TIM1

0693W00000JMxTcQAL.pngin main, just start the timer channels:

  MX_TIM1_Init();
  /* USER CODE BEGIN 2 */
 
  HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1 );
  HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2 );
  HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_3 );
  HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_4 );
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */

and you will get 2 phase correlated PWMs with independent duty cycles:

0693W00000JMxVDQA1.pnghth

KnarfB

As KnarfB said above, in the 'G0 it can be done within a single timer.

In older models where the Combined/Asymmetric modes are not available in timers, this still can be pulled out by synchronizing a slave timer to a channel set to output compare in master timer; the compare value of this channel determines the delay.

JW

Hey KnarfB:

Thanks for your response! I threw your recommendations into a quick STM32G031-Nucleo project and got the dual synchronized outputs you promised (although quite different from your trace). I need to study your solution and (hopefully) tweak it to meet our requirements, but initially it looks very promising. I owe you a big one here!

Great. I used STM32L432KC with a prescaler down to 1ms/tick and a timer period (ARR) of 1000-1 in case you want to match the waveforms.

KnarfB