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: adca1_isr is not working

Tool/software: Code Composer Studio

Hello,

here is my code I want to trigger ADC though EPWM2. ADC is triggering fine but adca1_isr is not working I don't know why here is my code.

//###########################################################################

// FILE: epwm_updown_aq_cpu01.c

// TITLE: Action Qualifier Module - Using up/down count.

//

//! \addtogroup cpu01_example_list

//! <h1> EPWM Action Qualifier (epwm_updown_aq)</h1>

//!

//! This example configures ePWM1, ePWM2, ePWM3 to produce an

//! waveform with independant modulation on EPWMxA and

//! EPWMxB.

//!

//! The compare values CMPA and CMPB are modified within the ePWM's ISR.

//!

//! The TB counter is in up/down count mode for this example.

//!

//! View the EPWM1A/B(PA0_GPIO0 & PA1_GPIO1), EPWM2A/B(PA2_GPIO2 & PA3_GPIO3)

//! and EPWM3A/B(PA4_GPIO4 & PA5_GPIO5) waveforms via an oscilloscope.

//

//###########################################################################

// $TI Release: F2837xD Support Library v130 $

// $Release Date: Mon Oct 20 10:15:06 CDT 2014 $

//###########################################################################

// Device Headerfile and Examples Include File

#include "F28x_Project.h"

#include "F28377D_ADC.h"

#include "F28377D_ePWM.h"

#include "F28377D_GpioSetup.h"

#include "math.h"

#include "string.h"

#include "Solar_F.h"

 

void SPWM(float,float,int,int,int);

interrupt void cpu_timer0_isr(void);

interrupt void adca1_isr(void);

#define SIN_NUM 199

#define pi 3.1415926

#define PERIOD 2000

#define HALF_PERIOD PERIOD*0.5

CNTL_PI_F VC,IL;

float mag,a,z,ua,num,d,k;

float sintheta,v1,i1,vo[3],ia[3];;

int16 VC1,IL1; 

void main(void)

{

// Step 1. Initialize System Control:

// This example function is found in the F2837xD_SysCtrl.c file.

InitSysCtrl();

InitEPwm2Gpio();

// Step 2. Initialize GPIO:

// This example function is found in the F2837xD_Gpio.c file and

// illustrates how to set the GPIO to it's default state.

EDIS;

/******Voltage PI Regulator*****/

CNTL_PI_F_init(&VC);

VC.Ki = (500);

VC.Kp = (5);

VC.Umax= 10;

VC.Umin= -10;

/******Current PI Regulator*****/

CNTL_PI_F_init(&IL);

IL.Ki = (6000);

IL.Kp = (0.005);

IL.Umax= 30;

IL.Umin= -30;

// Step 3. Clear all interrupts and initialize PIE vector table:

// Disable CPU interrupts

DINT;

// Initialize the PIE control registers to their default state.

// The default state is all PIE interrupts disabled and flags

InitPieCtrl();

// Disable CPU interrupts and clear all CPU interrupt flags:

IER = 0x0000;

IFR = 0x0000;

// Initialize the PIE vector table with pointers to the shell Interrupt

// Service Routines (ISR).

// This will populate the entire table, even if the interrupt

// is not used in this example. This is useful for debug purposes.

// The shell ISR routines are found in F2837xD_DefaultIsr.c.

// This function is found in F2837xD_PieVect.c.

InitPieVectTable();

EALLOW; // This is needed to write to EALLOW protected registers

PieVectTable.ADCA1_INT = &adca1_isr;

PieVectTable.TIMER0_INT = &cpu_timer0_isr;

EDIS; // This is needed to disable write to EALLOW protected registers

EALLOW;

CpuSysRegs.PCLKCR0.bit.TBCLKSYNC =0;

EDIS;

InitEPwm2Example();

ConfigureADC();

SetupADCEpwm();

EALLOW;

CpuSysRegs.PCLKCR0.bit.TBCLKSYNC =1;

EDIS;

IER |= M_INT3; // Enable CPU INT3 which is connected to EPWM1-3 INT EPWM4-6 INT:

//init Timer

InitCpuTimers();

ConfigCpuTimer(&CpuTimer0, 200, 20000);//

CpuTimer0Regs.TCR.all = 0x4000; //to start Timer 0. The bit TSS inside register TCR will do the job.

PieCtrlRegs.PIEIER1.bit.INTx7 = 1; //Timer0 interrupt is directly connected to group INT1, Bit7

PieCtrlRegs.PIEIER1.bit.INTx6 = 1; // for ADC

IER |= M_INT1; // Enable CPU INT1 which is connected toTIMER,ADCIN

// Enable global Interrupts and higher priority real-time debug events:

EINT; // Enable Global interrupt INTM

ERTM; // Enable Global realtime interrupt DBGM

// Step 6. IDLE loop. Just sit and loop forever (optional):

}

interrupt void adca1_isr(void)

{ if(k>999)

k=0;

else

k++;

//Samlped voltage and current

i1=((float)(AdcaResultRegs.ADCRESULT1)-2210)*0.01;

v1=((float)(AdcaResultRegs.ADCRESULT3)-2192)*0.0364;

ia[0]=ia[1];

ia[1]=ia[2];

ia[2]=(ia[0]+ia[1]+i1)/3;

 

vo[0]=vo[1];

vo[1]=vo[2];

vo[2]=(vo[0]+vo[1]+v1)/3;

 

/*****voltage PI Regulator*****/

VC.Ref=a;

VC.Fbk=vo[2];

CNTL_PI_F_FUNC(&VC);

/*****Current PI Regulator*****/

IL.Ref=VC.Out;

IL.Fbk= ia[2];

CNTL_PI_F_FUNC(&IL);

d=IL.Out;

SPWM(d,100,0,0,0);

AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;

PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

}

void InitEPwm2Example()

{

//

// Setup TBCLK

//

EPwm2Regs.TBPRD = PERIOD ; // Set timer period

EPwm2Regs.TBPHS.bit.TBPHS = 0x0000; // Phase is 0

EPwm2Regs.TBCTR = 0x0000; // Clear counter

//

// Setup counter mode

//

EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;

EPwm2Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Disable phase loading

EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT

EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;

EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO; // Sync output is equal to zero

//

// Setup shadowing

//

EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;

EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;

EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO; // Load on Zero

EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;

//

// Setup compare

//

EPwm2Regs.CMPA.bit.CMPA = 0; //

//

// Set actions

//

EPwm2Regs.AQCTLA.bit.CAD = AQ_SET; // EPW1A

EPwm2Regs.AQCTLA.bit.CAU = AQ_CLEAR; // EPW1A

EPwm2Regs.AQCTLB.bit.CAD = AQ_CLEAR; // EPW1B

EPwm2Regs.AQCTLB.bit.CAU = AQ_SET; // EPW1B

//

// Interrupt where we will change the Compare Values

//

EPwm2Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO; // Select INT on Zero event INTSEL= interrupt selection

EPwm2Regs.ETSEL.bit.INTEN = ET_DISABLE; // Enable INT

EPwm2Regs.ETPS.bit.INTPRD = ET_1ST; // Generate INT on 1st event

//Start Conversion of ADC

EPwm2Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group

EPwm2Regs.ETSEL.bit.SOCASEL = 1;

EPwm2Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event

}

void ConfigureADC(void)

{

EALLOW;

//

//write configurations

//

AdcaRegs.ADCCTL2.bit.PRESCALE = 2; //set ADCCLK divider to /2

AdcSetMode(ADC_ADCA, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);

//

//Set pulse positions to late

//

  AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1;

//

//power up the ADC

//

AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1;

//

//delay for 1ms to allow ADC time to power up

//

DELAY_US(1000);

EDIS;

}

void SetupADCEpwm(void)

{

//

//Select the channels to convert and end of conversion flag

//

EALLOW;

AdcaRegs.ADCSOC1CTL.bit.CHSEL = 1; //SOC0 will convert pin ADCINA0 and ADCRESULT0

AdcaRegs.ADCSOC1CTL.bit.ACQPS = 28; //sample window is XX SYSCLK cycles

AdcaRegs.ADCSOC1CTL.bit.TRIGSEL = 7; //trigger on ePWM1 SOCA/C

 

AdcaRegs.ADCSOC3CTL.bit.CHSEL = 3; //SOC3 will convert pin ADCINA3 and A1 ADCRESULT3

AdcaRegs.ADCSOC3CTL.bit.ACQPS = 28; //sample window is XX SYSCLK cycles

AdcaRegs.ADCSOC3CTL.bit.TRIGSEL = 7; //trigger on ePWM1 SOCA/C

//

//Intrupt

AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 4; //end of SOC4 will set INT1 flag

AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1; //enable INT1 flag

AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared

 

EDIS;

}

interrupt void cpu_timer0_isr(void)

{

if(num<1000)

{num++;}

else

{num=0;}

z=2*3.14*num/1000;

a=30*sinf(z);

 

PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

}

void SPWM(float Ea,float DC,int ISA_DIRECTION,int ISB_DIRECTION,int ISC_DIRECTION )

{

//float KMag;

float CMP;

//KMag=PERIOD/DC;

//ePWMA

CMP=HALF_PERIOD+Ea*0.6;

EPwm2Regs.CMPA.bit.CMPA =(Uint16)CMP;

}

  • I'll have someone check your ADC ISR issue.

  • Hi Shah,

    Can you describe what you expect to happen, and what actually happens in your code?

    Usually the sequence for triggering the ISR would be:

    • ePWM generates SOC trigger
    • One or more ADC SOCs are configured to accept ePWM trigger
    • One ADCINT flag is set to trigger based on the end of one of the ADC SOCs
    • PIE is configured to enter ISR based on ADCINT flag

    Based on your description, if you are seeing ADC conversion results updating, probably the first two steps are functioning correctly.  You should therefore focus debug on the last two steps:

    • Is the ADCINT flag being set?
    • If the ADCINT flag is set, is the desired PIE INT enabled in the PIE
    • If the desired PIE INT is enabled, is it being set?
    • If the PIE INT is being set, is that INT line enabled in the CPU?
    • Is the correct ISR registered in the PIE vector table?
    • Is the ISR being entered?
    • If the ISR is only being entered once, are all the flags above being acknowledged correctly?
  • yes i have found the issue. CPU TIMER0 interrupt  as highest priority than ADC ISR, so it is always stopping ADC ISR  . then i used CPU TIMER1 ISR which has lower priority than ADC ISR. now my code is working fine