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: adc interrupt sampling timer error

Part Number: TM4C129XNCZAD

dear 

 i am not getting actual output when adc in interrupt mode . i want to sample adc at 10KHz . i used timer to generate interrupt please suggest me any modification.

/*
 * main.c
 */
 #include "stdbool.h"
#include "stdint.h"
#include "gpio.h"
#include "rom_map.h"
#include "driverlib/sysctl.h"
#include "inc/hw_memmap.h"
#include "pin_map.h"
#include "emac.h"
#include "systick.h"
#include "drivers/pinout.h"
#include "utils/ustdlib.h"
#include "driverlib/adc.h"
#include "math.h"
#include "driverlib/ssi.h"
#include "inc/tm4c129xnczad.h"
#include "grlib/grlib.h"
#include "grlib/widget.h"
#include "grlib/canvas.h"
#include "grlib/slider.h"
#include "drivers/frame.h"
#include "drivers/kentec320x240x16_ssd2119.h"
#include "drivers/sound.h"
#include "drivers/touch.h"
#include "driverlib/rom.h"
#include "driverlib/udma.h"
#include "driverlib/timer.h"
#include "driverlib/interrupt.h"
//#include "inc/hw_ints.h"

#define GPIO_PA2_SSI0CLK        0x0000080F
#define GPIO_PA3_SSI0FSS        0x00000C0F
#define GPIO_PA4_SSI0TX      0x0000100F
#define GPIO_PA5_SSI0RX      0x0000140F
void MT_SSIConfigure(void);
void MT_ADCConfigure(void);
void Timer_configure(void);
void Interrupt_configure(void);
//void Timer0IntHandler(void);
float dac_count,value,xval[27];

    float sum,temp,voltage,value;
uint32_t pui32ADC0Value[2];
void DAC_ldac(void);
uint32_t ui32Period1, ui32Period2;
uint32_t ui32SysClock;
uint32_t pui32DataTx;
const double firCoeffs32[26] = {

                                0.00042786716307723429,
                                 0.002919136775687219,
                                 0.0087411768920698726,
                                 0.01728389646188545,
                                 0.023790092406399139,
                                 0.020625746649647263,
                                 0.0026178235631764959,
                                -0.025784577131922413,
                                -0.047619527772776261,
                                -0.039756341015621199,
                                 0.012766667411548112,
                                 0.10310658429302662,
                                 0.20045692369728618,
                                 0.26366156038852501,
                                 0.26366156038852501,
                                 0.20045692369728618,
                                 0.10310658429302662,
                                 0.012766667411548112,
                                -0.039756341015621199,
                                -0.047619527772776261,
                                -0.025784577131922413,
                                 0.0026178235631764959,
                                 0.020625746649647263,
                                 0.023790092406399139,
                                 0.01728389646188545,
                                 0.0087411768920698726,
                                 0.002919136775687219,
                                 0.00042786716307723429,





};
void MT_ADCConfigure()
{
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
    GPIOPinTypeADC(GPIO_PORTK_BASE, GPIO_PIN_1);
    ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0);
    ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH17 | ADC_CTL_IE |
                                 ADC_CTL_END);
    ADCSequenceEnable(ADC0_BASE, 3);
    ADCIntClear(ADC0_BASE, 3);
}
void MT_SSIConfigure()
{
        SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
        GPIOPinConfigure(GPIO_PA2_SSI0CLK);
        GPIOPinConfigure(GPIO_PA3_SSI0FSS);
        GPIOPinConfigure(GPIO_PA4_SSI0TX);
        GPIOPinConfigure(GPIO_PA5_SSI0RX);
        GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_4 | GPIO_PIN_3 | GPIO_PIN_2);
        SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_3,
                               SSI_MODE_MASTER, 10000, 16);
        SSIEnable(SSI0_BASE);
}
void Timer_configure()
{
                  ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
                  ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
                  ui32Period1 = SysCtlClockGet();
                  ui32Period2 = (ui32SysClock / 10000);
                  TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period2 -1);
                  TimerControlTrigger(TIMER0_BASE,TIMER_A,true);
}
void Interrupt_configure()
{
                                          ROM_IntEnable(INT_TIMER0A);
                                          ROM_TimerIntEnable(TIMER0_BASE,TIMER_TIMA_TIMEOUT);
                                          ROM_IntEnable(INT_ADC0SS3);
                                          ROM_ADCIntEnable(ADC0_BASE,3);
                                          ROM_IntMasterEnable();
                                          ROM_TimerEnable(TIMER0_BASE,TIMER_A);
}
int main(void)
{
     int i,k;
     float dac_count,value;
     float sum,temp,voltage;
     uint32_t ui32SysClock,l;
     ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480),120000000);
     MT_ADCConfigure();
     Timer_configure();
     Interrupt_configure();
     MT_SSIConfigure();
     DAC_ldac();
     for(i=0;i<=26;i++)
             {
                   xval[i]=0;
             }


     while(1)
            {
                   MAP_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5,GPIO_PIN_5);
                   MAP_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3,GPIO_PIN_3);

                    dac_count= (sum*8190);
                    pui32DataTx=dac_count;
                    SSIDataPut(SSI0_BASE, pui32DataTx);
                    while(SSIBusy(SSI0_BASE))
                    {
                    }
                     MAP_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5, 0);
                     SSIIntClear(SSI0_BASE,SSI_RXFF);
                     MAP_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5,GPIO_PIN_5);

             }

    //return 0;
}
void DAC_ldac()
{
    ///  LDAC Signal
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    MAP_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_5);
    MAP_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5, GPIO_PIN_5);
   // Reset Signal
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    MAP_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3);
    MAP_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0);
}

void ADC0SS3IntHandler(void)
{

     ADCIntClear(ADC0_BASE, 3);
     ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value);
     xval[0]=(*pui32ADC0Value*3.3)/4096;
    


}
void Timer0IntHandler(void)
{
    ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
}

  • Here is a simple example project that uses the timer to trigger the ADC and then uses the uDMA to copy results into buffers. From CCS select "File" -> "Import", select "CCS Project", "next"  and chose "Select archive file".

    /cfs-file/__key/communityserver-discussions-components-files/908/1667.ADCwDMA.zip


  • dear bob, thanks for your reply as now i am stucked with adc which is sampling with 10k i am unable to see my adc output. i divided my application in three part adc reading dac writing and fir algo. but in first part i think adc is not correctly getting the data. i need your help as i have stucked in this. i am working hard. can you tell me why i am unable to see 1 khz in graph facility in ccs



     #include "stdbool.h"
    #include "stdint.h"
    #include "gpio.h"
    #include "rom_map.h"
    #include "driverlib/sysctl.h"
    #include "inc/hw_memmap.h"
    #include "pin_map.h"
    #include "emac.h"
    #include "systick.h"
    #include "drivers/pinout.h"
    #include "utils/ustdlib.h"
    #include "driverlib/adc.h"
    #include "math.h"
    #include "driverlib/ssi.h"
    #include "inc/tm4c129xnczad.h"
    #include "grlib/grlib.h"
    #include "grlib/widget.h"
    #include "grlib/canvas.h"
    #include "grlib/slider.h"
    #include "drivers/frame.h"
    #include "drivers/kentec320x240x16_ssd2119.h"
    #include "drivers/sound.h"
    #include "drivers/touch.h"
    #include "driverlib/rom.h"
    #include "driverlib/udma.h"
    #include "driverlib/timer.h"
    #include "driverlib/interrupt.h"
    void init_ADC(void);
    float voltage;
    uint32_t pui32ADC0Value[2];
    float xval[122],dac_count;
    void init_TIMER();
    
    uint32_t ui32Period;
        uint32_t ui32SysClock;
        uint32_t pui32DataTx;
        static uint32_t g_ui32SysTickCount;
         void Timer0AIntHandler(void)
        {
            //
            // Clear the timer interrupt flag.
            //
            TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
        }
    
        void SysTickIntHandler(void)
        {
            // Update our system tick counter.
            g_ui32SysTickCount++;
        }
    
        void ADCseq0Handler()
        {
            ADCIntClear(ADC0_BASE, 0);
            ADCSequenceDataGet(ADC0_BASE, 0, pui32ADC0Value);
            voltage=(*pui32ADC0Value*3.3)/4096;
    
        }
    
    
    
    /*
     * main.c
     */
    int main(void)
    {
        unsigned int i,k;
    
        ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480),12000000);
    
            MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);  //Enable the clock to TIMER0
            MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);    //Enable the clock to ADC module
    
            MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);   //Enables the clock to PORT k
            MAP_SysCtlDelay(30);
    
            MAP_SysTickPeriodSet(ui32SysClock / 100000u); //Sets the period of the SysTic counter to 10us
            MAP_SysTickIntEnable();
            MAP_SysTickEnable();
            init_ADC();
                init_TIMER();
     //   MT_SSIConfigure();
    //    DAC_ldac();
        MAP_IntMasterEnable();
           MAP_TimerEnable(TIMER0_BASE, TIMER_A); // Start everything
    
        while(1)
        {
    
    
    
    
    
    
    
    
    
    
               }
    
    
    
    }
    
    void init_TIMER()
    {
        MAP_TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC);
        // Set sample frequency to 16KHz (every 62.5uS)
        MAP_TimerLoadSet(TIMER0_BASE, TIMER_A, ui32SysClock/320000 -1);   //TODO: Timer Load Value is set here
        MAP_TimerControlTrigger(TIMER0_BASE, TIMER_A, true);
        MAP_TimerControlStall(TIMER0_BASE, TIMER_A, true); //Assist in debug by stalling timer at breakpoints
    }
    
    void init_ADC()
    {
        GPIOPinTypeADC(GPIO_PORTK_BASE, GPIO_PIN_1);
        SysCtlDelay(80);
    
        // Use ADC0 sequence 0 to sample channel 0 once for each timer period
        ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PIOSC | ADC_CLOCK_RATE_HALF, 1);
    
        SysCtlDelay(10); // Time for the clock configuration to set
    
        IntDisable(INT_ADC0SS0);
        ADCIntDisable(ADC0_BASE, 0);
        ADCSequenceDisable(ADC0_BASE,0);
        // With sequence disabled, it is now safe to load the new configuration parameters
    
        ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_TIMER, 0);
        ADCSequenceStepConfigure(ADC0_BASE,0,0,ADC_CTL_CH17| ADC_CTL_END | ADC_CTL_IE);
        ADCSequenceEnable(ADC0_BASE,0); //Once configuration is set, re-enable the sequencer
        ADCIntClear(ADC0_BASE,0);
      //  ADCSequenceDMAEnable(ADC0_BASE,0);
        ADCIntEnable(ADC0_BASE, 0);
        IntEnable(INT_ADC0SS0);
    
    }

  • OK, I see you are running the ADC off of the 16Mhz PIOSC. From the other thread I understand that when you apply a constant voltage, you get the expected results but with a 1KHz sine wave you do not get what you expect. Can you elaborate? What is the amplitude of the sine wave? What is the source impedance? What do the results look like? It may be a problem that your source impedance is too high for the default sample time.

  • 2 V input with 50ohm impedance. i ssampling the input at 16KHz which is sine wave of 2 Vinput. i want to get the same output from dac. i have taken input from adc and thn i sent it to dac.
  • THANKS FOR YOUR REPLY CAN YOU PLEASE TELL ME. HO WTO CHECK LOOP TIME TIMER VALUE IN CCS I MEAN TIME RELATED CHARACTERISTICS.
    I AM SAMPLING AT 16K A SINE WAVE. CAN I PRODUCE ACTUAL WAVEFORM AT DAC OUTPUT. I MEAN SIMPLE WRTING AT SPI PORT OF MICROCONTROLLER