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?????
Solved! Go to Solution.
You need to change the configuration to ELSB:ELSA = 0b01.
FTM1->CONTROLS[5].CnSC = 0x00000024;
The PWM signal will be HIGH from the match-up -> MOD -> to match-down.
Since MOD = 31250 which is 0.5s.
FTM1->CONTROLS[5].CnV = 30781; // 0.5s - 7.5ms
Hope it helps,
BR, Daniel
Hi,
Try this instead:
PCC->PCCn[PCC_FTM1_INDEX] |= PCC_PCCn_PCS(2) /* Clock src=2, 8 MHz SOSCDIV1_CLK */
BR, Daniel
Hi,
Sorry, I must have misread the description.
I have just run your code and it is center-aligned PWM.
You can see this:
The value of CNTIN is loaded into the FTM counter, and the counter increments until the value of MOD is reached, at which point the counter is decremented until it returns to the value of CNTIN and the up-down counting restarts.
It starts HIGH and it is driven LOW on match-up. The first pulse is therefore 7.5ms long.
It is driven HIGH on match-down and LOW on match-up again, so all the other pulses are 15ms long.
What exactly do you want to get?
Thanks,
Daniel
Hi Daniel:
First thank you for you response,
you said you had test my project,and result is PWM mode is correct. so l think ,if l configure PWM as 1hz,duty cycle is 15ms,the result should as below,center align duty cycle should be from 492.5ms to 507.5ms is hign, the othes time is low.
Just now I test PWM center mode, the next picture is the result,I just set PWM as 1hz and duty cycle is 15ms, why duty cycle is not at center,and the first duty cycle is how to generate?
the first duty cycle as below,duty cycle is 7.23ms.
You need to change the configuration to ELSB:ELSA = 0b01.
FTM1->CONTROLS[5].CnSC = 0x00000024;
The PWM signal will be HIGH from the match-up -> MOD -> to match-down.
Since MOD = 31250 which is 0.5s.
FTM1->CONTROLS[5].CnV = 30781; // 0.5s - 7.5ms
Hope it helps,
BR, Daniel
Hi
Thank you for you response.the problem has been resolved.
Hi
l have test the suggest way that set
PCC->PCCn[PCC_FTM1_INDEX] |= PCC_PCCn_PCS(2)
the result is also the same as PCC->PCCn[PCC_FTM1_INDEX] |= PCC_PCCn_PCS(1) ,the pwm mode is not center align.
Hi, I do not use SIRC CLOCk ,so l need set : PCC->PCCn[PCC_FTM1_INDEX] |= PCC_PCCn_PCS(1)
I just want set pwm mode is center align,please give me more messege or suggest . thank you.