Here is the code (one of many configurations),
W0 VAR WORD
W0=0
define OSC 40
DEFINE LCD_DREG PORTB
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 4
define LCD_EREG PORTB
DEFINE LCD_EBIT 5
TRISA=%111111
TRISB=%00000000
TRISC=%00001111
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 7
DEFINE ADC_SAMPLEUS 50
ADCON0=%00000000 ' CH0 as analog channel
ADCON1=%00011110
ADCON2=%10000111
Start:
ADCON0.0=1 ' A/D enable
PAUSE 2
Conversion:
ADCON0.1=1 ' Start (Go/Done)
SubC:
PAUSEUS 20
IF ADCON0.1=1 THEN SUBC
W0.LOWBYTE=ADRESL
W0.HIGHBYTE=ADRESH
LCDOut $fe, 1, "Counts ", #W0
lcdout $fe, $C0, "Result ", #(W0*4) ' 4096 mV ref.
PAUSE 500
GOTO Start
Hi,
While carefully reading your Datasheets ...
Did you notice the ADC input impedance had slightly changed ??? ... take care to the voltage source impedance !!! ( in your RC filters ... there's a series resistor !!! )
Your "symptoms" make me think it's a source impedance problem ...
Also consider the voltage offset of your buffers ... An AOP gives easily 10 mV offset !!! and from a batch to another, it can widely differ.
Could you show us a scheme of your input circuits ???
I Use a 2520 for my Honda Lawn tractor ( read air and oil temp - LM335 , plus oil pressure - MPX 5700 , with the inboard ADC) and readings are rock steady ...
My ref is a 4.096v from a TL431a ... trimmed with a 4.5 digits multimeter ...
The initial project was built around a 18F452 ... and I didn't notice any change.
Alain
Last edited by Acetronics2; - 8th March 2008 at 19:01.
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
Also in the datasheet for a 2550/4550...
The internal AD/RC oscillator is not a good idea on PIC chips if you want extreme accuracy.
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2395&stc=1&d=120499947 4" />
Try a different AD clock setting ...Also, since you're not using ADCIN, the ADC_ DEFINE's don't do anything.Code:ADCON2=%10100110 ; 64 TOSC, 8-TAD sample
<br>
Last edited by Darrel Taylor; - 8th March 2008 at 21:23. Reason: .
DT
High ADC accuracy and repeatability takes dedication at the PCB layout stage. There must be analog ground right beside the analog input and overall copper pour ground planes. Keeping all analog circuitry within its own fenced are of copper usually helps quite a bit.
Another good technique (thanks Melanie) is to take 16 readings, sort them, throw out the top 4 and the bottom 4 then average the eight values that are left. That technique eliminates the outliers and tames the last one or two counts.
I have also found several ADC ticks of noise/variability can be eliminated by locking the sampling point to the mains. I bring low voltage AC to an optocoupler and use that to trigger the ADC conversion. Varying the delay after the mains zero crossing will usually show a sweet spot where the fluorescent lights and other electrical loads are fairly quiet. I NEVER attempt 16 bit ADC without mains locking.
Sloppy techniques that are invisible with 8 bit conversion start showing up with 10 bits and can make the transition to 12 or 16 bit ADC a worthless expedition.
HTH
BrianT
Might help.
I think she's said it several times, here's one of them.
At least the sorting part.
http://www.picbasic.co.uk/forum/showthread.php?t=134 <-- 134
<br>
DT
Many Thanks to everybody for their supports,
Yes Alain, it may be impedance problem or Offset voltage drift in Op-Amps but it is not.
As I said before, I tried many techniques and schemes, I used OP27 (very low offset) with symmetrical power supply and I always precisely check that kind of voltage drifts. Then I used MAX6241 (4096mV ref with a single supply). Sometimes I used a series resistor(1-4,7k) in analog inputs and/or/not capacitors (100-470 nF) between these pins and GND.
May I ask you, did you ever precisely measure the voltages with a 1 mV (or lower) resolution voltmeter? If everything is okay may I see the summarized ADC section of your
code (if it is in PBP)? Because I'll be insane soon.
Thanks Darrell Taylor, I know, this code was one of the test code combinations.
I read the manual's A/D section and desperately tried many clock setting parameters and
also ADCIN command. These definition lines should be forgotten to be deleted.
Staistical sort method is the last way, I used this technique only on the Maxim's high speed
(100-200 kHz) 12-16 bits A/D converters. There was no need to use in 18F252.
There must be a structural difference between 18F252 and 2520 to affect their using technique and resulting difficulties.
BrianT, you are right, analog ground distribution is very important to prevent the voltage drops. I use protoboard for now but 18F252 was direct working in every condition. I don't understand this.
Namely, I compare everything with 18F252 comfort and then getting angry.
Can anybody write me a simple summarized code including definitions, settings and ADCIN usage. (I don't need high speed conversions. I want slow but stable and true results )
(for 2520,4520, 2550 or 4550, all they have same A/D structure).
And talk about differences between 18F252 or F452 and other new versions of these chips?
Then, once again, I will try it on a PCB.
Thank you
Selim
Bookmarks