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.

Question on PWM for motor control

I am running the 28335 chip for 3 phase motor control.  I am using the bldc motor control library originally designed for the 2808 chip.  I am expecting a 20Khz PWM frequency and 150 MHz system clock.  This indicates that the number of clock ticks per PWM period is 7500.  My motor has a max speed of 28000 RPM.  My expectation is that providing a 50% duty cycle (3750 clock ticks) to the PWM function should give me roughly  14000  RPM.  When I look at the PWM function the calculation used is this:

   // Convert "Period" (Q15) modulation function to Q0
   Tmp = (int32)p->PeriodMax*(int32)p->MfuncPeriod;   // Q15 = Q0*Q15
   Period = (int16)(Tmp>>15);                         // Q15 -> Q0 (Period)
 
   // Check PwmActive setting
    if (p->PwmActive==1)                   // PWM active high
   {
      GPR0_BLDC_PWM = 0x7FFF - p->DutyFunc;  
   }
   else if (p->PwmActive==0)              // PWM active low
   {
      GPR0_BLDC_PWM = p->DutyFunc;
   }

   // Convert "DutyFunc" or "GPR0_BLDC_PWM" (Q15) duty modulation function to Q0
   Tmp = (int32)Period*(int32)GPR0_BLDC_PWM;     // Q15 = Q0*Q15

      EPwm1Regs.AQCSFRC.bit.CSFA = 0;       // Forcing disabledd on output A of EPWM1  
      EPwm1Regs.AQCTLA.bit.CAU = 2;         // Set high when CTR = CMPA on UP-count
      EPwm1Regs.AQCTLA.bit.ZRO = 1;         // Set low when CTR = Zero
      EPwm1Regs.CMPA.half.CMPA = (int16)(Tmp>>15); // PWM signal on output A of EPWM1 (Q15 -> Q0) 
      EPwm1Regs.AQCSFRC.bit.CSFB = 1;       // Forcing a continuous Low on output B of EPWM1

This indicates that the CMPA is setting the off time on the PWM and with the 50% I provided gave an off time of 6640 clock ticks leaving 860 clock ticks of on time.  I am only getting 1/4 of the expected RPMs.  Which makes sense to me since the on time is roughly 1/4.

 

What I can't figure out is what the calculation is trying to do.  MfuncPeriod is 0x7fff.

 

My guess is that I am missing something fundamental about how this PWM library works but something just doesn't seem right to me.  Can anyone clarify this for me?  Thanks.

  • Hello Christopher

    I haven't seen this entire system code before and therefore will make few assumptions [:)] This portion of code is not calculating duty ratio rather setting required PWM states once the required duty ratio is known. The variable "period" is the result of the calculation determining the required duty ratio. This variable "period" is most likely calculated in another section of the code - may be in speed loop or in current loop implementation. Once the period and the sector is known this code sets up PWM1 accordingly. Note only PWM1A is switching and PWM1B is kept off for the whole time for this sector. There should be another portion of the code which sets the other leg of the inverter.

    By the way, I am not sure about your assumption that 50% duty ratio will provide 50% of maximum RPM as the RPM will depend on your motor load and depending on your load you may need more or less duty ratio to obtain a certain RPM.

  • Thanks for your reply.  I only put a part of the code for example purpose.  There is a switch statement for the PWM commutation state which sets the PWM on the appropriate A channel and the high on the appropriate B channel.  I am trying to understand what the calculation is actually doing.  Granted my assumption that 50% PWM duty ratio does not equal 50% RPM with no load on the motor, I still want to know why the calculation takes my 50% input and converts it to 77%off time during the PWM period.

  • Well, there must be some sort of scaling involved or if the calculation is done in speed loop or current loop then the durty ratio will be calculated based on the current state of your system. You may need to go through line by line code to find the exact spot where your input is taken into account for calculation or you can contact TI hotline with specific questions about this system  and hopefully you will have an answer from the author of this code.

  • I am currently running with a fixed PWM until I am confident that things are running as expected.  With the original calculation:

    // Convert "Period" (Q15) modulation function to Q0
       Tmp = (int32)p->PeriodMax*(int32)p->MfuncPeriod;   // Q15 = Q0*Q15
       Period = (int16)(Tmp>>15);                         // Q15 -> Q0 (Period)
     
       // Check PwmActive setting
        if (p->PwmActive==1)                   // PWM active high
       {
          GPR0_BLDC_PWM = 0x7FFF - p->DutyFunc;  
       }
       else if (p->PwmActive==0)              // PWM active low
       {
          GPR0_BLDC_PWM = p->DutyFunc;
       }

       // Convert "DutyFunc" or "GPR0_BLDC_PWM" (Q15) duty modulation function to Q0
       Tmp = (int32)Period*(int32)GPR0_BLDC_PWM;     // Q15 = Q0*Q15

          EPwm1Regs.AQCSFRC.bit.CSFA = 0;       // Forcing disabledd on output A of EPWM1  
          EPwm1Regs.AQCTLA.bit.CAU = 2;         // Set high when CTR = CMPA on UP-count
          EPwm1Regs.AQCTLA.bit.ZRO = 1;         // Set low when CTR = Zero
          EPwm1Regs.CMPA.half.CMPA = (int16)(Tmp>>15); // PWM signal on output A of EPWM1 (Q15 -> Q0) 
          EPwm1Regs.AQCSFRC.bit.CSFB = 1;       // Forcing a continuous Low on output B of EPWM1

    p->PeriodMax is 7500 (number of clock ticks in a 20 KHz cycle with 150 MHz clock)

    p->MfuncPeriod is 0x7fff (some sort of magic number from the TI example code)

    p->DutyFunc is 3750 (1/2 of 7500 to give 50% PWM)

     

    PWM is set to low from 0 to count CMPA and then switches to active (high).  CMPA is coming up as 6640.  Therefore, the PWM is low for 6640 and then high for 860. 

     

    I will see if TI will respond to my query on what the calculation is intended to do and what the purpose of the 0x7fff magic numbers.

  • One quick correction: the 2808 doesn't run at 150MHz, but 100MHz max.

    Another thing is whether you're using symmetric PWM or not, as this could halve your PWM frequency for a given timer period.

    Have you checked the PWM signals with a scope ?

  • I am running the 28335 which is 150 MHz and have made the necessary corrections to determine the period.  I have checked on a scope and the period is 50 us which indicates the 20 KHz frequency.  The scope also verified that the 50% I am feeding in is giving 11 us on time out of 50 us.  I am also setup for asymmetric PWM.