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.

Value of 16F877A ADC in decimal

Status
Not open for further replies.

Mortalo

New Member
Hi !

Im doing a project using the adc (ADRESH(easier) => 8bits) and LCD. I'm using a configuration that in the input of the adc i'm gonna have 5v when im sensing 10Amp. 2.5v when im sensing 5AMP and so on.
so i need the value of the adc in volts and then to multiply that value for 2.
So i i'm thinking that i need to do this.

ADCVal = ( Vin *255 ) / 5

so i need vin..

vin = ( ADCVal * 5 ) / 255

Asumming that my vin is 2.5v the adc will read 7F, 127 in decimal so substituting in the formula.

vin = (127 * 5 ) / 255 = 2.49v

Now i multiply that for 2 to get amps.

2.49 * 2 = 4.9 amps.

i need to send 4.9 amps to the LCD, so im thinking to multiply 4.9 by 10 to have 49 an then by some means, im going to extract the 4 and then convert it to ASCII send it to the LCD, send the " . " and then convert the 9 in ASCII and sen it to the LCD.

The problem is that i dont have any idea on how to begin converting bin to decimal in PIC, and after i have a value like " 49 " how to extrat the 4 and the 9 to send it to the LCD in ASCII.

If any of you coul teach me an easier way to do this it would be cool or some routines to do what i want.

I have encountered some routines to convert binary to BCD but i dont want the digits extracted because i need to substitute the ADCval in Decimal. Well im confused.

Thanks.
 
hi,
There is a recent thread asking the same question.

How to convert binary/hex to decimal/ascii for a display.

Look a Nigels tutorials.
Here:


IIRC Tutorial 3.2, a conversion routine in part of the tut.
 
Last edited:
As suggested, my tutorials include what you need - to multiply by 2 a simple binary shift is all that's required. You also don't need any silly multiply by tens either, simply keep the numbers as integers and insert the decimal point where it needs to go in the display routine.

Check tutorial 11 for details.
 
Amp calculation

I don't think your calculation will always be correct, you need to AD the amps directly by using a 1 Ohm resistor in your circuit and measure the voltage drop over the 1 Ohm resistor if there is a 25 ma thru the resistor you will get a 25mv voltage drop, so you have to use two AD channels one for volt and one for amp
 
Last edited:
hi chrismicro im planing to sense 0 - 10 amp. a friend of mine is doing the hardware for that. So hes gonna make sure that at 10 amp i'm going to send 5volts to the ADC. 5 amps 2.5 volts you know linear.

So i need to send those values to the LCD in case that the value of the current its fractionary like 6.6 amps for example, i'm going to sense in the ADC the voltaje corresponding thats going to be 3.3 volts in 8 bits the converter.

And thats where the trouble begins.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top