cancel
Showing results for 
Search instead for 
Did you mean: 

2 pwm-signals with a different starting time

thilo
Associate II
Posted on January 21, 2003 at 02:42

2 pwm-signals with a different starting time

5 REPLIES 5
thilo
Associate II
Posted on December 17, 2002 at 09:50

Hello,

I want to generate two pwm-signals with a different starting time (90° phase shift). I use the ST72521 and I have two timers on board. The signal and the pulselength is 50 : 50. To get the maximal frequency I need a starting ramp. I have the knowledge about generating a pwm signal with a timer, but the problem is the different starting time of the 2nd signal.

Is it possible to generate this signals and the ramp with a Timerinterrupt ? Is there anybody who can help me, maybe with a example in c? Thanks a lot.

thilo
maxime2399
Associate II
Posted on December 19, 2002 at 21:47

I think there is no easy way to synchronise the timers as you are saying.

(they are not designed for that)

But you can imagine doing the function using one timer in compare mode and using the two output compare to generate the two signals.

the disadvantage of this method is that you do not have anymore a precise control of your PWM period.

What are your PWM frequency and precision requirement?

thilo
Associate II
Posted on December 20, 2002 at 11:03

Thanks a lot for your answer. My PWM frequency has to be between 500Hz to 1000Hz. The most important requirement in my application is the phase shift between the signals.

maxime2399
Associate II
Posted on December 23, 2002 at 17:43

At such a low frequency you should have no problem to implement it by software.

try something like that:

T is the PWM period and Ton+Toff=T.

in Timer initialisation:

OC1: Whatever

OC2: OC1 + T/2

CR2 register: OC1E=OCE2=1, OPM=PWM=0, CC1:CC0=01

CR1 register: OCIE=1, FOLV1=FOLV2=1, OLVL1 & OLVL2 = original PWM state

CR1 register: OCIE=1, FOLV1=FOLV2=0, OLVL1 & OLVL2 = complementary of previous line

in OC1 Timer Interrupt routine:

In case OLVL1 = 0: OC1 <- OC1+Ton

Else: OC1 <- OC1+Toff

Toggle OLVL1

in OC2 Timer Interrupt routine:

In case OLVL2 = 0: OC2 <- OC1+Ton

Else: OC2 <- OC1+Toff

Toggle OLVL2

thilo
Associate II
Posted on January 21, 2003 at 02:42

Thanks a lot. This was a great idea!