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.

ADC interrupt never occurs

I  am having some trouble getting the ADC interrupt to occur. I am using the launch pad with CCSv5.4.

When I run the program the handler for the ADC never occurs; the while loop continuously runs. I think I have called all the interrupt enable functions I need and set the interrupt setting correctly. Does anyone see the issue?

This is my addition to the startup file (startup_ccs.c):

extern void IntADC1Handler(void);

.

IntADC1Handler,                      // ADC Sequence 0

This is my code:

#include <stdint.h>
#include <stdbool.h>
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/pwm.h"
#include "driverlib/debug.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/adc.h"
#include "inc/hw_gpio.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_pwm.h"
#include "inc/hw_types.h"

void IntADC1Handler(void);

uint32_t testValues[8] = {0,0,0,0,0,0,0,0};
int test = 0;


#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif

int main(void)
{

SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|
SYSCTL_OSC_MAIN);

SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);


PWMGenEnable(PWM0_BASE, PWM_GEN_0);
PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN);
PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_0,PWM_INT_CNT_ZERO | PWM_TR_CNT_LOAD);
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 1024);
PWMPulseWidthSet(PWM0_BASE, PWM_GEN_0, 512);
GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6);
GPIOPinConfigure(GPIO_PB6_M0PWM0);
PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT | PWM_OUT_0_BIT, true);

GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_7);
ADCSequenceConfigure(ADC0_BASE,0,ADC_TRIGGER_PWM0,0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0|ADC_CTL_IE|ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, 0);
ADCIntClear(ADC0_BASE, 0);
ADCIntEnable(ADC0_BASE,0);
IntEnable(ADC_INT_SS0);

IntMasterEnable();

while(1)
{

while(!ADCIntStatus(ADC0_BASE, 0, false))
{
} //wait for ADC to finish


test = 1;


// ADCSequenceEnable(ADC0_BASE, 0);


}
}

void IntADC1Handler(void){
//
// Go into an infinite loop.
//
ADCSequenceDataGet(ADC0_BASE, 0, testValues);

ADCIntClear(ADC0_BASE, 0);
}

  • Quickly - several things jump out:

    a)   IntADC1Handler,   // ADC Sequence 0  Suspect your MCU has 2 ADC modules (ADC0 & ADC1) - everywhere else you use ADC0 - ADC1 usage as you show here seems unwise

    b)  IntEnable(ADC_INT_SS0);   might  IntEnable(INT_ADC0SS0);  prove superior?

    c) not thrilled w/your calling order:  here is what works - our group:  (safest to first disable - then config!)

        ROM_IntDisable(INT_ADC0SS0);           // note we use ROM calls - yours will work as well
        ROM_ADCIntDisable(ADC0_BASE, 0);
        ROM_ADCSequenceDisable(ADC0_BASE, 0);

       and then SeqConfig, SeqStepConfig, SeqEnable, ADCIntClear, ADCIntEnable, IntEnable

    d) while not (yet) yielding an error - PWMOutputState shows 2 entries - yet you've PinTyped & PinConfig'ed just PB6.  Neighbor PB7 serves ready/able to provide that missing link...

    Do not know - nor like the singular vendor focus of CCS - so cannot advise in that regard...  Guidance here should get you closer - if not, "all the way."

  • Thanks for your help!

    I changed  "ADC_INT_SS0" to "INT_ADC0SS0" and the interrupt occurred.

    However, now the interrupt does not end (continuously running). At the end of the interrupt function I call ADCIntClear(ADC0_BASE, 0); to clear the adc interrupt flag. Is there another flag I need to clear?

  • Stuart Miller said:
    At the end of the interrupt function I call ADCIntClear

    Calling ADCIntClear - that late (at the end) of your interrupt handler - often allows the interrupt handler to be immediately re-entered.  Sounds very much like your situation - mais oui - mon ami?

    Move that ADCIntClear() to an earlier location w/in your handler...   (and thanks for your verify)

    For the record - we trigger an ADC Sequence via a PWM Generator - and employ this method to clear:

    HWREG(ADC0_BASE + ADC_O_ISC) = ADC_ISC_IN0;   // clears ADC0 - Sequence 0