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.

TM4C129XNCZAD: ADCProcessorTrigger is not causing an interrupt in the appropriate ADC sequence.

Part Number: TM4C129XNCZAD

Hello, I have a custom board that uses TM4C129XNCZAD as the processor and I have some values that are sent to the ADC from GPIO pins. I have followed the sample code in the Peripheral Driver Library document and for some reason ADCProcessorTrigger() does not cause an interrupt to fire. Here is the code I have:

Initialization method used to initialize the ADC and the sequences, the last function maps the values read from ADC to buffers to be used in the code and send to an UI. There are more pins that go to the ADC but I didn't include that for privacy reasons.

void InitializeADC( void )
{

    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_ADC0)){

    }
                                          */
    ADCHardwareOversampleConfigure( ADC0_BASE, 4 );

    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1);

    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_ADC1)){

    }
    
    ADCHardwareOversampleConfigure( ADC1_BASE, 4 );

    //Enable the ADC inputs on port B.
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

    /* Set the ADC pins for analog input mode.                          */
    GPIOPinTypeADC( GPIO_PORTB_BASE,
                    (GPIO_PIN_4    |
                     GPIO_PIN_5 ) );

    InitializeADC0Sequence0();
    InitializeADC0Sequence1();
    InitializeADC1Sequence0();
    InitializeADC1Sequence1();

    MapCPUAnalogValues();
}

Sequence initialization for Sequence 0 of ADC 0.

//Initializes ADC 0 sequence 0 for PORT B and P ADC inputs.
static void InitializeADC0Sequence0( void )
{
    //
    // Disable the ADC sequence and interrupts for safe reconfiguration of 
    // the ADC sequences.
    //
    IntDisable(INT_ADC0SS0);
    ADCIntDisable(ADC0_BASE, 0);
    ADCSequenceDisable(ADC0_BASE, 0);

    ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 2);

    //
    // Program the sequence.
    //
    ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH10); // Optical Amplifier Heater Current.
    ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH11); // Seed Laser Photodiode Current.
    ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH22); // 15V Voltage Monitor.
    ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH23); // Exta Analog Input
    ADCSequenceStepConfigure(ADC0_BASE, 0, 4, ( ADC_CTL_END | ADC_CTL_IE ) );

    //
    // Re-enable the ADC sequence code.
    //
    ADCSequenceEnable(ADC0_BASE, 0);
    ADCIntEnable(ADC0_BASE, 0);
    IntEnable(INT_ADC0SS0);
}

Interrupt handler for Sequence 0 ADC 0. DataBuffer is defined somewhere else, changed name for privacy.

//Handles the interrupt for ADC 0 Sequence 0
void InterruptHandlerADC0Seq0( void )
{
    
    ADCIntClear(ADC0_BASE, 0);

    ADCSequenceDataGet(ADC0_BASE, 
                       0, 
                       DataBuffer);
}

ADCProcessorTrigger Call for Sequence 0 ADC 0.

    if( ADCTriggerCounter == 3 )
    {
        ADCProcessorTrigger( ADC0_BASE, 0 );
    }

I have tested the code using debug points to make sure everything runs through and all the initialization code runs. ADCProcessorTrigger() for all of the sequences also gets called but my debug points in the interrupt handlers never get called. I also tried running the sample code given in the Peripheral Driver Library with nothing else running and it did not work either (https://www.ti.com/lit/ug/spmu298e/spmu298e.pdf?ts=1644196373578&ref_url=https%253A%252F%252Fwww.google.com%252F) this code gets stuck at:

//
// Wait until the sample sequence has completed.
//
while(!ADCIntStatus(ADC0_BASE, 0, false))
{
}

Any help on why the ADC code is not working is appreciated. 

Thanks for the assistance.

  • Hi Omer,

      Two things I notice:

      1. You didn't specify any channel for your step 4. See below line of your code. 

    ADCSequenceStepConfigure(ADC0_BASE, 0, 4, ( ADC_CTL_END | ADC_CTL_IE ) );

      If ADC_CTL_CH23 is the last step in the group to generate interrupt then you should change to below specifying ADC_CTL_CH23 as the last channel in the group and to generate interrupt once ADC_CTL_CH23 is sampled. If you have another channel after ADC_CTL_CH23  then you need to specify it accordingly. 

     ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH10); // Optical Amplifier Heater Current.
    ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH11); // Seed Laser Photodiode Current.
    ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH22); // 15V Voltage Monitor.
    ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH23 | ADC_CTL_END | ADC_CTL_IE )); // Exta Analog Input

      2. In your ADCSequenceConfigure() you specify sequencer number 2(SS2) while all of your channels are in sequencer number 0 (SS0). You should change:

    from:

    ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 2);

    to: 

    ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);

  • Hello, I added the changes you suggested but it did not resolve the issue. The first change makes sense to me but the second change seems irrelevant because the field that you asked me to change is priority not the sequence number. I was thinking it could be an issue with the way ADC Clock is set but I tried setting the clock with different parameters and tried just not setting it. Neither approach worked. Any more advice will be appreciated.

  • Hi,

      Can you add

    //
    // Enable processor interrupts.
    //
    IntMasterEnable();

  • Ok so I fixed the issue by changing my system clock settings to

     

       uint32_t ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                                   SYSCTL_OSC_MAIN |
                                                   SYSCTL_USE_PLL |
                                                   SYSCTL_CFG_VCO_240), 50000000);

    I was not using the PLL previously and I read somewhere that ADC uses PLL so I assume what was happening was PLL wasn't starting up since it wasn't used so ADC wasn't able to access it. Also adding IntMasterEnable() may be an issue for others but that function is already called in my code earlier so it did not change anything for me.

    Thanks for the help.