PDA

View Full Version : Want to display less decimal places on LCD from 16bit ADC



Ryan7777
- 12th June 2015, 15:47
Hi all,

I am reading a 0-10VDC signal with a 16-bit ADC.

So I am taking the LONG (just in case I need the room later) variable that I am reading that 16bit number into, lets say 10 volts for %1111111111111111 (65535) and multiplying it by 15259 to get = 999998565

And then to read it out on my LCD, I'm doing the typical:

LCDOUT $FE, 1 DEC myADCvariable / 100000000, "." , DEC8 myADCvariable // 100000000

to get a nice decimal representation of the voltage = 9.99998565

The issue is that I want to only see the first 4 decimal places to the right of the decimal, as there is some noise (out of my control, reading from a board that has the 16bit ADC and I can't add filter caps to it etc.) and the last few bits flip around.

I've tried everything that I can think of, but not coming up with a solution.

If I try: LCDOUT $FE, 1 DEC myADCvariable / 100000000, "." , DEC4 myADCvariable // 1000 - then I get = 9.8565 and those last four digits are going crazy... and they are the wrong 4 digits anyway!

I need = 9.9999 (well closer to 10.0 whatever with a calibration factor, but one problem at a time.)

What do I need to be doing to only get the decimal places I need and mask the ones I don't? :confused:

Thanks!

Ryan

Dave
- 12th June 2015, 18:20
Ryan, just take the modulo part and send it to another variable. Then display with as many digits as you like. Something like this:
myADCvariable_fraction = myADCvariable // 100000000
LCDOUT $FE, 1 DEC myADCvariable / 100000000, "." , myADCvariable_fraction / 10000
That should give you 4 decimal places.

Ryan7777
- 12th June 2015, 22:14
Thanks so much, Dave!

Works great!

This is what I ended up with just in case someone else ever needs to know:



DataIn VAR WORD
DataInLong VAR LONG
DataInLong_fraction VAR LONG

DataIn = %1111111111111111

LCDOUT $FE, 2, "VOLTAGE IN BINARY:"
LCDOUT $FE, $C0, BIN16 DataIn
DataInLong = (DataIn * 15259)
DataInLong_fraction = DataInLong // 100000000
LCDOUT $FE, $94, "VOLTAGE IN DECIMAL:"
LCDOUT $FE, $D4, DEC DataInLong / 100000000, ".", DEC4 DataInLong_fraction / 10000

On my LCD if DataIn is full %1111111111111111 - I now get:

VOLTAGE IN BINARY:
1111111111111111
VOLTAGE IN DECIMAL:
9.9999

Like I expect

Thanks again! :D