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 sampling

Hi, 

Below is my code for an ADC sampling. i'm writing a ADC code for sampling the result from a pressure transducer.

Below is my code and i having 2 error when i build the program, but i have no idea how to get the input from the pressure transducer. Anyone can check for the code below?

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/sysctl.h"
#include "driverlib/adc.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
#include "driverlib/interrupt.h"

int main(void)
{
uint32_t ui32ADC0Value[4];

SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);

SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); //Enable ADC0 Peripheral

ADCSequenceEnable(ADC0_BASE,0);


ADCHardwareOversampleConfigure(ADC0_BASE, 64);

ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);

ADCSequenceStepConfigure(ADC0_BASE,0,0,ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE,0,1,ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE,0,2,ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE,0,3,ADC_CTL_CH0|ADC_CTL_IE | ADC_CTL_END);

ADCSequenceEnable(ADC0_BASE, 0);


while(1)
{

ADCIntClear(ADC0_BASE,0);//Clear ADC interrupt
ADCProcessorTrigger(ADC0_BASE,0); //Trigger ADC interrupt

while(!ADCIntStatus(ADC0_BASE, 0, false))
{
}

ADCSequenceDataGet(ADC0_BASE,0,ui32ADC0Value);

SysCtlDelay(2000000);

}

}

Thank you.

  • Hello Jia,

    When you go to Console of CCS what does the error show up as. Edit -> Console

    Regards
    Amit
  • Hi Amit,

    Really appreciate your help.

    Below has shown in the console of CCS:


    undefined first referenced
    symbol in file
    --------- ----------------

    >> Compilation failure
    ADCHardwareOversampleConfigure ./main.obj
    ADCIntClear ./main.obj
    ADCIntStatus ./main.obj
    ADCProcessorTrigger ./main.obj
    ADCSequenceConfigure ./main.obj
    ADCSequenceDataGet ./main.obj
    ADCSequenceEnable ./main.obj
    ADCSequenceStepConfigure ./main.obj
    SysCtlClockSet ./main.obj
    SysCtlDelay ./main.obj
    SysCtlPeripheralEnable ./main.obj

    error #10234-D: unresolved symbols remain
    error #10010: errors encountered during linking; "ADC.out" not built
    gmake: *** [ADC.out] Error 1
    gmake: Target `all' not remade because of errors.

    **** Build Finished ****
  • Hello Jia

    The driver lib.lib pre compiled library is missing in the linker stage

    You would need to add the same from the to aware installation.

    Regards

    Amit

  • Hi Amit,

    Thanks for your help. The error has been solved. There is no result when i was collecting an input signal from the pressure transducer. Anyone can help?

    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/debug.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/adc.h"
    #include "driverlib/gpio.h"
    #include "driverlib/timer.h"
    #include "driverlib/interrupt.h"

    int main(void)
    {
    uint32_t ui32ADC0Value[4];

    volatile uint32_t ui32PressureAvg;

    SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); //Enable ADC0 Peripheral

    ADCSequenceEnable(ADC0_BASE,0);

    GPIOPinTypeADC(GPIO_PORTE_BASE,GPIO_PIN_3);

    ADCHardwareOversampleConfigure(ADC0_BASE, 64);

    ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);

    ADCSequenceStepConfigure(ADC0_BASE,0,0,ADC_CTL_CH0);
    ADCSequenceStepConfigure(ADC0_BASE,0,1,ADC_CTL_CH0);
    ADCSequenceStepConfigure(ADC0_BASE,0,2,ADC_CTL_CH0);
    ADCSequenceStepConfigure(ADC0_BASE,0,3,ADC_CTL_CH0|ADC_CTL_IE | ADC_CTL_END);

    ADCSequenceEnable(ADC0_BASE, 0);


    while(1)
    {

    ADCIntClear(ADC0_BASE,0);//Clear ADC interrupt
    ADCProcessorTrigger(ADC0_BASE,0); //Trigger ADC interrupt

    while(!ADCIntStatus(ADC0_BASE, 0, false))
    {
    }

    ADCSequenceDataGet(ADC0_BASE,0,ui32ADC0Value);

    GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE,GPIO_PIN_2);

    SysCtlDelay(2000000);

    }


    }

  • Hello Jia,

    There are multiple things to consider

    1. Is the code executing? I doubt... Why because Port E is not enabled when you configure the GPIO for ADC function. Has to be in a Bus Fault Handler.

    2. What is the analog output from the transducer. Is it measurable by a multimeter and in the range of conversion of ADC and step size of the ADC per LSB. Please note that there is a delta error for the ADC.

    What you should try is to connect fixed voltage signals like 1.2V, 1.8V, etc till 3.3V to see if the conversion is happening to test the TM4C code.

    Regards
    Amit
  • Hi Amit,

    I'm so sorry to keep bothering you. :( As i'm a newie to TIVA.

    Pertaining to your questions:
    1. May i know what is Bus Fault Handler??

    2. It's a Millivolt analog output. Yes is measurable by multimeter and in the range of conversion of ADC and step size of the ADC per LSB. Sorry, what is delta error for ADC?

    We used a fixed voltage signals of 3.3V to convert the signal.

    Thanks and sorry.....
  • Hello Jia,

    I saw from the question that indeed you are a newbie. But the questions are the right questions you ask. So here are the answers

    1. The bus fault handler, is to handle any unexpected issue that the CPU code execution may encounter. In this case since the peripheral is not enabled, the read or write to it will not yield the correct data. Hence a Bus Fault is raised so that program execution is aborted and the CPU goes to the bus fault handler to indicate of terminated program execution

    2. The delta error is the number of LSB's of ADC conversion which would be seen when the voltage is held constant and a conversion is done over and over again.

    Regards
    Amit