|
|
View previous topic :: View next topic |
Author |
Message |
rodrigobarg
Joined: 20 Jun 2014 Posts: 3 Location: Dundee, UK
|
ADC range |
Posted: Fri Jun 20, 2014 7:08 am |
|
|
Hi, I'm trying to read a voltage, but the normal range of the PIC16F77A is 0-5V, but since I'm measuring lower than 3, I'd like to change it to 0-3V or even 0-2V. Is that possible? Also, I tried using AN0_AN1_VSS_VREF in setup_adc_ports so AN3 is my reference voltage, but if I put a reference voltage of, say, 2V in pin_AN3, how can I get the exactly value of VSS_REF (pin_A3) so I can convert the result of read_adc() to the voltage reading (something like (VSS/1023)*reading). Thanks! |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Fri Jun 20, 2014 8:57 am |
|
|
Read the data sheet.
It will tell you what the acceptable range for Vref is.
If it won't go down to 2V, use an OPA to amplify your input signal.
Mike
EDIT
Quote: | Hi, I'm trying to read a voltage, but the normal range of the PIC16F77A is 0-5V, but since I'm measuring lower than 3, I'd like to change it to 0-3V or even 0-2V. Is that possible? Also, I tried using AN0_AN1_VSS_VREF in setup_adc_ports so AN3 is my reference voltage, but if I put a reference voltage of, say, 2V in pin_AN3, how can I get the exactly value of VSS_REF (pin_A3) so I can convert the result of read_adc() to the voltage reading (something like (VSS/1023)*reading). Thanks! |
I cannot find your PIC16F77A on the microchip website.
I suspect you are actually using a PIC16F77 or more likely a PIC16F877A |
|
|
rodrigobarg
Joined: 20 Jun 2014 Posts: 3 Location: Dundee, UK
|
|
Posted: Mon Jun 23, 2014 3:16 am |
|
|
Yes, PIC16F877A, sorry, and thanks for the answer. But then, how do I set it to 2V? Or if I use the pin with an input voltage of around 2-3V, is it possible to get this value so I can convert the 1-1023 number to the actual voltage. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Mon Jun 23, 2014 5:17 am |
|
|
Mike is right that you must use an 'rail to rail' opamp to amplify your sensor's output. Table 15-12 of the datasheet has 'all the numbers' but can be confusing.The minimum deltaV is 2.5V.
If your sensor only has a 2volt range, one solution is to use a precision X2 opamp to now give a 0-4.00V signal to the PIC. AT the same time, use a Vref chip of 4.096 as the Vref+ input to the ADC section.This combination would probably yield the best overall results for you.JUst be very,very careful with parts layout, PCB traces, bypass caps, etc. All those will affect the performance(accuracy) of the ADC!
For best results measure the signal 10x and take the Olympic average.It a very fast way to get 'stable' readings.
hth
jay |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
Re: ADC range |
Posted: Mon Jun 23, 2014 7:20 am |
|
|
Hi,
rodrigobarg wrote: | how can I get the exactly value of VSS_REF (pin_A3) so I can convert the result of read_adc() to the voltage reading (something like (VSS/1023)*reading). Thanks! |
You have to measure the value of the reference, and then use it in your program. I've found that part to part these references can vary a little bit, but individually they are quite stable. For example, I use a precision 2.5V reference in a project, and the output from board to board can vary by as much as +/-10mV. Each board is very stable at it's output value, but none is *exactly* 2.5V. In my application, that's unacceptable, so I need to apply a correction. I could measure each one, and hard code the value (a lot of work), or by measuring a couple of 'known values' and doing some algebra, I can generate a correction as part of a calibration process.
John |
|
|
rodrigobarg
Joined: 20 Jun 2014 Posts: 3 Location: Dundee, UK
|
|
Posted: Mon Jun 23, 2014 7:49 am |
|
|
Thanks, guys! So, by the data sheet, the default value of reference is 5.12V? Or is it 5V? |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Mon Jun 23, 2014 8:50 am |
|
|
rodrigobarg wrote: | Thanks, guys! So, by the data sheet, the default value of reference is 5.12V? Or is it 5V? |
There really isn't a "default" reference voltage. Also, that chip doesn't have a built in reference.
You can use the supply voltage as the reference. This is probably what you mean by "default". If the supply is 5V then your ADC range is 0 to 5V. If your supply is 4.5V then your ADC range is 0 to 4.5V. This is simple, but not very accurate and is probably noisy. It is possible to calibrate the supply to work out what voltage is really is, but it will change and there will be a fair bit, or even a lot of noise. To do that you will need a very stable voltage to compare the supply to. Even the very best supply is not really good enough to be called a "reference".
To use a range that's different from the supply, and to get much better accuracy with reduced noise, then you must use an external reference connected to the Vref+ input. There are a lot of reference ICs that you can use. I currently use Microchip's MCP1541 4.096V IC, giving a convenient 4mV per bit for 10 bit and 1mV per bit for 12 bit ADCs, but there are many others giving many different voltages.
You can also offset the range by using a non-zero volts Vref-, but this is uncommon.
There are restrictions on the voltage of the reference, it cannot be too small, and it can not be more than the supply voltage. The details are in the datasheet.
As other people have said, you can use op-amps to bring the range of the signal into a more suitable range for the ADC, but for best performance there are many things to get right, otherwise various offsets and gain errors can reduce ADC accuracy.
Sometimes there's no need to be very accurate, and the supply will do OK. Other times you might not need the full accuracy of the ADC, and a reduced range is OK, but using an external reference. There are surprisingly few applications that really need all the ADC bits at the best possible accuracy. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Mon Jun 23, 2014 10:52 am |
|
|
Another 'problem' when using the power supply voltage as the ADC reference is that the power supply will 'dip' under load. So while it might be 5.05 most of the time, turning on a load(relay,LEDs,etc.) will lower the Vdd which affects the ADC reference.
Depending on your application this can have serious issues ! Since you're using 10bit mode, we have to assume you want great readings and for that a very stable precision calibrated reference is required.
hth
jay |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|