ADC ground ref setting

An area to discuss 8-bit PIC specific problems and examples

Moderator: Benj

Post Reply
jadiflow
Flowcode v5 User
Posts: 273
Joined: Thu Apr 17, 2008 9:59 am
Has thanked: 19 times
Been thanked: 16 times
Contact:

ADC ground ref setting

Post by jadiflow »

Hi all,

I have a long standing issue with the ADC in my PIC16F1788. I have set the ADC ref to external pin 5, and supply that with a 4.096 ref and that seems to work OK. I am assuming that the ADC ground ref is set to external as well, pin 4.
But it seems that the PIC actually uses its Vss as the ADC ground ref because I see errors depending on ground current.

Can someone confirm (or not) that when using external ref, it automagically uses external ground ref (REF-) as well?

(And I forgot how to get to the config page of the ADc too ...)

Jan Didden
Linear Audio

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: ADC ground ref setting

Post by stefan.erni »

Hi Jan

I guess you have to set the ADC Negative Voltage Reference Configuration bit to 1.

regards

Stefan
AD-refpin.PNG
AD-refpin.PNG (129.55 KiB) Viewed 6455 times
AD-refpin2.PNG
AD-refpin2.PNG (245.24 KiB) Viewed 6455 times

jadiflow
Flowcode v5 User
Posts: 273
Joined: Thu Apr 17, 2008 9:59 am
Has thanked: 19 times
Been thanked: 16 times
Contact:

Re: ADC ground ref setting

Post by jadiflow »

Hello Stefan, thank you for this!
When I do this in the initialization, at the start of the program, is that then not overridden when the ADC is initialized?
Not sure when the ADC initialization happens; does it happen with the first macro call to it? If that happens and there is an error in that process, that could explain my issue.
I know there was a similar error in the system call for the ADC in a PIC16F688 if I remember correctly, several years ago. That was fixed with an update of the 'CAL' macro.

Jan Didden
Linear Audio

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: ADC ground ref setting

Post by stefan.erni »

Hi Jan

I'm not sure if Flowcode supports the selection for the Vref negative (ground) pin for the ADC.
You must first initialize the converter with FC and then change the bit.

regards

Stefan

jadiflow
Flowcode v5 User
Posts: 273
Joined: Thu Apr 17, 2008 9:59 am
Has thanked: 19 times
Been thanked: 16 times
Contact:

Re: ADC ground ref setting

Post by jadiflow »

Hello Stefan,

The situation is a bit more clear after I did some more testing today.

I am measuring with the DMM directly on the ADC input pins, pin 4 (-ref) and pin 24, the AN9 input I use, measuring less than 1mV. I have a short routine that sets ADCON2 bits 2, 1, 0 to 101, then reads the ADC (8 samples, 100us delay) and display the # of counts read. And that count is about 28.
The +ref to -ref voltage is 4.101VDC, directly at the PIC pins.

So this definitely seems wrong.

Jan Didden
Linear Audio

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: ADC ground ref setting

Post by stefan.erni »

Hi Jan

Can you post a schema from the hardware? How did you connect the ADC input?
The source for ADC input should be a low impedance. You also have to be careful with possible offset voltages.
And can you test with about 2Volt on the input? Sometimes there is a surprise when the ADC does not run at all.

regards

Stefan

jadiflow
Flowcode v5 User
Posts: 273
Joined: Thu Apr 17, 2008 9:59 am
Has thanked: 19 times
Been thanked: 16 times
Contact:

Re: ADC ground ref setting

Post by jadiflow »

Hello Stefan, I kept the source impedance low, 499 ohms. I will check those things you mentioned.
I had another question: if I use the ADC in single ended mode, what is the reference for the S/H input? I know that the reference voltage for the ADC can be external, but what is then the ref for the input signal? Should that then also be referred to the external ref-?

Edit: When I connect the ref- pin 4 to Vss it works very well with just an LSB or two error. I tried to recreate that by setting ADCON1:2 to zero, make Vss the ref-, but that didn't have the same result. Hmmm.

Jan Didden
Linear Audio
Last edited by jadiflow on Wed Oct 21, 2020 9:52 am, edited 1 time in total.

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: ADC ground ref setting

Post by stefan.erni »

Hi Jan

Some small PiC just have VDD and VSS, some big PiC have additional Analog power pin AVDD and AVSS

regards

Stefan
Pic-small.png
Pic-small.png (60.5 KiB) Viewed 6349 times
Pic_Big.png
Pic_Big.png (266.53 KiB) Viewed 6349 times

jadiflow
Flowcode v5 User
Posts: 273
Joined: Thu Apr 17, 2008 9:59 am
Has thanked: 19 times
Been thanked: 16 times
Contact:

Re: ADC ground ref setting

Post by jadiflow »

Stefan, the PIC16F1788 has no analog power pins.

BTW: When I connect the ref- pin 4 to Vss it works very well with just an LSB or two error. I tried to recreate that by setting ADCON1:2 to zero, make Vss the ref-, but that didn't have the same result. Hmmm.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: ADC ground ref setting

Post by medelec35 »

Hi Jan,
As default, Flowcode uses GND for -ve reference and VDD as positive reference.
Within ADC properties you can select Vref+ pin so then the two references are Vref+ pin and GND
If either does not work then could be a bug.
Martin

jadiflow
Flowcode v5 User
Posts: 273
Joined: Thu Apr 17, 2008 9:59 am
Has thanked: 19 times
Been thanked: 16 times
Contact:

Re: ADC ground ref setting

Post by jadiflow »

Martin, thanks for chiming in. As I understand it, if you select external reference (ref+) in the ADC setup it also automagically sets ref- to an external pin, not to Vss. In my case I route both ref+ and ref- from the source to the controller board to be sure I do not pick up any DC offset on the way.

But I may be on to something: it looks like the flatcable connecting the two boards is not reliable, and that sometimes the ref- connection drops out or becomes high impedance and the ref- is then only connected to ground all the way back at the power supply and that longish route has a DC offset.
So I believe that is the reason, when I jumpered ref- to Vss on the controller board, the issue was gone. That's the reason why I investigated this ref- business.

Still have to do some testing to confirm. Funny how these things manifest themselves in areas that basically are OK ...

Jan Didden
Linear Audio

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: ADC ground ref setting

Post by medelec35 »

Your welcome Jan.
jadiflow wrote:
Wed Oct 21, 2020 12:26 pm
if you select external reference (ref+) in the ADC setup it also automagically sets ref-
No, it's as i stated:
medelec35 wrote:
Wed Oct 21, 2020 10:01 am
select Vref+ pin so then the two references are Vref+ pin and GND
It could be C code you are adding which is causing Vref- to be connected?
Should not require any C code to work with Vref+
Otherwise if no C code is used and Vref- is selected, then its a bug.
Martin

Post Reply