Eren Aydemir

MC9S08EL32 TPM Interrupt

Discussion created by Eren Aydemir on Jul 24, 2012
Latest reply on Jul 25, 2012 by Eren Aydemir

Hi Everyone,

 

Iam using MC9S08EL32 MCU and trying a make blinking LED periodically. Iam not much familiar with this MCU and need to use it. Just 2 weeks past with this MCU. Here is my code:

 

#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */    
#include "utility.h"
#define LED PTBD_PTBD5
char button_counter;

void MCU_init(void)
{

LED=0;
button_counter=0;


TPM1SC = 0x00; /* Stop and reset counter */
TPM1MOD = 0x05DCU; /* Period value setting */
(void)(TPM1SC == 0); /* Overflow int. flag clearing (first part) */
/* TPM1SC: TOF=0,TOIE=1,CPWMS=0,CLKSB=0,CLKSA=1,PS2=1,PS1=1,PS0=0 */
TPM1SC = 0x4E; /* Int. flag clearing (2nd part) and timer control register setting */
/* ### Init_GPIO init code */
/* PTBPE: PTBPE5=0 */
PTBPE &= (unsigned char)~0x20;
/* PTBDD: PTBDD5=1 */
PTBDD |= (unsigned char)0x20;

}

 

__interrupt void isrVtpm1ovf(void)
{
button_counter++;
}

 

void main(void) {

if(button_counter>100) {
LED = ~LED;
button_counter=0;
}

 

What is wrong with this code? If is not what is suppose to be changed? Am I suppose to be used TPM overflow flag (TPMSC1_TOF)  or what? Thank you.

Outcomes