I am using MC9S08AW60A with DEMO9S08AW60E Board (Freescale). I have studied about the timers given with the MCU. I wish to know how exactly to Implement timers by code. The Freescale suite also comes with Processor Expert (a GUI to configure the MCU).
I have written the following code to light-up the LED's in a sequential manner WITHOUT using a DELAY function i.e only by altering/using TIMERS and INTERNAL CLOCK GENERATOR.
//------------CODE BEGINS------------
PTFDD = 0xFF;
TPM1SC = 0x0E;//configures the Timer 1 Status and Control Register
TPM1C2SC = 0x98;//configures the TImer 1 CHANNEL 2 Status and Control Register
ICGC1= 0xE8; //Have altered the ICG with respect to TPM.
ICGC2= 0x8E;
//As you can see i have not altered the ICG in any way.And the same values as above
//(for TPM) i have emulated using the Processor Expert.
for (i=1;i<=8;i++)
{
if (i==8) i = 1;
if (i==1) PTFD = 0x01;
if (i==2) PTFD = 0x02;
if (i==3) PTFD = 0x04;
if (i==4) PTFD = 0x08;
if (i==5) PTFD = 0x10;
if (i==6) PTFD = 0x20;
if (i==7) PTFD = 0x40;
}
//----------CODE ENDS-----------------
But all I get:
- LEDs are on but very dim, I think they're toggling very quickly. Am I right?
- Also, Do I need to change the ICG settings if using TImer?
- Also, i have initialized the device with Processor Expert and written the same as code. does it interfere. (i have made sure both represent the same values,else it would have shown me an error.
On the data sheet, refer to page 165 for the timer/PWM and page 129 for Inter Clock Generator.