newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Fri Nov 03, 2006 10:31 pm |
|
|
If the A/D converter is set to 8 bit resolution, change "1023" to "255". The following is for 10 bit resolution.
binary reading = (analog voltage/reference voltage) * 1023
Example: PIC's A/D Vref+ (positive reference) is +5V, analog input voltage = 3.0V: binary reading = 613.8 which may appear as either 613 or 614.
Note that there is a limit to the actual Vref+ you can use if you opt for an external reference voltage. For most PICs, if Vdd = 5V, the lowest Vref+ can be is 3.0V. The highest Vref+ can be is something like Vdd + 0.3V. Consult the PIC's data sheet for guidance.
These calculations assume that Vref- is 0V (ground). You can set Vref- to a non-zero value, but then the calculation for binary reading above is not valid. |
|