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.

PWM with variable Frequency

Other Parts Discussed in Thread: TMS320F28023, CONTROLSUITE

Hello

I'm new to the TMS320F28023.

I have worked through the examples from TI and i already have a PWM Signal with fixed Frequency and where i can vary the duty cycle.

But now i need a PWM Signal which turns on when Timebase = 0. So i set EPwm2Regs.AQCTLA.bit.ZRO = AQ_SET. But now i need the PWM Signal turned off when it reaches a certain value. And the next Period should start when the value reaches zero. 

I need the signal for a PFC stage which works in Critical Conduction Mode. Does anyone has an idea how i can realize such a signal?

  • turn on at timer = 0

    turn off at  CMPA = certain value

    you will set the frequency of the period by changing the value of the time base

     

  • Variable frequency PWM can be achieved by changing the period value so that is kind of straight forward ... I believe you are asking more than that but I was not able to understand your requirement - will it be possible for you to post a PWM waveform for a better understanding of your requirement?

  • I hope this picture better discribes my requirements. As you can see the PWM turn on when the counter is zero. With the EPwm2Regs.AQCTLA.bit.ZRO = AQ_SET; i realize this. Now the current rises and when it reaches the reference waveform it should turn off. Then the current drops down till zero an i turn the PWM on again. As you can see the frequency changes with the sinus waveform. I have to change the Timebase ever cycle. But i don't know how to realize this.

    I already calculate the reference waveform out of 2 ADC values. The current is another ADC value. My problem is now at what point i must reset the Timebasecounter and how to change the Timebase dynamically.

    Already thanks for your help!!

     

  • Hi all,

    I need also help in this issue,i need same above PWM signals to drive MOSFET inverter Gate.I am not getting an idea how much value i have to set TBPRD (for 50Hz sinusoidal output ) and where should i have to specify the sinewave in CMPA or somewhere ? and also how to get the sine wave which should compare with traingular wave?

    please help me

     

    Regards,

    Naveen Rangu

  • I really don't know if this helps:

    You have a constant on time and a variable off time. Each time current reaches zero, you can turn on the output for a constant time. To realize this, uses a down counter that starts with current = 0. After reaching the constant time, turn it off and wait until current is zero again. Then you will get exactly the waveform in the picture.

    Hope this could solve your problem

    Eggi

  • This helps a lot but i don't know how to end a PWM Cycle before it reaches the Timebasecounter. I tried too reset the Timebasecounter when the current = 0, but it doesn't work. Is there anything i have to consider when i reset the Timebasecounter?

            pid1.Ref = 6200 ;                                        
            pid1.Fdb = AdcResult.ADCRESULT2;                        
            PID_MACRO(pid1);                                      
            curve = ((float)(pid1.Out)/3100)*AdcResult.ADCRESULT0;
              
              
              
               while (AdcResult.ADCRESULT1 < curve )                  
               {           
                   AdcRegs.ADCSOCFRC1.bit.SOC1 = 1;                  
              }
               new_CMPA = EPwm2Regs.TBCTR;                              
               EPwm2Regs.CMPA.half.CMPA = new_CMPA;                   
               while (AdcResult.ADCRESULT1 > 0)                      
               {
                   AdcRegs.ADCSOCFRC1.bit.SOC1 = 1;                  
               }
               EPwm2Regs.TBCTR = 0x0000;       

    This is my code so far. The Pid1 generates my reference curve. The ADCRESULT1 is the current. When it reaches the reference curve i set the CMPA value so the PWM turns off. Then i wait until the current = 0 and i reset the Timebasecounter.

  • Hello Christian

    Well, I see your problem. But if i have a look at your picture, then I see the sinus curce to stop pwm but also the information that pwm has a constant on time!! I think the sinus curve is the result of this constant on time and the current reaches zero after maybe a capacitor unload event.

    I'm really not confirm in programming 28035 but i think it should be possible to stop pwm and then restart it with next event current = 0.

    On Delfino the solution to stop pwm is as follows:

    void StopPWM(void)
    {
        EALLOW;
        EPwm1Regs.TZFRC.bit.OST = 1;
        EPwm2Regs.TZFRC.bit.OST = 1;
        EPwm3Regs.TZFRC.bit.OST = 1;
        EDIS;
    }

    But i really don't know if this works on your device.

    Maybe it could also be a solution to change your driver to be on at low signal at the gate.

     

     

     

  • I would do something like Eggi.

    Don't worry about the changing frequency time base, just generate your fixed PWM duty cycle.

    Then you just have to synch the PWM on to the event that kicks if off (current = 0).

    May be able to do this easily on Piccolo using the comparator and reset ePWM function.

     

  • First i want to thank you all for the help, but i still don't get the controller to do what i want.

    I tried different things but none is working. I set the Timebase = 1000 and the CMPA = 500. And then i execute the following codes:

             if (EPwm2Regs.TBCTR >= 750)
               {
                   EPwm2Regs.TBPRD = EPwm2Regs.TBCTR;
                   EPwm2Regs.TBCTR = 0x0000;
               }    

    I watch the TBCTR through a watch window and i can see that it is reset if TBCTR >= 750. But if i watch the signal out of the Port i can't see anything.

    With the following code The PWM gets high at the beginning and gets low at Timebase = CMPA. At Timebase = 750 the new Timebase is set and the Timebasecounter is reset and everything works.  I watch the signal with an oscilloscope and it looks good. If i don't set the TBPRD new it doesn't work. Why i can't just reset the Timebasecounter?

              if (EPwm2Regs.TBCTR == 750)
               {
                   EPwm2Regs.TBPRD = EPwm2Regs.TBCTR;
                   EPwm2Regs.TBCTR = 0x0000;
               }

    Can somebody tell my why i don't get a signal with the first code? Is there any bit or flag i have to pay attention to?

  • Hello Christian,

    Well, the pwm pin just changes if any counter compare register value is reached. So, if you look at your first example, the reset just sets the countervalue to zero. So it will never reach 1000.

    If you look at the sprufz6.pdf (I know its a delfino document) you find a lot of the behaviour of pwm module. Have a look at chapter 3, Applications to Power Topologies.

    Regards

    Eggi

  • In section one 

    1. The PWM will be high CMPA = 500

    2. And then low until CTR>=750

    3. then the PRD register will be updated to the CTR value of "750", the CTR will be set to 0, and your PWM will go high.

    4. If this is a loop, your CTR will still be >=750 so it will re-enter this code and just keep resetting the CTR=0 and your PWM will remain high

     

     

  • Hello Mr Clearman


    Actually the PRD is 767 and the PWM signal is low. I guess the difference between 750 and 767 is the time the controller needs to update the register.

    Your right that this is a loop, but i don't understand what you mean with point 4. The first three points i see like you. You say that CTR >= 750 but i reset the CTR? So it is zero or am i wrong?

  • ok, disregard, I mis-read your code.

  • Ok, looking at your code up above again, are you just sitting in a loop polling the ADC value over and over during your entire control loop cycle?

    Even if you get this to work you're going to spend all your time and cycles just on creating a single PWM output.  You need to find a way to do this with hardware.

    Can you ouput your reference waveform and use the comparator to reset the ePWM?

  • Eggi,

    This is essentially a cycle by cycle current controller, correct?  You WILL want to use the comparators on Piccolo, or external comparators with other 28x devices.

    Look at page 99 here

    http://focus.ti.com/lit/ug/spruge9d/spruge9d.pdf

     

    This PFC example may be helpful. Install and look at documentation (this is being cleaned and released late June for controlSUITE)

    http://focus.ti.com/docs/toolsw/folders/print/sprc307.html