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.

CCS/TMS320F28379D: F28379d servo development board PWM and sdfm synchronous current sampling problem

Part Number: TMS320F28379D


Tool/software: Code Composer Studio

你好!

1、I use the f23379d servo code( path:C:\ti\controlSUITE\development_kits\TMDSIDDK_v2.0\IDDK_PM_Servo_F2837x_v2_00_00_00),The PWM output is high level output(configure:(*ePWM[chanel]).DBCTL.bit.POLSEL =  DB_ACTV_HIC;),Use sd_current_sense only current mode,the motor can run normally and the current sampling is correct. if the motor is not connected to the motor, the current sample is 0;

2、As a new board, I need to change the output PWM logic to active lowconfigure:(*ePWM[chanel]).DBCTL.bit.POLSEL =  DB_ACTV_LOC;),The use of sd_current_sense current mode, when the new board is not connected with the motor, can be taken to the current, but the current sampling is not 0, In simulation mode  ,  I   find the current large jump phenomenon, I judge that the SDFM current sampling does not synchronize with the PWM. How can the changes be synchronized?  Can you help me to solve, thank you! 

3、The following code is PWM high level output, SDFM current sampling and PWM is synchronous, verify good; now I want to change to PWM low level, and SDFM current sampling and PWM synchronization, where needs to change?

 

The code reads as follows::

(notes:The original is db_actv_hic high level output valid, now I want to changed to db_actv_loc level output valid,I find Current sampling is incorrect。)  

void HOS_PWM_Int()
{
volatile int16 temp;

// Initialize PWM module  
EALLOW;
CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 0; // 

HOS_PWMChanelUpDwnCntCnf(1,INV_PWM_TICKS,200);
HOS_PWMChanelUpDwnCntCnf(2,INV_PWM_TICKS,200);
HOS_PWMChanelUpDwnCntCnf(3,INV_PWM_TICKS,200);


HOS_PWMChanelUpCntCnf(4,SDFM_TICKS); //Sigma 
EPwm4Regs.CMPA.bit.CMPA=EPwm4Regs.TBPRD>>1; 


// ********************************************************************
//PWM 11 for syncing up the SD filter windows with motor control PWMs
// ********************************************************************
//==================SD =======================================
HOS_PWMChanelUpCntCnf(11,INV_PWM_TICKS);  

// configure 2 and 3 as slaves
/*================== =======================================*/
EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN; 
EPwm2Regs.TBCTL.bit.PHSEN = TB_ENABLE; // 
EPwm2Regs.TBPHS.bit.TBPHS = 2; // 
EPwm2Regs.TBCTL.bit.PHSDIR = TB_UP; // 

EPwm3Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN;
EPwm3Regs.TBCTL.bit.PHSEN = TB_ENABLE; // 
EPwm3Regs.TBPHS.bit.TBPHS = 2; // 
EPwm3Regs.TBCTL.bit.PHSDIR = TB_UP; // 

//==================Sigma =======================================

EPwm4Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN; //Sigma 
//==================EPWM11 SD =======================================
EPwm11Regs.TBCTL.bit.PHSEN = TB_ENABLE; //SD
EPwm11Regs.TBPHS.bit.TBPHS = 2;
EPwm11Regs.TBCTL.bit.PHSDIR = TB_UP;
EPwm11Regs.CMPC = EPwm11Regs.TBPRD - SDFM_TICKS*(OSR_RATE+1)*3/2;/ 
EPwm11Regs.CMPA.bit.CMPA = (SDFM_TICKS*(OSR_RATE+1)*3/2) + 500; // 500 is arbitrary

EPwm11Regs.CMPD = 0;
// ***********************************
// Set up GPIOs for PWM functions
// **************************************
InitEPwm1Gpio();/ 
InitEPwm2Gpio();// 
InitEPwm3Gpio(); 


InitEPwm4Gpio();//clk for Sigma Delta  

EDIS;

EALLOW;

EPwm11Regs.ETSEL.bit.INTSEL= ET_CTRU_CMPA ;  
EPwm11Regs.ETSEL.bit.INTEN = 1;// Enable INT EPWMxINTn 
EPwm11Regs.ETPS.bit.INTPRD = ET_1ST;

EDIS;

PhaseCurrentHwInit(); / 
BusVoltageDetectInit();/ 
Init_Val();
 
// TODO Feedbacks OFFSET Calibration Routine
EALLOW;
CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 1;
EDIS;
offset_SDFM1 = 0;
offset_SDFM2 = 0;

for (OffsetCalCounter=0; OffsetCalCounter<20000; )
{
if(EPwm11Regs.ETFLG.bit.INT==1)// 
{
if(OffsetCalCounter>1000)
{
offset_SDFM1 = K1*offset_SDFM1 + K2*(temp=SDFM1_READ_FILTER1_DATA_16BIT)*SD_PU_SCALE_FACTOR;
offset_SDFM2 = K1*offset_SDFM2 + K2*(temp=SDFM1_READ_FILTER2_DATA_16BIT)*SD_PU_SCALE_FACTOR;

}
EPwm11Regs.ETCLR.bit.INT=1; 
OffsetCalCounter++;
}
}

//TODO ISR Mapping
// ****************************************************************************
// ****************************************************************************
EALLOW;
//PWM11 INT is used to trigger Motor Control ISR
EPwm11Regs.ETSEL.bit.INTSEL = ET_CTRU_CMPA; 

EPwm11Regs.ETSEL.bit.INTEN = 1; // Enable INT
EPwm11Regs.ETPS.bit.INTPRD = ET_1ST; // Generate INT on every event

PieVectTable.EPWM11_INT = &MotorControlISR;
PieCtrlRegs.PIEIER3.bit.INTx11 = 1; // Enable PWM11INT in PIE group 3

EPwm11Regs.ETCLR.bit.INT=1;

IER = 0x185;

EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
EDIS;

}
//========================================================================

//TODO
void HOS_PWMChanelUpDwnCntCnf(uint16 chanel, uint16 period, uint16 dead_band)
{
EALLOW;

// Time Base SubModule Registers
(*ePWM[chanel]).TBCTL.bit.PRDLD = TB_IMMEDIATE; // set Immediate load
(*ePWM[chanel]).TBPRD = period / 2; // PWM frequency = 1 / period
(*ePWM[chanel]).TBPHS.bit.TBPHS = 0; //set time base phase high
(*ePWM[chanel]).TBCTR = 0; //Time Base Counter
(*ePWM[chanel]).TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;
(*ePWM[chanel]).TBCTL.bit.HSPCLKDIV = TB_DIV1;
(*ePWM[chanel]).TBCTL.bit.CLKDIV = TB_DIV1;

(*ePWM[chanel]).TBCTL.bit.PHSEN = TB_DISABLE;
(*ePWM[chanel]).TBCTL.bit.SYNCOSEL = TB_CTR_ZERO; //sync "down-stream"

// Counter Compare Submodule Registers
(*ePWM[chanel]).CMPA.bit.CMPA = 0; // set duty 0% initially
(*ePWM[chanel]).CMPCTL.bit.SHDWAMODE = CC_SHADOW;
(*ePWM[chanel]).CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;

// Action Qualifier SubModule Registers
(*ePWM[chanel]).AQCTLA.bit.CAU = AQ_CLEAR; 
(*ePWM[chanel]).AQCTLA.bit.CAD = AQ_SET;  

// Active high complementary PWMs - Set up the deadband  
(*ePWM[chanel]).DBCTL.bit.IN_MODE = DBA_ALL;  
(*ePWM[chanel]).DBCTL.bit.OUT_MODE = DB_FULL_ENABLE; // 
(*ePWM[chanel]).DBCTL.bit.POLSEL =  DB_ACTV_HIC; 
(*ePWM[chanel]).DBRED.all = dead_band; // 
(*ePWM[chanel]).DBFED.all = dead_band; //  
EDIS;
}
//TODO
void HOS_PWMChanelUpCntCnf(uint16 chanel, uint16 period)
{
EALLOW;
// Time Base SubModule Registers
(*ePWM[chanel]).TBCTL.bit.PRDLD = TB_IMMEDIATE; // set Immediate load
(*ePWM[chanel]).TBPRD = period-1; // PWM frequency = 1 / period  
(*ePWM[chanel]).TBPHS.bit.TBPHS = 0;
(*ePWM[chanel]).TBCTR = 0;
(*ePWM[chanel]).TBCTL.bit.CTRMODE = TB_COUNT_UP;
(*ePWM[chanel]).TBCTL.bit.HSPCLKDIV = TB_DIV1;
(*ePWM[chanel]).TBCTL.bit.CLKDIV = TB_DIV1;

(*ePWM[chanel]).TBCTL.bit.PHSEN = TB_DISABLE; // 
(*ePWM[chanel]).TBCTL.bit.SYNCOSEL = TB_CTR_ZERO; // sync "down-stream"  

// Counter Compare Submodule Registers  
(*ePWM[chanel]).CMPA.bit.CMPA = 0; // set duty 0% initially  0
(*ePWM[chanel]).CMPCTL.bit.SHDWAMODE = CC_SHADOW; // 
(*ePWM[chanel]).CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;

// Action Qualifier SubModule Registers
(*ePWM[chanel]).AQCTLA.bit.CAU = AQ_CLEAR; // 
(*ePWM[chanel]).AQCTLA.bit.ZRO = AQ_SET; // 

// Active high complementary PWMs - Set up the deadband  
(*ePWM[chanel]).DBCTL.bit.IN_MODE = DBA_ALL;
(*ePWM[chanel]).DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
(*ePWM[chanel]).DBCTL.bit.POLSEL =  DB_ACTV_HIC;  
(*ePWM[chanel]).DBRED.all = 0; // 
(*ePWM[chanel]).DBFED.all = 0; // 
EDIS;
}


//TODO Motor Control ISR
interrupt void MotorControlISR(void)
{
GPIO_WritePin(59 , 0);
EINT;

MotorControl_ISR();

//dx DLOG_4CH_F_FUNC(&dlog_4ch1);
EPwm11Regs.ETCLR.bit.INT = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
GPIO_WritePin(59 , 1);

}// MainISR Ends Here