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.

Question on ADC (for PIC16F877A)

Status
Not open for further replies.

Viann

New Member
Hi, I have some questions on the ADC of a PIC.

I understand that the ADC converts an analog signal into a digital signal.
So lets say I have an input of 4V, how the ADC would convert it is that it would give a corresponding digital bit.

My question is, how do we manipulate the corresponding digital bit?

Or if I am somewhat wrong in my understanding, a clearer question would be how I could convert the 5V input into a reading that will digitally state 5V, where that reading would be displayed on an LCD?

Thanks in advance.
 
Check out my tutorials, which explain what you need - but essentially the output of the ADC is from 0-1023 - it's up to you what those numbers represent.
 
If the ref+ is same as the supply voltage then:
5 v / 1024 step = 0.0048828125 = 4.88 mV or round it up to 5 mv per step
When the ADC register read DECIMAL 1 then the ADC input voltage is 0.00488 V, at DEC 512 the ADC input voltage is 2.500V.
To display this value you multiply the ADC register value with 5, so 512 * 5 = 2560 "101000000000", now you convert this binary value to BCD, this way you will have 2,5,6,0 in 4 register.
Display the first digit"2", place a decimal point".", display the second digit"5" and so on if desired.
A few example:
12 *5 = 60 = 0.06 = 60mV /0.06 Volt, actual voltage 0.585 V
383*5 = 1915 = 1.915 V /1.91 Volt, actual voltage 1.870 V
512*5 = 2560 = 2.560 V /2.56 Volt, actual voltage 2.500 V ~+2.4% error
513*5 = 2565 = 2.565 V /2.56 Volt, actual voltage 2.504 V
514*5 = 2570 = 2.570 V /2.57 Volt, actual voltage 2.509 V

1024*5= 5120 = 5.120 V /5.12 Volt the error show here big time, since we are multiplying with 0.005 and not 0.0048828125

If you want a bit better accuracy try to multiply the ACD value with 488 instead of 5
512 * 488 = 249856 = 2.49856 V or 2.49 V actual voltage 2.500 V ~-0.8% error
513 * 488 = 250344 = 2.50344 V or 2.50 V actual voltage 2.504 V
514 * 488 = 250832 = 2.50832 V or 2.50 V actual voltage 2.509 V
515 * 488 = 251320 = 2.51320 V or 2.51 V actual voltage 2.514 V

I would not bother to make better than 100mV resolution out of it.

Hope this helps.
Csaba
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top