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.

TM4C1294NCPDT: Uniform ADC sampling using TIVA tm4c129NCPDT board

Part Number: TM4C1294NCPDT

Hi,

 i want take adc samples using tiva board , i tried with the tiva example code on tiva TM4c129 board in that i am taking samples from the adc along with that time stamp from the Hibernation module (sec : sub seconds)

and i am sending that data to the UART at 460800 baud rate i am able to get the samples , but the problem is sampling time is not uniform (i observed the sub seconds counter , the interval between each sample is changing ). how to make it as uniform as much as possible.

thank you in advance.

  • Rupendra,
    Apparently your issue is not related to the ADC (actually, it surely is not). Rather, it is a matter of how you are structuring your code execution.
    - Look carefully at your code, understand WHEN is each function called.
    - WHEN do you get your timestamps? At the same moment in which you put the text output message together? Or at the moment in which you just finished the ADC reading?
    - Consider that it does not make sense to execute ONE ADC reading for every "visual" output of your values: you typically need to sample it much faster, apply some filtering or other processing, and output the results on a slower rate.
    Draw some code blocks, visualize your interrupts, time controlling, and so on, and you will figure out how to create a regular, stable timed execution.
    Cheers
    Bruno
  • Greetings Bruno,

    Well advised - although "paragraphing/bullet-pointing" would make those sound ideas (more) visually appealing.       (more - to be kind)

    At its heart - you've suggested:

    • "break-up" of the "whole" into individually probed/analyzed - constituent parts
    • observation & possible alteration of code's execution chronology
    • "speed, ease, enhance" such "code design & analysis" via block diagrams (possibly flow-charts) - which highlight relationships, interconnects, and sequences

    Such ARE the "Rules of KISS" - which direct attention to, "One Small and "Measurable" Step at a time - ONLY when that "step is proven/verified" - may one proceed! 

    It is that (vital) "Laser Focus" (one small step) - and test/verify (via a "carefully" chosen MEASURABLE means) - which your keen analysis does not (to me) adequately highlight - and best drives (and yields) user success.

  • hey thanks for your answers,

       but i am unable to understand what you are saying to give more information about my problem here i am attaching the code and output which i am getting,

      if u observe the output , the difference between the sub seconds counter value is not the same for each sample (time interval) how to make it uniform , is there any possibility by changing code  .

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    #include <stdbool.h>
    #include <stdint.h>
    #include <time.h>
    #include "inc/hw_memmap.h"
    #include "driverlib/adc.h"
    #include "driverlib/adc.c"
    #include "driverlib/gpio.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/uart.h"
    #include "driverlib/uart.c"
    #include "utils/uartstdio.h"
    #include "driverlib/hibernate.h"
    uint32_t g_ui32SysClock;
    void
    ConfigureUART0(void)
    {
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTStdioConfig(0,460800,g_ui32SysClock);
    }
    int
    main(void)
    {
    uint32_t pui32ADC0Value[1]={0};
    g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
    SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
    SYSCTL_CFG_VCO_480), 120000000);
    ConfigureUART0();
    //
    // The ADC0 peripheral must be enabled for use.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    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.
    //
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
    //
    // 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
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Rupendra,

    Thank you for posting the image. I believe the initial explanation was good already, and I had understood what your problem is. For what is worth, the period differences are not too significant.

    Read again what I posted initially, and there is no "running away from it": you WILL NEED to understand what is written there, even if you have to read a few times and search more information about timers and embedded programming in other sites to help you.

    You need to control the timing of your code. Do you understand the timer hardware which is part of your MCU? Are you using timers? Are you using interrupts on the ADC? Do you have an oscilloscope to help you practicing this? You can simply generate timed pulses and measure them on the scope for a clearer understanding.

    One other thing that you need to answer (to yourself) is "when are you recording those time counter values"? Is it when you prepare the text output message? When the sample is finished? Sometime in between?

    There are lots of possible solutions - and for now, we don't even know if there is a problem, because the numbers are close enough and you have not stated what sort of precision is REQUIRED on your project. Getting a bit into the joking side, you can simply use sprintf(outputString,"2033 10:10:7:%04d",adcValue); and you will ALWAYS have a regular interval, won't you? Just an unpolite way of saying that a solution can only be crafted when there is a clear objective.

    Regards

    Bruno

  • Hi Bruno,

    Bruno Saraiva said:
    Apparently your issue is not related to the ADC (actually, it surely is not). Rather, it is a matter of how you are structuring your code execution.

    Actually might posters issue be directly related to the several types of ADC trigger methods available for sampling an analog input signal. My opinion much as yours (comments) seems to point out is application software execution is intertwined with hardware timing control of the ADC samples (window). So how can the ADC be ruled out as not being the cause of a condition noted by posters later print out of varied time stamps.

    It appears poster has some kind of ADC triggered sample window timing, the question then becomes what kind of trigger, how often and when as your key points. Perhaps the poster could show a small portion of ADC configuration for our curiosity?

  • Hello Brett,

    Google Maps reveals the "last hours" of your "Thanksgiving Turkey" - allowed to "free-range" - w/in your (dare I mention) (near) pristine - yet (green-free) "DEAD FET Strewn" (burial ground/back yard.)

    Might the combination of tomorrow's:

    • ingesting that "FET gulping" bird
    • and other "meal prep" - managed by your compact "heater oven" (so often (earlier) used as BP's "reflow solder device") 

    somehow "lessen" your holiday spirit/enjoyment?     (we're told you've the local ER on speed dial)

    The power of that mapping system always amazes - we note the (almost) return of (some) green - upon (each) of your neighbor's yards...       (i.e. discarded FETs may have to be "buried" deeper!)

  • Bruno, that deserves a Like, maybe even a kudo. You're writing some excellent content.

    Robert
  • What - (just) Bruno - timely/topical/EPA (Turkey/FET) comment "escapes" such LIKE?       (even tho - and especially tho - bullet points enhance legibility!)