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.

CCS/LAUNCHXL-F28377S: SFO HRPWM

Part Number: LAUNCHXL-F28377S

Tool/software: Code Composer Studio

Hi, 

I do not know which value is the right to write in the TBPRDHR Register. I have autoconversion enabled.

Lets assume the EPWMCLK=TBCLK is running with 100MHz. SYSCLK is running with 200MHz. And i want to create a PWM period of 100.05kHz.

Set the TBPRD Register value to 999 to get 100kHz.

For the TBPRDHR  Register value i am not sure.

One coarse step is equivalent to 0.1kHz, so 0.05kHz would be the half. So do i write 65535/2 in the TBPRDHR Register???

  • Hi Jonas,

    Have you looked at the hrpwm_prdupdown_sfo_v8 example in ControlSUITE? I think this will help clarify some things for you.  Here is the applicable loop from the code:

    //
            // Sweep PeriodFine as a Q16 number from 0.2 - 0.999
            //
            for(PeriodFine = 0x3333; PeriodFine < 0xFFBF; PeriodFine++)
            {
                if(UpdateFine)
                {
                    //
                    // Because auto-conversion is enabled, the desired
                    // fractional period must be written directly to the
                    // TBPRDHR (or TBPRDHRM) register in Q16 format
                    // (lower 8-bits are ignored)
                    //
                    // EPwm1Regs.TBPRDHR = PeriodFine;
                    //
                    // The hardware will automatically scale
                    // the fractional period by the MEP_ScaleFactor
                    // in the HRMSTEP register (which is updated
                    // by the SFO calibration software).
                    //
                    // Hardware conversion:
                    // MEP delay movement = ((TBPRDHR(15:0) >> 8) *  HRMSTEP(7:0) +
                    //                       0x80) >> 8
                    //
                    for(i=1; i<PWM_CH; i++)
                    {
                        (*ePWM[i]).TBPRDHR = PeriodFine; //In Q16 format
                    }
                }
                else
                {
                    //
                    // No high-resolution movement on TBPRDHR.
                    //
                    for(i=1; i<PWM_CH; i++)
                    {
                        (*ePWM[i]).TBPRDHR = 0;
                    }
                }
    
                //
                // Call the scale factor optimizer lib function SFO(0)
                // periodically to track for any change due to temp/voltage.
                // This function generates MEP_ScaleFactor by running the
                // MEP calibration module in the HRPWM logic. This scale
                // factor can be used for all HRPWM channels. HRMSTEP
                // register is automatically updated by the SFO function.
                //
                status = SFO(); // in background, MEP calibration module
                                // continuously updates MEP_ScaleFactor
    
                if(status == SFO_ERROR)
                {
                    error();   // SFO function returns 2 if an error occurs & # of
                }              // MEP steps/coarse step exceeds maximum of 255.
            } // end PeriodFine for loop

  • Hi Kris,
    I know this example. My problem is the conversion of the float value e.g. 0.5 as Q16 number.
    Is my understanding correct (float value)*2^16 = (Q16 in decimal)?
    float Q16 Q16 in decimal
    0.0 0x0000 0
    0.1 0x1999 6553
    0.5 0x8000 32768
    0.9999847 0xffff 65535
    I read that the last 8 Bit in the TBPRDHRRegister are ignored so:
    float Q16 Q16 in decimal
    0.0 0x0000 0
    0.1 0x1990 6544
    0.5 0x8000 32768
    0.9997559 0xfff0 65520

    The range i can adjust is form 0.0 to ~ 0.99976. Is this correct?
    When i wirte 32768 to the TBPRDHR the period will be exdented by half of a TBCLK cycle?