AnsweredAssumed Answered

ADuC7060 PWM update/reload

Question asked by tcachat on Mar 12, 2013
Latest reply on Jan 14, 2016 by MMA

Dear all,

 

We use a PWM output not to control a motor or produce an analog level, but to produce a square wave at variable frequency (the duty cycle needs to be about 1/2). We have discovered unexpected behavior of the PWM when we change the period. The code is the following

 

GP1CON |= BIT16; // PWM output on P1.4

PWMCON    = BIT7+BIT6 + BIT3 + BIT0; // Prescaler, reload, enable,

 

...

 

while(1) {

 

  dwPeriodeOutTmp = 0x141;

  PWM1COM0 = dwPeriodeOutTmp>>1;

  PWM1LEN = dwPeriodeOutTmp;

 

... wait for some time, observe the output

 

  dwPeriodeOutTmp = 0x140;

  PWM1COM0 = dwPeriodeOutTmp>>1;

  PWM1LEN = dwPeriodeOutTmp;

 

... wait for some time, observe the output

}

 

At the time when the period is changed, it can happen that the output is stalled at high for about 100 ms, which is the maximal period of the PWM according to the prescaler (possibly it happens when the counter precisely reach 0x140 at the time of change).

 

If we do the same thing with 0x140 and 0x139, it is different: the output stays low for one normal period, then there is a very short glitch.

 

We have tried to remove BIT3 (reload) in PWMCON, without effect. It seems we cannot use interrupt to update the PWM Timer at the right moment. Is there a better way to update it? I would prefer not to stop it and start it again.

 

Outcomes