Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

problem of display number on LCD

Status
Not open for further replies.

meera83

New Member
i m using PIC16F877, i want to display ADC(0-5V) on LCD display that show a number 0.00-10.00..

i didn't use floating point instead i used decimal point to display the 2 digit of division..

the problem is the biggest number that is showed will become out of range..

for example, the formula is x multiply 393 div 100 = y

when x= 250, y=982 and i will manually put a decimal point after the number of 9 so y=9.82

but when x=254, y=998 ==9.98
and at maximum x=255, y=1002 ==10.02

but the maximum number that i want to show is 10.00..so how to make a change on the formula in order to let the display show only 0.00-10.00??
 
Don't need the division, just drop the lowest byte!
255 * 1000 = 255000 = (0003 E418)h
drop last byte from result will return (0000 03E4) = 1000 = 10.00

178 * 1000 / 255 = 698.0392
178 * 1000 = (0002 B750)h = (0000 02B7)h = 695 = 6.95
 
bananasiong said:
x multiply 1000 div 255 = y
Well, Meera's formula is intended to be the same. x multiply 393 div 100. But, the value 393 is incorrect. She should be using 392.

1000 / 255 == 392.1568...

Mike
 
mcs51mc said:
Don't need the division, just drop the lowest byte!
255 * 1000 = 255000 = (0003 E418)h
drop last byte from result will return (0000 03E4) = 1000 = 10.00

178 * 1000 / 255 = 698.0392
178 * 1000 = (0002 B750)h = (0000 02B7)h = 695 = 6.95

Huh? 0000 03E4 = 996 not 1000

This technique does give approximate results because what you are really doing is ( x * 1000 ) / 256 instead of ( x * 1000 ) / 255

Mike
 
mike50 said:
Huh? 0000 03E4 = 996 not 1000
Shame on me :(

mike50 said:
This technique does give approximate results because what you are really doing is ( x * 1000 ) / 256 instead of ( x * 1000 ) / 255

Mike
The (almost) correct way is to multiply the input by 3.921569........
To keep accuracy multiply that by 256 to get 1003.921569
Closest integer is 1004

Calculate as follow
1) Operand A = x (unsigned 8 bit)
2) Operand B = 1004 (unsigned 16 bit)
3) Result = Op A * Op B (unsigned 24 bit)
4) Drop lowest byte of 24 bit result

Op A = x = 178 = (B2)h
Op B = 1004 = (03EC)h
Result = 178712 = (02 BA 18)h
Drop last byte result in (02 BA)h = 698 = 6.98

Evaluation in Excel shows max error of 0.0098 on final result (xx.xx)!!
Is this accurate enough??
 
mcs51mc said:
Shame on me :(


The (almost) correct way is to multiply the input by 3.921569........
To keep accuracy multiply that by 256 to get 1003.921569
Closest integer is 1004

Calculate as follow
1) Operand A = x (unsigned 8 bit)
2) Operand B = 1004 (unsigned 16 bit)
3) Result = Op A * Op B (unsigned 24 bit)
4) Drop lowest byte of 24 bit result

Op A = x = 178 = (B2)h
Op B = 1004 = (03EC)h
Result = 178712 = (02 BA 18)h
Drop last byte result in (02 BA)h = 698 = 6.98

Evaluation in Excel shows max error of 0.0098 on final result (xx.xx)!!
Is this accurate enough??

Yes, this is the best way to do it. y = ( x * 1004 ) / 256 gives the most accurate answer using integer multiplication only and no division (since division by 256 is free).

Thanks for a wonderful technique.

Mike
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top