A capacitor might be needed, what are you reading?
For example...
A LM34/35 will be unstable sometime depending on cable and all will need a capacitor from signal to ground (zero rail) to keep it from fluctuating. 22uf works well.
A capacitor might be needed, what are you reading?
For example...
A LM34/35 will be unstable sometime depending on cable and all will need a capacitor from signal to ground (zero rail) to keep it from fluctuating. 22uf works well.
Dave
Always wear safety glasses while programming.
I see you are using an external Vref. Are you certain it is stable? Also, I have had better results using the "real" clock (not R/C) for the ADC clock. At 20Mhz, you can use Fosc/32 (ADCON2 = %10000010) in most chips.
Make sure the source impedance into the ADC pin is < 2K, and use a .1uF to ground from the ADC Pin.
If you have the time, take 4 to 16 samples, add them together and divide to get an average.
Charles Linquist
I only need 2 analog inputs, no other configuration without Vref+ unless I enable more analog input pins.
I'm connecting phototransistor with pull up 350K to +5V, does this mean I need to increase ADC_SAMPLEUS?
The circuit only have one +5V source, so I connect Vref+ to Vdd pin of PIC directly without any resistor. Is this ok?
You can connect Vref to Vdd, but it is easier just to set ADCON1 bits 5&4 to "0" which connects Vref to Vdd internally.
Also, READ YOUR DATASHEET. Here is a cut and paste directly from the A/D section of the 18F8722 datasheet:
The
maximum recommended impedance for analog
sources is 2.5 kΩ.
Other chips have similar recommendations.
Your 350K is WAAAAAY too high! If you really need a 350K pull-up, you will
have to buffer the analog signal with an op-amp to get accurate readings.
If you just want to sense the presence of an object, you would be better off using a digital input, and connecting the collector of your phototransistor to 5V through a 10K or 22K resistor.
Charles Linquist
I would suggest to use an opamp as a unity gain buffer befor feeding the ADC of the PIC.
As Charles stated 350K is too high for the ADC to work reliable.
Also to be sure that the PIC is working OK, use a trimmer in the place of the phototransistor and check the results. If they are stable and seem expected then you can be sure that PIC is OK. Of course it would be a very good idea to average the samples. Have a look at Darrels averaging routine at his site:
http://www.pbpgroup.com/modules/wfse...hp?articleid=7
Ioannis
Can anyone tell me why I am getting 16 bit results from this code? I expect at 5 volts in I should see 1023 but I see 65535.I am using a 16f616.
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50
TRISA = 255 ' Set PORTA to all input
ADCON1 = 2 ' PORTA is analog
ADCIN 0, A0 ' PORTA.0 PIN 13
Bookmarks