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.

TMS320F28379D: Difficulty in using two ADC ISRs

Part Number: TMS320F28379D

Hi 

I am using ADCA as differential mode and ADCB as single ended and triggering all ADC channel with EPWM5 , I am able to receive the data from the channel that are written in ADC A ISR but unable to get into ADC B ISR.

Attaching the code below   . 

I really appreciate it if you take a look and see which part of the code I need to change

Thanks in Advanced .


#include "F28x_Project.h"
#include "math.h"
//float32 PI 3.14159265359;
extern void InitSysCtrl(void);
void Gpio_select(void);
void Setup_ePWM(void);
void ConfigureADC(void);
void SetupADCSoftware(void);
interrupt void adcAINT1_isr(void);
interrupt void adcBINT2_isr(void);

//variables

float32 PI= 3.14159265359;
float32 AdcaResult_Current=0;
float32 AdcaResult_Current1=0;
float32 sub_current=0;

float32 AC_input_vtg =0;
float32 AC_input_current =0;
float32 DC_output_vtg = 0;

float32 Actual_AC_input_vtg =0;
float32 Actual_AC_input_current =0;
float32 Actual_DC_output_vtg = 0;


Uint32 EPwm_time_counter= 0 ;

//variable used for implementing Low pass filter for offset cal
float32  Current_offset=0;
float32  Current_offset_Old=0;
float32  AdcaResult_Current_Old=0;
float32  f1 = 10;                    // low pass filter cutoff frequency
float32  Tsw = 0.000008;


//variable for stopping the loop of 10 sec and ON the EPWM for one time
int initialize=5;

//*********Protection for PFC converter*********//
float32 Actual_Current_result=0;
float32 Current_Limit_Positive=10;
float32 Current_Limit_Negative=-10;
float32 DC_link_Limit_Positive=100;
float32 DC_link_Limit_Negative=-1;
int inc=0;
Uint32 cheque_counter=0;
int m=0;                // check if code line passes to  main Closed loop code

int TBPRD =800;

// variable for Ramp Input Current to Boost Converter
int Normal_Operation_Counter=0;
Uint32 Soft_Start_Counter=0;
float32 Current_inc=0;

//Current PI variable
int   Duty_count=0;
float32 Current_Ref = 5; //RMS
float32 Ref_Current_1 = 0;
float32 Error_Current_new_1=0;
float32 Actual_Current_1=0;    //Actual Current
float32 Duty_new_1=0;
float32 K1_i=0.01012985999999999747744894;
float32 K2_i=0.009034739999999999437996223;
float32 Error_Current_old_1=0;
float32 Duty_old_1=0;

//Digital Low Pass Filter
float32 sub_current_new=0;
float32 sub_current_new_filter=0;
float32 sub_current_old_filter=0;
float32 sub_current_old=0;


void main(void)
{

    InitSysCtrl();
    DINT;
    Gpio_select();

    Setup_ePWM();
    EALLOW;
    ClkCfgRegs.PERCLKDIVSEL.bit.EPWMCLKDIV = 0;
    ConfigureADC();
    SetupADCSoftware();
    EDIS;

    InitPieCtrl();
    IER = 0x0000;
    IFR = 0x0000;
    InitPieVectTable();

    EALLOW;
    PieVectTable.ADCA1_INT=&adcAINT1_isr;   
    PieVectTable.ADCB1_INT=&adcBINT2_isr;


    IER |= M_INT1;
    IER |= M_INT2;
    PieCtrlRegs.PIEIER1.bit.INTx1 = 1;
    PieCtrlRegs.PIEIER1.bit.INTx2 = 1;
    EINT;
    ERTM;

    EDIS;

while(1)
{

}
}
void Gpio_select(void)
{
    EALLOW;

    GpioCtrlRegs.GPAMUX1.bit.GPIO8=1; // ePWM5A active used to take sample

    GpioCtrlRegs.GPAMUX1.bit.GPIO9=0; // Setting pin as GPIO Relay
    GpioCtrlRegs.GPADIR.bit.GPIO9=1;  //setting pin as output pin

    GpioCtrlRegs.GPAMUX1.bit.GPIO10=1; // ePWM6A active for fast leg top
    GpioCtrlRegs.GPAMUX1.bit.GPIO11=1; // ePWM6B active for fast leg bottom

    GpioCtrlRegs.GPAMUX1.bit.GPIO4=0; //Setting pin as gpio slow leg top
    GpioCtrlRegs.GPADIR.bit.GPIO4=1;  //setting pin as output pin

    GpioCtrlRegs.GPAMUX1.bit.GPIO5=0; //Setting pin as gpio slow leg bottom
    GpioCtrlRegs.GPADIR.bit.GPIO5=1;  //setting pin as output pin

    GpioCtrlRegs.GPBMUX1.bit.GPIO32=0; //Setting pin as gpio check
    GpioCtrlRegs.GPBDIR.bit.GPIO32=1;  //setting pin as output pin

    EDIS;
}

void ConfigureADC(void)
{
    EALLOW;

    AdcaRegs.ADCCTL2.bit.PRESCALE = 6; //Divide by 4 so 200MHz/4=50Mhz
    AdcSetMode(ADC_ADCA, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_DIFFERENTIAL);
    AdcSetMode(ADC_ADCB, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);
    AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1;//power up ADC
    EDIS;
    DELAY_US(1000);
}

void SetupADCSoftware(void)
{
    Uint16 acqps; // acquisition time
    if(ADC_RESOLUTION_12BIT == AdcaRegs.ADCCTL2.bit.RESOLUTION)
    {
        acqps = 14; //75ns
    }
    else
    {
        acqps =63;//320ns
    }

    EALLOW;

    AdcaRegs.ADCSOC0CTL.bit.CHSEL = 0; //AC current 1
    AdcaRegs.ADCSOC0CTL.bit.ACQPS = acqps;
    AdcaRegs.ADCSOC0CTL.bit.TRIGSEL = 13;//here we are specifically telling that epwm5A is start of conversion for ADCA2

    AdcaRegs.ADCSOC1CTL.bit.CHSEL = 1; // AC current 2
    AdcaRegs.ADCSOC1CTL.bit.ACQPS = acqps;
    AdcaRegs.ADCSOC1CTL.bit.TRIGSEL = 13;//here we are specifically telling that epwm5A is start of conversion for ADCA2

    AdcbRegs.ADCSOC2CTL.bit.CHSEL = 2; // AC Grid Voltage
    AdcbRegs.ADCSOC2CTL.bit.ACQPS = acqps;
    AdcbRegs.ADCSOC2CTL.bit.TRIGSEL = 13;//here we are specifically telling that epwm5A is start of conversion for ADCA2

    AdcbRegs.ADCSOC3CTL.bit.CHSEL = 3; // DC link Voltage
    AdcbRegs.ADCSOC3CTL.bit.ACQPS = acqps;
    AdcbRegs.ADCSOC3CTL.bit.TRIGSEL = 13;//here we are specifically telling that epwm5A is start of conversion for ADCA2

    AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 1; //end of SOC1 will set INT1(ADCA_ISR1) flag
    AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1;   //enable INT1 flag
    AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared

    AdcbRegs.ADCINTSEL1N2.bit.INT2SEL = 3; //end of SOC3 will set INT2(ADCB_ISR2) flag
    AdcbRegs.ADCINTSEL1N2.bit.INT2E = 1;   //enable INT2 flag
    AdcbRegs.ADCINTFLGCLR.bit.ADCINT2 = 1; //make sure INT2 flag is cleared

    EDIS;

}

void Setup_ePWM(void)
{

   //EPWM 5A for controlling ADC sampling
        EPwm5Regs.TBCTL.bit.CLKDIV=0;         //(Set clock division=00) divide by 1
        EPwm5Regs.TBCTL.bit.HSPCLKDIV=0;      //(Set high speed clock division=00)divide by 1
        EPwm5Regs.TBCTL.bit.CTRMODE=2;        //up-Down Mode
        EPwm5Regs.TBPRD=TBPRD;                //Period corresponding to 125kHz
        EPwm5Regs.CMPA.bit.CMPA =TBPRD*0.5;   //50% duty cycle
        EPwm5Regs.AQCTLA.all=0x0090;          //set high when TBCTR=CMPA and low when TBCTR=0

        EPwm5Regs.TBCTL.bit.SYNCOSEL=TB_CTR_ZERO;       //Giving a SYS out bit at TBCTL zero
        EPwm5Regs.TBPHS.bit.TBPHS=0;          //Set phase angle of ePWM4 is 0
        EPwm5Regs.TBCTL.bit.PHSEN=0;          //Set as a master

        EPwm5Regs.TBCTL.bit.PRDLD = TB_SHADOW;        //The period register (TBPRD) is loaded from its shadow register
        EPwm5Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;   //Shadow mode
        EPwm5Regs.CMPCTL.bit.LOADAMODE = CC_CTR_PRD;   //Load on CTR = Zero: Time-base counter equal to zero

        EPwm5Regs.ETSEL.bit.SOCAEN = 1;       //Epwm5A is used as start of conversion for ADC
        EPwm5Regs.ETSEL.bit.SOCASEL = 1;      //Enable event time based counter to zero
        EPwm5Regs.ETPS.bit.SOCAPRD = 3;       //at every third event it has to generate event
        EPwm5Regs.ETCLR.bit.SOCA = 1;         //Clear flag

        EPwm5Regs.ETSEL.bit.INTEN = 0;        //Enable ePWM Interrupt (EPWMx_INT) Generation
        EPwm5Regs.ETSEL.bit.INTSEL = 1;       //enable event time
        EPwm5Regs.ETPS.bit.INTPRD = 3;        //at every third event it has to generate event
        EPwm5Regs.ETCLR.bit.INT = 1;          //Clear flag

   //EPWM 6 for controlling 125KHz legs
        EPwm6Regs.TBCTL.bit.CLKDIV=0;           //(Set clock division=00) divide by 1
        EPwm6Regs.TBCTL.bit.HSPCLKDIV=0;        //(Set high speed clock division=00)divide by 1
        EPwm6Regs.TBCTL.bit.CTRMODE=2;          //up-Down Mode
        EPwm6Regs.TBPRD=TBPRD;                  //Period corresponding to 125kHz
        EPwm6Regs.CMPA.bit.CMPA =TBPRD*0.5;    //38% duty cycle
        EPwm6Regs.DBCTL.bit.POLSEL = 2;         //Active High Complementary inverted signal will be observed at ePWMB
        EPwm6Regs.DBCTL.bit.OUT_MODE = 3;       //fully enabled RED and FED
        EPwm6Regs.DBRED.all = 0;                //RED 200ns
        EPwm6Regs.DBFED.all = 0;                //FED 200ns
        EPwm6Regs.AQCTLA.all=0x0090;            //set high when TBCTR=CMPA and low when TBCTR=0

        EPwm6Regs.TBCTL.bit.SYNCOSEL=0;         //Giving a SYS in bit
        EPwm6Regs.TBCTL.bit.PHSDIR=1;
        EPwm6Regs.TBCTL.bit.PHSEN=1;           //Set as a slave
        EPwm6Regs.TBPHS.bit.TBPHS=2;            //Set phase angle of ePWM2 is 0

}


interrupt void adcAINT1_isr(void)
{


    AdcaResult_Current = AdcaResultRegs.ADCRESULT0; //AdcaResult_Current and AdcaResult_Current1 both values are almost same
    AdcaResult_Current1 = AdcaResultRegs.ADCRESULT1;

    AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;        //clear INT1 flag

    if(1 == AdcaRegs.ADCINTOVF.bit.ADCINT1)
              {
                  AdcaRegs.ADCINTOVFCLR.bit.ADCINT1 = 1;    //clear INT1 overflow flag
                  AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;    //clear INT1 flag
              }

    PieCtrlRegs.PIEACK.bit.ACK1 = PIEACK_GROUP1;


}
interrupt void adcBINT2_isr(void)

{
    m=1;
    GpioDataRegs.GPBSET.bit.GPIO32=1;

    AC_input_vtg =  AdcbResultRegs.ADCRESULT2;
   // AC_input_current = AdcaResultRegs.ADCRESULT1 - AdcaResultRegs.ADCRESULT2; //AdcaResult_Current and AdcaResult_Current1 both values are almost same
    DC_output_vtg =  AdcbResultRegs.ADCRESULT3;

   
    AdcbRegs.ADCINTFLGCLR.bit.ADCINT2 = 1;
       if(1 == AdcaRegs.ADCINTOVF.bit.ADCINT2)
          {
              AdcaRegs.ADCINTOVFCLR.bit.ADCINT2 = 1;    //clear INT1 overflow flag
              AdcaRegs.ADCINTFLGCLR.bit.ADCINT2 = 1;    //clear INT1 flag
          }
       PieCtrlRegs.PIEACK.bit.ACK2 = PIEACK_GROUP1;
       GpioDataRegs.GPBCLEAR.bit.GPIO32=1;
               //reset

}

  • Hi,

    I think this is your problem: 

    If that does not resolve your issue, here are a couple things to check. If you look at the registers while debugging, do you see any activity on result register 3 for ADCB? Do you see the flag going high for ADCB INT2?

    Best Regards,

    Ben Collier