C2000 如何調整佔空比

2019-03-26 14:45发布

各位前輩們
正在學習怎麼使用DSP
這個範例程式裡
Example_2806xEPwmUpDownAQ
C2000 如何調整佔空比呢??
我去調整CMPA,但怎麼調佔空比還是50幾%而已??如何把佔空比調到95%呢??
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

__interrupt void epwm3_isr(void)
{

   // Update the CMPA and CMPB values
//   update_compare(&epwm3_info);

   // Clear INT flag for this timer
   EPwm3Regs.ETCLR.bit.INT = 1;

   // Acknowledge this interrupt to receive more interrupts from group 3
   PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}


#define EPWM3_TIMER_TBPRD  2000 // Period register 2000
#define EPWM3_MAX_CMPA     1800
#define EPWM3_MIN_CMPA     200
#define EPWM3_MAX_CMPB     1950
#define EPWM3_MIN_CMPB     50


void InitEPwm3Example(void)
{


   // Setup TBCLK
   EPwm3Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;// Count up/down
   EPwm3Regs.TBPRD = EPWM3_TIMER_TBPRD;          // Set timer period
   EPwm3Regs.TBCTL.bit.PHSEN = TB_DISABLE;       // Disable phase loading
   EPwm3Regs.TBPHS.half.TBPHS = 0x0000;          // Phase is 0
   EPwm3Regs.TBCTR = 0x0000;                     // Clear counter
   EPwm3Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;      // Clock ratio to SYSCLKOUT
   EPwm3Regs.TBCTL.bit.CLKDIV = 7;//TB_DIV1;

   // Setup shadow register load on ZERO
   EPwm3Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
   EPwm3Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
   EPwm3Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
   EPwm3Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;   

  // Set Compare values
   EPwm3Regs.CMPA.half.CMPA = EPWM3_MIN_CMPA;    // Set compare A value
   EPwm3Regs.CMPB = EPWM3_MAX_CMPB;              // Set Compare B value

   // Set Actions
   EPwm3Regs.AQCTLA.bit.PRD = AQ_SET;            // Set PWM3A on period
   EPwm3Regs.AQCTLA.bit.CBD = AQ_CLEAR;          // Clear PWM3A on event B, down count

   EPwm3Regs.AQCTLB.bit.PRD = AQ_CLEAR;          // Clear PWM3A on period
   EPwm3Regs.AQCTLB.bit.CAU = AQ_SET;            // Set PWM3A on event A, up count

   // Interrupt where we will change the Compare Values
   EPwm3Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO;     // Select INT on Zero event
   EPwm3Regs.ETSEL.bit.INTEN = 1;                // Enable INT
   EPwm3Regs.ETPS.bit.INTPRD = ET_3RD;           // Generate INT on 3rd event



   // Information this example uses to keep track
   // of the direction the CMPA/CMPB values are
   // moving, the min and max allowed values and
   // a pointer to the correct ePWM registers
   epwm3_info.EPwm_CMPA_Direction = EPWM_CMP_UP;   // Start by increasing CMPA &
   epwm3_info.EPwm_CMPB_Direction = EPWM_CMP_DOWN; // decreasing CMPB
   epwm3_info.EPwmTimerIntCount = 0;               // Zero the interrupt counter
   epwm3_info.EPwmRegHandle = &EPwm3Regs;          // Set the pointer to the ePWM module
   epwm3_info.EPwmMaxCMPA = EPWM3_MAX_CMPA;        // Setup min/max CMPA/CMPB values
   epwm3_info.EPwmMinCMPA = EPWM3_MIN_CMPA;      
   epwm3_info.EPwmMaxCMPB = EPWM3_MAX_CMPB;   
   epwm3_info.EPwmMinCMPB = EPWM3_MIN_CMPB;  
}

void update_compare(EPWM_INFO *epwm_info)
{


   // Every 10'th interrupt, change the CMPA/CMPB values
   if(epwm_info->EPwmTimerIntCount == 1)
   {
       epwm_info->EPwmTimerIntCount = 0;

       // If we were increasing CMPA, check to see if
       // we reached the max value.  If not, increase CMPA
       // else, change directions and decrease CMPA
           if(epwm_info->EPwm_CMPA_Direction == EPWM_CMP_UP)
           {
               if(epwm_info->EPwmRegHandle->CMPA.half.CMPA < epwm_info->EPwmMaxCMPA)
               {
                  epwm_info->EPwmRegHandle->CMPA.half.CMPA++;
               }
               else
               {
                  epwm_info->EPwm_CMPA_Direction = EPWM_CMP_DOWN;
              epwm_info->EPwmRegHandle->CMPA.half.CMPA--;
               }
           }

           // If we were decreasing CMPA, check to see if
       // we reached the min value.  If not, decrease CMPA
       // else, change directions and increase CMPA
           else
           {
               if(epwm_info->EPwmRegHandle->CMPA.half.CMPA == epwm_info->EPwmMinCMPA)
               {
                  epwm_info->EPwm_CMPA_Direction = EPWM_CMP_UP;
                  epwm_info->EPwmRegHandle->CMPA.half.CMPA++;
               }
               else
               {
                  epwm_info->EPwmRegHandle->CMPA.half.CMPA--;
               }
           }

           // If we were increasing CMPB, check to see if
       // we reached the max value.  If not, increase CMPB
       // else, change directions and decrease CMPB
           if(epwm_info->EPwm_CMPB_Direction == EPWM_CMP_UP)
           {
               if(epwm_info->EPwmRegHandle->CMPB < epwm_info->EPwmMaxCMPB)
               {
                  epwm_info->EPwmRegHandle->CMPB++;
               }
               else
               {
                  epwm_info->EPwm_CMPB_Direction = EPWM_CMP_DOWN;
                  epwm_info->EPwmRegHandle->CMPB--;
               }
           }

           // If we were decreasing CMPB, check to see if
       // we reached the min value.  If not, decrease CMPB
       // else, change directions and increase CMPB


           else
           {
               if(epwm_info->EPwmRegHandle->CMPB == epwm_info->EPwmMinCMPB)
               {
                  epwm_info->EPwm_CMPB_Direction = EPWM_CMP_UP;
                  epwm_info->EPwmRegHandle->CMPB++;
               }
               else
               {
                  epwm_info->EPwmRegHandle->CMPB--;
               }
           }
   }
   else
   {
      epwm_info->EPwmTimerIntCount++;
   }

   return;
}

此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。