cancel
Showing results for 
Search instead for 
Did you mean: 

How to configure PWM as Gated output?

GenuineDeveloper
Associate III

Hi,

I am using STM32F072VBT6. I need a PWM waveform output that is gated with a PWM output of another timer channel.

I am using TIM3_CH1 as the master that will control the output of another PWM of TIM2_CH1. Please refer the image for clarity. I need waveform (C) as output. So far, I am able to generate waveforms (A) and (B) separately, now I need the gated output. Is it possible by software? Or should I use a AND gate IC externally?

0690X00000DXUt4QAH.jpg

1 ACCEPTED SOLUTION

Accepted Solutions

In TIM3, set CH1 (OC1REF) as TRGO in TIM3_CR2.MMS.

In TIM2, set TIM3 as TRGI source (in TIM2_SMCR.TS, see "internal trigger connection" at the end of TIM2_SMCR subchapter), and set Gated Mode in TIM2_SMCR.SMS.

JW

View solution in original post

2 REPLIES 2

In TIM3, set CH1 (OC1REF) as TRGO in TIM3_CR2.MMS.

In TIM2, set TIM3 as TRGI source (in TIM2_SMCR.TS, see "internal trigger connection" at the end of TIM2_SMCR subchapter), and set Gated Mode in TIM2_SMCR.SMS.

JW

The period of the master should be an exact multiple of the period of the slave, i.e. (TIM3->ARR + 1) % (TIM2->ARR + 1) should be 0, because the master PWM is gating the slave counter, not the output. Otherwise the TIM2_CH1 output would sometimes remain high, if TIM3_CH1 goes low at the wrong time.