본문 바로가기

[DSP]/DSP280x-M

[DSP280x-M EVM]보드 테스트 - TMS320F2808 ePWM 1Mhz PWM제어

[DSP280x-M EVM]보드 테스트 - TMS320F2808 ePWM 1Mhz PWM제어



#define PWM_10KHZ    10000 //10 KHz
#define PWM_100KHZ    1000 //100 KHz
#define PWM_125KHZ    800  //125 KHz
#define PWM_167KHZ    600  //167 KHz
#define PWM_200KHZ    500  //200 KHz
#define PWM_400KHZ    250  //400 KHz
#define PWM_500KHZ    200  //500 KHz
#define PWM_1MHZ    100  //1 MHz
#define PWM_2MHZ    50  //2 MHz
#define PWM_4MHZ    25  //4 MHz
#define PWM_5MHZ    20  //5 MHz
#define PWM_8_33MH    12  //8.33 MHz
#define PWM_10MHZ    10  //10.0 MHz
#define PWM_20MHZ    5  //20.0 MHz

void InitPwm(void)
{
  HRPWM6_Config(PWM_1MHZ );   //1MHz, duty 50%
}

void PwmSet3(unsigned int Period)
{
 SetPwm6APeriod(PWM_1MHZ , Period);
}


#if _ENABLE_PWM6
void SetPwm6Period(unsigned int Frequency, unsigned int Period)
{
    EPwm6Regs.TBPRD = Frequency;
    EPwm6Regs.CMPA.half.CMPA = Frequency-(Frequency*(Period/100));
}

void SetPwm6APeriod(unsigned int Frequency, unsigned int Period)
{
    EPwm6Regs.TBPRD = Frequency;
    EPwm6Regs.CMPA.half.CMPA = Frequency-(Frequency*(Period/100));
}

void SetPwm6BPeriod(unsigned int Frequency, unsigned int Period)
{
    EPwm6Regs.TBPRD = Frequency;
    EPwm6Regs.CMPB = Frequency-(Frequency*(Period/100));
}

void HRPWM6_Config(unsigned int Freq)
{
   EPwm6Regs.TBPRD = period;                      // Set timer period
   EPwm6Regs.TBPHS.half.TBPHS = 0x0000;           // Phase is 0
   EPwm6Regs.TBCTR = 0x0000;                      // Clear counter

   // Setup TBCLK
   EPwm6Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up
   EPwm6Regs.TBCTL.bit.PHSEN = TB_DISABLE;        // Disable phase loading
   EPwm6Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;       // Clock ratio to SYSCLKOUT
   EPwm6Regs.TBCTL.bit.CLKDIV = TB_DIV1;

   EPwm6Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;    // Load registers every ZERO
   EPwm6Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
   EPwm6Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
   EPwm6Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;   


    :
}


main()함수
#include "system.h"
#include "serial.h"
//#include "timer.h"
#include "epwm.h"

void main(void)
{
 //DSP System Initialize
 SystemInit();

 Led1Init();
 Led1On();

 DebugInit(BAUD_57600);
 DebugPrint("ePWM Test Program\r\n");

 InitPwm();

while(1)
 {
  if(DebugIsByte())
  {
   switch(DebugGetByte())
   {
    case '+':
     DebugPrint("PWM=");
     U0_PutInt(pwm_period);
     DebugPrint("\r\n");
     SetPwm6Period(PWM_FREQ, pwm_period);
     pwm_period++;
     break;

    case '-':
     DebugPrint("PWM=");
     U0_PutInt(pwm_period);
     DebugPrint("\r\n");
     SetPwm6Period(PWM_FREQ, pwm_period);
     pwm_period--;
     break;
   }
  }
 }
}
반응형