Hi,
I am working on TMS320f2833(delfino experimenter kit). i am trying to drive 6 ePWMs. i was able drive all PWMs. but whn i started adding my application code it is not responding as expected. Below is my code -
/*************************************/
typedef struct
{
volatile struct EPWM_REGS *EPwmRegHandle;
Uint16 EPwm_CMPA_Direction;
Uint16 EPwm_CMPB_Direction;
Uint16 EPwmTimerIntCount;
/*added by PS on 27022016*/
Uint16 uhwDutyCycle_PWM_A;
Uint16 uhwDutyCycle_PWM_B;
Uint16 uhwDutyCycle_PWMA2;
Uint16 uheLUTIndex;
}EPWM_INFO;
// Prototype statements for functions found within this file.
void InitEPwm1Example(void);
void InitEPwm2Example(void);
void InitEPwm3Example(void);
__interrupt void epwm1_isr(void);
__interrupt void epwm2_isr(void);
__interrupt void epwm3_isr(void);
void update_compare(EPWM_INFO*, Uint16);
// Global variables used in this example
EPWM_INFO epwm1_info;
EPWM_INFO epwm2_info;
EPWM_INFO epwm3_info;
// Configure the period for each timer
#define EPWM1_TIMER_TBPRD 497 // Period register
#define EPWM2_TIMER_TBPRD 497 // Period register
#define EPWM3_TIMER_TBPRD 497 //10 usec ->753 // Period register
#define NO_DUTYCYCLE_COUNT 497 /*same as period - TBPRD*/
#define _100_PERCENT_DUTYCYCLE_COUNT 0 /*ZERO means high*/
void main()
{
/*init PWM and ADC*/
fnConfigPWMModule();
....
....
while(1)
{
fnReadADCData();
vstPSApp.hwVa = vunADCData.stAdcData.uhwADC_A_0 - vunADCData.stAdcData.uhwADC_B_0;
vstPSApp.hwVb = vunADCData.stAdcData.uhwADC_A_1 - vunADCData.stAdcData.uhwADC_B_1;
vstPSApp.hwVc = vunADCData.stAdcData.uhwADC_A_2 - vunADCData.stAdcData.uhwADC_B_2;
vstPSApp.hwIa = vunADCData.stAdcData.uhwADC_A_3 - vunADCData.stAdcData.uhwADC_B_3;
vstPSApp.hwIb = vunADCData.stAdcData.uhwADC_A_4 - vunADCData.stAdcData.uhwADC_B_4;
vstPSApp.hwIc = vunADCData.stAdcData.uhwADC_A_5 - vunADCData.stAdcData.uhwADC_B_5;
vstPSApp.hwDCVtg = vunADCData.stAdcData.uhwADC_A_6 - vunADCData.stAdcData.uhwADC_B_6;
vstPSApp.hwDCCrnt = vunADCData.stAdcData.uhwADC_A_7 - vunADCData.stAdcData.uhwADC_B_7;
vstPSApp.hwVab = vstPSApp.hwVa - vstPSApp.hwVb;
vstPSApp.hwVbc = vstPSApp.hwVb - vstPSApp.hwVc;
vstPSApp.hwVca = vstPSApp.hwVc - vstPSApp.hwVa;
if (vstPSApp.hwVab > vstPSApp.hwVbc && vstPSApp.hwVab > vstPSApp.hwVca)
{
vstPSApp.ubySectorABFlag = SET;
}
else
{
vstPSApp.ubySectorABFlag = RESET;
}
if (vstPSApp.hwVab < vstPSApp.hwVbc && vstPSApp.hwVab < vstPSApp.hwVca)
{
vstPSApp.ubySectorBAFlag = SET;
}
else
{
vstPSApp.ubySectorBAFlag = RESET;
}
/*****P1A and P1B*****/
if(vstPSApp.ubySectorABFlag == SET)
{
uhwDutyCycle1 = (Uint16)(vstPSApp.hwVab/COVERSION_FACTOR_ADC_TO_PWM);
/*epwm1_info.uhwDutyCycle_PWMA2 = (Uint16)(vstPSApp.hwVab/COVERSION_FACTOR_ADC_TO_PWM);*/
epwm1_info.uhwDutyCycle_PWM_B = 0/*_100_PERCENT_DUTYCYCLE_COUNT*/;
}
else if(vstPSApp.ubySectorBAFlag == SET)
{
epwm1_info.uhwDutyCycle_PWM_A = 250/*_100_PERCENT_DUTYCYCLE_COUNT*/;
uhwDutyCycle1 = 250;
epwm1_info.uhwDutyCycle_PWM_B = 0/*(Uint16)((vstPSApp.hwVab * MAKE_IT_POSITIVE)/COVERSION_FACTOR_ADC_TO_PWM)*/;
}
else
{
epwm1_info.uhwDutyCycle_PWM_A = NO_DUTYCYCLE_COUNT;
epwm1_info.uhwDutyCycle_PWM_B = NO_DUTYCYCLE_COUNT;
}
......
......
.....
.....
}
}
void fnConfigPWMModule(void)
{
// For this case just init GPIO pins for ePWM1, ePWM2, ePWM3
// These functions are in the DSP2833x_EPwm.c file
InitEPwm1Gpio();
InitEPwm2Gpio();
InitEPwm3Gpio();
// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.EPWM1_INT = &epwm1_isr;
PieVectTable.EPWM2_INT = &epwm2_isr;
PieVectTable.EPWM3_INT = &epwm3_isr;
EDIS; // This is needed to disable write to EALLOW protected registers
// For this example, only initialize the ePWM
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
EDIS;
InitEPwm1Example();
InitEPwm2Example();
InitEPwm3Example();
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
EDIS;
// Enable CPU INT3 which is connected to EPWM1-3 INT:
IER |= M_INT3;
// Enable EPWM INTn in the PIE: Group 3 interrupt 1-3
PieCtrlRegs.PIEIER3.bit.INTx1 = 1;
PieCtrlRegs.PIEIER3.bit.INTx2 = 1;
PieCtrlRegs.PIEIER3.bit.INTx3 = 1;
}
__interrupt void epwm1_isr(void)
{
// Update the CMPA and CMPB values
update_compare(&epwm1_info,ONE);
// Clear INT flag for this timer
EPwm1Regs.ETCLR.bit.INT = 1;
//EPwm1Regs.CMPA.half.CMPA = 300/*uhwDutyCycle1*/;
//EPwm1Regs.CMPB = epwm1_info.uhwDutyCycle_PWM_B;
// Acknowledge this interrupt to receive more interrupts from group 3
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
__interrupt void epwm2_isr(void)
{
// Update the CMPA and CMPB values
update_compare(&epwm2_info,TWO);
// Clear INT flag for this timer
EPwm2Regs.ETCLR.bit.INT = 1;
// Acknowledge this interrupt to receive more interrupts from group 3
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
__interrupt void epwm3_isr(void)
{
// Update the CMPA and CMPB values
update_compare(&epwm3_info,THREE);
// 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;
}
void update_compare(EPWM_INFO *epwm_info, Uint16 uhwPWMEvent/*uhwDutyCycleForPWM_A*/)
{
#if 1
epwm_info->EPwmRegHandle->CMPB = epwm_info->uhwDutyCycle_PWM_B; // Set Compare B value
switch(uhwPWMEvent)
{
case ONE:
epwm_info->EPwmRegHandle->CMPA.half.CMPA = uhwDutyCycle1;
break;
case TWO:
epwm_info->EPwmRegHandle->CMPA.half.CMPA = uhwDutyCycle1;
break;
case THREE:
epwm_info->EPwmRegHandle->CMPA.half.CMPA = uhwDutyCycle1;
break;
default :
epwm_info->EPwmRegHandle->CMPA.half.CMPA = uhwDutyCycle1;
break;
}
#endif
#if 0
epwm_info->EPwmRegHandle->CMPA.half.CMPA = uhwDutyCycle1/*epwm_info->uhwDutyCycle_PWMA2/*epwm_info->uhwDutyCycle_PWM_A*/; // Set compare A value
epwm_info->EPwmRegHandle->CMPB = epwm_info->uhwDutyCycle_PWM_B; // Set Compare B value
#endif
#if 0
// Every 10'th interrupt, change the CMPA/CMPB values
if(epwm_info->EPwmTimerIntCount == 65000)
{
epwm_info->EPwmRegHandle->CMPA.half.CMPA = 300 /*epwm_info->uhwDutyCycle_PWM_A rguhwDutyCycleLUT_A[epwm_info->uheLUTIndex]*/; // Set compare A value
epwm_info->EPwmRegHandle->CMPB = epwm_info->uhwDutyCycle_PWM_B/*rguhwDutyCycleLUT_B[epwm_info->uheLUTIndex]*/; // Set Compare B value
epwm_info->EPwmTimerIntCount = 0;
if(epwm_info->uheLUTIndex >= (MAX_ENTRIES-1))
{
epwm_info->uheLUTIndex = 0;
}
else
{
epwm_info->uheLUTIndex++;
}
}
else
{
epwm_info->EPwmTimerIntCount++;
}
#endif
return;
}
void InitEPwm1Example()
{
// Initialization Time
// = = = = = = = = = = = = = = = = = = = = = = = =
EPwm1Regs.TBPRD = EPWM1_TIMER_TBPRD; // Period = 2´600 TBCLK counts
EPwm1Regs.CMPA.half.CMPA = NO_DUTYCYCLE_COUNT; // Compare A PWM off
EPwm1Regs.CMPB = NO_DUTYCYCLE_COUNT; // Compare B PWM off
EPwm1Regs.TBPHS.half.TBPHS = 0; // Set Phase register to zero
EPwm1Regs.TBCTR = 0; // clear TB counter
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Symmetric
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Phase loading disabled
EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // TBCLK = SYSCLKOUT
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO; // load on CTR = Zero
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO; // load on CTR = Zero
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET;
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR;
EPwm1Regs.AQCTLB.bit.CBU = AQ_SET;
EPwm1Regs.AQCTLB.bit.CBD = AQ_CLEAR;
// Interrupt where we will change the Compare Values
EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO; // Select INT on Zero event
EPwm1Regs.ETSEL.bit.INTEN = 1; // Enable INT
EPwm1Regs.ETPS.bit.INTPRD = ET_1ST; // 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
epwm1_info.EPwm_CMPA_Direction = EPWM_CMP_UP; // Start by increasing CMPA &
epwm1_info.EPwm_CMPB_Direction = EPWM_CMP_DOWN; // decreasing CMPB
epwm1_info.EPwmTimerIntCount = 0; // Zero the interrupt counter
epwm1_info.EPwmRegHandle = &EPwm1Regs; // Set the pointer to the ePWM module
}
/**************************************/
basically i want read ADC input and drive PWM. but when i enable orange colour portion PWM doesnt toggle but where as if i enable green portion it works fine. i am not able to get what is mistake i m doing here. both cases ISR is getting invoked. but in case of ORANGE coloured portion PWM - A is always high evn is CMPA values are changing.....
please can anybody help?..
thanks
Pratik