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.

TMS320F280025C: ADC INTERRUPT IS NOT TRIGGERED

Part Number: TMS320F280025C

Hello everyone,

     I want to read adc voltage in ISR but somehow my isrCount is not increment.

I am using ADCA3/C5  

ADC is triggered using epwm1 SOCA...

Note: I run the demo code "adc_ex2_epwm_tempsensor". this code is working fine also  isrCount is incremented.

I am attaching a code for your ref. Please check.

//
// Included Files
//
#include "f28x_project.h"

//
// Defines
//
#define RESULTS_BUFFER_SIZE 256

//
// Globals
//
uint16_t sensorSample = 0;
uint16_t isrCount = 0;
int16_t sensorTemp = 0;

//
// Function Prototypes
//
void initADC(void);
void initEPWM(void);
void initADCSOC(void);
__interrupt void AdcA3ISR(void);

//
// Main
//
void main(void)
{
//
// Initialize device clock and peripherals
//
InitSysCtrl();

//
// Initialize GPIO
//
InitGpio();

//
// Disable CPU interrupts
//
DINT;

//
// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
//
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).
//
InitPieVectTable();

//
// Map ISR functions
//
EALLOW;
PieVectTable.ADCA3_INT = &AdcA3ISR; // Function for Adca interrupt 1
EDIS;

//
// Configure the ADC and power it up
//
initADC();

//
// Configure the ePWM
//
initEPWM();

//
// Setup the ADC for ePWM triggered conversions on channel 1
//
initADCSOC();


EALLOW;

//
// Enable PIE interrupt
//
PieCtrlRegs.PIEIER10.bit.INTx3 = 1;

//
// Sync ePWM
//
CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 1;

//
// Enable global Interrupts and higher priority real-time debug events:
//
IER |= M_INT10; // Enable group 10 interrupts

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

//InitTempSensor(3.3f);

//
// Start ePWM
//
EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOCA
EPwm1Regs.TBCTL.bit.CTRMODE = 0; // Unfreeze, and enter up count mode

//
// Wait while ePWM causes ADC conversions, which then cause interrupts,
// which fill the results buffer, eventually setting the bufferFull
// flag
//
while(1)
{
}
}

//
// initADC - Function to configure and power up Adca.
//
void initADC(void)
{
//
// Setup VREF as internal
//
SetVREF(ADC_ADCA, ADC_INTERNAL, ADC_VREF3P3);

EALLOW;

//
// Set AdcaLK divider to /4
//
AdcaRegs.ADCCTL2.bit.PRESCALE = 6;

//
// Set pulse positions to late EOC
//
AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1;

//
// Power up the ADC and then delay for 1 ms
//
AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1;
EDIS;

DELAY_US(1000);
}

//
// initEPWM - Function to configure ePWM1 to generate the SOC.
//
void initEPWM(void)
{
EALLOW;

EPwm1Regs.ETSEL.bit.SOCAEN = 0; // Disable SOC on A group
EPwm1Regs.ETSEL.bit.SOCASEL = 4; // Select SOC on up-count
EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event

EPwm1Regs.CMPA.bit.CMPA = 0x0800; // Set compare A value to 2048 counts
EPwm1Regs.TBPRD = 0x1000; // Set period to 4096 counts

EPwm1Regs.TBCTL.bit.CTRMODE = 3; // Freeze counter

EDIS;
}

//
// initADCSOC - Function to configure ADCA's SOC0 to be triggered by ePWM1.
//
void initADCSOC(void)
{
//
// Select the channels to convert and the end of conversion flag
//
EALLOW;

AdcaRegs.ADCSOC0CTL.bit.CHSEL = 0x03; // SOC0 will convert pin A3

AdcaRegs.ADCSOC0CTL.bit.ACQPS = 45; // Sample window is 10 SYSCLK cycles
AdcaRegs.ADCSOC0CTL.bit.TRIGSEL = 5; // Trigger on ePWM1 SOCA

AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 0; // End of SOC0 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 AdcA3ISR(void)
{

isrCount++;
//
// Add the latest result to the buffer
// ADCRESULT0 is the result register of SOC0
sensorSample = AdcaResultRegs.ADCRESULT0;

//
// Clear the interrupt flag
//
AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;

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

//
// Acknowledge the interrupt
//
PieCtrlRegs.PIEACK.all = PIEACK_GROUP10;
}

  • Hello Sayali,

    //
    // Map ISR functions
    //
    EALLOW;
    PieVectTable.ADCA3_INT = &AdcA3ISR; // Function for Adca interrupt 1
    EDIS;

    You have enabled ADCA Interrupt 1, but the ISR is mapped to ADCA interrupt 3.

    This should be:

    PieVectTable.ADCA1_INT = &AdcA1ISR;

    And you should rename the ISR to ADCA1 ISR. The interrupt is not the ADC input channel; in this case the two are mixed up.

    Ibukun

  • Hello 

    As I mentioned in the very first line that I am using ADCA3 in this code. In the comment section 1 is mistakenly written instead of 3.

  • My point above is that you have mixed up the interrupt number with the ADC channel. ADCA3 is a channel (input pin). The channel is configured in ADCSOCxCTL.CHSEL only. There are four interrupts per ADC (INT1-4), and these are the ones you map to the PIE vector table. In this case, ADCA3_INT actually means: ADC-A module, interrupt signal number 3 (out of 4).

    The comment is actually correct as per your intention.

    Ibukun

  • Hi Ibukun,

    Still I am little bit confused about interrupt. Can you please write code for me if I want to generate interrupt  on (signal name is :A3, pin no 12(80 qfp package).

  • Hi Sayali,

    I mentioned the code fix in my first post:

    • The entry in PieVectTable needs to be ADCA1_INT
    • The ISR needs to be renamed to ADCA1ISR

    That should fix your issue.

    Just understand that the pin number (A3) and the interrupt number (INT1) are not the same thing and are not related to each other. Please take a look at the ADC chapter in the device TRM for more explanation on how ADC interrupts work if this is not clear.

    Ibukun