AnsweredAssumed Answered

why I set PWM model is center align,but result is not I set ?

Question asked by jinshuai xu on Apr 25, 2019
Latest reply on May 7, 2019 by jinshuai xu

Hi

    Now ,l meet a question,I set PWM model is center align,but the result is not center align ,when I want set PWM as 1hz frequency and drvlen is 15 millisecond,l will set function 

     low_PumpDrv(100, 15) ,below is my setting。

void low_PumpDrv(uint16_t period, uint16_t drvlen) //drvlen is millisecond
{
uint16_t MOD_value;
uint16_t CNV_value;
uint16_t temp_peroid_time;

temp_peroid_time = 1000 * 100 / period; //Based on the cycle time, calculate the time taken for a cycle
drvlen = ((drvlen * 100*100) / temp_peroid_time); //Based on the input value, calculate the occupy(0-100)。

MOD_value = 31250 * 100 / period; //8M/128/2
CNV_value = (uint32_t)MOD_value * drvlen / 100/100; //占空比数值

PCC->PCCn[PCC_FTM1_INDEX] &= ~PCC_PCCn_CGC_MASK; /* Ensure clk disabled for config */
PCC->PCCn[PCC_FTM1_INDEX] |= PCC_PCCn_PCS(1) /* Clock Src=1, 8 MHz SOSCDIV1_CLK */
| PCC_PCCn_CGC_MASK; /* Enable clock for FTM regs */
FTM1->MODE |= FTM_MODE_WPDIS_MASK; /* Write protect to registers disabled (default) */

//FTM1->SC &= ~0x00200000; /* CLOSE PWM FTM1_CH5 */
FTM1->SC = FTM_SC_CPWMS_MASK;//FTM counter operates in Up-Down Counting mode.

//FTM1->SC = 0x00000020;
FTM1->COMBINE = 0x00000000;/* FTM mode settings used: DECAPENx, MCOMBINEx, COMBINEx=0 */

FTM1->POL = 0x00000000; /* Polarity for all channels is active high (default) */
FTM1->CNTIN = 0;
FTM1->MOD = MOD_value; /* FTM1 counter final value (used for PWM mode) */
/* FTM1 Period = 2*(MOD-CNTIN) */
/* 8MHz /128 = 62500/2=31250 /x=1hz */

FTM1->CONTROLS[5].CnSC = 0x00000028; /* FTM1 ch5: edge-aligned PWM */
FTM1->CONTROLS[5].CnV = CNV_value; /* FTM1 ch5 compare value  */
FTM1->CNT = 0;

FTM1->DEADTIME = FTM_DEADTIME_DTPS(3) | FTM_DEADTIME_DTVAL(7);
// FTM1->SC |= 0x07; //Divide by 128
// FTM1->SC |= 0x18; //open clock
// FTM1->SC |= 0x00200000; //open channel
FTM1->SC |= 0x0020001f;

}

 

 I use oscilloscope capture the wave is below ,the start is when I  call   low_PumpDrv(100, 15).

 

please help me quickly ,How to set register?????

Outcomes