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.

TMS320F28035: Adding PWM_C to HRPWM example

Part Number: TMS320F28035
Other Parts Discussed in Thread: CONTROLSUITE

I am currently using the example project "Example_2803xHRPWM_Symmetric_Duty_Cycle_SFO_V6" from the "controlSUITE\device_support" folder as a template to implement HRPWM. I would like to add a third PWM output to drive a 3 phase load. I added ePWM3 to the HRPWM_Config() function. However, I haven't been able to synchronize the third output to the first two.

What are the correct register settings, and where should they be placed in the code, to ensure this synchronization occurs properly?

Thank you!

  • I’ll take a look at it for you peter.
  • You have  to make sure to set up your synchronization scheme based on one of the following.

  • Peter,
    Are you still having issues syncing the third PWM?

    Regards,
    Cody
  • Peter,

    It has been a while since your last update. I assume that you were able to resolve your issue. If this isn’t the case, please reject this resolution and reply to this thread. If this thread is locked, please make a new thread describing the current status of your issue.

    -Tommy
  • I haven't had the time yet to work on this issue, but will hopefully try it out later this week

  • Hello,

    I tried looking at  this but comp sci is really not my jam..

    If you could simply point out what needs to be set where, I'd greatly appreciate it. My code is below

    void HRPWM_Config(period)
    {
       Uint16 j;
       // ePWM channel register configuration with HRPWM
       // ePWMxA toggle low/high with MEP control on Rising edge
       EALLOW;
       SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;     // Disable TBCLK within the EPWM
       EDIS;
    
       for (j=1;j<4;j++)
       {
           (*ePWM[j]).TBCTL.bit.PRDLD = TB_SHADOW;             // set Shadow load
           (*ePWM[j]).TBPRD = period;                          // PWM frequency = 1/(2*TBPRD)
           (*ePWM[j]).CMPA.half.CMPA = period / 2;             // set duty 50% initially
           (*ePWM[j]).CMPA.half.CMPAHR = (0 << 8);             // initialize HRPWM extension
           (*ePWM[j]).TBPHS.all = 0;
    
           (*ePWM[j]).TBCTR = 0;
    
    	   (*ePWM[j]).TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;     // Select up-down count mode
           (*ePWM[j]).TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;
           (*ePWM[j]).TBCTL.bit.HSPCLKDIV = TB_DIV1;
           (*ePWM[j]).TBCTL.bit.CLKDIV = TB_DIV1;              // TBCLK = SYSCLKOUT
           (*ePWM[j]).TBCTL.bit.FREE_SOFT = 0;
    
           (*ePWM[j]).CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;      // LOAD CMPA on CTR = 0
           (*ePWM[j]).CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
           (*ePWM[j]).CMPCTL.bit.SHDWAMODE = CC_SHADOW;
           (*ePWM[j]).CMPCTL.bit.SHDWBMODE = CC_SHADOW;
    
           (*ePWM[j]).AQCTLA.bit.CAU = AQ_SET;                 // PWM toggle high/low
    	   (*ePWM[j]).AQCTLA.bit.CAD = AQ_CLEAR;
           (*ePWM[j]).AQCTLB.bit.ZRO = AQ_SET;                 // PWM toggle high/low
    	   (*ePWM[j]).AQCTLB.bit.PRD = AQ_CLEAR;
    	    EALLOW;
           (*ePWM[j]).HRCNFG.all = 0x0;
    	   (*ePWM[j]).HRCNFG.bit.EDGMODE = HR_BEP;          // MEP control on both edges
           (*ePWM[j]).HRCNFG.bit.CTLMODE = HR_CMP;          // CMPAHR and TBPRDHR HR control
    	   (*ePWM[j]).HRCNFG.bit.HRLOAD  = HR_CTR_ZERO_PRD; // load on CTR = 0 and CTR = TBPRD
           (*ePWM[j]).HRCNFG.bit.AUTOCONV = 1;              // Enable autoconversion for HR period
    	   (*ePWM[j]).HRPCTL.bit.HRPE = 1;                  // Turn on high-resolution period control.
           (*ePWM[j]).TBCTL.bit.PHSEN = 1;
    	   (*ePWM[j]).HRPCTL.bit.TBPHSHRLOADE = 1;          // Enable TBPHSHR sync (required for updwn count HR control)
            EDIS;
    	}
        EALLOW;
        EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO;	// disable ePWM1 SYNC output [3]
        EPwm2Regs.TBCTL.bit.PHSEN = 1;
        EPwm2Regs.TBCTL.bit.PHSDIR = 1;				// count up after SYNC event
    	EPwm2Regs.TBPHS.half.TBPHS = 2;				// initial - coarse phase offset relative to ePWM1
    
        SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;      // Enable TBCLK within the EPWM
        EPwm1Regs.TBCTL.bit.SWFSYNC = 1;            // Synchronize high resolution phase to start HR period
    
        EDIS;
    }
    
    // FreqCtlISR - interrupts at ePWM1 TBCTR = 0.
    // This ISR updates the compare and period registers for ePWM modules within the same period.
    __interrupt void FreqCtlISR(void)
    {
    
        EALLOW;
    	    EPwm2Regs.TBCTL.bit.PHSEN = 0;
    	EDIS;
    
    
    	isr_cnt++;
    
    	   EPwm1Regs.CMPA.half.CMPA = CMPa_Reg;
           EPwm1Regs.CMPA.half.CMPAHR = CMPa_HR;         // change duty cycle
    
           EPwm2Regs.CMPA.half.CMPA = CMPb_Reg;
           EPwm2Regs.CMPA.half.CMPAHR = CMPb_HR;         // change duty cycle
    
           EPwm3Regs.CMPA.half.CMPA = CMPc_Reg;
           EPwm3Regs.CMPA.half.CMPAHR = CMPc_HR;         // change duty cycle
    
        // re-initialise for next PWM interrupt
    	PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;   		// acknowledge PIE interrupt
    	EPwm1Regs.ETCLR.bit.INT = 1;					// clear interrupt bit
    }

  • Peter,

          The sync chain is described in the images that Nima has provided you. These images, which can be found in the F28035 TRM, describe how the PWMs are connected together. The TRM can be found at the top of the product page, or  under the "Technical Documents" tab.

    The HRPWM's are an enhancement of the ePWM module, for this reason you will need to reference the ePWM section regularly. It is absolutely necessary for you to understand the ePWM module as it is the base of the HRPWM enhancements.

    If you need help finding more resources to help get you on your feet I can recommend some( for example the video in my signature). If after reviewing the documentation you have pointed questions, please let me know and I will help.

    Regards,
    Cody 

  • Please post back if you still have issues, I will be closing the thread soon.

    If you have more questions feel free to start a new thread.

    Regards,
    Cody