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.

Not Able to update Real time ADC Data on TFT Screen

Other Parts Discussed in Thread: TM4C129XNCZAD

Hi all,

I'am trying to display the ADC Data on my LCD Display . My problem is i'am not able to update the data continuously on the display.

Initially I've connected a potientometer on the ADC channel for testing purpose.

When I debug the code I get the pot value on the display once, but when i adjust the potentiometer the value does not change on the display screen. I know Iam missing something very small but i'am just not able to click it. below is my code. I've color highlighted all the diff functions for easy recognition

extern  volatile uint32_t adcResult=0;
 uint32_t ui32ADC0Value[1];
int main(Void)
{
//uint32_t i;
    //uint32_t ui32ADC0Value[1];
    /* Setup System Clock */

    ui32SysClock = SysCtlClockFreqSet((SYSCTL_OSC_INT | SYSCTL_USE_PLL |
                                         g_psDisplayMode->ui32VCOFrequency),
                                        g_psDisplayMode->ui32SysClockFrequency);
    g_ui32SysClock = ui32SysClock;




    /* Initialize Peripherals */
    PinoutSet();

    Adc_Init();


    g_pui16SDRAM = SDRAMInit(ui32SysClock);

    if(!g_pui16SDRAM)
    {
       UARTprintf("Application requires SDRAM but this is not present!\n");
       while(1);
    }

    g_pui32DisplayBuffer = (uint32_t *)g_pui16SDRAM;
    g_pui16Palette = (uint16_t *)g_pui16SDRAM;


    /* Launch GUI */
    gui_Init();


    /* Super Loop */
    while(1)
    {
        /* Check for System Status Icons */

        /* Take a break, Have a KitKat */
        SysCtlDelay(ui32SysClock/100);

        /* Handle UI Inputs */
        WidgetMessageQueueProcess();
    }
}
void Adc_Init()
{

    SysCtlPeripheralDisable(SYSCTL_PERIPH_ADC0);

        SysCtlPeripheralReset(SYSCTL_PERIPH_ADC0);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

    while(!(SysCtlPeripheralReady(SYSCTL_PERIPH_ADC0)));

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

        while(!(SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOE)));
        GPIOPinTypeADC(GPIO_PORTE_BASE,GPIO_PIN_5);
}


void Adc_Read()
{
                                    ADCSequenceDisable(ADC0_BASE, 3);
                                    ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);

                                    ADCSequenceStepConfigure(ADC0_BASE,3,0,ADC_CTL_CH8|ADC_CTL_IE|ADC_CTL_END);

                                    ADCSequenceEnable(ADC0_BASE, 3);
                                    ADCIntClear(ADC0_BASE, 3);
                                    ADCProcessorTrigger(ADC0_BASE, 3);

                                    while(!ADCIntStatus(ADC0_BASE, 3, false))
                                                {
                                                }
                                                ADCSequenceDataGet(ADC0_BASE, 3, ui32ADC0Value);
                                                adcResult= ui32ADC0Value[0];
}

*******************customized GUI display*******************

#include "common.h"
#include "homeUI.h"
#include "pixbuf.h"
#include "driverlib/sysctl.h"
#include "inc/hw_sysctl.h"
#include "utils/ustdlib.h"
#include "driverlib/adc.h"
//#include "grlib/Container.h"


extern volatile uint32_t ui32SysClock;
 extern volatile uint32_t adcResult;

void gui_Init()
{


    /* Initialize Graphics Driver */
    DisplayInit(ui32SysClock);

    GrRaster16BppDriverInit(g_pui32DisplayBuffer);
    GrContextInit(&guiMainContext, &g_sGrRaster16BppDriver);

    FillScreen(ClrBlack);

    TouchScreenInit(ui32SysClock);
    TouchScreenCallbackSet(WidgetPointerMessage);
    WidgetAdd(WIDGET_ROOT, (tWidget *)&guiBackGround);
    //WidgetAdd(WIDGET_ROOT, (tWidget *)&guiAcquisitionPage);
    WidgetPaint(WIDGET_ROOT);
    WidgetMessageQueueProcess();
    void Adc_Read();
    void OnIntroPaint(tWidget *psWidget, tContext *psContext);
 
}

Canvas(guiBackGround, WIDGET_ROOT, 0, 0, &g_sGrRaster16BppDriver,
       X_OFFSET, Y_OFFSET, 800, 480,
       CANVAS_STYLE_APP_DRAWN,
                                  0, 0, 0, 0, 0, 0, OnIntroPaint);


void OnIntroPaint(tWidget *psWidget, tContext *psContext)
{
    char sensorValue[100];

    while(1)
    {
    Adc_Read();
    usprintf(sensorValue,"%d", adcResult );
    GrContextFontSet(psContext, g_psFontCmss32b);
                GrContextForegroundSet(psContext, ClrCyan);
                GrStringDraw(psContext, "Heart Rate = ", -1,
                                             250, 250, 0);
                GrStringDraw(psContext, sensorValue, 10,
                                 500, 250, true);

                WidgetPaint(WIDGET_ROOT);
    }
}

  • Sumit Mourya said:
    When I debug the code I get the pot value on the display once, but when i adjust the potentiometer the value does not change on the display screen.

    My friend - good job (Bravo) on:

    • using the forum's code editor
    • color-coding different code sections for (your) and your helpers ease/clarity

    That said - you've NOT complied w/KISS - have you?   Your troubleshooting does NOT directly deal w/that ADC value!   Instead - transfers it (we (only) hope successfully) to your TFT screen.   This signals that, "one or two of two" program elements may be improper:

    • your ADC operation - on subsequent ADC loops - may be bad
    • your transmission of the ADC value to the TFT - and any further processing - may be bad
    • or both

    KISS very much assists by enabling your focus on, "One and only one" program element at a time.   Thus should not you employ your IDE to insure that "all subsequent ADC values prove correct" - BEFORE you transfer them to your TFT?   As good as your descriptive write-up is - we don't note that fact!

    Now it may be that your IDE does not allow your "read" of the ADC as such intrusion (by the IDE) "spoils" the ADC reading.   Should this prove the case - does it not prove useful to copy your ADC result to (another/SAFER) variable - which may then be (regularly) examined - to greatly improve your test/troubleshoot?

    I (now) note that you've done that - your result is w/in variable adcResult.   Does that variable reflect your (changed) pot position?

    Also is Port_E pin 5 (really) represented by "ADC_CTL_CH8?   Perhaps you are not really "connected" as you hope...   Have you read the voltage - at the MCU - on your targeted ADC pin.   (Be careful!)

    Overall a very nice forum presentation - please do consider KISS - its "free" - immensely helpful - and vastly under-promoted here & "most schools."

  • Hi Cb1_mobile,

    thanks for replying to my post!

    POINT 1 :-

    when you say " I (now) note that you've done that - your result is w/in variable adcResult.   Does that variable reflect your (changed) pot position? 

    Answer - yes it does. when i check  below code using breakpoint at ADCIntClear(ADC0_BASE, 3), i get the changed value (0-4096) on( "watch expression in refresh all windows mode") adcResult when I change the pot position .

    while(1)

    {

    ADCIntClear(ADC0_BASE, 3);
                                        ADCProcessorTrigger(ADC0_BASE, 3);

                                        while(!ADCIntStatus(ADC0_BASE, 3, false))
                                                    {
                                                    }
                                                    ADCSequenceDataGet(ADC0_BASE, 3, ui32ADC0Value);
                                                    adcResult= ui32ADC0Value[0];
    }

    POINT 2 :-

    Also is Port_E pin 5 (really) represented by "ADC_CTL_CH8?   Perhaps you are not really "connected" as you hope...   Have you read the voltage - at the MCU - on your targeted ADC pin.

     

    ANSWER-
    Iam using TM4C129XNCZAD MCU. The datasheet says that PE5 is AIN8.

    I dont know where iam doing it wrong. pls help

  • Well answered - thank you.   Today is "moving day" @ my firm's (giant) contractor.   May be several hours (perhaps less) before I can reestablish net connection.

    As you succeed w/your transfer once - but only once - I suggest that you look very closely at that transfer code - and seek to, "RETURN to the initial conditions" of that first (and only) successful transfer.   It seems likely that (something) is changing - which precludes the (proper) arrival of new data.

    As we are (now) operating in accord w/KISS - cannot you monitor the data transfer to the TFT?   Usually it is necessary to "Readdress the screen cursor" so that you may "over-write" the (earlier) data.   I suspect that:

    • you are not passing NEW data to the correct screen address (same as the first transfer did)
    • your TFT screen handler is NOT replacing the first (successful) value w/subsequent ones

    This should get you going until I (or another) returns.   I've been in the display biz for a LONG time - we've not encountered such an issue.   Usually data goes to the WRONG screen location - which enables the FIRST data sent to "persist" - and in this case the new screen data is noted.   (imperfectly positioned/located)

  • Hi,

    I was able to resolve the issue. All i had to do is add the AdcInit() function along with AdcRead(). I was thinking that I have to Intitalize the Adc only once , but that is not the case. Adc initialization has to be done evry time if you want a new value.

    Learned something new from this problem.

    void OnIntroPaint(tWidget *psWidget, tContext *psContext)

    {

       char sensorValue[100];

    Adc_Init();

       Adc_Read();

       usprintf(sensorValue,"%d", adcResult );

       GrContextFontSet(psContext, g_psFontCmss32b);

                   GrContextForegroundSet(psContext, ClrCyan);

                   GrStringDraw(psContext, "Heart Rate = ", -1,

                                                250, 250, 0);

                   GrStringDraw(psContext, sensorValue, 10,

                                    500, 250, true);

                   WidgetPaint(WIDGET_ROOT);

      

    }

  • Sumit Mourya said:
    Adc initialization has to be done every time if you want a new value.

    Very much doubt that - my friend!   (i.e. such cannot be true!)

    Perhaps Amit (or other) vendor staff will confirm - but in our (many) years of ADC usage - NEVER/EVER have we found the need for "every time" ADC init...

  • Even i never thought it would work that way!! I was surprised as well.
    when i tried to print a simple counter by writing " adcResult=adcResult+1" instead of "adcResult= ui32ADC0Value[0]" , the up counter was displayed with the value increasing everytime.

    Then I Realized that my ADC is not getting initialized the second time. i pulled off the "Adc_Init()" from main function and placed it inside "OnIntroPaint(tWidget *psWidget, tContext *psContext)" function.

    And it started working.
  • That is NOT proof! Something else is amiss - I assure you that some way/how you are (improperly) operating the ADC.
  • Agreed, I've likewise found no need to re-init the A/D.

    Maybe the A/D is not being re-triggered?

    Robert
  • Merci monsieur Robert.

    Hard to argue w/always (impressive), "Self-Awarded, Verify Answer!"
  • I'm not arguing with anybody. I'm just a beginner in coding and you guys are expert, perhaps that's why I'm here to find a solution to my problem. I'm just telling the way the code is behaving.
    I know that re initializing the ADC every time is not the correct way(that's why I'm stuck with this problem for 1 week) . I just want to know where am I doing it wrong ?
  • Nor are (we) arguing w/you - yet it is our "duty" to record our "doubt" for the need for Each/Every time an A/D re-init. Such would (gravely) reduce the ADC's throughput - cannot be required.

    May I suggest that you review vendor's API Source code - focused upon your ADC Init().   It seems likely that something you're doing is causing some change(s) to that init - and (that) explains why (excess) ADC inits are required.

    One other (potential) issue dawns - that being that the ADC init() is NOT (really) required - but the "added time it requires" enables the ADC to continue its operation. You may test for this condition by employing (other, blind to the ADC) function calls (in place of ADC init) (i.e. repeatedly blink an Led) and noting if they too - enable your ADC to function properly...

  • Sumit Mourya said:
    . I just want to know where am I doing it wrong ?

    I did give you a suggestion, have you explored it?

    Robert