Set the duty cycle

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

Set the duty cycle

Jump to solution
2,778 Views
xgy_upc
Contributor III

In McDrv_pwm3ph_ftm.c in bldc_ref_sol, there is a MCDRV_FtmSetDutyCycle function, which I'm not sure about the duty cycle Settings.

 

i16Duty = MLIB_Mul_F16((i16InpDuty), (this->ui16PwmModulo) / 4);

i16FirstEdge = -(this->ui16PwmModulo) / 4 - i16Duty;

 i16SecondEdge = (this->ui16PwmModulo) / 4 + i16Duty;

I think the PWM waveform generated by this setting is shown in the figure below.So the final duty cycle is not consistent with the duty cycle of the input function.I want to know where did I get it wrong?

IMG_20200725_215539.jpg

0 Kudos
1 Solution
2,655 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hello 相国 尹,

As the function mention, the input duty cycle is an escalated frac number so the -1 = 0% and +1 = 100%. So the value need it for the 20% is FRAC(-0.6). 

Best Regards,

Alexis Andalon

View solution in original post

0 Kudos
9 Replies
2,655 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hello,

The description of the API is the following one:

MCDRV_FtmSetDutyCycle – updates duty cycle generated with PWM module.  In variable f16DutyCycle there is stored new value of duty cycle in the fractional number representation. Fractional number value in range <-1; +1) is then processed and scaled in appropriate PWM driver function to fit the actual PWM module configuration.

So in the dutyCyle variable previously the value is escalated to match the wanted duty cycle.

Best Regards,

Alexis Andalon

0 Kudos
2,655 Views
xgy_upc
Contributor III

Dear Alexis Andalon,

I don't think you understand my question.

I mean I drew the PWM waveform according to the program statement, but the duty ratio of this PWM is not consistent with the duty cycle of the function input. I want to know what the problem is.

0 Kudos
2,655 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hello 相国 尹,

What did you draw is correct, by default, but as the description mention the i16InpDuty should be a fractional number between -1 and 1, and the multiplication function will escalate the value to match the appropriate module. So if the value if -1 the PWM duty will be 0% and if the value is 1 will be 100%.

Best Regards,

Alexis Andalon

0 Kudos
2,655 Views
xgy_upc
Contributor III

I know that i16InpDuty is a fraction and a numerical match.Did you notice that the duty cycle of PWM wave I drew is different from the duty cycle of function input?For example, the duty cycle of the function input is 20%, but the duty cycle of the PWM wave I have drawn is 60%IMG_20200806_094554.jpg

0 Kudos
2,655 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hello 相国 尹,

In this case that you want the 20% duty cycle, what is the value that you put in the i16InpDuty that corresponds to 20%?

Best Regards,

Alexis Andalon

0 Kudos
2,655 Views
xgy_upc
Contributor III

Hello  Alexis Andalon,

The value  is FRAC(0.2)  in the i16IputDuty.

Best Regards,

xiangguo

0 Kudos
2,655 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hello  相国 尹,

Try with FRAC(-0.4).

Best Regards,

Alexis Andalon

0 Kudos
2,655 Views
xgy_upc
Contributor III

Hello,Alexis Andalon

if I use the FRAC(-0.4),the final duty cycle is 30%. As the function,the duty cycle of input should be the final duty cycle of PWM.

Best Regards,

xiangguoyin

0 Kudos
2,656 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hello 相国 尹,

As the function mention, the input duty cycle is an escalated frac number so the -1 = 0% and +1 = 100%. So the value need it for the 20% is FRAC(-0.6). 

Best Regards,

Alexis Andalon

0 Kudos