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.

TMDSCNCD28027: How to reset the ramp generator when the phase is terminated by a sync event and doesn't reach TBPRD.

Part Number: TMDSCNCD28027
Other Parts Discussed in Thread: TMS320F28379D

I have a variable frequency LLC application where each phase of the F28027 can be terminated by a comparator before reaching the TBPRD value.  At this point the TBPHS register is loaded, which resets TBCTR to 0.  However, it may also not be terminated by the comparator, and count all the way to TBPRD.

The problem:  If the comparator does not trip during a given phase, the ramp generator does not reset.  This means that the ramp generator  continues counting down into the next phase.  This can cause premature termination of the next phase, because the reference to the comparator will be too low.

I need a method to force the ramp generator to reset at the end of the phase, regardless of whether the comparator trips or not.  The only method I've come up with is to toggle the DACSOURCE bit in the ISR:

        Comp1Regs.DACCTL.bit.DACSOURCE = 0; // 0 - DACVAL

        Comp1Regs.DACCTL.bit.DACSOURCE = 1; // 1 - Internal ramp for slope compensation

But this takes time (I've implemented it in C) which is slowing down my minimum period.  Is there a more elegant way of resetting the ramp generator?

Thanks,

Ciaran

AMER_US_VT-Burlington

  • Ciaran,

    Can you try changing the HRPCTL[PWMSYNCSEL] setting so that the PWMSYNC signal is generated by TBCTR=0?

    -Tommy

  • Hi Tommy.

    One important detail I forgot to mention was that the PWMSYNC is generated by EPWM4, which is operating as a slave to EPWM1 with a phase offset of MIN_PERIOD.  It's job is to start the ramp generator after a certain amount of time has elapsed since the start of the cycle.  PWMSYNC is generated when EPWM4 is at TBCTR=0 (using HRPCTL[PWMSYNCSEL] as you suggested), not by EPWM1 at TBCTR=0.

    What I want to do is also force the ramp generator reset when EPWM1 TBCTR=0 in addition to the PWMSYNC from EPWM4 at TBCTR.  I am doing this with the ISR as described in OP but would like to do it in hardware.  

    Thanks,

    Ciaran

  • Ciaran,

    Is the intent of resetting on EPWM1 = 0 in order to mask the trips?

    -Tommy

  • If you want to avoid trips between EPWM1=0 and EPWM4=0, you can consider using the BLANKING window on EPWM1.

  • Tommy,

    This is a variable frequency LLC with peak charge mode control (PQMC).  PQMC works similar to peak current mode control in a buck, except rather than the comparator determining the duration of one phase at a fixed frequency, two comparators each control the duration of one of two phases (+ and -).  So when the comparators are in control, the period of each phase and hence the switching frequency are variable.

    EPWM1 drives the primary side switch with complementary outputs A & B.  Its TBPRD is set to the maximum period, so if the comparators don't trip, the EPWM1 outputs toggle at the max period.  If the comparators trip, they create a sync event that resets the EPWM1 counter and force the outputs to toggle.  But I also need to set a minimum period.  I am using the blanking window to prevent the comparators from resetting EPWM1 before the minimum period has expired.  I use EPWM4 to generate a PWMSYNC signal that starts the ramp generators in the comparators immediately after the minimum period has expired and the blanking window terminates.  That prevents premature resetting of the ramp generator during the blanking window.

    My issue occurs when the comparators do not trip during a given phase, so EPWM1 times out at TBPRD.  This resets EPWM1 but not the ramp generators in the comparators - they keep counting down into the next cycle.  This can produce premature triggering of the comparator while the blanking window is active early in the next cycle, because the comparator reference will be too low.  Two bad things can happen when the comparator trips too soon: 1) the period can be terminated prematurely if the trip occurs after the blanking window, creating a too short period; 2) the ramp generator can be reset prematurely if the trip occurs before the blanking window terminates, creating a too long period.

    Anyway, my solution seems to be working well now and the ISR is fast enough after some improvements.  This is the code that I execute every cycle in the ISR:

    EALLOW;
    if(GpioDataRegs.GPADAT.bit.GPIO0)
    { // EPWM1 output A is high, enable COMP1
    EPwm1Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP1OUT; // select COMP1 as input to event filter
    Comp1Regs.DACCTL.bit.DACSOURCE = 1; // 1 - Internal ramp for slope compensation
    Comp2Regs.DACCTL.bit.DACSOURCE = 0; // 0 - DACVAL;
    }
    else
    { // EPWM1 output B is high, enable COMP2
    EPwm1Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP2OUT; // select COMP2 as input to event filter
    Comp2Regs.DACCTL.bit.DACSOURCE = 1; // 1 - Internal ramp for slope compensation
    Comp1Regs.DACCTL.bit.DACSOURCE = 0; // 0 - DACVAL;
    }
    EDIS;

    For reference, this is how the EPWM1, EPWM4, and Comparators are configured:

    EALLOW;

    // Configure ePWM1AB (used to switch primary half-bridge FETs)

    // Time-Base Submodule Registers
    EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW; // set load on CTR=0
    EPwm1Regs.TBPRD = MAX_PERIOD-1; // PWM frequency = 1 / period
    EPwm1Regs.TBCTR = 0;
    EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;
    EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
    EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;
    EPwm1Regs.TBCTL.bit.PHSEN = 1; // 1 = enable loading counter register from phase register
    EPwm1Regs.TBCTL.bit.SYNCOSEL = 1; // 1 = sync output when counter = 0
    EPwm1Regs.TBPHS.half.TBPHS = 0; // phase register value
    // Counter-Compare Submodule Registers
    EPwm1Regs.CMPA.half.CMPA = 0; // set duty 0% initially
    EPwm1Regs.CMPB = 0; // set duty 0% initially
    EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
    EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_PRD;
    // Digital Compare Submodule Registers
    EPwm1Regs.DCTRIPSEL.bit.DCAHCOMPSEL = 8; // 8 = DCAH = Comparator 1 output initially (ISR switches this between Comp1 and Comp2 each phase)
    EPwm1Regs.TZDCSEL.bit.DCAEVT1 = 2; // 2 = DCAEVT1 set on DCAH high(will become active as Comparator output goes high)
    EPwm1Regs.DCACTL.bit.EVT1SRCSEL = 1; // 1 = Use filtered DCEVTFILT Signal (filtered by event window, see below)
    EPwm1Regs.DCACTL.bit.EVT1SYNCE = 1; // 1 = SYNC Generation Enabled
    EPwm1Regs.TZCTL.bit.DCAEVT1 = 3; // 3 = Do nothing on EPWM1A output on event
    EPwm1Regs.DCFCTL.bit.SRCSEL = 0; // 0 = Filter source = DCAEVT1
    EPwm1Regs.DCFCTL.bit.PULSESEL = 1; // 0 = Filter start on TBCTR = 0
    EPwm1Regs.DCFCTL.bit.BLANKE = 1; // 1= Enable Blanking window
    EPwm1Regs.DCFCTL.bit.BLANKINV = 0; // 0 = Blanking window not inverted
    EPwm1Regs.DCFOFFSET = 0; // Set filter offset to 0
    EPwm1Regs.DCFWINDOW = MIN_PERIOD; // Blanking window duration = MIN_CYCLE
    // EPwm1Regs.DCFOFFSET = MAX_PERIOD-3; // Set filter offset to TBPRD-3 to compensate for 3 clock delay to start blanking window (wraps to next cycle)
    // EPwm1Regs.DCFWINDOW = MIN_PERIOD+3; // Blanking window duration = MIN_CYCLE, plus 3 to compensate for starting window 3 clocks early.
    // Action-Qualifier Submodule Registers
    EPwm1Regs.AQCTLA.bit.ZRO = 3; // 3 = when counter = zero toggles EPWM1A output
    EPwm1Regs.AQCTLA.bit.CAU = 0; // 0 = Do nothing (action disabled)
    EPwm1Regs.AQCTLA.bit.PRD = 0; // 0 = Do nothing (action disabled)
    EPwm1Regs.AQCTLB.bit.ZRO = AQ_NO_ACTION;
    EPwm1Regs.AQCTLB.bit.CAU = AQ_NO_ACTION;
    EPwm1Regs.AQCTLB.bit.PRD = AQ_NO_ACTION;
    // Dead-Band Generator Submodule Registers
    EPwm1Regs.DBCTL.bit.IN_MODE = 0; // 0 = EPWM1a input only
    EPwm1Regs.DBCTL.bit.POLSEL = 2; // EPWM1b inverted
    EPwm1Regs.DBCTL.bit.OUT_MODE = 3; // dead-band applied to both EPWM1a and EPWM1b outputs
    EPwm1Regs.DBRED = RED; // sets the deadband timing
    EPwm1Regs.DBFED = FED; // sets the deadband timing

    // Configure EPWM4 to generate ISR and ramp generator PWMSYNC timings

    // Time-Base Submodule Registers
    EPwm4Regs.TBCTL.bit.PRDLD = TB_IMMEDIATE; // set Immediate load
    EPwm4Regs.TBPRD = MAX_PERIOD-1; // PWM frequency = 1 / period
    EPwm4Regs.TBCTR = 0;
    EPwm4Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;
    EPwm4Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
    EPwm4Regs.TBCTL.bit.CLKDIV = TB_DIV1;
    EPwm4Regs.TBCTL.bit.PHSEN = TB_ENABLE;
    EPwm4Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN;
    EPwm4Regs.TBPHS.half.TBPHS = Epwm4_Tbphs; // sets phase for EPWM4 on sync
    // Counter-Compare Submodule Registers
    EPwm4Regs.CMPA.half.CMPA = Epwm4_CmpA; // Sets EPWM4 output pulse start and trigger point for CNTL_ISR
    EPwm4Regs.CMPB = 0; // set duty 0% initially
    EPwm4Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
    EPwm4Regs.CMPCTL.bit.LOADAMODE = CC_CTR_PRD;
    // Action-Qualifier Submodule Registers
    EPwm4Regs.AQCTLA.bit.ZRO = 1; // 1 = output low
    EPwm4Regs.AQCTLA.bit.CAU = 2; // 2 = output high
    EPwm4Regs.AQCTLA.bit.PRD = 0; // 0 = Do nothing (action disabled)
    EPwm4Regs.AQCTLB.bit.ZRO = AQ_NO_ACTION;
    EPwm4Regs.AQCTLB.bit.CAU = AQ_NO_ACTION;
    EPwm4Regs.AQCTLB.bit.PRD = AQ_NO_ACTION;
    // High Resolution Period Control Register
    EPwm4Regs.HRPCTL.bit.PWMSYNCSEL = 1; // PWMSYNC generated at EPWM4 TBCTR = 0 for synchronizing comparator ramp generators

    // Configure the comparator and ramp generator blocks
    Comp1Regs.COMPCTL.bit.SYNCSEL = 1; // Sync output with SYSCLK / use Qualification
    Comp1Regs.COMPCTL.bit.QUALSEL = 4; // Qualification period = 4 clocks
    Comp1Regs.COMPCTL.bit.CMPINV = 0; // Output High when true
    Comp1Regs.COMPCTL.bit.COMPDACEN = 1; // Power up Comparator locally
    Comp1Regs.COMPCTL.bit.COMPSOURCE = 0; // Connect the inverting input to internal DAC
    Comp1Regs.COMPCTL.bit.QUALSEL = 3; // Comparator output must be active for 2 consecutive clocks before resetting the RAMP
    Comp1Regs.DACVAL.bit.DACVAL = 0x3FF; // Set DAC output - Q10
    Comp1Regs.DACCTL.bit.DACSOURCE = 1; // 0 - DACVAL; 1 - Internal ramp for slope compensation
    Comp1Regs.DACCTL.bit.RAMPSOURCE = 3; // 3 = PMW4
    Comp1Regs.RAMPDECVAL_SHDW = Slope; // Set initial slope

    Comp2Regs.COMPCTL.bit.SYNCSEL = 1; // Sync output with SYSCLK / use Qualification
    Comp2Regs.COMPCTL.bit.QUALSEL = 4; // Qualification period = 4 clocks
    Comp2Regs.COMPCTL.bit.CMPINV = 0; // Output High when true
    Comp2Regs.COMPCTL.bit.COMPDACEN = 1; // Power up Comparator locally
    Comp2Regs.COMPCTL.bit.COMPSOURCE = 0; // Connect the inverting input to internal DAC
    Comp2Regs.COMPCTL.bit.QUALSEL = 3; // Comparator output must be active for 2 consecutive clocks before resetting the RAMP
    Comp2Regs.DACVAL.bit.DACVAL = 0x3FF; // Set DAC output - Convert to Q10
    Comp2Regs.DACCTL.bit.DACSOURCE = 1; // 0 - DACVAL; 1 - Internal ramp for slope compensation
    Comp2Regs.DACCTL.bit.RAMPSOURCE = 3; // 3 = PMW4
    Comp2Regs.RAMPDECVAL_SHDW = Slope; // Set initial slope

    EDIS;

    Thanks,

    Ciaran

  • Thanks.  I am using the blanking window as you suggest.  Details in my other response.

  • Ciaran,

    It does sound like you have bumped into a limitation of hardware capabilities on this device. I'm glad that the ISR is working for you. If further optimization is needed, you can also port to assembly.

    If you still have the option of evaluating other devices, newer devices (like the F28004x family) have improved CMPSS (comparator) and EPWM modules that might enable additional options. For example the CMPSS provides a hardware means to introduce a delay between PWMSYNC reset and when the ramp generator begins to decrement.

    -Tommy

  • Tommy,

    Thanks.  I did some more optimizing of the ISR today.  I studied the disassembled C code and I don't think I can improve on what the compiler did.  I did eliminate a double context save, because my C ISR code was calling an assembly ISR and the context was getting saved and restored by both of them.  At this point the ISR is plenty fast enough for this application.

    >> If you still have the option of evaluating other devices, newer devices (like the F28004x family) have improved CMPSS (comparator) and EPWM modules

    I have some new TMS320F28379D LaunchPads to play with for a higher frequency converter application.  Do these have those improvements?  If nothing else they are a lot faster than the F28027.

    - Ciaran

  • Ciaran,

    Yes, the F2837x family was the first to use the CMPSS module.  F28004x has some minor CMPSS updates for improved ease of use.

    This Peripheral Reference Guide is helpful for seeing what is available in each device family.

    -Tommy

  • Tommy,

    Thanks.  I will look more into more into the 28004x family.  This description of the improved CMPSS in Table 32 of the Peripheral Reference Guide seems to address exactly the problems I've been dealing with at the EPWM boundaries.  

    1 Blanking capability added that helps clear and reset the existing/imminent trip conditions near EPWM boundaries. Fixed Trip vs Clear-and reset arbitration when the RAMP generator is used. CMPSS Pos/Neg signals are independently selected via an analog subsystem MUX scheme.  

    I've had 3 types of problems, all related to coordinating the ramp generator with the EPWM:

    1. Comparator doesn't trip so ramp generator doesn't reset and continues to count down into the next phase
    2. Comparator trips during blanking window so ramp generator resets but the EPWM doesn't.
    3. Comparator trips about the same time as EPWM reset, resulting in a double reset of the EPWM (and double toggle of outputs)

    I've got workarounds to all three problems now, but it will be better if it's done in the comparator module.

    For any users reading this thread looking for solutions to a similar problem, these are my workarounds:

    1. Force reset of ramp generator by toggling the CompxRegs.DACCTL.bit.DACSOURCE bit in an ISR.
    2. Use a second EPWM to generate a PWMSYNC pulse to start the ramp generator after the blanking window in the first EPWM is terminated.
    3. Delay the toggling of the EPWM outputs for >= 3 clocks using CMPA or CMPB.  This does not avoid double resets of EPWM but does avoid double toggling of outputs.

    - Ciaran

    P.S. After a quick look at the TMS320F28004x Microcontrollers Technical Reference Manual SPRUI33C, to see if my issues are addressed by the CMPSS, this is my first take:

    1. Comparator doesn't trip so ramp generator doesn't reset and continues to count down into the next phase
      1. No improvement:  in Figure 16.5 there are no additional hooks to reset the ramp generator in this case.  
    2. Comparator trips during blanking window so ramp generator resets but the EPWM doesn't.
      1. No improvement:  in Figure 16.1 the EPWMBLANK is applied after the COMPHSTS reset is sent to reset the ramp generator.
    3. Comparator trips about the same time as EPWM reset, resulting in a double reset of the EPWM (and double toggle of outputs)
      1. Improvement:  The EPWMBLANK signal looks like it could blank the comparator trip near the end of the maximum period, preventing double reset of the EPWM

    If I could make a suggestion for a future iteration of the C2000 architecture, it would be to add more control over the ramp generator reset.  These type of inputs would be useful:

    1. Blanking capability for the COMPHSTS signal to avoid unwanted ramp generator resets
    2. A PWMSYNC type of input to force a reset of the ramp generator at specific times or events
    3. Control register bits to force (or prevent) a ramp generator reset by software.

    Ciaran

  • After a quick look at the TMS320F28004x Microcontrollers Technical Reference Manual SPRUI33C, to see if my issues are addressed by the CMPSS, this is my first take:

    1. Comparator doesn't trip so ramp generator doesn't reset and continues to count down into the next phase
      1. No improvement:  in Figure 16.5 there are no additional hooks to reset the ramp generator in this case.  
    2. Comparator trips during blanking window so ramp generator resets but the EPWM doesn't.
      1. No improvement:  in Figure 16.1 the EPWMBLANK is applied after the COMPHSTS reset is sent to reset the ramp generator.
    3. Comparator trips about the same time as EPWM reset, resulting in a double reset of the EPWM (and double toggle of outputs)
      1. Improvement:  The EPWMBLANK signal looks like it could blank the comparator trip near the end of the maximum period, preventing double reset of the EPWM

    If I could make a suggestion for a future iteration of the C2000 architecture, it would be to add more control over the ramp generator reset.  These type of inputs would be useful:

    1. Blanking capability for the COMPHSTS signal to avoid unwanted ramp generator resets
    2. A PWMSYNC type of input to force a reset of the ramp generator at specific times or events
    3. Control register bits to force (or prevent) a ramp generator reset by software.

  • Ciaran Brennan said:
    1. Comparator doesn't trip so ramp generator doesn't reset and continues to count down into the next phase
            a. No improvement:  in Figure 16.5 there are no additional hooks to reset the ramp generator in this case. 

    Would you be able to use a single EPWM for both actuation and PWMSYNC generation by taking advantage of the RAMPDLY function? That should help to take care of the boundary condition reset slop from using two phase-shifted EPWMs.

    Ciaran Brennan said:
    2. Comparator trips during blanking window so ramp generator resets but the EPWM doesn't.
            a. No improvement:  in Figure 16.1 the EPWMBLANK is applied after the COMPHSTS reset is sent to reset the ramp generator.

    The trip signal that is sent downstream to the EPWM is selectable via the CTRIPxSEL MUX. When using the EPWMBLANK feature, you would select a synchronized path (MUX Selections 1-3). These synchronizers all use EPWMBLANK as a reset signal so they will also blank the ramp generator COMPSTS reset signal until EPWMBLANK is deasserted.

    Ciaran Brennan said:
    A PWMSYNC type of input to force a reset of the ramp generator at specific times or events

    The improved CMPSS + EPWM system enables additional flexibility for when PWMSYNC is generated.  Instead of only 0 or PRD, it is now possible to generate PWMSYNC on CMPC or CMPD match.

    Ciaran Brennan said:
    Control register bits to force (or prevent) a ramp generator reset by software.

    Would you still consider this to be necessary with the above clarifications?

  • Tommy,

    Thanks for the clarifications.  It's a lot better than it first appeared!

    >> Would you be able to use a single EPWM for both actuation and PWMSYNC generation by taking advantage of the RAMPDLY function?

    >> The improved CMPSS + EPWM system enables additional flexibility for when PWMSYNC is generated.  Instead of only 0 or PRD, it is now possible to generate PWMSYNC on CMPC or CMPD match.

    Those are nice features.  The additional flexibility of generating PWMSYNC using a counter compare during the blanking window would solve problem #1 (comparator doesn't trip so ramp generator doesn't reset).  The EPWMBLANK and RAMPDLY should solve my problem #2 (Comparator trips during blanking window so ramp generator resets but the EPWM doesn't).  

    >> These synchronizers all use EPWMBLANK as a reset signal so they will also blank the ramp generator COMPSTS reset signal until EPWMBLANK is deasserted.

    Excellent!  I missed the path from EPWMBLANK to the reset pin on the latch immediately following the comparator.  

    I've found this sequence is necessary on the F28027 to avoid bad things at the boundaries:

    1. TBCTR=0
    2. Start EPWM blanking window
    3. Toggle EPWM output (CMPA)
    4. Switch comparator input to event filter (DCAHCOMPSEL)
    5. Disable ramp generator for last phase (DACSOURCE=0, DACVAL = max value)
    6. Force reset of ramp generator for this phase (DACSOURCE=1)
    7. End EPWM blanking window
    8. Start ramp generator for this phase (PWMSYNC from a second EPWM)

    How is this accomplished with the CMPSS? My guess:

    1. TBCTR=0
    2. Start EPWM blanking window (same)
    3. Start comparator blanking window (EPWMBLANK)
    4. Toggle EPWM output (same)
    5. Switch comparator input to event filter (same)
    6. Force reset of ramp generator for this phase (EPWMSYNCPER, set by CMPC)
    7. End EPWM blanking window (same)
    8. End comparator blanking window (EPWMBLANK)
    9. Start ramp generator for this phase (RAMPDLY)

    Would this work?  I am worried about the relative timing of the EPWM blanking and the comparator blanking, that there would be race conditions.

    >> "Control register bits to force (or prevent) a ramp generator reset by software."  Would you still consider this to be necessary with the above clarifications?

    Not if the sequence I proposed above works.  It's still desirable though.  One of the powerful attributes of the C2000 is the ability to supplement the capabilities of the hardware with ISR code where necessary.  I think having hooks to do that in the CMPSS would add capability.

  • Ciaran Brennan said:
    Would this work?  I am worried about the relative timing of the EPWM blanking and the comparator blanking, that there would be race conditions.

    Yes, you have the correct understanding. The EPWMBLANK signal in the CMPSS is taken directly from the internal blanking logic of the EPWM. The blanking window for both modules will be synchronized by design.

    Ciaran Brennan said:
    Not if the sequence I proposed above works.  It's still desirable though.  One of the powerful attributes of the C2000 is the ability to supplement the capabilities of the hardware with ISR code where necessary.  I think having hooks to do that in the CMPSS would add capability.

    We will take this into consideration. For now, it should still be possible to perform the DACSOURCE toggle as you had done on F2802x.

  • I'm convinced.  I'm ordering a F280049 Launchpad to try it out.

  • Ciaran,

    I'm glad that you have decided to evaluate F28004x.  It has a lot of capability for a small device.  You should also expect to see CLB support rolling out over the next few months.

    -Tommy