PWM frequency and duty how to set?

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

PWM frequency and duty how to set?

4,912件の閲覧回数
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 返答(返信)

4,890件の閲覧回数
_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 件の賞賛
返信

4,829件の閲覧回数
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 件の賞賛
返信