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-F280049C: HRPWM set duty TBPRDHR

Part Number: LAUNCHXL-F280049C

Tool/software: Code Composer Studio

hi, 

1.I copied the code from the example hrpwm_ex2_prdupdown_sfo_v8,
however, there is no control through the TBPRDHR or EPwm1Regs.CMPA.bit.CMPAHR register. through the register EPwm1Regs.CMPA.bit.CMPA control works, but it is not HRPWM. SFO calibration succeeds.
2. I also want to understand how I can quickly turn off any of the channels, preferably without changing the settings. I can probably do this by changing the GPAMUX1 register, but this is probably a bad idea.

Initialization code:

    EALLOW;
    GpioCtrlRegs.GPAPUD.bit.GPIO0 = 1;  // Disable pull-up on GPIO0 (EPWM1A)
    GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1; // Configure GPIO0 as EPWM1A
    GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1;  // Disable pull-up on GPIO1 (EPWM1B)
    GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1; // Configure GPIO1 as EPWM1B
    EDIS;

    EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW; // set Shadow load
    EPwm1Regs.TBPRD = Period;              // PWM frequency = 1/(2*TBPRD)
    EPwm1Regs.CMPA.bit.CMPA = Period / 3;  // set duty 50% initially
    EPwm1Regs.CMPA.bit.CMPAHR = (1 << 8);  // initialize HRPWM extension
    EPwm1Regs.CMPB.bit.CMPB = Period / 3;  // set duty 50% initially
    EPwm1Regs.CMPB.all |= 1;
    EPwm1Regs.TBPHS.all = 0;
    EPwm1Regs.TBCTR = 0;

    EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Select up-down
                                                   // count mode
    EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;
    EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
    EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1; // TBCLK = SYSCLKOUT
    EPwm1Regs.TBCTL.bit.FREE_SOFT = 11;

    EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO; // LOAD CMPA on CTR = 0
    EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
    EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
    EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;

    EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; // PWM toggle high/low
    EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR;
    EPwm1Regs.AQCTLB.bit.CBU = AQ_SET; // PWM toggle high/low
    EPwm1Regs.AQCTLB.bit.CBD = AQ_CLEAR;

    EALLOW;
    EPwm1Regs.HRCNFG.all = 0x0;
    EPwm1Regs.HRCNFG.bit.EDGMODE = HR_BEP;          // MEP control on both edges.
    EPwm1Regs.HRCNFG.bit.CTLMODE = HR_CMP;          // CMPAHR and TBPRDHR HR control.
    EPwm1Regs.HRCNFG.bit.HRLOAD = HR_CTR_ZERO_PRD;  // load on CTR = 0 and CTR = TBPRD
    EPwm1Regs.HRCNFG.bit.EDGMODEB = HR_BEP;         // MEP control on both edges
    EPwm1Regs.HRCNFG.bit.CTLMODEB = HR_CMP;         // CMPBHR and TBPRDHR HR control
    EPwm1Regs.HRCNFG.bit.HRLOADB = HR_CTR_ZERO_PRD; // load on CTR = 0 and CTR = TBPRD
    EPwm1Regs.HRCNFG.bit.AUTOCONV = 1;              // Enable autoconversion for HR period
    EPwm1Regs.HRPCTL.bit.TBPHSHRLOADE = 1;          // Enable TBPHSHR sync (required for updwn count HR control)
    EPwm1Regs.HRPCTL.bit.HRPE = 1;                  // Turn on high-resolution period control.
    EPwm1Regs.TBCTL.bit.SWFSYNC = 1;                // Synchronize high resolution phase to start HR period
    EDIS;

    EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
    EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
    EPwm1Regs.DBFED.bit.DBFED = 20;
    EPwm1Regs.DBRED.bit.DBRED = 20;

  • EPwm1Regs.CMPA.bit.CMPAHR = (1 << 8);  // initialize HRPWM extension

    This is writing to the CMPAHR register. But if you would like an example with HR Phase shift exists in the bitfield example.

    Do you want to use HRPWM driverlib examples or bitfield? I recommend driverlib.

  • Also to shut off a PWM when needed, you can use the TRIPZONE module. If an external signal is shutting off your PWM use the INPUT XBAR and EPWM XBAR to get the signal to the TripZone module. If you want to use SW, you can just use FORCE through SW in the TripZone module (in OST mode).

  • Do let me know which type of example you are looking for and I can tell you where to find them.

    Nima

  • Hi,

    1. I would like to control the width via TBPRDHR register because I have included EPwm1Regs.HRCNFG.bit.AUTOCONV. How can I control it through TBPRDHR without additional libraries?
    2.As far as I understand, TRIPZONE can turn off both PWM channels (off - EPwm1Regs.TZFRC.bit.OST, on - EPwm1Regs.TZCLR.bit.OST), but I need to turn off one channel.

    In addition, when I set any value in EPwm1Regs.TBPRDHR, synchronization of EPwm1 with other EPwm fails

  • in addition...
    Do I understand correctly?
    you need to install duty in two stages:
    1.install EPwm1Regs.CMPA.bit.CMPA
    2.set fractional part EPwm1Regs.CMPA.bit.CMPAHR

    The value of the fractional part of the 8 most significant bits. Does this mean that I can set the fractional part from 0 to 255 for any calibration values MEP_ScaleFactor?

  • When I set duty in two steps:
    1.install EPwm1Regs.CMPA.bit.CMPA
    2.set fractional part EPwm1Regs.CMPA.bit.CMPAHR

    Everything works well, but in order for the complementary channel to change too, you have to set the fractional part for channel B, EPwm1Regs.CMPB.bit.CMPBHR = EPwm1Regs.CMPA.bit.CMPAHR.
    This is normal?

    Is it normal to use this method of frequently disconnecting one of the channels? this method works:

    EALLOW;
    if (...)
    {
      GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0;
      GpioDataRegs.GPADAT.bit.GPIO0 = 0;
    }
    else
    {
      GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1;
    }
    EDIS;

  • You can shut off one ePWM output only using TZ if you set the TZ to be active only in one of the EPWMxA/B output registers.


  • Yes if you AUTOCONV ON, then yes your understanding is correct, any number from 0 to 255 in the most significant 8 bits.

    Nima

  • Max Av said:
    Everything works well, but in order for the complementary channel to change too, you have to set the fractional part for channel B, EPwm1Regs.CMPB.bit.CMPBHR = EPwm1Regs.CMPA.bit.CMPAHR.

    Yes you have to set the BHR as well.

    Max Av said:

    Is it normal to use this method of frequently disconnecting one of the channels? this method works:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    EALLOW;
    if (...)
    {
      GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0;
      GpioDataRegs.GPADAT.bit.GPIO0 = 0;
    }
    else
    {
      GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1;
    }
    EDIS;

    I guess that would work but I recommned shutting off a PWM by forcing an action in TZ/DC/ or the action qualifier module.

  • Hi, Nima

    Thanks for the tip, it works. However, it is not clear to me why these registers are protected if they are used frequently.
    In addition, if I want to use the TZ for emergency shutdown, then I cannot turn off the PWM channel separately, or I will have to quickly change the TZ settings. Isn't there some even more elegant way? :)

    EPwm1Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
    EPwm1Regs.TZCTL.bit.TZB = TZ_NO_CHANGE;
    
    ...
    
    if (...)
    {
      EALLOW;
      EPwm1Regs.TZFRC.bit.OST = 1;
      EDIS;
    }
    else
    {
      EALLOW;
      EPwm1Regs.TZCLR.bit.OST = 1;
      EDIS;
    }

  • I think this is what you're looking for :)

    AQCSFRC

    AQCSFRC.CSFB

    AQCSFRC.CSFA