PWM frequency and duty how to set?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

PWM frequency and duty how to set?

6,369 次查看
pandi
Contributor III

In MKV31F512VLL12 FTM   how to set constant PWM frequency and duty if any formula give to me help

for us. 

                                   Thank you 

BR 

PANDI

0 项奖励
回复
2 回复数

6,347 次查看
_Leo_
NXP TechSupport
NXP TechSupport

Hi,

Thank you so much for your interest in our products and for using our community.

In the SDK of the FRDM-KV31F there are the following PWM examples with the FTM that you could take as reference.

_Leo__0-1708717744341.png

Hope it helps you.

Have a nice day!

0 项奖励
回复

6,286 次查看
pandi
Contributor III

hi

@_Leo_ 

 FTM PWM channels how to set constant frequency and duty .

ex;16 KHZ and 50 duty how to set

This code register level program. output 10 KHZ  frequency constant  but when above 10 KHZ  did not constant of frequency and duty how to set?

void TIM0_PWM_Init(uint32_t pwm_freq) {

uint32_t clk_freq = SystemCoreClock;

uint32_t pwm_period = clk_freq / pwm_freq;

SIM->SCGC5 |= SIM_SCGC5_PORTC_MASK;

PORTC->PCR[1] = PORT_PCR_MUX(0x4); // FTM0_CH0 on PTC1

PORTC->PCR[2] = PORT_PCR_MUX(0x4); // FTM0_CH1 on PTC2

PORTC->PCR[3] = PORT_PCR_MUX(0x4); // FTM0_CH2 on PTC3

SIM->SCGC6 |= SIM_SCGC6_FTM0_MASK;

FTM0->MODE |= FTM_MODE_WPDIS_MASK;

FTM0->MOD = pwm_period - 1;

FTM0->CONTROLS[0].CnSC = FTM_CnSC_MSB_MASK | FTM_CnSC_ELSB_MASK;

FTM0->CONTROLS[1].CnSC = FTM_CnSC_MSB_MASK | FTM_CnSC_ELSB_MASK;

FTM0->CONTROLS[2].CnSC = FTM_CnSC_MSB_MASK | FTM_CnSC_ELSB_MASK;

FTM0->CONTROLS[0].CnV = (pwm_period * 60) / 50;

FTM0->CONTROLS[1].CnV = (pwm_period * 50) / 100;

FTM0->CONTROLS[2].CnV = (pwm_period * 50) / 100;

FTM0->SC = FTM_SC_PS(0); // No prescaler

FTM0->SC |= FTM_SC_CLKS(1); // System clock

FTM0->SC|=FTM_SC_TOF_MASK;

NVIC_EnableIRQ(FTM0_IRQn);

 

}

void UpdateFTM0_Channel(uint8_t channel, uint32_t pwm_freq, uint8_t dutyCyclePercent) {

if (dutyCyclePercent > 100) {

dutyCyclePercent = 100;

}

uint32_t clk_freq = SystemCoreClock;

uint32_t pwm_period = clk_freq / pwm_freq;

FTM0->MOD = pwm_period - 1;

uint32_t cnvValue = (pwm_period * dutyCyclePercent) / 100;

if (channel < 3) {

FTM0->CONTROLS[channel].CnV = cnvValue;

}

FTM0->PWMLOAD |= FTM_PWMLOAD_LDOK_MASK;

}

UpdateFTM0_Channel(1,2016,50);  

OR

HOW TO SET GENERATED CODE?

            Thank you

BR

PANDI

 

0 项奖励
回复