This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADC value display on Kentec lcd using Tm4c123g launchpad.

Hello,

I am trying to display ADC output on Kentec Lcd using GrStringDraw function but its showing the character on lcd instead of decimal value that is its displaying  'M' instead of 77.

Which graphic lib shall i use to display decimal number.

Thank you

  • Might this work - when reading your ADC the results will vary between 1 and 4 digits. (let's choose 3416 as your (decimal) ADC count/reading)

    Now - when attempting to send that numeric data to your display - you must convert that 12 bit value into, "Decimal Ascii." That may be done by adding 0x30 to each individual ADC digit. (i.e. 3416 is sent to the display as: 0x33 - 0x34 - 0x31 - 0x36)

    Note that your ADC register likely will contain a "Hex value" - which you must convert to decimal. (usually by "hex2dec" code-function)

  • Hello Turjasu,

    To do so first declare a character array

    char pcBuf[50];

    then convert the string by using usnprintf (I used system clock frequency)

    usnprintf(pcBuf, sizeof(pcBuf), "%d", ui32SysClockFreq);

    GrStringDrawCentered(&sContext, pcBuf, -1,
    GrContextDpyWidthGet(&sContext) / 2, 50, false);


    Regards
    Amit
  • Hello Amit,

    I am trying a similar thing, but instead of using the ADC I am using a reed switch to measure rpm. I have the rpm value calculated and stored as the variable timer. I would like to display Timer on the screen, but i keep getting the value D. instead of my string "RPM:  " with the value i want displayed after it. this is my code I'm working with now. I have a function setting up the display value, and then trying to display it on a canvas. I would like to display my variable timer which has the rpm value on the screen. 

    The yellow squiggle says "tContext **" is incompatible with parameter type of "const tContext"

    Then this is for the canvas

    The Yellow squiggle says "void(*)(uint32_t, tContext *)" cannot be used to initialize an entity type of "void(*)(tWidget, tContext *)"

    Thanks,

    Mike 

  • Hello Mike

    Did you try to typecast it?
  • Hello Amit,

    Yes, I think in the code above it i tried typecasting it in the one part i have commented out above. I am not sure what is going wrong i am not getting a value to display or even RPM: i only have an ascii number. Any other suggestions?

    Thanks,

    Michael Winter 

  • Michael Winter75 said:
    The yellow squiggle says "tContext **" is incompatible with parameter type of "const tContext"

    The first argument to GrStringDraw is supposed to be a pointer to type tContext, yet the following line is passing the address of a pointer to type tContext:

    GrStringDraw (&sContext,string,-1,100,50,0);

    That statement should be changed to remove the extraneousness ampersand:

    GrStringDraw (sContext,string,-1,100,50,0);

    Michael Winter75 said:
    The Yellow squiggle says "void(*)(uint32_t, tContext *)" cannot be used to initialize an entity type of "void(*)(tWidget, tContext *)"

    The first argument of the callback function PrintRPM is supposed to be of type tWidget* (grlib type) yet the first argument of the PrintRPM function is a uint32_t for the timer value. The first argument of the PrintRPM function needs to be changed to of type tWidget*. That means the PrintRPM function will need a different means of obtaining the timer value to format for display, e.g. via a global variable.

     

  • Thanks Chester, 

    I fixed what you said, and I am still not able to display what i want. In my code i have listed above I have two ways of doing it. One is commented out, and the other isn't. Which one should I use? the one that i currently done have commented out how does it know that I'm trying to display "RPM: %f"? and the %f is the timer value? Also do I need any special initializations to write a string to a canvas? besides the canvas configuration i have and the function that I'm trying to pass into it? 

    Thank,

    Michael Winter 

  • Hello Amit,

    I tried what you have said, and a lot with trying to get the "RPM: %.1f" for displaying the rpm as a float. I am not getting the output i like instead of seeing RPM i see an ascii value. Any suggestions as to how to fix this or a different way to display this value? 


    Thanks,

    Mike.

  • Michael Winter75 said:
    I tried what you have said, and a lot with trying to get the "RPM: %.1f" for displaying the rpm as a float.

    Which function are you using to format the string?

    Looking at TivaWare 2.1.4.178 there is no support for floating point in the uvsnprintf() function.

    You can use the sprintf() family of functions in the compiler run-time-library to format floating point values, as long as the TI ARM compiler --printf_support option is set to full:

  • Might we ask, "Why would "float" be required to display RPM?"  (especially as a "single" Reed switch serves as low-tech pick-up.)

    You (should) note that Chester has been good enough to report that "float" is NOT supported!    (in your present usage, code situation)

    Burdening the program (and helpers) w/this demand may not make great sense...

  • I figured i would get a decimal point to show as your rpm could be 65.7. As for now should i use %d? instead just to get it to display as one number?

    Thanks,
    Mike
  • i am using sprintf now i wasn't sure which one to used, but I found that sprintf would work best. I am not sure which %d or %f to use. Also i am trying to display "RPM: %d" so shouldn't i see "RPM: " with no number after it if i have not data going into it as a test? The canvas only shows "D."

    Thanks,
    Mike
  • This (really) is Chester's post. (to answer)

    Firm/I have produced/sold hundreds (likely thousands) of RPM tracking/reporting/displaying devices (via motor control) - and rarely (perhaps never) has a decimal point been required.

    Again - Chester has been so good as to report that "float" is incompatible w/your present code implementation.    (and proves w/out (real) merit - w/single Reed switch as input source!)

    KISS dictates that you employ the simplest method possible to, "Get something to (somewhat) work" - only later should your attempt target "refinement and/or perfection!"

  • Yea i have tried it with out the %f or %d to even get just "RPM" to show, but it doesn't. I think it could have something to do with the setup of me trying to pass this as a function into a canvas? I have this as a function called PrintRPM, and i am trying to pass this into the function spot of the canvas. When i type in the text spot of the canvas "RPM" it will show up. I am not sure why it won't work with trying to pass it as a function.

    Thanks,
    Mike
  • You are noting that vendor's Graphic API "giveth" and (sometimes) "taketh away."

    You've been "stuck" in this, "Failed display of RPM" for quite some time - and as this is a VERY common Display requirement - it is hard to understand how this Graphic API has so impeded your highly (predictable) display usage!    You may consider employing (your own) method of "Screen Writes" should Chester prove unable to "crack this bottleneck."   (He's quite good - I'm trying to "ease" his efforts by "killing float"..)

    It would appear that if you are able to, "Place OTHER (not Live/Acquired) Text or Numerals - at the correct Screen Locations" you must (somehow) force/manipulate your, "Live Acquired, RPM Data" into agreement w/the data style/type/format which - more generally - succeeded.

    Should note that as a past Display Vendor - we developed our own Graphic Code System - which (easily/immediately) enables placement of "live, acquired data" upon the "Widget-Free" (thus "Live Data Welcoming") Screen!

  • Michael Winter75 said:
    I think it could have something to do with the setup of me trying to pass this as a function into a canvas?

    I don't have any code myself to demonstrate passing a function into a canvas, but looking at TivaWare_C_Series-2.1.4.178\examples\boards\dk-tm4c129x\grlib_demo\grlib_demo.c that is done in two places:

    - The g_sIntroduction canvas, using the OnIntroPaint function

    - The g_sPrimitives canvas, using the OnPrimitivePaint function

    Do those examples help?