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.

  • TI Thinks Resolved

TM4C129ENCPDT: ADC Configuration for TM4c129ENCPDT

Intellectual 300 points

Replies: 3

Views: 56

Part Number: TM4C129ENCPDT

I'm trying to configure the ADC on a custom board.  At present, my code compiles but I dont see that the ADC ISR is being called.  This is code ported from a nearly identical application (same processor, maybe minor clock differences).  Relevant code snippets below.  I'd appreciate any suggestions!

//////////////////Main Program/////////

int main(void)
{
    //Initializations
        PinoutSet();
        sysclock = SysCtlClockFreqSet(SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_25MHZ, 25000000);
        adc_configuration();

    //Superloop
    while(1){

        ADCProcessorTrigger(ADC0_BASE, 0); //base, SequenceNumber

        SysCtlDelay(LoopDelay * (sysclock / 3 / 1000)); //introduces 100ms delay - 3 b/c SysCtlDelay takes 3 clock cycles - 1000 b/c unit conversion
    }
}

void adc_configuration(){
    //Onboard ADC Configuration to read 3 external analog inputs on pins 13,14,15 and internal temperature
    //read on sequence 0 with highest priority
    //TODO - add measurements for heater voltage on pins 127/PD6/AIN5, 128/PD7/AIN4 and 12V rail 12/PE3/AIN0
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); //p.501 of Tivaware manual
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    //ADCClockConfigSet(ADC0_BASE,ADC_CLOCK_SRC_PLL | ADC_CLOCK_RATE_FULL,1);
    ADCClockConfigSet(ADC0_BASE,ADC_CLOCK_SRC_MOSC | ADC_CLOCK_RATE_FULL,1);
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_ADC0))
    {
    }
    //ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_ALWAYS, 0); //Base, SequenceNum, Trigger, Priority
    ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0); //Base, SequenceNum, Trigger, Priority
    ADCSequenceStepConfigure(ADC0_BASE, 0, 0, (ADC_CTL_CH1)); //Base, SequenceNum, Step, Config
    ADCSequenceStepConfigure(ADC0_BASE, 0, 1, (ADC_CTL_CH2)); //Base, SequenceNum, Step, Config
    ADCSequenceStepConfigure(ADC0_BASE, 0, 2, (ADC_CTL_CH3)); //Base, SequenceNum, Step, Config
    ADCSequenceStepConfigure(ADC0_BASE, 0, 3, (ADC_CTL_TS | ADC_CTL_IE | ADC_CTL_END)); //Base, SequenceNum, Step, Config
    ADCReferenceSet(ADC0_BASE, ADC_REF_EXT_3V);
    //ADCReferenceSet(ADC0_BASE, ADC_REF_INT);
    ADCSequenceEnable(ADC0_BASE, 0); //Base, SequenceNum
    ADCIntRegister(ADC0_BASE, 0, adc_int_handler); //Base, SequenceNum, ISR Handler pointer
    ADCIntEnable(ADC0_BASE, 0); //Base, SequenceNum
}

void adc_int_handler(void) {
        adc_int_counter++;
        ADCSequenceDataGet(ADC0_BASE, 0, adc_buffer);
        rail_voltage_24v = adc_buffer[0];
        rail_voltage_5v = adc_buffer[1];
        rail_voltage_3v3 = adc_buffer[2];

        rail_voltage_24v_volts = ((float) rail_voltage_24v) / ((float) 0xFFF) * 3 * 9.635; //12-bit ADC, 3V reference, 9.635x divider attenuation
        rail_voltage_5v_volts = ((float) rail_voltage_5v) / ((float) 0xFFF) * 3 * 2; //12-bit ADC, 3V reference, 2x divider attenuation
        rail_voltage_3v3_volts = ((float) rail_voltage_3v3) / ((float) 0xFFF) * 3 * 1.330; //12-bit ADC, 3V reference, 1.330x divider attenuation

        tiva_temperature = adc_buffer[3];
        ADCIntClear(ADC0_BASE, 0); //base, SequenceNumber
    }



  • Hi Jack,

      Did you mean the only thing compared to the working program was the clock configuration?

      If your system clock frequency is meant to be the same frequency as the MOSC, then please still use the PLL instead of the MOSC as the clock source to reach the final system clock frequency. Let me know if that resolves the issue. 

      Let something like below. 

    ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
    SYSCTL_OSC_MAIN |
    SYSCTL_USE_PLL |
    SYSCTL_CFG_VCO_480), 25000000);

    regards,

    Charles

     

  • In reply to Charles Tsai:

    This appears to have resolved the issue.

    I would appreciate a brief explanation if possible?  My ADC configuration included the line below, and my understanding was that it would run just fine off of the MOSC?

        //ADCClockConfigSet(ADC0_BASE,ADC_CLOCK_SRC_PLL | ADC_CLOCK_RATE_FULL,1);
        ADCClockConfigSet(ADC0_BASE,ADC_CLOCK_SRC_MOSC | ADC_CLOCK_RATE_FULL,1);

    Thanks very much for the help!

  • In reply to JaPaBo:

    Hi Jack,

      I think you may be hitting SYSCTL#23 errata. Please also refer to the below post and the solution provided by Bob.

    Detail of the errata can be found here.

    regards,

    Charles

     

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.