Skip to main content
Bhavik
Associate II
February 17, 2022
Solved

How to put Delay or offset Between two PWM Pulse.

  • February 17, 2022
  • 5 replies
  • 4709 views

Hello Members,

I am new to STM32 MCUs. I am trying to generate PWM and try to modify on fly and it works. But my requirement is to have a delay between two pulse on time and it should not align to each other on any edge. Please see the photo to understand the expected output.

So requirement is, How to put Delay or offset Between two or multiple PWM Pulse?

0693W00000JQD45QAH.jpg 

MCU: STM32L476

STM32CubeIDE 1.8.0

Thanks

Bhavik

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

The most flexible way is to use combined PWM mode available on some timers. You need 2 timer channels per PWM. This allows you to set the offset for each of the 4 edges indivually. With CubeMX like:

0693W00000JQDMDQA5.pnghth

KnarfB

5 replies

waclawek.jan
Super User
February 17, 2022

Read Combined PWM mode subchapter of TIM chapter.

You can't do this with any arbitrary channel, though.

JW

KnarfB
KnarfBBest answer
Super User
February 17, 2022

The most flexible way is to use combined PWM mode available on some timers. You need 2 timer channels per PWM. This allows you to set the offset for each of the 4 edges indivually. With CubeMX like:

0693W00000JQDMDQA5.pnghth

KnarfB

Bhavik
BhavikAuthor
Associate II
February 18, 2022

@KnarfB​ Thanks for quick reply I tried the mentioned setting but It wont work.

As mentioned I am using STM32L476RG Nucleo Board for testing. Any Clue?

KnarfB
Super User
February 18, 2022

I'm using Nulceo-STM32L432KC here, should be quite similar.

Did you start the PWM channels in the code:

 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 );

hth

KnarfB