MC9S08EL32 TPM Interrupt

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

MC9S08EL32 TPM Interrupt

664 Views
e_ay
Contributor I

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.

Labels (1)
0 Kudos
2 Replies

394 Views
bigmac
Specialist III

Hello,

 

Problem 1:  Your program structure is wrong - main() function should never exit.  I suggest that you create a new project using the wizard, that will provide a framework for the file main.c.  You can then "fill in the blanks" with your project code.

 

Problem 2: In the absence of an explicit vector table definition, your ISR definition needs to incorporate the required vector number so that the appropriate vector will be correctly programmed.

__interrupt <vector_number> void ISR_name( void);

However, if you have used Processesor Expert, a vector table may already exist.

 

Problem 3:  Your ISR code needs to clear the overflow interrupt flag for the TPM module, otherwise you will immediately re-enter the ISR.

 

Regards,

Mac

 

0 Kudos

395 Views
e_ay
Contributor I

Thank you for your reply bigmac. Actually one of the problem is my processor expert doesnt work. Iam trying to generate code from old version (3.2 i guess) with processor expert and copying files to new version but lots of error appearing. I have looked at videos and documents of freescale and see that in the processor expert menu there sould be "view" but i dont have any. Is my program limited version?. I put 2 pictures in order to see my processor exp menu and my codewarrior version.

 

Regards.

 

 

0 Kudos