ADC value to Digits

10 views
Skip to first unread message

flyway38

unread,
Aug 2, 2022, 6:33:35 AM8/2/22
to jallib
Hello All,

New question.
Sorry if asked already.
I need to find the quickest way to convert my ADC value (10bits) into digits format.
Need to show this result in an Oled Display using my digit fonts in this format; "X.XXX", where max value to show is 5V, so as an example and assuming my ADC is reading half voltage (0x0200) it would show on display "2.500".
Have my code (working ok) here, but wanted to know if there is any better / faster way to do it;

CODE:
   mmVal = (dword(mVal) * 5 * 1000) / 1024
   vShowValU = mmVal / 1000
   vShowValD = (mmVal - vShowValU * 1000) / 100
   vShowValC = (mmVal - vShowValU * 1000 - vShowValD * 100) / 10
   vShowValM = mmVal - vShowValU * 1000 - vShowValD * 100 - vShowValC * 10
   --
   OLED_0in95_rgb_DisplayImage(10,20,byte(vShowValU),fColorH,fColorL,fColorMH,fColorML,20)
   OLED_0in95_rgb_DisplayImage(25,20,10,fColorH,fColorL,fColorMH,fColorML,20)
   -- Decimal DOT OLED_0in95_rgb_DisplayImage(40,20,byte(vShowValD),fColorH,fColorL,fColorMH,fColorML,20)
 OLED_0in95_rgb_DisplayImage(55,20,byte(vShowValC),fColorH,fColorL,fColorMH,fColorML,20)
 OLED_0in95_rgb_DisplayImage(70,20,byte(vShowValM),fColorH,fColorL,fColorMH,fColorML,20)

Thank you all.
Cheers.

Filipe Santos

vsurducan

unread,
Aug 3, 2022, 12:41:53 AM8/3/22
to jal...@googlegroups.com
5V/1024=0.0049 (rounded). That means it's worth it to display max 2.50, there is no better resolution. ( 2.500, 2.505 or 2.495 are all in the same ADC resolution error, last digit should be then absent).
Perhaps integrating your OLED library with the format library?

--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/faab018f-fd46-488a-82ba-a898d98c5128n%40googlegroups.com.

flyway38

unread,
Aug 4, 2022, 7:22:56 AM8/4/22
to jallib
Hi Vasile,

Thankyou for the heads up.

FS
Reply all
Reply to author
Forward
0 new messages