Puzzled with results from ADCON1 -vref acting strange - Anyone help?

Status
Not open for further replies.

bigal_scorpio

Active Member
Hi to all,

I am doing a project with the 16F872 and need all the AD inputs.

I have set ADCON1 to %10000010 which as I read the datasheet means that the result will be roght justified and ALL AD challels will be ok to use and the references will be taken internally from VDD and VSS.

My problem is that when I use channel 2 the readings on the other channels are affected, actually moving with the channel 2 input as if I had -vref set to channel 2.

Is there some trick to using all the ADs without the vrefs or am I going to have to do without channel 2?

Thanks, Al
 
Depending on the source impedances feeding the ADC you need to delay when you change channels, this is to give the internal sample and hold capacitor time to charge/discharge - if you read too soon, you're effectively still reading the previous channel as well.
 
Hi Nigel,

Hope your road is not flooded now?

I am using a 50uS delay between samples, is that enough mate.?

This is the actual subroutine.

Code:
      PAUSEUS 50                      ' Wait for A/D channel acquisition time
        ADCON0.2 = 1                    ' Start conversion
        WHILE ADCON0.2                  ' Wait for it to complete
        adval.highbyte = ADRESH         'Write conversion result
        adval.lowbyte = ADRESL
        adval = (adval */ 500)>>2 	     ' Equates to: (adval * 500)/1024 
        WEND

Should that do it or do I need a longer pause or better code maybe?

Al
 
Last edited:
Hi Nigel,

Hope your road is not flooded now?

If my road is flooded then Derbyshire is in deep trouble

I live pretty well top of a hill - incidently under a mile away from the source of the Rother that gives it's name to your city.

I am using a 50uS delay between samples, is that enough mate.?

I wouldn't have thought it's anywhere near enough, but as I said it depends on the source impedance.

What are you doing?, is there any need for samples that often?. In my tutorials I used 20mS delay time.
 
Hi nigel,

I meant the bottom of the road where I once parked mate, but thinking on you had a Landy? So the bit of rain wouldn't worry you eh? hehe

As to the delay. Just changed to 500 then 20000 and still the problem remains!

I have noticed that even when both ch0 and ch1 are at 0 input then ch1 still displays a reading whenever ch2 is connected.

I am trying to make a rudimentary thermometer with one of the old 2 pin sensors from a computer. The ones that used to come with some mainboards to measure the case temp or the temp of a HD etc. It is just a small black bit of silicon between 2 wires that are shrouded in clear plastic. Measured it gives 1kohm at 0 degC and 60k at 100C so I made a voltage divider with a 10k and the sensor and read the output, which with my meter is (from 5v) .45v at 0C and 4.28 at 100C.

I am condidering having to rethink the entire project now. I really needed all 5 of the inputs. I will be measuring 2 voltages, 2 currents and the temperature. If I can't get past this error I may have to start again maybe using a 16F887 with more AD channels. But it means entirely scrapping my build. Doh!

Al
 
Hi nigel,

I meant the bottom of the road where I once parked mate, but thinking on you had a Landy? So the bit of rain wouldn't worry you eh? hehe

Those are only puddles - nothing to be concerned about (apart from the poor state of the private road).

I had, and still have, a Fiat Punto - although I also bought a Suzuki Jimny 4x4 last year - as we've had some bad winters the last few years, and I needed a second car as my daughter keeps wanting to borrow the Punto (when she's back from Uni). The Jimny also has air-con which is nice, on the occasional warm day.


There should be no interaction between channels, are you sure you don't have a hardware problem? (pins shorted together). Replace your thermistors with variable resistors, and alter them whilst monitoring the voltage on the PIN pins with a meter - obviously if other than the correct one changes you have a hardware problem.

As for your reading speed you only need it fast enough to sensibly update the display, so 100mS between readings would be fine.
 
What is your configuration for ADCON0? Note that the ADCS bits are extremely important - these really set your acquisition time. Table 10-1 tells you how to set them; depending on your OSC frequency.

From your routine:
Code:
PAUSEUS 50                      ' Wait for A/D channel acquisition time
        ADCON0.2 = 1                    ' Start conversion
        WHILE ADCON0.2                  ' Wait for it to complete
        adval.highbyte = ADRESH         'Write conversion result
        adval.lowbyte = ADRESL
        adval = (adval */ 500)>>2 	     ' Equates to: (adval * 500)/1024 
        WEND

It should really look like:
Code:
PAUSEUS 50                      ' Wait for A/D channel acquisition time
        ADCON0.2 = 1                    ' Start conversion
        WHILE ADCON0.2                  ' Wait for it to complete
        WEND
        adval.highbyte = ADRESH         'Write conversion result
        adval.lowbyte = ADRESL
        adval = (adval */ 500)>>2 	     ' Equates to: (adval * 500)/1024

Happy swiming - I could trade you some of our sun from toasty Arizona
 
Good spot - he has reading the result before the conversion finished (probably before it even started?).
 
We'd only complain it was too hot!

Didn't we have some warm days back in March?, and nothing much since.

I lived in SA for a spell... as did Eric..... I wouldn't complain.... Believe me...

Languer!! That was a good spot.... I missed it.
 
Hi guys,

You beauty languer! Absolutely perfect now and all problems gone.

Cheers mate and thanks to everyone involved.

Ian, I know its wet here but I believe its even worse where you are!

Like Nigel said we would only moan if it was too hot! We just need to evolve as British people need to - probably gills and flippers would be the next step. hehehe

Al
 
Glad to help.

Gills and flippers ah? An aquamanish look.

We're no better over here; complain all year about lack of rain, and two days of rain and already complaining about when the sun will come out. All i know is hot as hell right now and I'm soon going to start the rain dance
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…