Hello Earl Orlando,
Unfortunately I can not share the complete code. But I will let here some functions.
Core Clock is 48MHz.
Bus/Flash clock is 24MHz.
FTM1 prescale = 16.
TP_SIR_PER_1 = 0x1F4 will give 3kHz
TP_SIR_PER_2 = 0x3E8 will give 1,5kHz
Yes, I checked with pins the configurations are OK.
The first time I turn on the pwm using this function. After I change the duty cicle using FTM1 interrupt
void initPwm(unsigned int mod){
SIM_SCGC6 |= SIM_SCGC6_TPM1_MASK;
SIM_SOPT2 |= SIM_SOPT2_TPMSRC(1); // MCGFLLCLK clock source
PORTB_PCR5 = PORT_PCR_ISF_MASK | PORT_PCR_MUX(0x2);
TPM1_CNT=0;
TPM1_MOD=mod; //TMP_PERIOD
TPM1_SC=0x5; //PRESCALER=16
TPM1_SC |=0x08|TPM_SC_TOIE_MASK;
TPM1_C1SC=TPM_CnSC_MSB_MASK| TPM_CnSC_ELSA_MASK;
TPM1_C1V=mod/2; //DUTY CYCLE 50%
turnOnInt(INT_IRQ_TPM1);
}
void FTM1_IRQHandler(){
TPM1_SC |= TPM_SC_TOF_MASK;
if(flag.change){
flag.change=0;
if(!step.pwm){
TPM1_CNT = 0;
TPM1_MOD= TP_SIR_PER_1;
TPM1_C1V = TP_SIR_DC_1; // DUTY CYCLE EM 50%
step.pwm=1;
}
else{
TPM1_CNT = 0;
TPM1_MOD = TP_SIR_PER_2;
TPM1_C1V = TP_SIR_DC_2; // DUTY CYCLE EM 50%
step.pwm=0;
}
}
}
I modified somethings because the code and comments were in another language.
Thanks!