Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

ADC, Code or Hardware problem?

Status
Not open for further replies.

adamthole

New Member
I am using a PIC 16F88 to display the temperature. The vref is 2.5V.
A portion of the code is as follows:

Code:
unsigned long get_temp()
{
	go = 1;
	while (go);
	return (adresh * 256 + adresl);
}

and then in main the following is part of a loop:
Code:
tempvalue = get_temp();
temp = ((tempvalue * 250) / 1023);

temp value, and temp are unsigned long

Is that code correct? The output likes to skip some numbers, which doesn't make sense to me since the resolution is well within the range of being able to detect a 10mV change.
 
It sounds like the code is working fine but you think there may be errors.

You don't say whether you are using any of the other ADC channels. If you are then you need a delay between selecting the channel and setting the Go bit. Check the data sheet for acquisition time.

Mike.
 
You don't mention the hardware at all, is the source impedance feeding the ADC below the maximum specified in the datasheet? (about 2K). If not you need to insert delays between channel changes.
 
Nigel Goodwin said:
You don't mention the hardware at all, is the source impedance feeding the ADC below the maximum specified in the data sheet? (about 2K).

Has anyone else noticed? If you look at the data sheet for the 16F88, on page 119 it states in the text that the impedance should be less than 2.5K. On the same page a little lower in the shaded box, note 3 states it should be less than 10k!!

I first noticed this in the 16F818 sheet and it seems microchip haven't noticed yet.

Mike.
 
I also have an issue with how low the reference voltage can go. I am using a PIC16F873 which is similar to the PIC16F88 and I vary the voltage applied to the Vref+ pin to adjust the "gain" of the A/D converter. I need to do this because I use two channels and the relative gain of each must track as close as possible. To cut the story short, the A/D converter becomes very inaccurate when the Vref goes below the 2.5V level.
 
BTW, I was looking at your code and the line:

Code:
      return (adresh * 256 + adresl);

Adresh and adresl are located on different banks. Have you verified that the compiler automatically switches banks when addressing these registers? I don't program in C when using PICs and so it would be interesting to know how a compiler reacts to registers on the wrong bank.
 
Pommie said:
Has anyone else noticed? If you look at the data sheet for the 16F88, on page 119 it states in the text that the impedance should be less than 2.5K. On the same page a little lower in the shaded box, note 3 states it should be less than 10k!!

There is no contradiction. The source impedance has two effects.

1. It increase the time for the input voltage to charge up the A/D capacitor. In this respect, the smaller the source imedance the faster the A/D rate one can achieve. Higher values just means longer wait time before the A/D can start. This is not a limiting factor.

2. It forms a voltage divider with the input leakage impedance and cause error in conversion result. In this respect the limiting value is 10K or less.
 
Thanks for verifying that it is not the code.

I changed some of the settings in the ADCON registers, now the A/D is running at FOSC/64, as opposed to FOSC/2 as it was originally. (I'm running at 8MHz). It now works fine, and does not skip the values. I guess it was just running too fast to let the caps fully charge?

I am using the AD to read two different voltages. Should I add further delays or is FOSC/64 enough? It seems to be working fine.

When it says that the impedance should be less than 10K ohm, does that mean that the voltage divider used to limit the voltage into the converter should be less than 10K total?
 
adamthole said:
When it says that the impedance should be less than 10K ohm, does that mean that the voltage divider used to limit the voltage into the converter should be less than 10K total?

It means the source impedance should be less than that, and preferebly less than the 2.5K value mentioned in the datasheet.

How is your's connected?.
 
adamthole said:
I changed some of the settings in the ADCON registers, now the A/D is running at FOSC/64, as opposed to FOSC/2 as it was originally. (I'm running at 8MHz). It now works fine, and does not skip the values. I guess it was just running too fast to let the caps fully charge?

It is strange that the Microchip datasheet also specify a min. clock frequency for A/D using a certain crystal and its not always slower the better.

I guess a longer A/D time would be less accurate, because of the discharge in the sampling capacitor? I simply don't know.

Please read the 16F88 datasheet P.118 on this.

adamthole said:
I am using the AD to read two different voltages. Should I add further delays or is FOSC/64 enough? It seems to be working fine.

The datasheet suggested 32 TOSC. Have you tried this yet?

adamthole said:
When it says that the impedance should be less than 10K ohm, does that mean that the voltage divider used to limit the voltage into the converter should be less than 10K total?

Imagine you are inside the PIC and looking out from the pin to the outside world. Arrange the voltage divider resistors such that you should not see an impedance value of more than 10K.
 
I don't currenty have it set up in any certain way. I was playing around with dividing it in 2 with 2 5.1K resistors, and it worked. It also worked with 2 10K resistors, and that is all I tried it with.

Thanks for the info on that it should only be "seeing" 10K or less, possibly preferably below 2.5K? I'll just read the datasheet and experiment until I am happy with the results.

I will change the FOSC to Fosc/32, see if it makes any difference.

Thanks for the help everyone.
 
Status
Not open for further replies.

Latest threads

Back
Top