AnsweredAssumed Answered


Question asked by John McCosh on Jun 30, 2014
Latest reply on Aug 8, 2014 by vicentegomez

I am trying to get the timer to generate a 1 KHz squarewave using the output
compare function.  The timer is setup as follows:


// Timer1 Init  Run timer at 1 MHz  2 MHz bus clock

TPMSC = 0x01;           // select divide by 2 clock disabled

TPMMOD = 0xFFFF;  // Set modulus

TPMC0V = 0x01F4;    // Set initial half period (500)

TPMC0SC = 0x54;     // enable interrupt, toggle pin on compare

TPMSC = 0x09;         // enable timer 1us per tick bus clk / 2


The Timer ISR looks like this:


// Timer Channel 0 Interrupt

interrupt VectorNumber_Vtpmch0 void TPMCH0 (void)


     byte    temp;

      temp = TPMC0SC;      // Clear interrupt flag

     TPMC0SC_CH0F = 0;


     TPMC0V += 500;         // Schedule next interrupt


    //  Code to toggle another pin to test interrupt etc.

     if (PTBD_PTBD6 == 1)


           PTBD_PTBD6 = 0;




           PTBD_PTBD6 = 1;




I would expect to see Pin 16, PTA0/KBIP0/TPMCH0/ADP0/ACMP+, or Pin 7, PTB5/TPMCH0
toggle at a 1 KHz rate depending on the setting of the SOPT2 register, bit 4. 


I added some test code to wiggle pin PTB6 on each interrupt to verify that the ISR and timer

setup is correct.  PTB6 wiggles at 1 KHz as expected, verifying the timer setup and ISR functionality. 


I have tried writing 0x00 as well as 0x10 to SOPT2 and verified that neither PTA0 or PTB5 wiggle.


I have also verified that neither pin is being loaded (lifted pins or parts removed).


I have tested two PCBs with the same result.


The parts I am using are the samples provided by Arrow, MC9308QB8CTG with markings:




I am using Code Warrior for microcontrollers IDE version 5.9.0 with the latest service packs installed.


Clearly, I am missing something but don’t see it.