CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

problem with A/D
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Wed Dec 23, 2009 1:27 pm     Reply with quote

[quote="djole_nisam_ja"]
mkuang wrote:
SET wrote:
See:

In addition, the Thevenin equivalent impedance as seen by the PIC A/D pin should be less than 10k (or is it 5K, you have to check the datasheet) or you may get the accuracy you are looking for.


Excuse me mkuang, could you give me a help a bit.

Do you say that if I measure voltage on ADC pin (with voltmeter), I am actually not measuring the whole voltage (which measures the PIC) because of the ADC pin´s resistance?


When was the last time your voltmeter was calibrated? How do you know how accurate it is even if the input signal is a nice dc level. Also be careful when you set your voltmeter on "auto-scale" as is common with some of these newer models your results may not be as accurate with some older models where you can specify the input voltage range you are looking for. In these older models the voltmeter can switch in the optimal value series resistor for measurement.

The differences between what the voltmeter measures and the PIC it looks like its about 1% or so, which could partially be attributed to this effect.

Also, to elaborate a little more (you may know this already) your voltmeter form a voltage divider with your source voltage. Now modern voltmeters typically have input impedances greater than a 10e9 Ohms so this is probably not a big deal unless your source impedance is very very large (like a megaohm or more). The PIC datasheet, however, specifies a maximum input impedance of 5-10K (you can check) or the results may be as accurate as you like it to be. At high source impedance you may also need more time for the A/D capacitors to charge to the final values.

These are just some of the problems you should be aware of.
djole_nisam_ja



Joined: 10 Dec 2009
Posts: 18

View user's profile Send private message

PostPosted: Wed Dec 23, 2009 1:46 pm     Reply with quote

FvM wrote:
Quote:
Do you say that if I measure voltage on ADC pin (with voltmeter), I am actually not measuring the whole voltage (which measures the PIC) because of the ADC pin´s resistance?
Right. You would need an oscilloscope to watch the input voltage at the sampling moment, which
is actually dropping due to the source resistance and the ADC's input impedance. The voltmeter is too
slow to follow it.

Your previous statement about a voltage factor 5 versus 50 is still confusing. You may want to dump the
actual ADC code and check the calculation by pencil and paper method. From the shown code, I can't follow
a factor of 50.


Yes, I know it is confusing to use 50 instead of 5, it confuses me too.

At first I used 5, and it worked ok. After a while (I made some measurements with ADC) LCD started to give me results shifted to the right for 1 space.

Example: instead of showing 1.43 it showed 0.14

so I figured it out that I could fix it by multiplying with 50 instead of 5.

But why this happened?
djole_nisam_ja



Joined: 10 Dec 2009
Posts: 18

View user's profile Send private message

PostPosted: Wed Dec 23, 2009 3:00 pm     Reply with quote

[quote="mkuang"]
djole_nisam_ja wrote:
mkuang wrote:
SET wrote:
See:

In addition, the Thevenin equivalent impedance as seen by the PIC A/D pin should be less than 10k (or is it 5K, you have to check the datasheet) or you may get the accuracy you are looking for.


Excuse me mkuang, could you give me a help a bit.

Do you say that if I measure voltage on ADC pin (with voltmeter), I am actually not measuring the whole voltage (which measures the PIC) because of the ADC pin´s resistance?


When was the last time your voltmeter was calibrated? How do you know how accurate it is even if the input signal is a nice dc level. Also be careful when you set your voltmeter on "auto-scale" as is common with some of these newer models your results may not be as accurate with some older models where you can specify the input voltage range you are looking for. In these older models the voltmeter can switch in the optimal value series resistor for measurement.

The differences between what the voltmeter measures and the PIC it looks like its about 1% or so, which could partially be attributed to this effect.

Also, to elaborate a little more (you may know this already) your voltmeter form a voltage divider with your source voltage. Now modern voltmeters typically have input impedances greater than a 10e9 Ohms so this is probably not a big deal unless your source impedance is very very large (like a megaohm or more). The PIC datasheet, however, specifies a maximum input impedance of 5-10K (you can check) or the results may be as accurate as you like it to be. At high source impedance you may also need more time for the A/D capacitors to charge to the final values.

These are just some of the problems you should be aware of.


Well I bought it recently and it is. It is digital multimeter without "auto-scale" function.

Yeah, I know how voltmeters works and my impedance is around 15KOhms, so it wouldn´t be that much trouble for the voltmeter, but it could be for the PIC (from what you said about range of 5-10KOhms).

I looked for maximum input impedance here http://ww1.microchip.com/downloads/en/DeviceDoc/39631E.pdf

but couldn´t find anything.
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Wed Dec 23, 2009 3:16 pm     Reply with quote

djole_nisam_ja wrote:


my impedance is around 15KOhms, so it wouldn´t be that much trouble for the voltmeter, but it could be for the PIC (from what you said about range of 5-10KOhms).

I looked for maximum input impedance here http://ww1.microchip.com/downloads/en/DeviceDoc/39631E.pdf

but couldn´t find anything.



Fromm the 18F2525/4620 datasheet (I don't have the bandwidth to download the datasheet for your PIC but I imagine it is very similar):

19.1 A/D Acquisition Requirements
For the A/D converter to meet its specified accuracy,
the charge holding capacitor (CHOLD) must be allowed
to fully charge to the input channel voltage level. The
analog input model is shown in Figure 19-3. The
source impedance (RS) and the internal sampling
switch (RSS) impedance directly affect the time
required to charge the capacitor CHOLD. The sampling
switch (RSS) impedance varies over the device voltage
(VDD). The source impedance affects the offset voltage
at the analog input (due to pin leakage current). The
maximum recommended impedance for analog
sources is 2.5 kΩ.
After the analog input channel is
selected (changed), the channel must be sampled for
at least the minimum acquisition time before starting a
conversion.


So it is actually much worse, 2.5k versus 5 or 10k. And it appears this is not solved by using a longer acquisition time.
Ttelmah
Guest







PostPosted: Wed Dec 23, 2009 3:43 pm     Reply with quote

mkuang wrote:
SET wrote:
See:

So '3.2' means *at least* 3 digits before the decimal point (adding spaces if reqd) and *at least* 2 digits after the decimal point.


No, it means at least 3 digits before the decimal point, adding leading zeros if required (not spaces) and exactly 2 digits after the decimal point.

In addition, the Thevenin equivalent impedance as seen by the PIC A/D pin should be less than 10k (or is it 5K, you have to check the datasheet) or you may get the accuracy you are looking for.

I'm sorry mkuang, but you too are missing the point.

In C, the number in front of the DP, in a printf specification, _does not_ give the number of digits 'in front' of the DP. It specifies the _minimum width_ that the _total_ output wll be padded out to. So '3.2', implies there _will_ be a minimum of three characters output, and two will be after the decimal point. Not three in front.....

Best Wishes
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Wed Dec 23, 2009 3:48 pm     Reply with quote

[quote="Ttelmah"][quote="mkuang"]
SET wrote:
See:


In C, the number in front of the DP, in a printf specification, _does not_ give the number of digits 'in front' of the DP. It specifies the _minimum width_ that the _total_ output wll be padded out to. So '3.2', implies there _will_ be a minimum of three characters output, and two will be after the decimal point. Not three in front.....

Best Wishes


You are right. Thanks for correcting me. I was trying out code that had three decimals before the decimal point anyway so it wasn't a good example because obviously the minimum field width is satisfied at three.
Ttelmah
Guest







PostPosted: Wed Dec 23, 2009 3:59 pm     Reply with quote

djole_nisam_ja wrote:
Ttelmah wrote:
I'd suggest that the problem is elsewhere. The accuracy of your Vref, or the source impedance of the circuit itself, or possibly noise on the circuit (because the PIC ADC, is capacitive, it tends to integrate noise on the incoming voltage, while voltmeters may tend to record 'peak' values).
Using a high accuracy Vref, and oversampling 16*, I have got good correlation between the PIC ADC, out to five digits, with a freshly calibrated Fluke DVM.....
However using the supply for Vref, often gives problems, since the PIC also tends to integrate noise on the supply line. This tends to give a lower than expected reading, and might be what you are seeing.

Best Wishes


Could you please explain me what did you mean by "it tends to integrate noise on the incoming voltage" and by "oversampling 16*".

I am using Vref from my UNI-DS3 Development Board which I bought from Mikroelektronika, you think that could be a reason for this or something else?


First, the recommended source impedance is section 19.1, on the data sheet for your chip.

The PIC ADC, is a internal capacitor, connected via the FET's in the multiplexor, and the ADC itself, to the external pin. The resistances presented by these FETs, are slightly assymetric in their behaviour. Because of this, if you connect a voltage that has high frequency noise on it, the voltage that gets stored on the internal capacitor, tends to be slightly different from the 'average' voltage.

In certain circumstances, it is possible to extend the effective accuracy of the ADC, by averaging multiple samples. This depends on the nature of noise on the signal, the overall quality of other components etc.. This is 'oversampling'.

You are using the supply, if you select 5v. The board offers you the option to use a 'proper' 4.096v reference, or Vcc (the supply). The supply will be worse than 1% accurate 'at best'. Switch to using the 4.096v reference, and rescale the arithmetic for this, and you may well find things improve, but you do need to lower the source impedance being fed by your external circuit.

Best Wishes
djole_nisam_ja



Joined: 10 Dec 2009
Posts: 18

View user's profile Send private message

PostPosted: Wed Dec 23, 2009 4:00 pm     Reply with quote

mkuang wrote:
djole_nisam_ja wrote:


my impedance is around 15KOhms, so it wouldn´t be that much trouble for the voltmeter, but it could be for the PIC (from what you said about range of 5-10KOhms).

I looked for maximum input impedance here http://ww1.microchip.com/downloads/en/DeviceDoc/39631E.pdf

but couldn´t find anything.



Fromm the 18F2525/4620 datasheet (I don't have the bandwidth to download the datasheet for your PIC but I imagine it is very similar):

19.1 A/D Acquisition Requirements
For the A/D converter to meet its specified accuracy,
the charge holding capacitor (CHOLD) must be allowed
to fully charge to the input channel voltage level. The
analog input model is shown in Figure 19-3. The
source impedance (RS) and the internal sampling
switch (RSS) impedance directly affect the time
required to charge the capacitor CHOLD. The sampling
switch (RSS) impedance varies over the device voltage
(VDD). The source impedance affects the offset voltage
at the analog input (due to pin leakage current). The
maximum recommended impedance for analog
sources is 2.5 kΩ.
After the analog input channel is
selected (changed), the channel must be sampled for
at least the minimum acquisition time before starting a
conversion.


So it is actually much worse, 2.5k versus 5 or 10k. And it appears this is not solved by using a longer acquisition time.


Thanks man for helping me. It is the same for mine, so I´m way over maximum limit, that is probably the reason for my troubles.

Will buy new components and will report results back here.

THANKS AGAIN
djole_nisam_ja



Joined: 10 Dec 2009
Posts: 18

View user's profile Send private message

PostPosted: Wed Dec 23, 2009 4:04 pm     Reply with quote

Ttelmah wrote:
djole_nisam_ja wrote:
Ttelmah wrote:
I'd suggest that the problem is elsewhere. The accuracy of your Vref, or the source impedance of the circuit itself, or possibly noise on the circuit (because the PIC ADC, is capacitive, it tends to integrate noise on the incoming voltage, while voltmeters may tend to record 'peak' values).
Using a high accuracy Vref, and oversampling 16*, I have got good correlation between the PIC ADC, out to five digits, with a freshly calibrated Fluke DVM.....
However using the supply for Vref, often gives problems, since the PIC also tends to integrate noise on the supply line. This tends to give a lower than expected reading, and might be what you are seeing.

Best Wishes


Could you please explain me what did you mean by "it tends to integrate noise on the incoming voltage" and by "oversampling 16*".

I am using Vref from my UNI-DS3 Development Board which I bought from Mikroelektronika, you think that could be a reason for this or something else?


First, the recommended source impedance is section 19.1, on the data sheet for your chip.

The PIC ADC, is a internal capacitor, connected via the FET's in the multiplexor, and the ADC itself, to the external pin. The resistances presented by these FETs, are slightly assymetric in their behaviour. Because of this, if you connect a voltage that has high frequency noise on it, the voltage that gets stored on the internal capacitor, tends to be slightly different from the 'average' voltage.

In certain circumstances, it is possible to extend the effective accuracy of the ADC, by averaging multiple samples. This depends on the nature of noise on the signal, the overall quality of other components etc.. This is 'oversampling'.

You are using the supply, if you select 5v. The board offers you the option to use a 'proper' 4.096v reference, or Vcc (the supply). The supply will be worse than 1% accurate 'at best'. Switch to using the 4.096v reference, and rescale the arithmetic for this, and you may well find things improve, but you do need to lower the source impedance being fed by your external circuit.

Best Wishes


You are the greatest man. THANKS A LOT.

Will try this tomorrow definitely with new components and will report here.
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Wed Dec 23, 2009 4:11 pm     Reply with quote

djole_nisam_ja wrote:

Thanks man for helping me. It is the same for mine, so I´m way over maximum limit, that is probably the reason for my troubles.

Will buy new components and will report results back here.

THANKS AGAIN

You can buffer the input with a unity gain follower (a good opamp like the OP290) will do nicely. That will solve your impedance issue.

By oversampling like Ttelmah was referring to, you are effectively increasing the resolution of the A/D. Just think about if you have a 1 bit A/D (either a zero or one) and you sampling a large number of times, the mean of the sample converges on the actual value of the input. On one design we needed 14 bit resolution but don't want to shove out major $$$ for a 14 bit or 16 bit A/D we just use a 12 bit and oversample. Of course this works by sacfificing some speed.
djole_nisam_ja



Joined: 10 Dec 2009
Posts: 18

View user's profile Send private message

PostPosted: Wed Dec 23, 2009 4:40 pm     Reply with quote

Yeah, I will try oversampling. Speed is what I don't need but accuracy I do need.
djole_nisam_ja



Joined: 10 Dec 2009
Posts: 18

View user's profile Send private message

PostPosted: Wed Dec 23, 2009 5:15 pm     Reply with quote

Oh, Ttelmah, one more thing.

Regarding Vref=4.096V, my board has jumper for changing this (either you would like 5V or 4.096V) but it is just for external ADC(onboard chip MCP3204).

So I assume that I will have to find where to take this voltage from (on the board) and to give it to my made circuit?
djole_nisam_ja



Joined: 10 Dec 2009
Posts: 18

View user's profile Send private message

PostPosted: Fri Dec 25, 2009 4:23 pm     Reply with quote

Hi everyone,

just to post my results.

I made my circuit with total impedance <2,5KOhm and it work ok.

Haven´t yet tried with Vref=4,096V, but even Vref=5V work all right.

Thanks for helping me this to sort out.

THANKS MEN
project2010



Joined: 14 Mar 2010
Posts: 21

View user's profile Send private message

PostPosted: Thu Mar 25, 2010 12:47 pm     Reply with quote

dear sir i have some question on the following statement.

setup_adc_ports(AN0); < how can i set adc of AN0,AN1,AN2 in one line? like this
setup_adc_ports(AN0);
setup_adc_ports(AN1);
setup_adc_ports(AN2);

setup_adc(ADC_CLOCK_DIV_8); < what is the effect if it's DIV_16/32
delay_us(20); <must be 20us?

what is the difference between the above statement? i have try it
but i can't see the difference.

volts = (float)(adc_value * 5)/1023.0;
volts = (adc_value * 5)/1023.0;

thank you Very Happy
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 25, 2010 12:55 pm     Reply with quote

Always post your PIC. Each PIC has different options for the ADC.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4  Next
Page 2 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group