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.

Setting the sampling rate for tiva c series microcontroller

Other Parts Discussed in Thread: TM4C123GH6PM

Hi everyone

Recently i am working with tm4c123gh6pm tiva lauchpad.I want to operate one ADC of this microcontroller at 1ksps rate.I read theAPI s that have been provided with tivaware.But i m really confused how to set the sampling rate as no where it has been mentioned explicitely.Am I missing something.Please help me with this.

Thanks

Arun

  • Hello Arunabha,

    The Sampling rate of the ADC is the maximum back-to-back conversion rate. So if you do not modify the settings then it is 1MSPS maximum rate. For a rate like 1KSPS, what you would need to do is to set a timer to trigger the ADC every 1ms. The ADC will then convert the channel periodically to get the 1KSPS rate. On the other hand if you want to use the processor to trigger the ADC, then generate an interrupt from the timer at 1ms interval and in the Interrupt Handler of the Timer, the CPU can trigger the ADC.

    Regards

    Amit

  • Thanks.Moving forward.

  • Hi

    I am trying to capture data from 4 input sources using 4 channel of a adc in tm4c123gh6pm.I am using keil uvision4 for debugging.But I am not getting the samples as expected.I am giving a pure sinusoid from a function generator.But it looks like I am getting improper output samples.Please suggest me if i am doing anything wrong.I am attachin gmy code below.

    //*****************************************************************************
    //
    // single_ended.c - Example demonstrating how to configure the ADC for
    //                  single ended operation.
    //
    // Copyright (c) 2010-2013 Texas Instruments Incorporated.  All rights reserved.
    // Software License Agreement
    // 
    //   Redistribution and use in source and binary forms, with or without
    //   modification, are permitted provided that the following conditions
    //   are met:
    // 
    //   Redistributions of source code must retain the above copyright
    //   notice, this list of conditions and the following disclaimer.
    // 
    //   Redistributions in binary form must reproduce the above copyright
    //   notice, this list of conditions and the following disclaimer in the
    //   documentation and/or other materials provided with the  
    //   distribution.
    // 
    //   Neither the name of Texas Instruments Incorporated nor the names of
    //   its contributors may be used to endorse or promote products derived
    //   from this software without specific prior written permission.
    // 
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    // 
    // This is part of revision 2.0.1.11577 of the Tiva Firmware Development Package.
    //
    //*****************************************************************************
    
    #include <stdbool.h>
    #include <stdint.h>
    #include "hw_memmap.h"
    #include "adc.h"
    #include "gpio.h"
    #include "pin_map.h"
    #include "sysctl.h"
    #include "uart.h"
    #include "uartstdio.h"
    #include "timer.h"
    //*****************************************************************************
    //
    //! \addtogroup adc_examples_list
    //! <h1>Single Ended ADC (single_ended)</h1>
    //!
    //! This example shows how to setup ADC0 as a single ended input and take a
    //! single sample on AIN0/PE7.
    //!
    //! This example uses the following peripherals and I/O signals.  You must
    //! review these and change as needed for your own board:
    //! - ADC0 peripheral
    //! - GPIO Port E peripheral (for AIN0 pin)
    //! - AIN0 - PE7
    //!
    //! The following UART signals are configured only for displaying console
    //! messages for this example.  These are not required for operation of the
    //! ADC.
    //! - UART0 peripheral
    //! - GPIO Port A peripheral (for UART0 pins)
    //! - UART0RX - PA0
    //! - UART0TX - PA1
    //!
    //! This example uses the following interrupt handlers.  To use this example
    //! in your own application you must add these interrupt handlers to your
    //! vector table.
    //! - None.
    //
    //*****************************************************************************
    
    //*****************************************************************************
    //
    // This function sets up UART0 to be used for a console to display information
    // as the example is running.
    //
    //*****************************************************************************
    /*void
    InitConsole(void)
    {
        //
        // Enable GPIO port A which is used for UART0 pins.
        // TODO: change this to whichever GPIO port you are using.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    
        //
        // Configure the pin muxing for UART0 functions on port A0 and A1.
        // This step is not necessary if your part does not support pin muxing.
        // TODO: change this to select the port/pin you are using.
        //
        GPIOPinConfigure(GPIO_PA0_U0RX);
        GPIOPinConfigure(GPIO_PA1_U0TX);
    
        //
        // Enable UART0 so that we can configure the clock.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    
        //
        // Use the internal 16MHz oscillator as the UART clock source.
        //
        UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
    
        //
        // Select the alternate (UART) function for these pins.
        // TODO: change this to select the port/pin you are using.
        //
        GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
        //
        // Initialize the UART for console I/O.
        //
        UARTStdioConfig(0, 115200, 16000000);
    }*/
    
    //*****************************************************************************
    //
    // Configure ADC0 for a single-ended input and a single sample.  Once the
    // sample is ready, an interrupt flag will be set.  Using a polling method,
    // the data will be read then displayed on the console via UART0.
    //
    //*****************************************************************************
    int
    main(void)
    {
        //
        // This array is used for storing the data read from the ADC FIFO. It
        // must be as large as the FIFO for the sequencer in use.  This example
        // uses sequence 3 which has a FIFO depth of 1.  If another sequence
        // was used with a deeper FIFO, then the array size must be changed.
        //
        uint32_t pui32ADC0Value1[1],pui32ADC0Value2[1],pui32ADC0Value3[1],pui32ADC0Value4[1];
    	uint32_t data1[100],data2[100],data3[100],data4[100];
    	int i=100;
    
        //
        // Set the clocking to run at 20 MHz (200 MHz / 10) using the PLL.  When
        // using the ADC, you must either use the PLL or supply a 16 MHz clock
        // source.
        // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
        // crystal on your board.
        //
        SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);
    
        //
        // Set up the serial console to use for displaying messages.  This is
        // just for this example program and is not needed for ADC operation.
        //
        //InitConsole();
    
        //
        // Display the setup on the console.
        //
       // UARTprintf("ADC ->\n");
       // UARTprintf("  Type: Single Ended\n");
        //UARTprintf("  Samples: One\n");
        //UARTprintf("  Update Rate: 250ms\n");
        //UARTprintf("  Input Pin: AIN0/PE7\n\n");
    
        //
        // The ADC0 peripheral must be enabled for use.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    
        //
        // For this example ADC0 is used with AIN0 on port E7.
        // The actual port and pins used may be different on your part, consult
        // the data sheet for more information.  GPIO port E needs to be enabled
        // so these pins can be used.
        // TODO: change this to whichever GPIO port you are using.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    
        //
        // Select the analog ADC function for these pins.
        // Consult the data sheet to see which functions are allocated per pin.
        // TODO: change this to select the port/pin you are using.
    		
    	/*timer***********************************/	
    		
    		SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    
    		
    		 TimerConfigure(TIMER0_BASE,TIMER_CFG_PERIODIC);
    		
    		TimerLoadSet(TIMER0_BASE, TIMER_A,5000);          /*set the timer to fs=2 ksps load value */
    		                                                   
    																											/*if timer loading value=5000; fs=1 ksps
    																											* sysclock=20mhz so tsys=1/2000000sec;to get 1ms delay
    																											*we need to load timer with 1ms/0.5us***/
    		  TimerEnable(TIMER0_BASE, TIMER_A);
    		
    		
    		
    		
    		
    		
    		
    		
        //
        GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
    		GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2);
    		GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1);
    		GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4);
    		
    
        //
        // Enable sample sequence 3 with a processor signal trigger.  Sequence 3
        // will do a single sample when the processor sends a signal to start the
        // conversion.  Each ADC module has 4 programmable sequences, sequence 0
        // to sequence 3.  This example is arbitrarily using sequence 3.
        //
      //  ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
    		
    		ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0);
    
        //
        // Configure step 0 on sequence 3.  Sample channel 0 (ADC_CTL_CH0) in
        // single-ended mode (default) and configure the interrupt flag
        // (ADC_CTL_IE) to be set when the sample is done.  Tell the ADC logic
        // that this is the last conversion on sequence 3 (ADC_CTL_END).  Sequence
        // 3 has only one programmable step.  Sequence 1 and 2 have 4 steps, and
        // sequence 0 has 8 programmable steps.  Since we are only doing a single
        // conversion using sequence 3 we will only configure step 0.  For more
        // information on the ADC sequences and steps, reference the datasheet.
        //
    		TimerControlTrigger(TIMER0_BASE, TIMER_A, true);
    		for(i=0;i<100;i++)
    		{
        ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE |
                                 ADC_CTL_END);
    
        //
        // Since sample sequence 3 is now configured, it must be enabled.
        //
        ADCSequenceEnable(ADC0_BASE, 3);
    
        //
        // Clear the interrupt status flag.  This is done to make sure the
        // interrupt flag is cleared before we sample.
        //
        ADCIntClear(ADC0_BASE, 3);
    
        //
        // Sample AIN0 forever.  Display the value on the console.
        //
      //  while(1)
    	//for(i=0;i<100;i++)
       // {
            //
            // Trigger the ADC conversion.
            //
           // ADCProcessorTrigger(ADC0_BASE, 3);
    			//TimerControlTrigger(TIMER0_BASE, TIMER_A, true);
    
            //
            // Wait for conversion to be completed.
            //
            while(!ADCIntStatus(ADC0_BASE, 3, false))
            {
            }
    
            //
            // Clear the ADC interrupt flag.
            //
            ADCIntClear(ADC0_BASE, 3);
    
            //
            // Read ADC Value.
            //
            ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value1);
    //i= pui32ADC0Value;
            //
            // Display the AIN0 (PE7) digital value on the console.
            //
           // UARTprintf("AIN0 = %4d\r", pui32ADC0Value[0]);
    data1[i]=pui32ADC0Value1[0];
    				//SysCtlDelay(2000);
    				
    			//	pui32ADC0Value[0]=0;
            //
            // This function provides a means of generating a constant length
            // delay.  The function delay (in cycles) = 3 * parameter.  Delay
            // 250ms arbitrarily.
            //
          //  SysCtlDelay(SysCtlClockGet() / 12);
    			
    				//SysCtlDelay(250);
    			
    			ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH1 | ADC_CTL_IE |
                                 ADC_CTL_END);
    			
    			ADCSequenceEnable(ADC0_BASE, 3);
    			
    			  ADCIntClear(ADC0_BASE, 3);
    			 while(!ADCIntStatus(ADC0_BASE, 3, false))
            {
            }
    			
    			 ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value2);
    			data2[i]=pui32ADC0Value2[0];
    			
    		//	}
    		
    			//SysCtlDelay(250);
    		
    			ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH2 | ADC_CTL_IE |
                                 ADC_CTL_END);
    			
    			ADCSequenceEnable(ADC0_BASE, 3);
    			
    			  ADCIntClear(ADC0_BASE, 3);
    			 while(!ADCIntStatus(ADC0_BASE, 3, false))
            {
            }
    			
    			 ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value3);
    			data3[i]=pui32ADC0Value3[0];
    			
    			//}		
    			//SysCtlDelay(250);
    			
    			
    			ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH9 | ADC_CTL_IE |
                                 ADC_CTL_END);
    			
    			ADCSequenceEnable(ADC0_BASE, 3);
    			
    			  ADCIntClear(ADC0_BASE, 3);
    			 while(!ADCIntStatus(ADC0_BASE, 3, false))
            {
            }
    			
    			 ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value4);
    			data4[i]=pui32ADC0Value4[0];
    			
    		//	SysCtlDelay(250);
    			}	
    			
    			
    			
    			while(1);
    }
    

    thanks

    Arun

  • Hi

    Arunabha, you need to do ADCSequenceDisable before you configure it. So i guess configuring it to a diferent chanel doesn't realy work.

  • Thanks for ur reply.With ADCsequencedisable() I have tried but the same problem.Sometimes i am getting two consecutive samples of one channel is same.If I set  time loading value to 20000 instead of 5000 then I am getting a more proper output.But in this case my sampling frequency has been equals to 0.5ksps considering the 4 channels together.i want a sampling frequency of atleast 1 ksps.Quite confused.

    Thanks

    Arun

  • You sure those values are correct?

    At 20Mhz the value of 20000 should mean more or less 1k values per second.

    Also you didn't use TimerADCEventSet

    You did remember to re-enable the ADC after disabling it and seting it up? Sometimes with trying to get sometigh right it's easy to forget some basic things like that

  • Hi

    Just above the for loop I have used that TimerControlTrigger();.Yea with 20000 we can get sampling rate of 1ksps but in my code i am reading data from 4 channels by suing a for loop.So effective sampling rate is getting one fourth of 20000.I am uploading my new edited code as per ur suggestion to enable adc sequence.Please have a look.

    //*****************************************************************************
    //
    // single_ended.c - Example demonstrating how to configure the ADC for
    //                  single ended operation.
    //
    // Copyright (c) 2010-2013 Texas Instruments Incorporated.  All rights reserved.
    // Software License Agreement
    // 
    //   Redistribution and use in source and binary forms, with or without
    //   modification, are permitted provided that the following conditions
    //   are met:
    // 
    //   Redistributions of source code must retain the above copyright
    //   notice, this list of conditions and the following disclaimer.
    // 
    //   Redistributions in binary form must reproduce the above copyright
    //   notice, this list of conditions and the following disclaimer in the
    //   documentation and/or other materials provided with the  
    //   distribution.
    // 
    //   Neither the name of Texas Instruments Incorporated nor the names of
    //   its contributors may be used to endorse or promote products derived
    //   from this software without specific prior written permission.
    // 
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    // 
    // This is part of revision 2.0.1.11577 of the Tiva Firmware Development Package.
    //
    //*****************************************************************************
    
    #include <stdbool.h>
    #include <stdint.h>
    #include "hw_memmap.h"
    #include "adc.h"
    #include "gpio.h"
    #include "pin_map.h"
    #include "sysctl.h"
    #include "uart.h"
    #include "uartstdio.h"
    #include "timer.h"
    //*****************************************************************************
    //
    //! \addtogroup adc_examples_list
    //! <h1>Single Ended ADC (single_ended)</h1>
    //!
    //! This example shows how to setup ADC0 as a single ended input and take a
    //! single sample on AIN0/PE7.
    //!
    //! This example uses the following peripherals and I/O signals.  You must
    //! review these and change as needed for your own board:
    //! - ADC0 peripheral
    //! - GPIO Port E peripheral (for AIN0 pin)
    //! - AIN0 - PE7
    //!
    //! The following UART signals are configured only for displaying console
    //! messages for this example.  These are not required for operation of the
    //! ADC.
    //! - UART0 peripheral
    //! - GPIO Port A peripheral (for UART0 pins)
    //! - UART0RX - PA0
    //! - UART0TX - PA1
    //!
    //! This example uses the following interrupt handlers.  To use this example
    //! in your own application you must add these interrupt handlers to your
    //! vector table.
    //! - None.
    //
    //*****************************************************************************
    
    //*****************************************************************************
    //
    // This function sets up UART0 to be used for a console to display information
    // as the example is running.
    //
    //*****************************************************************************
    /*void
    InitConsole(void)
    {
        //
        // Enable GPIO port A which is used for UART0 pins.
        // TODO: change this to whichever GPIO port you are using.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    
        //
        // Configure the pin muxing for UART0 functions on port A0 and A1.
        // This step is not necessary if your part does not support pin muxing.
        // TODO: change this to select the port/pin you are using.
        //
        GPIOPinConfigure(GPIO_PA0_U0RX);
        GPIOPinConfigure(GPIO_PA1_U0TX);
    
        //
        // Enable UART0 so that we can configure the clock.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    
        //
        // Use the internal 16MHz oscillator as the UART clock source.
        //
        UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
    
        //
        // Select the alternate (UART) function for these pins.
        // TODO: change this to select the port/pin you are using.
        //
        GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
        //
        // Initialize the UART for console I/O.
        //
        UARTStdioConfig(0, 115200, 16000000);
    }*/
    
    //*****************************************************************************
    //
    // Configure ADC0 for a single-ended input and a single sample.  Once the
    // sample is ready, an interrupt flag will be set.  Using a polling method,
    // the data will be read then displayed on the console via UART0.
    //
    //*****************************************************************************
    int
    main(void)
    {
        //
        // This array is used for storing the data read from the ADC FIFO. It
        // must be as large as the FIFO for the sequencer in use.  This example
        // uses sequence 3 which has a FIFO depth of 1.  If another sequence
        // was used with a deeper FIFO, then the array size must be changed.
        //
        uint32_t pui32ADC0Value1[1],pui32ADC0Value2[1],pui32ADC0Value3[1],pui32ADC0Value4[1];
    	uint32_t data1[100],data2[100],data3[100],data4[100];
    	int i=100;
    
        //
        // Set the clocking to run at 20 MHz (200 MHz / 10) using the PLL.  When
        // using the ADC, you must either use the PLL or supply a 16 MHz clock
        // source.
        // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
        // crystal on your board.
        //
        SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);
    
        //
        // Set up the serial console to use for displaying messages.  This is
        // just for this example program and is not needed for ADC operation.
        //
        //InitConsole();
    
        //
        // Display the setup on the console.
        //
       // UARTprintf("ADC ->\n");
       // UARTprintf("  Type: Single Ended\n");
        //UARTprintf("  Samples: One\n");
        //UARTprintf("  Update Rate: 250ms\n");
        //UARTprintf("  Input Pin: AIN0/PE7\n\n");
    
        //
        // The ADC0 peripheral must be enabled for use.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    
        //
        // For this example ADC0 is used with AIN0 on port E7.
        // The actual port and pins used may be different on your part, consult
        // the data sheet for more information.  GPIO port E needs to be enabled
        // so these pins can be used.
        // TODO: change this to whichever GPIO port you are using.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    
        //
        // Select the analog ADC function for these pins.
        // Consult the data sheet to see which functions are allocated per pin.
        // TODO: change this to select the port/pin you are using.
    		
    	/*timer***********************************/	
    		
    		SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    
    		
    		 TimerConfigure(TIMER0_BASE,TIMER_CFG_PERIODIC);
    		
    		TimerLoadSet(TIMER0_BASE, TIMER_A,25000);          /*set the timer to fs=2 ksps load value */
    		                                                   
    																											/*if timer loading value=5000; fs=1 ksps
    																											* sysclock=20mhz so tsys=1/2000000sec;to get 1ms delay
    																											*we need to load timer with 1ms/0.5us***/
    		  TimerEnable(TIMER0_BASE, TIMER_A);
    		
    		
    		
    		
    		
    		
    		
    		
        //
        GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
    		GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2);
    		GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1);
    		GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4);
    		
    
        //
        // Enable sample sequence 3 with a processor signal trigger.  Sequence 3
        // will do a single sample when the processor sends a signal to start the
        // conversion.  Each ADC module has 4 programmable sequences, sequence 0
        // to sequence 3.  This example is arbitrarily using sequence 3.
        //
      //  ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
    		
    		ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0);
    
        //
        // Configure step 0 on sequence 3.  Sample channel 0 (ADC_CTL_CH0) in
        // single-ended mode (default) and configure the interrupt flag
        // (ADC_CTL_IE) to be set when the sample is done.  Tell the ADC logic
        // that this is the last conversion on sequence 3 (ADC_CTL_END).  Sequence
        // 3 has only one programmable step.  Sequence 1 and 2 have 4 steps, and
        // sequence 0 has 8 programmable steps.  Since we are only doing a single
        // conversion using sequence 3 we will only configure step 0.  For more
        // information on the ADC sequences and steps, reference the datasheet.
        //
    		TimerControlTrigger(TIMER0_BASE, TIMER_A, true);
    		for(i=0;i<100;i++)
    		{
        ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE |
                                 ADC_CTL_END);
    
        //
        // Since sample sequence 3 is now configured, it must be enabled.
        //
        ADCSequenceEnable(ADC0_BASE, 3);
    
        //
        // Clear the interrupt status flag.  This is done to make sure the
        // interrupt flag is cleared before we sample.
        //
        ADCIntClear(ADC0_BASE, 3);
    
        //
        // Sample AIN0 forever.  Display the value on the console.
        //
      //  while(1)
    	//for(i=0;i<100;i++)
       // {
            //
            // Trigger the ADC conversion.
            //
           // ADCProcessorTrigger(ADC0_BASE, 3);
    			//TimerControlTrigger(TIMER0_BASE, TIMER_A, true);
    
            //
            // Wait for conversion to be completed.
            //
            while(!ADCIntStatus(ADC0_BASE, 3, false))
            {
            }
    
            //
            // Clear the ADC interrupt flag.
            //
            ADCIntClear(ADC0_BASE, 3);
    
            //
            // Read ADC Value.
            //
            ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value1);
    //i= pui32ADC0Value;
            //
            // Display the AIN0 (PE7) digital value on the console.
            //
           // UARTprintf("AIN0 = %4d\r", pui32ADC0Value[0]);
    data1[i]=pui32ADC0Value1[0];
    				//SysCtlDelay(2000);
    			 ADCSequenceDisable(ADC0_BASE, 3);	
    			//	pui32ADC0Value[0]=0;
            //
            // This function provides a means of generating a constant length
            // delay.  The function delay (in cycles) = 3 * parameter.  Delay
            // 250ms arbitrarily.
            //
          //  SysCtlDelay(SysCtlClockGet() / 12);
    			
    				//SysCtlDelay(250);
    			
    			ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH1 | ADC_CTL_IE |
                                 ADC_CTL_END);
    			
    			ADCSequenceEnable(ADC0_BASE, 3);
    			
    			  ADCIntClear(ADC0_BASE, 3);
    			 while(!ADCIntStatus(ADC0_BASE, 3, false))
            {
            }
    			
    			 ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value2);
    			data2[i]=pui32ADC0Value2[0];
    				 ADCSequenceDisable(ADC0_BASE, 3);	
    		//	}
    		
    			//SysCtlDelay(250);
    		
    			ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH2 | ADC_CTL_IE |
                                 ADC_CTL_END);
    			
    			ADCSequenceEnable(ADC0_BASE, 3);
    			
    			  ADCIntClear(ADC0_BASE, 3);
    			 while(!ADCIntStatus(ADC0_BASE, 3, false))
            {
            }
    			
    			 ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value3);
    			data3[i]=pui32ADC0Value3[0];
    				 ADCSequenceDisable(ADC0_BASE, 3);	
    			//}		
    			//SysCtlDelay(250);
    			
    			
    			ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH9 | ADC_CTL_IE |
                                 ADC_CTL_END);
    			
    			ADCSequenceEnable(ADC0_BASE, 3);
    			
    			  ADCIntClear(ADC0_BASE, 3);
    			 while(!ADCIntStatus(ADC0_BASE, 3, false))
            {
            }
    			
    			 ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value4);
    			data4[i]=pui32ADC0Value4[0];
    				 ADCSequenceDisable(ADC0_BASE, 3);	
    		//	SysCtlDelay(250);
    			}	
    			
    			
    			
    			while(1);
    }
    

  • Hi,

    wait, you want to get the 4 chanels at the same time?

    That isn't possible, it is possible to setup them so they are done sequencialy as fast as it can be but not at the same time. Your always using sequencer 3.

    The way you have it, the first chanel gets the sample when the timer triggers it and the second chanel is triggered 1ms after.

  • Hi

    yea instead of 1ms i want it to be like 0.5 ms.But while i am trying to do that the adc samples are not being proper.Like two consecutive sample of a channel are being same or not in the order they should be as per my input.yea its not possible to sample all four channels at the same time i know.At a time i just want one sample from every channel and then again i want the same so i have used one for loop and sequence 3.Hope i could make problem clear to you.thanks so  much for your effort and time.

    Arun

  • Hi,

    could you be more clear about the values you are getting and why you think they are improper? What is the frequency and amplitude of the wave you are providing the ADC?

    Also you still haven't setup the adc trigger event. Even if the default is what you want (wich i dont remember if it is), you should do so.

    Well i am with insomnia right now but also to tired too actualy get up and work on my project wich is mostly electronic so i'll take the oportunity to help you with programing since i don't have to get up :p 

  • Hi

    everyone,

    I have given a proper sine signal with 100 mv amp,25hz freq+200mv offset to 4 channels of tm4c123gh6pm adc.i am using the same input for 4 channels for experimental purpose..The samples are not coming in a particular order,here i have uploaded my  code and the graph of the data i am getting from one channel.Please have a look.

    //*****************************************************************************
    //
    // single_ended.c - Example demonstrating how to configure the ADC for
    //                  single ended operation.
    //
    // Copyright (c) 2010-2013 Texas Instruments Incorporated.  All rights reserved.
    // Software License Agreement
    // 
    //   Redistribution and use in source and binary forms, with or without
    //   modification, are permitted provided that the following conditions
    //   are met:
    // 
    //   Redistributions of source code must retain the above copyright
    //   notice, this list of conditions and the following disclaimer.
    // 
    //   Redistributions in binary form must reproduce the above copyright
    //   notice, this list of conditions and the following disclaimer in the
    //   documentation and/or other materials provided with the  
    //   distribution.
    // 
    //   Neither the name of Texas Instruments Incorporated nor the names of
    //   its contributors may be used to endorse or promote products derived
    //   from this software without specific prior written permission.
    // 
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    // 
    // This is part of revision 2.0.1.11577 of the Tiva Firmware Development Package.
    //
    //*****************************************************************************
    
    #include <stdbool.h>
    #include <stdint.h>
    #include "hw_memmap.h"
    #include "adc.h"
    #include "gpio.h"
    #include "pin_map.h"
    #include "sysctl.h"
    #include "uart.h"
    #include "uartstdio.h"
    #include "timer.h"
    //*****************************************************************************
    //
    //! \addtogroup adc_examples_list
    //! <h1>Single Ended ADC (single_ended)</h1>
    //!
    //! This example shows how to setup ADC0 as a single ended input and take a
    //! single sample on AIN0/PE7.
    //!
    //! This example uses the following peripherals and I/O signals.  You must
    //! review these and change as needed for your own board:
    //! - ADC0 peripheral
    //! - GPIO Port E peripheral (for AIN0 pin)
    //! - AIN0 - PE7
    //!
    //! The following UART signals are configured only for displaying console
    //! messages for this example.  These are not required for operation of the
    //! ADC.
    //! - UART0 peripheral
    //! - GPIO Port A peripheral (for UART0 pins)
    //! - UART0RX - PA0
    //! - UART0TX - PA1
    //!
    //! This example uses the following interrupt handlers.  To use this example
    //! in your own application you must add these interrupt handlers to your
    //! vector table.
    //! - None.
    //
    //*****************************************************************************
    
    //*****************************************************************************
    //
    // This function sets up UART0 to be used for a console to display information
    // as the example is running.
    //
    //*****************************************************************************
    /*void
    InitConsole(void)
    {
        //
        // Enable GPIO port A which is used for UART0 pins.
        // TODO: change this to whichever GPIO port you are using.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    
        //
        // Configure the pin muxing for UART0 functions on port A0 and A1.
        // This step is not necessary if your part does not support pin muxing.
        // TODO: change this to select the port/pin you are using.
        //
        GPIOPinConfigure(GPIO_PA0_U0RX);
        GPIOPinConfigure(GPIO_PA1_U0TX);
    
        //
        // Enable UART0 so that we can configure the clock.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    
        //
        // Use the internal 16MHz oscillator as the UART clock source.
        //
        UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
    
        //
        // Select the alternate (UART) function for these pins.
        // TODO: change this to select the port/pin you are using.
        //
        GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
        //
        // Initialize the UART for console I/O.
        //
        UARTStdioConfig(0, 115200, 16000000);
    }*/
    
    //*****************************************************************************
    //
    // Configure ADC0 for a single-ended input and a single sample.  Once the
    // sample is ready, an interrupt flag will be set.  Using a polling method,
    // the data will be read then displayed on the console via UART0.
    //
    //*****************************************************************************
    int
    main(void)
    {
        //
        // This array is used for storing the data read from the ADC FIFO. It
        // must be as large as the FIFO for the sequencer in use.  This example
        // uses sequence 3 which has a FIFO depth of 1.  If another sequence
        // was used with a deeper FIFO, then the array size must be changed.
        //
        uint32_t pui32ADC0Value1[1],pui32ADC0Value2[1],pui32ADC0Value3[1],pui32ADC0Value4[1];
    	uint32_t data1[100],data2[100],data3[100],data4[100];
    	int i=100;
    
        //
        // Set the clocking to run at 20 MHz (200 MHz / 10) using the PLL.  When
        // using the ADC, you must either use the PLL or supply a 16 MHz clock
        // source.
        // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
        // crystal on your board.
        //
        SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);
    
        //
        // Set up the serial console to use for displaying messages.  This is
        // just for this example program and is not needed for ADC operation.
        //
        //InitConsole();
    
        //
        // Display the setup on the console.
        //
       // UARTprintf("ADC ->\n");
       // UARTprintf("  Type: Single Ended\n");
        //UARTprintf("  Samples: One\n");
        //UARTprintf("  Update Rate: 250ms\n");
        //UARTprintf("  Input Pin: AIN0/PE7\n\n");
    
        //
        // The ADC0 peripheral must be enabled for use.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    
        //
        // For this example ADC0 is used with AIN0 on port E7.
        // The actual port and pins used may be different on your part, consult
        // the data sheet for more information.  GPIO port E needs to be enabled
        // so these pins can be used.
        // TODO: change this to whichever GPIO port you are using.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    
        //
        // Select the analog ADC function for these pins.
        // Consult the data sheet to see which functions are allocated per pin.
        // TODO: change this to select the port/pin you are using.
    		
    	/*timer***********************************/	
    		
    		SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    
    		
    		 TimerConfigure(TIMER0_BASE,TIMER_CFG_PERIODIC);
    		
    		TimerLoadSet(TIMER0_BASE, TIMER_A,20000);          /*set the timer to fs=2 ksps load value */
    		                                                   
    																											/*if timer loading value=5000; fs=1 ksps
    																											* sysclock=20mhz so tsys=1/2000000sec;to get 1ms delay
    																											*we need to load timer with 1ms/0.5us***/
    		  TimerEnable(TIMER0_BASE, TIMER_A);
    		
    		
    		
    		
    		
    		
    		
    		
        //
        GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
    		GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2);
    		GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1);
    		GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4);
    		
    
        //
        // Enable sample sequence 3 with a processor signal trigger.  Sequence 3
        // will do a single sample when the processor sends a signal to start the
        // conversion.  Each ADC module has 4 programmable sequences, sequence 0
        // to sequence 3.  This example is arbitrarily using sequence 3.
        //
      //  ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
    		
    	//	ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0);
    
        //
        // Configure step 0 on sequence 3.  Sample channel 0 (ADC_CTL_CH0) in
        // single-ended mode (default) and configure the interrupt flag
        // (ADC_CTL_IE) to be set when the sample is done.  Tell the ADC logic
        // that this is the last conversion on sequence 3 (ADC_CTL_END).  Sequence
        // 3 has only one programmable step.  Sequence 1 and 2 have 4 steps, and
        // sequence 0 has 8 programmable steps.  Since we are only doing a single
        // conversion using sequence 3 we will only configure step 0.  For more
        // information on the ADC sequences and steps, reference the datasheet.
        //
    		TimerControlTrigger(TIMER0_BASE, TIMER_A, true);
    		for(i=0;i<100;i++)
    		{
    			ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0);
        ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE |
                                 ADC_CTL_END);
    
        //
        // Since sample sequence 3 is now configured, it must be enabled.
        //
        ADCSequenceEnable(ADC0_BASE, 3);
    
        //
        // Clear the interrupt status flag.  This is done to make sure the
        // interrupt flag is cleared before we sample.
        //
        ADCIntClear(ADC0_BASE, 3);
    
        //
        // Sample AIN0 forever.  Display the value on the console.
        //
      //  while(1)
    	//for(i=0;i<100;i++)
       // {
            //
            // Trigger the ADC conversion.
            //
           // ADCProcessorTrigger(ADC0_BASE, 3);
    			//TimerControlTrigger(TIMER0_BASE, TIMER_A, true);
    
            //
            // Wait for conversion to be completed.
            //
            while(!ADCIntStatus(ADC0_BASE, 3, false))
            {
            }
    
            //
            // Clear the ADC interrupt flag.
            //
            ADCIntClear(ADC0_BASE, 3);
    
            //
            // Read ADC Value.
            //
            ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value1);
    //i= pui32ADC0Value;
            //
            // Display the AIN0 (PE7) digital value on the console.
            //
           // UARTprintf("AIN0 = %4d\r", pui32ADC0Value[0]);
    data1[i]=pui32ADC0Value1[0];
    				//SysCtlDelay(2000);
    			 ADCSequenceDisable(ADC0_BASE, 3);	
    			//	pui32ADC0Value[0]=0;
            //
            // This function provides a means of generating a constant length
            // delay.  The function delay (in cycles) = 3 * parameter.  Delay
            // 250ms arbitrarily.
            //
          //  SysCtlDelay(SysCtlClockGet() / 12);
    			
    				//SysCtlDelay(250);
    			ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0);
    			ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH1 | ADC_CTL_IE |
                                 ADC_CTL_END);
    			
    			ADCSequenceEnable(ADC0_BASE, 3);
    			
    			  ADCIntClear(ADC0_BASE, 3);
    			 while(!ADCIntStatus(ADC0_BASE, 3, false))
            {
            }
    			
    			 ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value2);
    			data2[i]=pui32ADC0Value2[0];
    				 ADCSequenceDisable(ADC0_BASE, 3);	
    		//	}
    		
    			//SysCtlDelay(250);
    		
    			ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH2 | ADC_CTL_IE |
                                 ADC_CTL_END);
    			
    			ADCSequenceEnable(ADC0_BASE, 3);
    			
    			  ADCIntClear(ADC0_BASE, 3);
    			 while(!ADCIntStatus(ADC0_BASE, 3, false))
            {
            }
    			
    			 ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value3);
    			data3[i]=pui32ADC0Value3[0];
    				 ADCSequenceDisable(ADC0_BASE, 3);	
    			//}		
    			//SysCtlDelay(250);
    			ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0);
    			
    			ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH9 | ADC_CTL_IE |
                                 ADC_CTL_END);
    			
    			ADCSequenceEnable(ADC0_BASE, 3);
    			
    			  ADCIntClear(ADC0_BASE, 3);
    			 while(!ADCIntStatus(ADC0_BASE, 3, false))
            {
            }
    			
    			 ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value4);
    			data4[i]=pui32ADC0Value4[0];
    				 ADCSequenceDisable(ADC0_BASE, 3);	
    		//	SysCtlDelay(250);
    			}	
    			
    			
    			
    			while(1);
    }
    

    This no way looks like a sine what i am giving as input.I dnt understand where i am doing wrong.As per my calculation my adc is working with 500sps for each channel as after 1 ms i am switching the channel and there are 4 channels in total i am using.Why i am not getting a proper data.please help me with this.

    Thanks

    Arun

  • Hi Amit

    According to your suggestion I have implemented the code with timer interrupt.but It seems like I am not getting appropriate sample values as per my input.My input is 25hz,100mvp-p with 200mv offset.here i have attached the code and the graph of the sampled output for one channel.please have a look.I am really not understanding how can i improve the adc output.

    //*****************************************************************************
    //
    // periodic_16bit.c - Example demonstrating a periodic 16-bit timer.
    //
    // Copyright (c) 2010-2013 Texas Instruments Incorporated.  All rights reserved.
    // Software License Agreement
    // 
    //   Redistribution and use in source and binary forms, with or without
    //   modification, are permitted provided that the following conditions
    //   are met:
    // 
    //   Redistributions of source code must retain the above copyright
    //   notice, this list of conditions and the following disclaimer.
    // 
    //   Redistributions in binary form must reproduce the above copyright
    //   notice, this list of conditions and the following disclaimer in the
    //   documentation and/or other materials provided with the  
    //   distribution.
    // 
    //   Neither the name of Texas Instruments Incorporated nor the names of
    //   its contributors may be used to endorse or promote products derived
    //   from this software without specific prior written permission.
    // 
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    // 
    // This is part of revision 2.0.1.11577 of the Tiva Firmware Development Package.
    //
    //*****************************************************************************
    
    #include <stdbool.h>
    #include <stdint.h>
    //#include "hw_ints.h"
    #include "hw_memmap.h"
    #include "gpio.h"
    #include "interrupt.h"
    #include "pin_map.h"
    #include "sysctl.h"
    #include "timer.h"
    #include "uart.h"
    #include "uartstdio.h"
    #include "adc.h"
    #include "tm4c123gh6pm.h"
    //*****************************************************************************
    //
    //! \addtogroup timer_examples_list
    //! <h1>16-Bit Periodic Timer (periodic_16bit)</h1>
    //!
    //! This example shows how to configure Timer0B as a periodic timer with an
    //! interrupt triggering every 1ms.  After a certain number of interrupts, the
    //! Timer0B interrupt will be disabled.
    //!
    //! This example uses the following peripherals and I/O signals.  You must
    //! review these and change as needed for your own board:
    //! - TIMER0 peripheral
    //!
    //! The following UART signals are configured only for displaying console
    //! messages for this example.  These are not required for operation of
    //! Timer0.
    //! - UART0 peripheral
    //! - GPIO Port A peripheral (for UART0 pins)
    //! - UART0RX - PA0
    //! - UART0TX - PA1
    //!
    //! This example uses the following interrupt handlers.  To use this example
    //! in your own application you must add these interrupt handlers to your
    //! vector table.
    //! - INT_TIMER0B - Timer0BIntHandler
    //
    //*****************************************************************************
    
    //*****************************************************************************
    //
    // Number of interrupts before the timer gets turned off.
    //
    //*****************************************************************************
    #define NUMBER_OF_INTS          100
    
    //*****************************************************************************
    //
    // Counter to count the number of interrupts that have been called.
    //
    //*****************************************************************************
    static volatile uint32_t g_ui32Counter = 0;
    uint32_t data1[100],data2[100],data3[100],data4[100];	//uint32_t data1[100],data2[100],data3[100],data4[100];
    //*****************************************************************************
    //
    // This function sets up UART0 to be used for a console to display information
    // as the example is running.
    //
    //*****************************************************************************
    /*
    void
    InitConsole(void)
    {
        //
        // Enable GPIO port A which is used for UART0 pins.
        // TODO: change this to whichever GPIO port you are using.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    
        //
        // Configure the pin muxing for UART0 functions on port A0 and A1.
        // This step is not necessary if your part does not support pin muxing.
        // TODO: change this to select the port/pin you are using.
        //
        GPIOPinConfigure(GPIO_PA0_U0RX);
        GPIOPinConfigure(GPIO_PA1_U0TX);
    
        //
        // Enable UART0 so that we can configure the clock.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    
        //
        // Use the internal 16MHz oscillator as the UART clock source.
        //
        UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
    
        //
        // Select the alternate (UART) function for these pins.
        // TODO: change this to select the port/pin you are using.
        //
        GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
        //
        // Initialize the UART for console I/O.
        //
        UARTStdioConfig(0, 115200, 16000000);
    }*/
    
    //*****************************************************************************
    //
    // The interrupt handler for the Timer0B interrupt.
    //
    //*****************************************************************************
    void
    Timer0AIntHandler(void)
    {
      uint32_t pui32ADC0Value1[1],pui32ADC0Value2[1],pui32ADC0Value3[1],pui32ADC0Value4[1];
    
        //
        // Clear the timer interrupt flag.
        //
    	 TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    	GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
    		GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2);
    		GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1);
    		GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4);
    
    	ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
    	
    	 ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE |
                                 ADC_CTL_END);
    	
    	  ADCSequenceEnable(ADC0_BASE, 3);
       
    ADCProcessorTrigger(ADC0_BASE, 3);
        //
        // Update the periodic interrupt counter.
        //
       // g_ui32Counter++;
    
    	// SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    	
    
    	   ADCIntClear(ADC0_BASE, 3);
    	  while(!ADCIntStatus(ADC0_BASE, 3, false))
            {
            }
    				ADCIntClear(ADC0_BASE, 3);
    ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value1);
    				data1[g_ui32Counter]=pui32ADC0Value1[0];
    				pui32ADC0Value1[0]=0;
    				ADCSequenceDisable(ADC0_BASE, 3);
        //
    				
    	
    
    
    				
    	ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH1 | ADC_CTL_IE |
                                 ADC_CTL_END);
    	
    	  ADCSequenceEnable(ADC0_BASE, 3);
       
    ADCProcessorTrigger(ADC0_BASE, 3);
        //
        // Update the periodic interrupt counter.
        //
       // g_ui32Counter++;
    
    	// SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    	
    
    	   ADCIntClear(ADC0_BASE, 3);
    	  while(!ADCIntStatus(ADC0_BASE, 3, false))
            {
            }
    				ADCIntClear(ADC0_BASE, 3);
    ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value2);
    				data2[g_ui32Counter]=pui32ADC0Value2[0];
    				pui32ADC0Value2[0]=0;
    				ADCSequenceDisable(ADC0_BASE, 3);
        //			
    
    
    
    
    
    				
    				
    	ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH2 | ADC_CTL_IE |
                                 ADC_CTL_END);
    	
    	  ADCSequenceEnable(ADC0_BASE, 3);
       
    ADCProcessorTrigger(ADC0_BASE, 3);
        //
        // Update the periodic interrupt counter.
        //
       // g_ui32Counter++;
    
    	// SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    	
    
    	   ADCIntClear(ADC0_BASE, 3);
    	  while(!ADCIntStatus(ADC0_BASE, 3, false))
            {
            }
    				ADCIntClear(ADC0_BASE, 3);
    ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value3);
    				data3[g_ui32Counter]=pui32ADC0Value3[0];
    				pui32ADC0Value3[0]=0;
    				ADCSequenceDisable(ADC0_BASE, 3);
        //			
    	
    
    				
    				
    				
    	ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH9 | ADC_CTL_IE |
                                 ADC_CTL_END);
    	
    	  ADCSequenceEnable(ADC0_BASE, 3);
       
    ADCProcessorTrigger(ADC0_BASE, 3);
        //
        // Update the periodic interrupt counter.
        //
       // g_ui32Counter++;
    
    	// SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    	
    
    	   ADCIntClear(ADC0_BASE, 3);
    	  while(!ADCIntStatus(ADC0_BASE, 3, false))
            {
            }
    				ADCIntClear(ADC0_BASE, 3);
    ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value4);
    				data4[g_ui32Counter]=pui32ADC0Value4[0];
    				pui32ADC0Value4[0]=0;
    				ADCSequenceDisable(ADC0_BASE, 3);
        //		
    
    				
    				
    			g_ui32Counter++;	
    				
    				
    				
        //
        if(g_ui32Counter == NUMBER_OF_INTS)
        {
            //
            // Disable the Timer0B interrupt.
            //
            IntDisable(INT_TIMER0A);
    
            //
            // Turn off Timer0B interrupt.
            //
            TimerIntDisable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    
            //
            // Clear any pending interrupt flag.
            //
            TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
        }
    }
    
    //*****************************************************************************
    //
    // Configure Timer0B as a 16-bit periodic counter with an interrupt
    // every 1ms.
    //
    //*****************************************************************************
    int
    main(void)
    {
        //uint32_t ui32PrevCount = 0;
     // uint32_t pui32ADC0Value1[1],pui32ADC0Value2[1],pui32ADC0Value3[1],pui32ADC0Value4[1];
    //	uint32_t data1[100],data2[100],data3[100],data4[100];
    //	int i=100;
        //
        // Set the clocking to run directly from the external crystal/oscillator.
        // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
        // crystal on your board.
        //
    	
    	 
    	
         SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |SYSCTL_XTAL_16MHZ);
    	
    	
    	
     // SysCtlADCSpeedSet(SYSCTL_ADCSPEED_500KSPS);
        //
        // The Timer0 peripheral must be enabled for use.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    		SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    	 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    		//SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    	// SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    	// GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
    	//	GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2);
    		//GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1);
    		//GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4);
    /*SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    	 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    	 GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
    		GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2);
    		GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1);
    		GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4);*/
        //
        // Set up the serial console to use for displaying messages.  This is
        // just for this example program and is not needed for Timer operation.
        //
       // InitConsole();
    
        //
        // Display the example setup on the console.
        //
       // UARTprintf("16-Bit Timer Interrupt ->");
       // UARTprintf("\n   Timer = Timer0B");
       // UARTprintf("\n   Mode = Periodic");
       // UARTprintf("\n   Number of interrupts = %d", NUMBER_OF_INTS);
       // UARTprintf("\n   Rate = 1ms\n\n");
    
        //
        // Configure Timer0B as a 16-bit periodic timer.
        //
        TimerConfigure(TIMER0_BASE, TIMER_CFG_A_PERIODIC);
    	 
        //
        // Set the Timer0B load value to 1ms.
        //
        TimerLoadSet(TIMER0_BASE, TIMER_A,40000);
    /*load value =40000 means sampling freq=500hz;
    load value =30000 means sampling fre=667hz;
    load value=20000 means sampling freq=1000hz
    load value=10000 means sampling freq=2000hz
    load value=5000 means sampling freq=4000hz;*/
        //
        // Enable processor interrupts.
        //
        IntMasterEnable();
    
        //
        // Configure the Timer0B interrupt for timer timeout.
        //
        TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    
        //
        // Enable the Timer0B interrupt on the processor (NVIC).
        //
        IntEnable(INT_TIMER0A);
    
        //
        // Initialize the interrupt counter.
        //
        g_ui32Counter = 0;
    
        //
        // Enable Timer0B.
        //
        TimerEnable(TIMER0_BASE, TIMER_A);
    
        //
        // Loop forever while the Timer0B runs.
        //
        while(1);
        //{
            //
            // If the interrupt count changed, print the new value
            //
            //if(ui32PrevCount != g_ui32Counter)
            //{
                //
                // Print the periodic interrupt counter.
                //
               // UARTprintf("Number of interrupts: %d\r", g_ui32Counter);
                //ui32PrevCount = g_ui32Counter;
    					
           // }
       // }
    }
    

    I really have no idea why it is not a proper sine.My input is pure I have checked with oscilloscope.Thaks

    Arun

  • Hi,

    a) Usualy, configurations should not be present in interrupts, but in the main program, at the beginning. Starting an interrupt with GPIOPinTypeADC is not a god idea - usually this kind of settings may take several more hidden cycles, due to the need to be synchronized to the high speed cpu bus. And once a pin type is defined, no need to re-type it every millisecond. So, move them outside interrupts.

    b) You do not provide any explanation for choosing multiple pins for a single input sequence (SS3) and you loose time in interrupt by enabling/disabling and configuring the sequencer. Instead, the sequencer 1 or 2 may be used for four channels/input pins, even for a single signal.

    c) Suggest to keep a single pin enabled for ADC, before interrupt and to check/verify such configuration.

    d) Just in case the problem is still present, would be better to find out what is the pin enabled at the discontinuity moment - see if it is the same in all cases or not.

    Petrei