Measuring signal of mV range using PIC 16F877A

Thread Starter

ranjith_asp

Joined Dec 15, 2007
1
I am planning to connect a couple of hall effect sensors to PIC Microcontroller.

The output signal range of the sensor is in mV ranges.

I want to know how to amplify this in order to connect to the PIC Analog ports, as PIC 16F877A has the Analog input range of 0-5V.

My questions:
1. What is the best way to amplify my mV range signals to a range of 0-3 VDC?

2. Can anyone know the resolution of the PIC's analog port? Is it 0.1 VDC or even lesser?
 

t06afre

Joined May 11, 2009
5,934
Hi you have the datasheet if not get here http://ww1.microchip.com/downloads/en/devicedoc/39582b.pdf
Then take a look at FIGURE 11-1: A/D BLOCK DIAGRAM. If we assume that VREF- is set to VSS. Each bit in the conversion result. Will have a "weight" equal to
(VREF+)/(2^10)=(VREF+)/(1024). As an example If VREF+ is equal to 5 volt and the conversion register after conversion contain the value 124 decimal. The ADC reading is equal to (5/1024)*124=0.605 volt. Refer to TABLE 17-14 for the range of ADC input and other signals
 

ErnieM

Joined Apr 24, 2011
8,377
An analog to digital converter will take an analog voltage and convert this to a pure number of courts by the relation:

Counts = (Vin / Vref) * 1023

Note when Vin = Vref you get an output count of 1023, which is the largest number from a 10 bit binary quantity. Keep in mind any over voltage to Vin will also give the same number, meaning you cannot "see" an over range.

If you solve for Vin and set the counts to one you get:

Vin = (Counts * Vref) / 1023 = Vref / 1023

Say you use a 4.096 reference voltage (that comes from a popular precision voltage reference chip). you would have a resolution of:

Vin = 4.096 volts / 1023 = .0040 volts

So you get a resolution of very close to 4 mV per count over the full input range.

Using such a reference you should take the max sensor output and amplify it so you get close to the 4.096V reference voltage. I usually leave a little room up top for unexpected large inputs.

The accuracy is different from the resolution. The accuracy is dependent on the gain between your sensor and the micro's analog input: if the gain has an accuracy of ±1% then your overall accuracy also varies by that, plus any sensor accuracy. The amp's offset will also affect the accuracy.

Such a system can be calibrated by applying a known input and comparing to the resultant output. If you can get two widely spaced readings you can calculate the correction (calibration) by assuming a straight line and doing some simple math to compute the slope and intercept.

If your sensor and amp are linear this will calibrate the system fairly accurately.
 

t06afre

Joined May 11, 2009
5,934
An analog to digital converter will take an analog voltage and convert this to a pure number of courts by the relation:

Counts = (Vin / Vref) * 1023

Note when Vin = Vref you get an output count of 1023, which is the largest number from a 10 bit binary quantity. Keep in mind any over voltage to Vin will also give the same number, meaning you cannot "see" an over range.

If you solve for Vin and set the counts to one you get:

Vin = (Counts * Vref) / 1023 = Vref / 1023

Say you use a 4.096 reference voltage (that comes from a popular precision voltage reference chip). you would have a resolution of:

Vin = 4.096 volts / 1023 = .0040 volts

So you get a resolution of very close to 4 mV per count over the full input range.

Using such a reference you should take the max sensor output and amplify it so you get close to the 4.096V reference voltage. I usually leave a little room up top for unexpected large inputs.

The accuracy is different from the resolution. The accuracy is dependent on the gain between your sensor and the micro's analog input: if the gain has an accuracy of ±1% then your overall accuracy also varies by that, plus any sensor accuracy. The amp's offset will also affect the accuracy.

Such a system can be calibrated by applying a known input and comparing to the resultant output. If you can get two widely spaced readings you can calculate the correction (calibration) by assuming a straight line and doing some simple math to compute the slope and intercept.

If your sensor and amp are linear this will calibrate the system fairly accurately.
I do not quite agree in what you write. A ten bit ADC can produce 1024 different readings zero inclued. To be very pedantic. If we go back to the example I gave in my first post. The resolution will be (VREF+)/(2^10). But the range of the ADC will be 0 to (VREF+)-((VREF+)/(2^10))
 

upand_at_them

Joined May 15, 2010
940
You can amplify it with an op-amp, such at the LM324. But you'll need to know the full range of the sensor to come up with the appropriate gain of the op-amp.
 

ErnieM

Joined Apr 24, 2011
8,377
I do not quite agree in what you write. A ten bit ADC can produce 1024 different readings zero inclued. To be very pedantic. If we go back to the example I gave in my first post. The resolution will be (VREF+)/(2^10). But the range of the ADC will be 0 to (VREF+)-((VREF+)/(2^10))
And to be pedantic right back at 'cha... :D

For "1024 different readings zero included." the largest number output is 1023, since zero counts as a state.

While it is quite true 2^10 = 1024, the largest 10 bit number is 1023 or in binary 11,1111,1111 (<== ten bits, see?).
 

THE_RB

Joined Feb 11, 2008
5,438
How do you reach that conclusion? Can you show your work?

How about showing just showing what input gives you 1 count.
I already proved how the scaling of PIC adc =1024 to you in another thread, including the answer to your above question (where at 5v; 1 ADC count =5/1024 = 4.8828mV).

But even after explaining it in 5 different ways I still don't think it sunk in. :(

If you want to give it another chance the thread is here;
http://forum.allaboutcircuits.com/showthread.php?t=69189
 

ErnieM

Joined Apr 24, 2011
8,377
This is for me quite basic ADC theory. Why are you so stubborn on this matter.
(Also see his Attached note linking to the "ABCs of ADCs Analog-to-Digital Converter Basics" by Nat Semi)

No wonder there is such confusion about this seemingly simple concept when such nonsense is printed. Referring to the Nat Semi app note, I agree with their definition of resolution on sheet 4 where they state "Resolution may also be defined as the size of the LSB (Least Significant Bit) or one count."

Hey, it's a definition, a priori true, but the usefulness of a definition lies in it's predictive ability. Also note no where in this app note do they even attempt to derive the resolution expression, it is merely stated, then they "play with the numbers" to get the desired result.

A theoretical (paper) converter is described as such:


Pay close attention to the conversion voltages on the right side coming out of the converter. They are centered on the inputs of 0.5, 1.5, 2.5, ... 6.5 and 7.5 volts. There is some slight of hand here to remove an extra volt from the input range: there is an extra half volt at the low end, and a missing half volt on the top. Thus the range of this converter is not 8 volts, but 7 volts, and if you compute the resolution as I recommend ( [voltage span]/[max count] ) you get the correct result of a resolution 1 volt, computed by:

[voltage span]/[max count]
[7 volts] / [7 counts] = 1 volt/count

While it is true:

8 volts / 2^3 counts
= 8 volts / 8 counts
= 1 volt/count

is the correct result it is completely unclear where the 8 volts term comes from. The circuit model doesn't use an 8 volt reference anywhere!

(Oh look, they draw 8V into the converter! But nowhere does 8V appear in the conversion outputs.)

The OP asked not about some theoretical converter, but about a Microchip PIC, and these have the min count centered about the point where the input equals the low reference voltage (typically zero), and the max count centered about the point where the input equals the high reference voltage. Applying some simple math to describe a linear straight line relationship yields the results I have stated.

In the other linked thread WBahn makes some excellent points (better then I could have made) in centering the results of the defining equation to minimize quantization errors. He keeps well in mind the goal here is given an A2D count how do we compute the most likely voltage that produced this resultant count.

The only point I am completely stubborn over is my complete refusal to entertain using the results from the "Journal of Computationally Efficient Methods for Predicting Inexact Results."

If any of you nay sayers would actually produce your work (as I have numerous times) I may help find either your error, or it may be correct the way you have defined your terms. One cannot comment on work not shown.

If anyone is unsure of the correct method, I only suggest to do the math yourself. You may learn something.
 

ErnieM

Joined Apr 24, 2011
8,377
Ah ha, someone who posts their work:
Ok, I concede. If the maximum voltage were 4V then,

3 = 3 to 4V
2 = 2 to 3V
1 = 1 to 2V
0 = 0 to 1V

So the resolution = 4V/4 = 1V.
Note the referenced figure for the Microchip PIC A2D shows the bottom transition centered on ZERO LSB (in volts), which is used here as the Vref- voltage. Their graph is not quite true for the top transition as it does not correctly show the transition centered about Vref+. (Hey, these are persnickety details and data sheets get copied over and over when it's the same module being used. Best to check the A2D reference chapter on the PIC32's where they finally get this figure correct.)

Now let's look at that data range again:

3 = 3 to 4V or 3.5V nominal
2 = 2 to 3V or 2.5V nominal
1 = 1 to 2V or 1.5V nominal
0 = 0 to 1V or 0.5V nominal

The nominal value is the center of where a bit transitions, and if you base your estimates against these numbers you get the best predictability doing the reverse calculation of going from counts to applied voltage.

Such a physical example circuit inside a PIC would have a reference voltage of 0.5V and 3.0V.

In this example, we thus have a range of:

Max input - min input = Vref+ - Vref- = 3.5V - 0.5V = 3.0V

and thus a resolution of :

3.0V / 3 counts = 1 volt/count
 

BillO

Joined Nov 24, 2008
999
According to Wikipedia

The voltage resolution of an ADC is equal to its overall voltage measurement range divided by the number of discrete values:



where M is the ADC's resolution in bits and EFSR is the full scale voltage range (also called 'span'). EFSR is given by:

 

THE_RB

Joined Feb 11, 2008
5,438
...
If any of you nay sayers would actually produce your work (as I have numerous times) I may help find either your error,
...
Arrogant much? :D

I spent about 3 days explaining this to you in the other thread I linked to above, including numerous proofs and you're still going on that scaling should be /(n-1)?

Linear data scaling between two scales is done using input:eek:utput, ie; output/input there is NO correct solution of output/(input-1) no matter how much you want it to be true.
 
Top