devonsc
Joined: 30 Nov 2004 Posts: 116 Helped: 1
|
26 Dec 2004 18:56 pic vref+ |
|
|
|
|
Hi, I've understand how to set-up the ADC module. By the way, I'm using PIC16F876.
I intend to divide my voltage by four through a voltage divider before applying it to the PIC for ADC conversion. However, I have problem understanding this:
For instance=>
a.) 4V, through a voltage divider, it would be 1V before being applied to the PIC for conversion.
b.) 5V, through a voltage divider, it would be 1.25V before being applied to the PIC for conversion but in this ADC module, will it take my 1.25V as 1V for conversion? If I won't face any problems in converting a 1.25V value, do you guys mind telling me on how do I store the converted binary value (which has decimal point)? I intend to store the converted value and call them later for LCD display.
Help needed...please?
|
|
XNOX_Rambo
Joined: 13 Jul 2002 Posts: 437 Helped: 87 Location: Far out, man!
|
26 Dec 2004 19:58 Re: Newbie in PIC - Using ADC module |
|
|
|
|
Hi devonsc,
In your PIC you can select reference voltages for the ADC. See figure 11-1 in
the datasheet.
If you use Vdd for Vref+ and Vss for Vref- the ADC will convert input voltages in
the range from Vss (0V) to Vdd (say +5V) - i.e. your input signal should never
exceed Vref+ - but - its maximum value should be close to this limit, so that
you use the ADC to its full capacity.
If your maximum input signal is 1.25 V you will have to use an external
reference of 1.25 V connected to the Vref+ pin. Otherwise you will be "throwing
away" a big portion of the ADC range.
As for the binary/decimal numbers question:
The ADC has a resolution of 10 bits. This means that its binary range is from
0000000000b to 1111111111b - or 000h to 3FFh. Having a Vref+ of +5 V and an
input value of e.g. 2.5 V would lead to a value of 1FFh after AD conversion, i.e. 3FFh/2.
The output from the ADC i thus always an integer value between 000h and 3FFh.
When you are to display the actual, decimal input value you need to multiply
your stored ADC value with Vref+ - but as the PIC doesn't use hardware floating
point arithmetic you are in a pickle...
Luckily there are floating point routines in assembler available - here is one example:
http://www.programmersheaven.com/zone5/cat197/15571.htm
The rest is easy...
/Rambo
|
|