Kaare Mai

QE128 Timer problem

Discussion created by Kaare Mai on Nov 9, 2009
Latest reply on Nov 10, 2009 by bigmac

Hi

 

I have a weird problem with the MC9S08QE128 device and timer operation.

 

I want to use a timer as a PWM output so i do it like this:

 

// Set PWM to BUSCLK and prescaler to 0

TPM1SC = 0x08;

 

// Edge-aligned PWM, High-true pulses

TPM1C2SC = 0x28;

 

// Set the period 

TPM1MOD = 32000;

 

// Set the duty cycle to 50%

TPM1C2V = 16000;

 

However the above code does not change the Modulo or the dutycycle the first time it is run. I need to run the above code block twice to get it to set the TPM1MOD and TPM1C2V registers and i need to wait at least 10mS between the two writes for it to work. Why is that?

 

Also, i use an external 32.768 Khz crystal and the bus is set to run at 20MHz. When i measure on the above mentioned output, it takes aprox. 2.5 seconds before the pwm is available from when i hit Run in the debugger.

Message Edited by Kaare on 2009-11-09 12:41 PM

Outcomes