Hi to all.
I'm using Timer/PWM Module, on my qe64, to get a timer. Until today I need only one timer
and with this code:
void init_tpm ()
{
// Impostazioni: attivazione clock alla periferica TPM1
SCGC1_TPM1 = 1;
// Impostazioni TPM1
TPM1SC = 0x48;
// 0b01001000
// |||||||| Divisore del clock della sorgente 111>>128;000>>1
// |||||||+-- TPM1SC_PS0 = 0;
// ||||||+--- TPM1SC_PS1 = 0;
// |||||+---- TPM1SC_PS2 = 0;
// |||||
// ||||| Settando i bit CLSKA/B del registro TPM1SC si
// ||||| sceglie come clk di riferimento il clk del bus
// |||||
// ||||+----- TPM1SC_CLKSA = 1;
// |||+------ TPM1SC_CLKSB = 0;
// ||+-------
// |+-------- TPM1SC_TOIE = 1;
// +--------- Sola lettura
// Impostazione del modulo del contatore: quando lo raggiunge si resetta
TPM1MOD = 20000;
// Impostando i bit EdgeLevelSelect il controllo delle porte non è
// della periferica TPM
TPM1C0SC_ELS0B = 0;
TPM1C0SC_ELS0A = 0;
TPM1C1SC_ELS1B = 0;
TPM1C1SC_ELS1A = 0;
TPM1C2SC_ELS2B = 0;
TPM1C2SC_ELS2A = 0;
}
and:
__interrupt VectorNumber_Vtpm1ovf void TI1_Interrupt (void)
{
// Reset del flag di overflow
TPM1SC_TOF = 0;
DisableInterrupts;
...
...
...
EnableInterrupts;
}
Now I need more timers. So i thinked to set the TPM counter as a free running timer counter and use
two channels.
I started with one channel. Here is the code:
void init_tpm1 ()
{
// Impostazioni: attivazione clock alla periferica TPM1
SCGC1_TPM1 = 1;
// Impostazioni TPM1
TPM1SC = 0x08; // no TOF - interrupt ENABLE
TPM1MOD = 0; // free running timer counter
// CH 0
TPM1C0SC = 0x40;
TPM1C0V = 20000;
// CH 1
TPM1C1SC = 0;
TPM1C1V = 0;
// CH 2
TPM1C2SC = 0;
TPM1C2V = 0;
}
and:
__interrupt VectorNumber_Vtpm1ch0 void TI0CH_Interrupt (void)
{
// Reset del flag di overflow
TPM1C0SC_CH0F = 0;
DisableInterrupts;
...
...
...
EnableInterrupts;
}
I expected to have the same behaviour. But I never reach __interrupt VectorNumber_Vtpm1ch0 void TI0CH_Interrupt (void)
Where I'm wrong?
Solved! Go to Solution.
Hello Roberto,
With the TPM channel pin disabled you should still obtain a compare interrupt, provided the channel interrupt is enabled by setting bit 6 of TPMxCnSC register.
Regards,
Mac
Update. I read and read the user manual.
Pag. 296:
«Setting ELSnB:ELSnA to 0:0 configures the related timer pin as a general purpose I/O pin not related to any timer
functions. This function is typically used to temporarily disable an input capture channel or to make the timer pin
available as a general purpose I/O pin when the associated timer channel is set up as a software timer that does
not require the use of a pin.»
I've seen if I use this option I haven't any interrupt. But I think that software timer generates interrupt or should I polling it?
Hello Roberto,
With the TPM channel pin disabled you should still obtain a compare interrupt, provided the channel interrupt is enabled by setting bit 6 of TPMxCnSC register.
Regards,
Mac
Hi BigMac!
I have understood the same. I set bit 6 (and EnableInterrupts )
TPM1C0SC = 0x40;
but I never reach (also in simultaion)
__interrupt VectorNumber_Vtpm1ch0 void TI0CH_Interrupt (void).
More: I try to put on on a pin (PTA6, TPM1CH2) => TPM1C2SC = 0x68; (edge aligned) using code found on "HCS08 Peripheral Module Quick Reference Guide" . In this case i reach
__interrupt VectorNumber_Vtpm1ch2 void TI2CH_Interrupt (void)
but with oscilloscope I didn't see anything on the pin.
:/