Dan Sweet

Troubles enabling TPM output compare - MC13213

Discussion created by Dan Sweet on Mar 17, 2008
Latest reply on Mar 24, 2008 by denny george

Hi all,

I've just started using an MC13213 mcu and am struggling setting up interrupts. I am trying to set up timer 0 channel 0 as an output compare to generate an interrupt to be used for a simple delay. I feel like I've set up all of the control registers properly, but once the program is running in the debugger (hiwave w/ P&E micro USB), the free running counter does not appear to be counting which in turn means an interrupt is never generated. Here is my initialization code:

    TPM1SC_CPWMS = 0; //set pwm for output compare
    TPM1SC_CLKSA = 0; //A:B -> 0:1 == System clock
    TPM1SC_CLKSB = 1;
    TPM1C0SC_MS0A  = 1;   //MS0A:MS0B -> 1:0 == outputcompare
    TPM1C0SC_MS0B  = 0;
    TPM1C0SC_ELS0A = 0;     //ELS0A:ELS0B -> 0:0 == software compare
    TPM1C0SC_ELS0B = 0;
    TPM1C0SC_CH0IE = 1;
    TPM1C0SC_CH0F = 0;
    TPM1C0V=TPM1CNT+E_PER_MS;   //set value register for compare

E_PER_MS is equal to the number of clock cycles per ms, so this interrupts once per ms.
Here is my interrupt code:

interrupt 5 void OC0Isr(){
    TPM1C0SC_CH0F;                //Read Flag
    TPM1C0SC_CH0F = 0;            //Clear Flag
    OCmSCnt++;                         /* Increment counter    */

My Delay function (delays a passed number of ms):

void OCDelay(INT16U ms){
    INT16U start_cnt;
    start_cnt = OCmSCnt;
    while((OCmSCnt - start_cnt) < ms){}  /* wait for ms to pass    */

My main function (just to blink an led every .5 seconds:

void main(void) {

 PTCDD = 0x10; // initialize PTC4 as output
 PTCD = 0;  // initialize PTC to 0

for(;:smileywink: {
    PTCD_PTCD4 = ~PTCD_PTCD4;  // invert the output
  } /* loop forever */

  /* please make sure that you never leave main */

Any ideas on what is going on here? I am using the default start08.c startup code, except I disabled the COP timer. Thanks for any suggestions,




Added p/n to subject.

Message Edited by NLFSJ on 2008-03-18 09:30 AM