This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28379S: HRPWM

Part Number: TMS320F28379S


Hi,

I have been able to turn on my HRPWM and write to the CMPA and CMPAHR registers. 

My questions is regarding calling the SFO to get an MEP_ScaleFactor.

Can I run the HRPWM without calling the SFO ?
What would be the error on the PWM without it ?

Here is my config for my HRPWM:

I'm using PWM4 with a constant frequency and I'm controlling the duty cycle. 

EPwm4Regs.TBCTL.bit.PRDLD = TB_IMMEDIATE; // set Immediate load
EPwm4Regs.TBPRD = 300;  // for 330kHz
EPwm4Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;
EPwm4Regs.TBCTL.bit.PHSEN = TB_DISABLE; // EPwm4 is the Master
EPwm4Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;
EPwm4Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
EPwm4Regs.TBCTL.bit.CLKDIV = TB_DIV1;
EPwm4Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm4Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm4Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO; // optional
EPwm4Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW; // optional
EPwm4Regs.AQCTLA.bit.ZRO = AQ_SET;
EPwm4Regs.AQCTLA.bit.CAU = AQ_CLEAR;
EPwm4Regs.AQCTLB.bit.ZRO = AQ_SET; // optional
EPwm4Regs.AQCTLB.bit.CBU = AQ_CLEAR; // optional

EALLOW; // Note these registers are protected
EPwm4Regs.HRCNFG.all = 0x0; // clear all bits first
EPwm4Regs.HRCNFG.bit.EDGMODE = HR_FEP; // Control Falling Edge Position
EPwm4Regs.HRCNFG.bit.CTLMODE = HR_CMP; // CMPAHR controls the MEP
EPwm4Regs.HRCNFG.bit.HRLOAD = HR_CTR_ZERO; // Shadow load on CTR=Zero

EPwm4Regs.HRPWR.bit.CALPWRON = 1;
EPwm4Regs.HRCNFG.bit.AUTOCONV = 1;
EDIS;
MEP_ScaleFactor = 66*256; // Start with typical Scale Factor

 When I load the duty cycle, I do it the following way :

 EPwm4Regs.CMPA.all = duty * EPwm4Regs.TBPRD * 65535;

(where duty is value between 0.001 and .8)

Do you have any recommendations ? 

  • Hi,

    PowerGuy said:
    Can I run the HRPWM without calling the SFO ?
    What would be the error on the PWM without it ?


    I would not suggest running HRPWM without SFO. This is required step to produce needed accuracy and resolution on the PWM output.
    Hence please use SFO.

    PowerGuy said:

     EPwm4Regs.CMPA.all = duty * EPwm4Regs.TBPRD * 65535;
    (where duty is value between 0.001 and .8)
    Do you have any recommendations ?

    This may work for typical scale factor, it's always recommended to use SFO.

  • I'm having trouble adding the SFO() function to my project.

    Please correct me if I'm wrong. 

    If I do not call the SFO, then the MEP Scale factor will stay at 66*256;

    In which was the accuracy of the HRPWM gets affected.  

    - What is the worst case condition in this case ?

    - How much resolution will I lose ?

    Again, my Period Reg is 300 (330kHz) with a nominal duty cycle of 40% my CMPA Reg is = 120 (about 7 bits resolution)

    Using CMPAHR should give me an additional 8 bits. Now I have 15 bits of resolution.

    I wouldn't mind losing 1 or 2 bits of resolution. 

    Calling SFO() in the background will update the MEP. 

  • Hi,

    PowerGuy said:

    - What is the worst case condition in this case ?

    - How much resolution will I lose ?



    It's not just loss of resolution but behaviour can be unpredictable and may result in glitches, hence it's not recommended.

    PowerGuy said:

    Calling SFO() in the background will update the MEP. 


    Yes - SFO takes care of tracking the MEP.

    PowerGuy said:
    I'm having trouble adding the SFO() function to my project.

    What exactly is the issue you are running into with SFO. Please create a post for this, so that the SFO experts can help resolve this.

  • The SFO works now. 

    Stills, the spec sheet does not mention that the SFO "MUST" be used. 

    So its worrisome the HRPWM can have unpredictable results without it.  

    Previously, without the autocalibration,  I was able to load the duty cycle like this :

    EPwm4Regs.CMPA.all = duty * EPwm4Regs.TBPRD * 65535;

    Now that SFO works, can I still load it the same way ? 

    Or, do I need to load them independently ? 
    EPwm4Regs.CMPA.bit.CMPA    = duty*EPwm4Regs.TBPRD ;

    EPwm4Regs.CMAP.bit.CMPHR = (duty*EPwm4Regs.TBPRD) << 8;

    The issue that I see with loading CMPHR separately, is that, I clamp my max duty to 80%, effectively I will be clamping the loaded value into the CMPHR to 80%.

  • Hi,

    You can use the CMPA/CMPAHR updates the way you are doing previously. SFO should not impact this part of the code.
    Are you enabling AUTOCONV bit in your software? If so, hardware will take care of the necessary conversion w.r.t. the MEP_scalefactor.

    Regarding the documentation feedback for SFO - we'll pursue this feedback any make necessary update to documentation, Thank you.