Why doesn't my Center_Align_PWM_Init function work based on S32K144EVB?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Why doesn't my Center_Align_PWM_Init function work based on S32K144EVB?

Jump to solution
790 Views
Ryan_Yu
Contributor II

My Edge_Align_PWM_Init function can work based on S32K144EVB, but when I configure CPWM, I select up-down counter,however it can't output CPWM. What is the reason? My Edge_Align_PWM_Init function and Center_Align_PWM_Init function codes are as follows, please help me check out.

Thanks

BR,

Ryan

 

void Edge_Align_PWM_Init(void)
{
/* Enable clock for PORTD */
PCC->PCCn[PCC_PORTD_INDEX] = PCC_PCCn_CGC_MASK;
/* Select and enable clock for FTM0 */
PCC->PCCn[PCC_FTM0_INDEX] = PCC_PCCn_PCS(1) | PCC_PCCn_CGC_MASK;

/* Set PORTD Pins for FTM0 */
PORTD->PCR[15] = PORT_PCR_MUX(2); //FTM0_Chan0
PORTD->PCR[16] = PORT_PCR_MUX(2); //FTM0_Chan1

/* Enable FTM0 update */
FTM0->MODE = FTM_MODE_FTMEN_MASK;

/* Enable sync, combine mode and dead-time for pair channel (n = 1) */
FTM0->COMBINE = FTM_COMBINE_COMP0_MASK | FTM_COMBINE_DTEN0_MASK;

/* Set MOD (10 Hz PWM frequency, 8MHz system frequency) */
FTM0->MOD = 6250 - 1;

/* Set CNTIN */
FTM0->CNTIN = 0;

/* Enable high-true pulses of PWM Signals*/
FTM0->CONTROLS[0].CnSC = FTM_CnSC_MSB_MASK | FTM_CnSC_ELSB_MASK;
FTM0->CONTROLS[1].CnSC = FTM_CnSC_MSB_MASK | FTM_CnSC_ELSB_MASK;

/* Set channel compare value (duty percent) */
FTM0->CONTROLS[0].CnV = 3125; // 50% duty cycle
FTM0->CONTROLS[1].CnV = 3125; // 50% duty cycle

/* Reset FTM Counter*/
FTM0->CNT = 0;

/* Insert DeadTime (1 us) */
FTM0->DEADTIME = FTM_DEADTIME_DTPS(3) | FTM_DEADTIME_DTVAL(7);

/* Clock select and enable PWM generation, pre_sc factor = 128, FTM0 clock frequency = 62.5 kHz */
FTM0->SC = FTM_SC_CLKS(3) | FTM_SC_PWMEN0_MASK | FTM_SC_PWMEN1_MASK | FTM_SC_PS(7);
}

void Center_Align_PWM_Init(void)
{
/* Enable clock for PORTD */
PCC->PCCn[PCC_PORTD_INDEX] = PCC_PCCn_CGC_MASK;
/* Select and enable clock for FTM0 */
PCC->PCCn[PCC_FTM0_INDEX] = PCC_PCCn_PCS(1) | PCC_PCCn_CGC_MASK;

/* Set PORTD Pins for FTM0 */
PORTD->PCR[15] = PORT_PCR_MUX(2); //FTM0_Chan0
PORTD->PCR[16] = PORT_PCR_MUX(2); //FTM0_Chan1

/* Enable FTM0 update */
FTM0->MODE = FTM_MODE_FTMEN_MASK;

/* Select up-down counter for center-align PWM */
FTM0->SC = FTM_SC_CPWMS_MASK;

/* Enable combine mode and dead-time for pair channel (n = 1) */
FTM0->COMBINE = FTM_COMBINE_COMP0_MASK | FTM_COMBINE_DTEN0_MASK;

/* Set MOD (10 Hz PWM frequency, 8MHz system frequency) */
FTM0->MOD = 3125 - 1;

/* Set CNTIN */
FTM0->CNTIN = 0;

/* Enable low-true pulses of PWM Signals */
FTM0->CONTROLS[0].CnSC = FTM_CnSC_ELSB_MASK;
FTM0->CONTROLS[1].CnSC = FTM_CnSC_ELSA_MASK;

/* Set channel compare value (duty percent) */
FTM0->CONTROLS[0].CnV = 1562; // ~50% duty cycle
FTM0->CONTROLS[1].CnV = 1562; // ~50% duty cycle

/* Reset FTM Counter*/
FTM0->CNT = 0;

/* Insert DeadTime (1 us) */
FTM0->DEADTIME = FTM_DEADTIME_DTPS(3) | FTM_DEADTIME_DTVAL(7);

/* Clock select and enable PWM generation, pre_sc factor = 128, FTM0 clock frequency = 62.5 kHz */
FTM0->SC = FTM_SC_CLKS(3) | FTM_SC_PWMEN0_MASK | FTM_SC_PWMEN1_MASK | FTM_SC_PS(7);

}

Tags (2)
0 Kudos
1 Solution
741 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@Ryan_Yu

I did't change anything but just copy your demo code to the function void Center_Align_PWM_Init()

1.

Senlent_1-1658122764319.png

2.

Senlent_0-1658122744526.png

the test result is ok in myside.

Senlent_2-1658122881424.jpeg

 

View solution in original post

0 Kudos
5 Replies
764 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@Ryan_Yu

you can refer to this example,i tested this demo code before,

https://www.nxp.com/search?keyword=AN5303&start=0 

Senlent_0-1658118232661.png

if you still have problem, please contact me.

0 Kudos
754 Views
Ryan_Yu
Contributor II
Tags (1)
0 Kudos
760 Views
Ryan_Yu
Contributor II

Hi, Senlent

Yes,I find and know the 'AN5303' document, in fact I refer to it.

Now the problem is: I configured the code according to the 'AN5303' document,  the actual test results show that the Edge-align PWM (EPWM) example is normal, but the Center-align PWM (CPWM) example is unsuccessful( there is no waveform output in either channel).

I observe that the edge-align PWM mode is selected when QUADEN = 0, DECAPEN = 0, MCOMBINE = 0,COMBINE = 0, CPWMS = 0. and MSnB = 1, and the center-align PWM mode is selected when
QUADEN = 0, DECAPEN = 0, MCOMBINE = 0, COMBINE = 0, and CPWMS = 1. So I write this code "FTM0->SC = FTM_SC_CPWMS_MASK". But no matter how I test, there is no waveform output in either channel.

There is nothing I can do, maybe I missed some details, so you can have a try and tell mw why.

Thanks

BR,

Ryan

 

0 Kudos
742 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@Ryan_Yu

I did't change anything but just copy your demo code to the function void Center_Align_PWM_Init()

1.

Senlent_1-1658122764319.png

2.

Senlent_0-1658122744526.png

the test result is ok in myside.

Senlent_2-1658122881424.jpeg

 

0 Kudos
722 Views
Ryan_Yu
Contributor II

Hi@Senlent

Your test result shows that the demo code and configuration of some register bits are no problem. That is significant to me. I know what I'm gonna do.

Thank you for taking the time to answer my questions.

非常感谢!

Best Regards,

Ryan Yu

0 Kudos