HC908QY4A PWM initialization with low-level on output

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HC908QY4A PWM initialization with low-level on output

3,550 Views
Soror
Contributor I
hi,

I initialized my HC908QY4A with a PWM to let an LED go on and off. That's working fine from 0 to 100%. After a reset the system starts with a dutycycle of 0%. My problem is that during the initialization of the PWM the LED flashes for a short moment. I realized that the PWM-output is set to a high level after the initialization. I think I reach the 0%-duty-cycle after starting the timer and reaching the first Toggle-On-Overflow.

So my question is: Is it possible to initialize a PWM whithout getting this short high level out of the port during the initialization?

Thanks a lot,

Soror


My code is:

TCH1H = 0;
TCH1L = 0;/* Store values to the duty-compare register */

setReg8(TSC, 0x10); /* Stop and reset counter */


//Set PWM-Mode with 0% DutyCycle
clrReg8Bits(TSC1, 0x03); /* Set conditions of 0 percent duty-cycle */

setReg8(TSC1, 0x58); /* Set up PWM mode => SETS OUTPUT TO HIGH LEVEL*/

clrReg8Bits(TSC, 0x80); /* Reset request flag and */
setReg8Bits(TSC, 0x40); /* enable interrupt */
setReg8(TMODH, 0x3F); /* and to the period-modulo register */
setReg8(TMODL, 0xFF);
TSC_PS = 0x00;//Val; /* Store given value to the prescaler */
TSC_TRST = 1;

clrReg8Bits(TSC, 0x20); /* Timer Start */

Message Edited by Soror on 2007-03-1303:12 PM

Labels (1)
0 Kudos
8 Replies

527 Views
bigmac
Specialist III
Hello,
 
To actually achieve a zero percent duty cycle, the toggle-on-overflow bit should remain clear after initialisation of the unbuffered PWM.  Only when a non-zero duty cycle is required should this bit be set, and this should occur within output compare ISR code, along with setting the new channel register value.  For the HC908 timer, this value should actually be one less than the duty cycle would suggest - for a value of zero, the pulse width would be one timer clock period.
 
Unless the PWM value is about to change, output compare interrupts should otherwise remain disabled for the channel used.
 
Regards,
Mac
 
0 Kudos

527 Views
Soror
Contributor I
Hi Mac,

Thanks a lot for your answer.

In case of a 0% duty-cycle I set the TOV bit to 0 in the ISR and thats working fine. Only during the initialisation of the MCU I get a short flash with a high level.


clrReg8Bits(TSC1, 0x03); /* Set conditions of 0 percent duty-cycle */
==> Disable TOV and MAX

setReg8(TSC1, 0x58); /* Set up PWM mode => SETS OUTPUT TO HIGH LEVEL*/
==> Setting PWM mode results in a high level on the output althought the TOV bit is disabled. Visible as a short flas.

Regards,

Soror
0 Kudos

527 Views
peg
Senior Contributor IV
Hi all,
 
It seems to me the problem is that the OP is trying to start PWM at a very low % and when it is enabled the pin is starting out high and so stays high until the intended pulse comes along and turns it off. Where in the documentation does it say what the intial output level is?
I seem to remember having a similar issue myself but can't exactly remember the solution.
I would try using the Output preset mode (ELSxB:ELSxA = 00) in order to preset the appropriate level before enabling the PWM.
 
0 Kudos

527 Views
rocco
Senior Contributor II
Hi, Soror:

Could the "short flash" be occurring before you initialize the PWM?

Before the timer is enabled, the pin is under control of the GPIO port. If the port's data register is set to one, and the port's data-direction register is also set to one, the port pin will drive high until the PWM is enabled and takes control of the pin.
0 Kudos

527 Views
Soror
Contributor I
hi mac,
hi rocco,
hi peg,

thanks a lot for your answers.

@rocco
I don't set the output or direction registers of the port so I think it should be configured as an input after reset.

@Mac
I'll also check the AN27012.pdf. I didn't check this paper yet, perhaps this will include the reason for my problem.

@peg
I tried all configurations of the PWM. Everyone starts with a short flash.

@all
Unfortunately I am in holidays for a few days. I'll try your solutions after my holidays next week. I'll report my experience shortly. Thanks a lot.



Regards,

Soror

Message Edited by Soror on 2007-03-1503:23 PM

0 Kudos

527 Views
bigmac
Specialist III
Hello Soror,
 
I wonder if your problem might be a question of correct sequencing of the setup of the bits in the TSC1 register.  Have a look at AN2701, and see if it might shed some light on the issue.
 
Regards,
Mac
 

Message Edited by bigmac on 2007-03-1512:56 PM

 

AN2701.pdf

Message Edited by t.dowe on 2009-09-16 10:13 AM
0 Kudos

527 Views
thisobj
Contributor III
Hello,

You mentioned that
"...only during the initialisation of the MCU I get a short flash with a high level".

If you have enabled the pullup resistor on the PTA1/TCH1 pin previous to the PWM setup routine, then there will be a momentary "high" on that pin until it becomes configured as an output channel.

Frank
0 Kudos

527 Views
Soror
Contributor I
Hi Frank,

thanks a lot for your answer. I don't set the pull-ups on the ports. I only activate KBI on ports A2 to A5. But this doesn't set the output A0 and A1 on a high level. Setting the registers TSC0 and TSC1 to 0x58 brings a high level out of the ports A0 and A1.

Regards,

Soror
0 Kudos