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

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

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

ソリューションへジャンプ
3,290件の閲覧回数
jinshuaixu
Contributor V

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).

pastedImage_3.png

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

0 件の賞賛
返信
1 解決策
3,018件の閲覧回数
danielmartynek
NXP TechSupport
NXP TechSupport

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.

pastedImage_3.png

Since MOD = 31250 which is 0.5s.

FTM1->CONTROLS[5].CnV = 30781; // 0.5s - 7.5ms

pastedImage_2.png

Hope it helps,

BR, Daniel

元の投稿で解決策を見る

0 件の賞賛
返信
8 返答(返信)
3,018件の閲覧回数
danielmartynek
NXP TechSupport
NXP TechSupport

Hi,

Try this instead:

PCC->PCCn[PCC_FTM1_INDEX] |= PCC_PCCn_PCS(2) /* Clock src=2, 8 MHz SOSCDIV1_CLK */

BR, Daniel

0 件の賞賛
返信
3,018件の閲覧回数
jinshuaixu
Contributor V

Hi 

   l have upload the project,this project use s32k144 .below is my development board.

pastedImage_1.png

0 件の賞賛
返信
3,017件の閲覧回数
danielmartynek
NXP TechSupport
NXP TechSupport

Hi,

Sorry, I must have misread the description.

I have just run your code and it is center-aligned PWM.

You can see this:

pastedImage_2.png

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.

pastedImage_3.png

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.

pastedImage_4.png

What exactly do you want to get?

Thanks, 

Daniel

0 件の賞賛
返信
3,018件の閲覧回数
jinshuaixu
Contributor V

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.
pastedImage_2.png

       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?

pastedImage_4.png

  the first duty cycle as below,duty cycle is 7.23ms.

      pastedImage_5.png

0 件の賞賛
返信
3,019件の閲覧回数
danielmartynek
NXP TechSupport
NXP TechSupport

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.

pastedImage_3.png

Since MOD = 31250 which is 0.5s.

FTM1->CONTROLS[5].CnV = 30781; // 0.5s - 7.5ms

pastedImage_2.png

Hope it helps,

BR, Daniel

0 件の賞賛
返信
3,016件の閲覧回数
jinshuaixu
Contributor V

Hi

    Thank you for you response.the problem has been resolved.

0 件の賞賛
返信
3,015件の閲覧回数
jinshuaixu
Contributor V

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.

0 件の賞賛
返信
3,015件の閲覧回数
jinshuaixu
Contributor V

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.

pastedImage_1.png

0 件の賞賛
返信