Good morning to everyone.
I'm new to kinetis microcontroller and I don't understand about TPM module.
I have just programmed my frdm k25 to use the TPM module. In particular I'd like to obtain
a very simple square wawe on the TPM0 ch0 (1 khz).
Till here I didn't find any problems.
This my code:
// Calls to init module
| // FTM0 - channel 0 -> 1 Khz square wave |
| TPM_TmInit(TPM_TIM0, MCGFLL_PLL, TPM_PRSC_001, 12000); |
PORTD_PCR0 = PORT_PCR_MUX(4); TPM_ChInit(TPM_TIM0, TPM_CH0, OC_TOG_ON_MATCH, 0, CHIE_DISABLE); // FTM0 - channel 2 -> pwm PORTD_PCR2 = PORT_PCR_MUX(4); TPM_ChInit(TPM_TIM0, TPM_CH2, PWM_CENTER_HI, 2400, INT_TPM0); |
On the second channel I'd like to have a pwm signal. And it works but I want a 20ms period.
If I want this ( I tried) I have to change the module and the prescale values if I want to obtain this.
But I don't have more the square wave.
So, how it's possible to have a square wawe of 1Kz and a pwm signal with 20 ms period on the same TPM moule ?
The module value affects all channel ?
Could be I have (just for example) for output compare, using the same TPM and different channel naturally but different frequency.
I dont'understand something ? What's wrong in my code ?
Thanks in advance.
// SUPPORT INIT FUNCIONS
// init TMP module
void TPM_TmInit(uint8 tpmtimer, uint8 tpmsrc, uint8 tpmprescaler, uint16 module)
{
TPM_Type *tpm[] = { TPM0, TPM1, TPM2 };
uint32 mask[] = { SIM_SCGC6_TPM0_MASK, SIM_SCGC6_TPM1_MASK, SIM_SCGC6_TPM2_MASK };
if(tpmtimer > 2)
return;
SIM->SCGC6 |= mask[tpmtimer]; // TPM clock gating
SIM->SOPT2 |= SIM_SOPT2_TPMSRC(tpmsrc); // TPM clock source
tpm[tpmtimer]->SC |= TPM_SC_CMOD(0x01) | TPM_SC_PS(tpmprescaler); // TPM always up counting, prescaler clock
tpm[tpmtimer]->MOD = module;
}
// init TMP channel
void TPM_ChInit(uint8 tpmtimer, uint8 channel, uint8 chmode, uint16 cnvalue, uint8 chie)
{
TPM_Type *tpm[] = { TPM0, TPM1, TPM2 };
if((tpmtimer > 2) || (channel > 5))
return;
tpm[tpmtimer]->CONTROLS[channel].CnV = cnvalue;
tpm[tpmtimer]->CONTROLS[channel].CnSC = chmode;
if(chie != 0)
{
tpm[tpmtimer]->CONTROLS[channel].CnSC |= TPM_CnSC_CHIE_MASK;
ConnectInterruptToCortex(chie);
}
}