thanks for pointing out the common TPM sections vs the channel sections. Not alot of empahsis in the manual on this.
http://www.freescale.com/files/microcontrollers/doc/data_sheet/MC9S08RG60.pdfI GOT THIS TO WORK AND WILL POST METHODS FOR PEEPS NEEDING THIS TOO. BOTH HERE AND ON THE SECOND THREAD TOO.
DISCUSSION:
Only 32/44/48pin hs08 processors have an external interrupt PTD2/IRQ. NOTE: MC9S08RC/RD/RE/RG processors have KBI interrupt modules. These get used up quick for a keyboard matrix and if you need antoher dedicated interrupt read on:
METHOD:
With respect of a TPM common counter and its connected independant channel units, the 28pin mc9s08dr32dwe has one main unit and two channels working of the main unit. The TPM overflow interrupt vector6, is common to channel 0&1 and is not efficient because its dependencies tie up two channels. 4example use only one channel, use vector4 for TPM zero input captre (your external interruptable pin PTD6/TPM1CH0) and you can still use vector5 on channel one as a continous running timer via the output compare mode.
//consider the code below as 90% fucntional
//***********Timer chan0&1 Initiliaztion**************************
TPM1SC = 0x08; //setup common ch1&0 control reg, clr TPM1CNTx
//clock=bus, scale=1, pwm=off, overflow irq=off
TPM1C0SC=0x48; //set ch0 as input capture w/ irq
//irq=on, PTD6/TPM1CH0=in capture mode, -e.
TPM1C1SC=0x90; //set ch1 as output compare, irq=off,
//output compare=on, softwre compare=on.
//*************setup interrupt vectors***********************
VECTOR 4 TPM0InputCaptre_ISR
VECTOR 5 TPM1OutputCompare_ISR
//******************
//*************interrupt service routines*************
interrupt 4 void TPM0InputCaptre_ISR (void){
TPM1C0SC = TPM1C0SC; //2part irq reset thingy.
TPM1C0SC &= 0x7F;
FlagTPM0InputCaptre++;} //report irq status to main emulation
interrupt 5 void TPM1OutputCompare_ISR (void){
TPM1C1SC = TPM1C1SC; //2part irq reset thingy.
TPM1C1SC &= 0x7F;
FlagTTPM1OutputCompare++;} //report irq status to main emulation.
//**********************
***************usage as continus timer on TPM1*************
void Wait500ms (void){
TPM1MODH = 0x1E; //with 8MHz OSC, Timer1 goes every 0.001 s
TPM1MODL = 0x84;
TPM1SC = 0x0F; //Set Prescaler = 128
TPM1C1SC=0xD0;} //enable tpm1 for irq on output compare.
for(FlagTTPM1OutputCompare=0;!FlagTTPM1OutputCompare;}; //loop till done.
//*****************
one big bad:
using this scheem as an external irq will not wake the processor from some types of sleep because there is no clock supporting the TPM operation in sleep.
//**********
Message Edited by jah on 2006-08-21 11:13 AM
Message Edited by jah on 2006-08-21 11:14 AM
Message Edited by jah on 2006-08-21 11:14 AM