[TMS320F28027] Piccolo 시리즈 PWM테스트
TI의 Piccolo 시리즈중 저렴한 TMS320F28027은 8채널의 ePWM(enhanced PWM Modules)이 있다.
GPIO0/EPWM1A
GPIO1/EPWM1B/COMP1OUT
GPIO2/EPWM2A
GPIO3/EPWM2B/COMP2OUT
GPIO4/EPWM3A
GPIO5/EPWM3B/ECAP1
GPIO6/EPWM4A/EPWMSYNCI/EPWMSYNCO
GPIO7/EPWM4B/SCIRXDA
테스트를 위해 EPWM1에 연결하여 간단히 LED램프제어 하는 예제를 테스트 해 보았다.
TMS320F28027 ePWM테스트 동영상
void SetPwm1Period(unsigned int Frequency, unsigned int Period)
{
EPwm1Regs.TBPRD = Frequency;
EPwm1Regs.CMPA.half.CMPA = Frequency-(Frequency*(Period/100.0));
}
void HRPWM1_Config(unsigned int period)
{
EPwm1Regs.TBPRD = period; // Set timer period
EPwm1Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm1Regs.TBCTR = 0x0000; // Clear counter
// Setup TBCLK
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Disable phase loading
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW; // Load registers every ZERO
EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
// Setup compare
EPwm1Regs.CMPA.half.CMPA = period / 2;
// Set actions
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; // Set PWM1A on Zero
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR;
EPwm1Regs.AQCTLB.bit.CAU = AQ_CLEAR; // Set PWM1A on Zero
EPwm1Regs.AQCTLB.bit.CAD = AQ_SET;
// Active Low PWMs - Setup Deadband
EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_LO;
EPwm1Regs.DBCTL.bit.IN_MODE = DBA_ALL;
EPwm1Regs.DBRED = 10;
EPwm1Regs.DBFED = 10;
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO0 = 0; // Enable pull-up on GPIO0 (EPWM1A)
GpioCtrlRegs.GPAPUD.bit.GPIO1 = 0; // Enable pull-up on GPIO1 (EPWM1B)
GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1; // Configure GPIO0 as EPWM1A
GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1; // Configure GPIO1 as EPWM1B
EDIS;
}
TI의 Piccolo 시리즈중 저렴한 TMS320F28027은 8채널의 ePWM(enhanced PWM Modules)이 있다.
GPIO0/EPWM1A
GPIO1/EPWM1B/COMP1OUT
GPIO2/EPWM2A
GPIO3/EPWM2B/COMP2OUT
GPIO4/EPWM3A
GPIO5/EPWM3B/ECAP1
GPIO6/EPWM4A/EPWMSYNCI/EPWMSYNCO
GPIO7/EPWM4B/SCIRXDA
테스트를 위해 EPWM1에 연결하여 간단히 LED램프제어 하는 예제를 테스트 해 보았다.
TMS320F28027 ePWM테스트 동영상
TMS320F28027 ePWM 제어 드라이버 코드
void SetPwm1Period(unsigned int Frequency, unsigned int Period)
{
EPwm1Regs.TBPRD = Frequency;
EPwm1Regs.CMPA.half.CMPA = Frequency-(Frequency*(Period/100.0));
}
void HRPWM1_Config(unsigned int period)
{
EPwm1Regs.TBPRD = period; // Set timer period
EPwm1Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm1Regs.TBCTR = 0x0000; // Clear counter
// Setup TBCLK
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Disable phase loading
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW; // Load registers every ZERO
EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
// Setup compare
EPwm1Regs.CMPA.half.CMPA = period / 2;
// Set actions
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; // Set PWM1A on Zero
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR;
EPwm1Regs.AQCTLB.bit.CAU = AQ_CLEAR; // Set PWM1A on Zero
EPwm1Regs.AQCTLB.bit.CAD = AQ_SET;
// Active Low PWMs - Setup Deadband
EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_LO;
EPwm1Regs.DBCTL.bit.IN_MODE = DBA_ALL;
EPwm1Regs.DBRED = 10;
EPwm1Regs.DBFED = 10;
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO0 = 0; // Enable pull-up on GPIO0 (EPWM1A)
GpioCtrlRegs.GPAPUD.bit.GPIO1 = 0; // Enable pull-up on GPIO1 (EPWM1B)
GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1; // Configure GPIO0 as EPWM1A
GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1; // Configure GPIO1 as EPWM1B
EDIS;
}
TMS320F28027 ePWM 예제 소스코드
void main(void)
{
unsigned int cnt = 0;
int flag = 0;
//DSP System Initialize
SystemInit();
DebugInit(BAUD_115200);
DebugPrint("LED Test\r\n");
//LED Initialize
Led1Init();
Led1On();
InitPwm();
SetPwm1Period(PWM_10KHZ, 50);
while(1)
{
if(flag)cnt--;
else cnt++;
if(cnt==100)flag = 1;
else if(cnt == 0)flag=0;
SetPwm1Period(PWM_100HZ, cnt);
Delay(cnt/2);
}
}
{
unsigned int cnt = 0;
int flag = 0;
//DSP System Initialize
SystemInit();
DebugInit(BAUD_115200);
DebugPrint("LED Test\r\n");
//LED Initialize
Led1Init();
Led1On();
InitPwm();
SetPwm1Period(PWM_10KHZ, 50);
while(1)
{
if(flag)cnt--;
else cnt++;
if(cnt==100)flag = 1;
else if(cnt == 0)flag=0;
SetPwm1Period(PWM_100HZ, cnt);
Delay(cnt/2);
}
}
반응형