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.

LAUNCHXL-F28379D: Current controller design using flipflops: Accessing EPWM signals inside DSP and using logic gates

Part Number: LAUNCHXL-F28379D

Tool/software:

Hi, I have DAB hardware for which the following code is developed using EPWM modules at 100 kHz in an open loop. My primary bridge uses EPWM 4 and 5, whereas my secondary bridge uses EPWM 1 and 2. These EPWM modules cannot be changed as they are hard-wired in the PCB trace. I have used up counting because the primary should lead the secondary, and by updating the TBPHS register of modules 4 and 5, I can create a leading PWM in modules 4 and 5 with EPWM 1 as my master.

void Setup_ePWM(void)
{
    // Primary Bridge
    //ePWM 4 Configuration
    EPwm4Regs.TBCTL.bit.CLKDIV=0;//(Set clock division=00b) divide by 1
    EPwm4Regs.TBCTL.bit.HSPCLKDIV=0;//(Set high speed clock division=00b)divide by 1
    EPwm4Regs.TBCTL.bit.CTRMODE=0;//UP Mode
    EPwm4Regs.TBPRD=fs;//Period corresponding to 100kHz
    EPwm4Regs.CMPA.bit.CMPA =0.5*fs;//50% duty cycle
    EPwm4Regs.TBPHS.bit.TBPHS=PHI;//Set phase angle
    EPwm4Regs.TBCTL.bit.PHSEN=TB_ENABLE;//Set as a Slave
    EPwm4Regs.TBCTL.bit.SYNCOSEL=TB_SYNC_IN;// Input from master
    EPwm4Regs.AQCTLA.all=0x0024;//set high when TBCTR=CMPA Up and low when TBCTR=TBPRD
    EPwm4Regs.DBCTL.bit.OUT_MODE=DB_FULL_ENABLE;//Enable dead band module
    EPwm4Regs.DBCTL.bit.POLSEL=2;//Inverted signal at ePWM4B
    EPwm4Regs.DBFED.all=30;//30 block in FALLING EDGE
    EPwm4Regs.DBRED.all=30;//30 block in RISING EDGE

    //ePWM 5 configuration
    EPwm5Regs.TBCTL.bit.CLKDIV=0;//(Set clock division=01b) divide by 1
    EPwm5Regs.TBCTL.bit.HSPCLKDIV=0;//(Set high speed clock division=00b)divide by 1
    EPwm5Regs.TBCTL.bit.CTRMODE=0;//UP Mode
    EPwm5Regs.TBPRD=fs;//Period corresponding to 100kHz
    EPwm5Regs.CMPA.bit.CMPA =0.5*fs;//50% duty cycle
    EPwm5Regs.TBPHS.bit.TBPHS=PHI;//Set phase angle
    EPwm5Regs.TBCTL.bit.PHSEN=TB_ENABLE;//Set as a Slave
    EPwm5Regs.TBCTL.bit.SYNCOSEL=TB_SYNC_IN; // Input from master
    EPwm5Regs.AQCTLA.all=0x0012;// ;//set low when TBCTR=CMPA Up and high when TBCTR=TBPRD
    EPwm5Regs.DBCTL.bit.OUT_MODE=DB_FULL_ENABLE;//Enable dead band module
    EPwm5Regs.DBCTL.bit.POLSEL=2;//Inverted signal at ePWM5B
    EPwm5Regs.DBFED.all=30;//30 block in FALLING EDGE
    EPwm5Regs.DBRED.all=30;//30 block in RISING EDGE

    // Secondary Bridge
    //ePWM 1 Configuration
    EPwm1Regs.TBCTL.bit.CLKDIV=0;//(Set clock division=01b) divide by 1
    EPwm1Regs.TBCTL.bit.HSPCLKDIV=0;//(Set high speed clock division=00b)divide by 1
    EPwm1Regs.TBCTL.bit.CTRMODE=0;//Up Mode
    EPwm1Regs.TBPRD=fs;//Period corresponding to 100kHz
    EPwm1Regs.CMPA.bit.CMPA =0.5*fs;//50% duty cycle
    EPwm1Regs.TBPHS.bit.TBPHS=0;//Set phase angle of ePWM1 is 0
    EPwm1Regs.TBCTL.bit.PHSEN=TB_DISABLE;//Set as a Master
    EPwm1Regs.TBCTL.bit.SYNCOSEL=TB_CTR_ZERO;// synchronous output at CTR=0
    EPwm1Regs.AQCTLA.all=0x0024;//set high when TBCTR=CMPA Up and low when TBCTR=TBPRD
    EPwm1Regs.DBCTL.bit.OUT_MODE=DB_FULL_ENABLE;//Enable dead band module
    EPwm1Regs.DBCTL.bit.POLSEL=2;//Inverted signal at ePWM1B
    EPwm1Regs.DBFED.all=30;//30 block in FALLING EDGE
    EPwm1Regs.DBRED.all=30;//30 block in RISING EDGE

    //ePWM 2 configuration
    EPwm2Regs.TBCTL.bit.CLKDIV=0;//(Set clock division=01b) divide by 1
    EPwm2Regs.TBCTL.bit.HSPCLKDIV=0;//(Set high speed clock division=01b)divide by 1
    EPwm2Regs.TBCTL.bit.CTRMODE=0;//Up Mode
    EPwm2Regs.TBPRD=fs;//Period corresponding to 100kHz
    EPwm2Regs.CMPA.bit.CMPA =0.5*fs;//50% duty cycle
    EPwm2Regs.TBPHS.bit.TBPHS=0;//Set phase angle of ePWM5 is 180
    EPwm2Regs.TBCTL.bit.PHSEN=TB_ENABLE;//Set as a Slave
    EPwm2Regs.TBCTL.bit.SYNCOSEL=TB_SYNC_IN; // Input from master
    EPwm2Regs.AQCTLA.all=0x0012;//set low when TBCTR=CMPA Up and high when TBCTR=TBPRD
    EPwm2Regs.DBCTL.bit.OUT_MODE=DB_FULL_ENABLE;//Enable dead band module
    EPwm2Regs.DBCTL.bit.POLSEL=DB_ACTV_HIC;//Inverted signal at ePWM2B
    EPwm2Regs.DBFED.all=30;//50 block in FALLING EDGE
    EPwm2Regs.DBRED.all=30;//50 RISING EDGE

    //ePWM 3 interrupt configuration for ADC sampling
    EPwm3Regs.TBCTL.bit.CLKDIV=0;//(Set clock division=01b) divide by 1
    EPwm3Regs.TBCTL.bit.HSPCLKDIV=0;//(Set high speed clock division=00b)divide by 1
    EPwm3Regs.TBCTL.bit.CTRMODE=0;//Up Mode
    EPwm3Regs.TBPRD=0.5*fs;//Period corresponding to 200kHz
    EPwm3Regs.CMPA.bit.CMPA =0.25*fs;//50% duty cycle
    EPwm3Regs.ETSEL.bit.INTEN = 1; // Enable ePWM3 Interrupt generation
    EPwm3Regs.ETSEL.bit.INTSEL = 2; // Enable event time-base counter equal to CMPA when the timer is incrementing
    EPwm3Regs.ETPS.bit.INTPRD = 1; //Generate interrupt on 1st event

    EALLOW;
    EPwm3Regs.ETSEL.bit.SOCASEL = 2; // Generate SOCA event on ePWM3 timer = TBPRD
    EPwm3Regs.ETPS.bit.SOCAPRD = 1; // Generate SOCA on 1st event
    EPwm3Regs.ETSEL.bit.SOCAEN = 1; // Enable EPWMxSOCA pulse
    EPwm3Regs.ETCLR.bit.SOCA = 1;
    EDIS;
}

Now, I have to go for a peak current control using the following logic. This logic is working in PLECS simulation.

Control block diagram

I have to access EPWM signals and use logic gates and flip-flops to implement this controller. Also, the Vo, Vin, Io, and Is signals are acquired using ADC pins. What should I write in the EPWM ISR function to make this controller work? This uses direct access to EPWM signals and uses a comparator, flipflop, and logic gates. 

I don't expect entire coding from anyone. Little suggestions from here and there would help.

  • Hello,
    Thanks for reaching, out and sorry for the late reply.
    To implement peak-current control I recommend using the comparator (CMPSS) submodule, to control the PWM modules. 
    You can refer to this reference design for an implementation of peak current control. https://www.ti.com/lit/ug/tidueo1b/tidueo1b.pdf.

    A PI controller can be used to control the desired peak current. This controller would run in the ISR, control the peak current, which is then written into the CMPSS registers.

    I hope this is helpful.

    Best regards,

    Andreas

  • Agree. But as you can see, I need to access the EPWM signals inside the DSP. Is that possible using any modules?

  • Hi,

    Can you elaborate a bit more why you need to access signals inside the EPWM module?
    Typically the module can be configured to do the required task without accessing signal in the module.


    As an example for peak current control you would configure the CMPSS module to reset the EPWM module when the current threshold is reached. The current threshold can be adjusted in the ISR.

    Best regards,

    Andreas

  • I'm trying to implement the control given in the attached figure in the post. I know I can do that using the embedded coder and using pins as GPIO pins. But I don't want to use embedded coder and want to code in CCS.

  • Hi,
    Sure, but you cannot implement a block diagram like this directly, you need to configure the different module like EPWM, CMPSS or ADC to work like in the block diagram. 
    In your example you need to generate gs1 and gs3 as a 50% duty cycle PWM.
    Next you generate gs5 and Gs7 the exact same way, but you add the comparator submodule, to overwrite the output if your current is greater than re reference. 
    This means you need to configure the CMPSS module to generate a event for example the DCA event. And then you configure your EPWM mule to set the output high or low when this event occurs. You can set this to a cycle by cycle event, so this will work every cycle. 
    You can find find some example code in this document as well:https://www.ti.com/lit/an/sprabu2/sprabu2.pdf

    Best regards,
    Andreas