EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

AD with 12F675 fluctuations

Started by d1camero April 8, 2004
--- In , "d1camero" <a8723@c...> wrote:
> BUT, when I removed the resistor divider network, and simply used
> the 12F675 to measure 0-5volts, the ADC works great, with an
> acceptable 1 bit fluctuation.

It seems to me that Igor's explaination, which you seemed to
discount, may be at least some of the problem.

From what I can tell you are trying to measure 10-15V by using a
resistor divider which will scale the 15V down to the necessary 5V.
It will also scale that 10V down to 3.33V. Thus, although the A/D
is measuring over a 0-5V range, the data of interest is in the 3.33-
5V range.

You want 0.01V accuracy on the original 10-15V range. The resistor
divider is also scaling this just like it scaled the original
voltage range. Think about it, in the original 10-15V range there
would be 500 steps (501 levels) at the .01V increments you desire.
500 steps in the 3.33-5V range works out to .0033V increments.

Thus using your resistor divider to measure .01V increments over a
10-15V range will require that you measure .0033V increments over a
3.33-5V range. Given that the A/D can measure to a resolution
of .00488V but at best has an error of +-1 LSB this means that you
are going to be +-0.015V at best.

Now I know this doesn't explain all of it but you should see that
there is no way you are going to get the .01V accuracy you desire by
taking this approach.

One other point is you you say that you have verified the voltage of
the 10-15V supply using two DVMs and it seems quite steady -- have
you looked at it with a scope? There is a good chance you will find
some ripple which the DVMs are filtering out but that the A/D is
seeing due to the speed of the sample/conversion. As others have
pointed out, putting a cap close to the input to the PIC should help
filter this out. As others have also pointed out it is imperative
that you not have too high of resistance as viewed from the PIC
A/D. The fact remains that even following these guidelines you are
not going to acheive the accuracy you desire with a resistor divider.




When I wanted to measure the voltage of a 24V storage battery (4
golf cart batteries in series) I used a rail to rail op amp to scale
the voltage. I was only interested in the range of 22 to 28 volts.

Read chapter 4 of Op Amps For Everyone (available free at
www.ti.com) and just rescale the range of interest to cover the
entire range of the A/D convertor. --- In , "Scott Lee" <midl_man@y...> wrote:
> --- In , "d1camero" <a8723@c...> wrote:
> > BUT, when I removed the resistor divider network, and simply
used
> > the 12F675 to measure 0-5volts, the ADC works great, with an
> > acceptable 1 bit fluctuation.
>
> It seems to me that Igor's explaination, which you seemed to
> discount, may be at least some of the problem.
>
> From what I can tell you are trying to measure 10-15V by using a
> resistor divider which will scale the 15V down to the necessary
5V.
> It will also scale that 10V down to 3.33V. Thus, although the A/D
> is measuring over a 0-5V range, the data of interest is in the
3.33-
> 5V range.
>
> You want 0.01V accuracy on the original 10-15V range. The
resistor
> divider is also scaling this just like it scaled the original
> voltage range. Think about it, in the original 10-15V range there
> would be 500 steps (501 levels) at the .01V increments you
desire.
> 500 steps in the 3.33-5V range works out to .0033V increments.
>
> Thus using your resistor divider to measure .01V increments over a
> 10-15V range will require that you measure .0033V increments over
a
> 3.33-5V range. Given that the A/D can measure to a resolution
> of .00488V but at best has an error of +-1 LSB this means that you
> are going to be +-0.015V at best.
>
> Now I know this doesn't explain all of it but you should see that
> there is no way you are going to get the .01V accuracy you desire
by
> taking this approach.
>
> One other point is you you say that you have verified the voltage
of
> the 10-15V supply using two DVMs and it seems quite steady -- have
> you looked at it with a scope? There is a good chance you will
find
> some ripple which the DVMs are filtering out but that the A/D is
> seeing due to the speed of the sample/conversion. As others have
> pointed out, putting a cap close to the input to the PIC should
help
> filter this out. As others have also pointed out it is imperative
> that you not have too high of resistance as viewed from the PIC
> A/D. The fact remains that even following these guidelines you
are
> not going to acheive the accuracy you desire with a resistor
divider.


At 12:44 PM 4/9/2004, d1camero wrote:

>BUT, when I removed the resistor divider network, and simply used
>the 12F675 to measure 0-5volts, the ADC works great, with an
>acceptable 1 bit fluctuation.
>
>So my question has changed: How can I accurately measure 10-15volts
>with the 675. Obviously a 1% resistor divider network introduces
>too much noise. Other ideas?

What value of resistors did you use? The specs state that the maximum
source impedance must be less than 2k5. You need a 3:1 divider where the
parallel value of the 2 resistors is less than 2k5 - this suggests the
divider resistors could be as high as 7k5 & 3k75.

The closest standard 1% values are 7k50 & 3k74. I'd put a 100R trimpot in
series with the bottom resistor and trim it for the correct reading out of
the A/D. This gives you an input impedance of about 10k.

I'd also add a cap (1u preferred, 100n OK) in parallel with the bottom
resistor if you can tolerate the slower response it gives you.

dwayne

--
Dwayne Reid <>
Trinity Electronics Systems Ltd Edmonton, AB, CANADA
(780) 489-3199 voice (780) 487-6397 fax

Celebrating 20 years of Engineering Innovation (1984 - 2004)
.-. .-. .-. .-. .-. .-. .-. .-. .-. .-
`-' `-' `-' `-' `-' `-' `-' `-' `-'
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.


The first problem is your requirements. Do you want .01 volt accuracy
or .01 volt repeatability at 15 volts?

If you want .01 volt accuracy, then your resistors need to be .01/15 or
better than 0.06% and a 12 bit AtoD.

Also your reference has to be that accurate.

Chad

--- d1camero <> wrote:
> Thanks for all the input. I have tried your suggestions (averaging,
> capacitors, sleeping) without any appeciable change in fluctuation.
>
> BUT, when I removed the resistor divider network, and simply used
> the 12F675 to measure 0-5volts, the ADC works great, with an
> acceptable 1 bit fluctuation.
>
> So my question has changed: How can I accurately measure 10-15volts
> with the 675. Obviously a 1% resistor divider network introduces
> too much noise. Other ideas?
>
> thanks
> d1


=====
My software has no bugs. Only undocumented features.

__________________________________



The source voltage under the scope looks fine. I am also using 1k
and 2k resistor for the voltage divider.

What alternatives are there?

Don

--- In , "Scott Lee" <midl_man@y...> wrote:
> --- In , "d1camero" <a8723@c...> wrote:
> > BUT, when I removed the resistor divider network, and simply
used
> > the 12F675 to measure 0-5volts, the ADC works great, with an
> > acceptable 1 bit fluctuation.
>
> It seems to me that Igor's explaination, which you seemed to
> discount, may be at least some of the problem.
>
> From what I can tell you are trying to measure 10-15V by using a
> resistor divider which will scale the 15V down to the necessary
5V.
> It will also scale that 10V down to 3.33V. Thus, although the A/D
> is measuring over a 0-5V range, the data of interest is in the
3.33-
> 5V range.
>
> You want 0.01V accuracy on the original 10-15V range. The
resistor
> divider is also scaling this just like it scaled the original
> voltage range. Think about it, in the original 10-15V range there
> would be 500 steps (501 levels) at the .01V increments you
desire.
> 500 steps in the 3.33-5V range works out to .0033V increments.
>
> Thus using your resistor divider to measure .01V increments over a
> 10-15V range will require that you measure .0033V increments over
a
> 3.33-5V range. Given that the A/D can measure to a resolution
> of .00488V but at best has an error of +-1 LSB this means that you
> are going to be +-0.015V at best.
>
> Now I know this doesn't explain all of it but you should see that
> there is no way you are going to get the .01V accuracy you desire
by
> taking this approach.
>
> One other point is you you say that you have verified the voltage
of
> the 10-15V supply using two DVMs and it seems quite steady -- have
> you looked at it with a scope? There is a good chance you will
find
> some ripple which the DVMs are filtering out but that the A/D is
> seeing due to the speed of the sample/conversion. As others have
> pointed out, putting a cap close to the input to the PIC should
help
> filter this out. As others have also pointed out it is imperative
> that you not have too high of resistance as viewed from the PIC
> A/D. The fact remains that even following these guidelines you
are
> not going to acheive the accuracy you desire with a resistor
divider.



--- In , "d1camero" <a8723@c...> wrote:
> The source voltage under the scope looks fine. I am also using 1k
> and 2k resistor for the voltage divider.
>
> What alternatives are there?

The cap that multiple people have suggested should smooth things but
you still have the problem that you will never get the accuracy that
you want.

You could always try the opamp as was mentioned here:
http://groups.yahoo.com/group/piclist/message/5438

--Scott


--- In , "d1camero" <a8723@c...> wrote:
> Thanks for all the input. I have tried your suggestions
(averaging,
> capacitors, sleeping) without any appeciable change in
fluctuation.
>
> BUT, when I removed the resistor divider network, and simply used
> the 12F675 to measure 0-5volts, the ADC works great, with an
> acceptable 1 bit fluctuation.
>
> So my question has changed: How can I accurately measure 10-
15volts
> with the 675. Obviously a 1% resistor divider network introduces
> too much noise. Other ideas?
>
> thanks
> d1

I tried to read a lot of the thread, but didn't find any notes on the
stability of the sensor output signal.

I use ADC from a sensor that has considerable noise. There is no
exact value to be found. Everything is some filtered signal that is
close to the actual value.

And for filtering, it can be done in software or hardware, but first
you need to know the frequency of the signal and the frequency of the
noise and then the amplitude of each.

Digital signal processing filtering is the no-holds-barred method at
great expense of time and effort. An R/C is the low tech method.

But, also as was pointed out, you are looking at only one third of
the range available so to amplify your value, you also amplify the
noise.

A software filter can be as simple as adding the last 10 readings,
and dividing by 10 (variations of this are in the archives)

Also, a software method of great value to reduce noise is to take a
sample 15 readings and taking the Arithmetic mean ( mathematical
average) or the Median (middle number disregarding frequency
distribution) or some other method.

I prefer the median as you can take an odd number of readings and
toss out the highest and lowest repeatedly until your last number is
left.

The Median method eliminates the huge variations of a mean
calculation that is skewed by a single high amplitude point. Data
log your point and play in Excel to see how the different methods
work.

So, to accurately measure, you need either an accurate signal or a
method of tossing the garbage.

As a note on signals and measurement, your error is the square root
of the sum of the squares of the errors in the process.

Consider linearity of your original sensor, hysteresis, temperature
effects on both the sensor and your ADC and power supply,
repeatability.... there are more.

I use the rule of thumb that to get an accurate signal, your sensing
needs to be 10 times more accurate than your final reading.

To see what I mean, measure a table with a ruler only using integer
inches or integer centimeters. do not count anything that falls
between the integers. your ADC is doing that also. Just because you
have 10 bit resolution does not mean you have 10 bit accuracy. I
consider that your measuring device must be between 4 times and 10
times more accurate than the device you want to read.

As far as your device goes, use an op-amp, use a simple first order
filter (R/C) and for testing, use a voltage divider on your power
supply to get a steady state signal to compare to your remote signal.

Another place to look is your cap on the PIC on the power supply.
That will help to eliminate some of the voltage fluctuations
generated by the PIC. Those variations will alter the reference
voltage of the ADC and those variations will effect your readings.

Another approach is to use an external ADC and DSP, but that is
probably getting away from the goal of an on-board ADC.

I don't know if this is adding to the confusion or helping to clarify
the problem. My hope is the latter. Dave



Here's my 12F675 C code, with noise filtering. I had the luxury of not
doing much else in the program so was able to use a float.

unsigned int ReadADC(void)
{
unsigned char i;
unsigned int ADC_VALUE;
float ADC_FILT;

// Channel 3
ADCON0 = 0b11001101;
ANSEL = 0b00011000;

ADC_FILT = 0; // Clear out previous count
for (i=0; i<255; i++) // 255 samples taken
{
ADIE = off; // Masking the interrupt
ADIF = off; // Resetting the ADC interupt bit
ADON = on; // ADC powered on
DelayUs(10); // settling time of sample
GODONE = on; // Start the ADC //
while(GODONE) continue; // Wait for conversion complete

ADC_VALUE = ADRESL; // ADC registers are split 2 and 8 bit
ADC_VALUE += (ADRESH << 8); // Combined into a single integer

// Software low pass filter to attenuate noise by -12dB.

ADC_FILT = ADC_FILT + ((ADC_VALUE - ADC_FILT) * 0.0625);
}
ADON = off; // ADC powered off
ADC_VALUE = (unsigned int) (ADC_FILT + 0.5); // Rounding
return (ADC_VALUE); // Return filtered & rounded ADC value
}

Regards

Ian

> -----Original Message-----
> From: Dave Mucha [mailto:]
> Sent: 10 April 2004 16:18
> To:
> Subject: [piclist] Measure 10-15 volts ***accurately*** (was Re: AD with
> 12F675 fluctuations) > --- In , "d1camero" <a8723@c...> wrote:
> > Thanks for all the input. I have tried your suggestions
> (averaging,
> > capacitors, sleeping) without any appeciable change in
> fluctuation.
> >
> > BUT, when I removed the resistor divider network, and simply used
> > the 12F675 to measure 0-5volts, the ADC works great, with an
> > acceptable 1 bit fluctuation.
> >
> > So my question has changed: How can I accurately measure 10-
> 15volts
> > with the 675. Obviously a 1% resistor divider network introduces
> > too much noise. Other ideas?
> >
> > thanks
> > d1
>
> I tried to read a lot of the thread, but didn't find any notes on the
> stability of the sensor output signal.
>
> I use ADC from a sensor that has considerable noise. There is no
> exact value to be found. Everything is some filtered signal that is
> close to the actual value.
>
> And for filtering, it can be done in software or hardware, but first
> you need to know the frequency of the signal and the frequency of the
> noise and then the amplitude of each.
>
> Digital signal processing filtering is the no-holds-barred method at
> great expense of time and effort. An R/C is the low tech method.
>
> But, also as was pointed out, you are looking at only one third of
> the range available so to amplify your value, you also amplify the
> noise.
>
> A software filter can be as simple as adding the last 10 readings,
> and dividing by 10 (variations of this are in the archives)
>
> Also, a software method of great value to reduce noise is to take a
> sample 15 readings and taking the Arithmetic mean ( mathematical
> average) or the Median (middle number disregarding frequency
> distribution) or some other method.
>
> I prefer the median as you can take an odd number of readings and
> toss out the highest and lowest repeatedly until your last number is
> left.
>
> The Median method eliminates the huge variations of a mean
> calculation that is skewed by a single high amplitude point. Data
> log your point and play in Excel to see how the different methods
> work.
>
> So, to accurately measure, you need either an accurate signal or a
> method of tossing the garbage.
>
> As a note on signals and measurement, your error is the square root
> of the sum of the squares of the errors in the process.
>
> Consider linearity of your original sensor, hysteresis, temperature
> effects on both the sensor and your ADC and power supply,
> repeatability.... there are more.
>
> I use the rule of thumb that to get an accurate signal, your sensing
> needs to be 10 times more accurate than your final reading.
>
> To see what I mean, measure a table with a ruler only using integer
> inches or integer centimeters. do not count anything that falls
> between the integers. your ADC is doing that also. Just because you
> have 10 bit resolution does not mean you have 10 bit accuracy. I
> consider that your measuring device must be between 4 times and 10
> times more accurate than the device you want to read.
>
> As far as your device goes, use an op-amp, use a simple first order
> filter (R/C) and for testing, use a voltage divider on your power
> supply to get a steady state signal to compare to your remote signal.
>
> Another place to look is your cap on the PIC on the power supply.
> That will help to eliminate some of the voltage fluctuations
> generated by the PIC. Those variations will alter the reference
> voltage of the ADC and those variations will effect your readings.
>
> Another approach is to use an external ADC and DSP, but that is
> probably getting away from the goal of an on-board ADC.
>
> I don't know if this is adding to the confusion or helping to clarify
> the problem. My hope is the latter. > Dave > to unsubscribe, go to http://www.yahoogroups.com and follow the
> instructions
> Yahoo! Groups Links > --
> Incoming mail is certified Virus Free.
> Checked by AVG Anti-Virus (http://www.grisoft.com).
> Version: 7.0.230 / Virus Database: 262.7.2 - Release Date: 08/04/04
>
--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 262.7.2 - Release Date: 08/04/04


Dave and Scott, thanks for the replies. This gives me something I
can work with.

Don


What am I missing here. Can someone help???

I figure that measuring 15 volts with a .01 volt or 10 millivolt
accuracy is .067%. The Fluke 87 is .05% accurate and lists for
$349.00. A 12F675 costs how much?

My head hurts.

Chad

--- d1camero <> wrote:
> The source voltage under the scope looks fine. I am also using 1k
> and 2k resistor for the voltage divider.
>
> What alternatives are there?
>
> Don >
>
> --- In , "Scott Lee" <midl_man@y...> wrote:
> > --- In , "d1camero" <a8723@c...> wrote:
> > > BUT, when I removed the resistor divider network, and simply
> used
> > > the 12F675 to measure 0-5volts, the ADC works great, with an
> > > acceptable 1 bit fluctuation.
> >
> > It seems to me that Igor's explaination, which you seemed to
> > discount, may be at least some of the problem.
> >
> > From what I can tell you are trying to measure 10-15V by using a
> > resistor divider which will scale the 15V down to the necessary
> 5V.
> > It will also scale that 10V down to 3.33V. Thus, although the A/D
> > is measuring over a 0-5V range, the data of interest is in the
> 3.33-
> > 5V range.
> >
> > You want 0.01V accuracy on the original 10-15V range. The
> resistor
> > divider is also scaling this just like it scaled the original
> > voltage range. Think about it, in the original 10-15V range there
> > would be 500 steps (501 levels) at the .01V increments you
> desire.
> > 500 steps in the 3.33-5V range works out to .0033V increments.
> >
> > Thus using your resistor divider to measure .01V increments over a
> > 10-15V range will require that you measure .0033V increments over
> a
> > 3.33-5V range. Given that the A/D can measure to a resolution
> > of .00488V but at best has an error of +-1 LSB this means that you
> > are going to be +-0.015V at best.
> >
> > Now I know this doesn't explain all of it but you should see that
> > there is no way you are going to get the .01V accuracy you desire
> by
> > taking this approach.
> >
> > One other point is you you say that you have verified the voltage
> of
> > the 10-15V supply using two DVMs and it seems quite steady -- have
> > you looked at it with a scope? There is a good chance you will
> find
> > some ripple which the DVMs are filtering out but that the A/D is
> > seeing due to the speed of the sample/conversion. As others have
> > pointed out, putting a cap close to the input to the PIC should
> help
> > filter this out. As others have also pointed out it is imperative
> > that you not have too high of resistance as viewed from the PIC
> > A/D. The fact remains that even following these guidelines you
> are
> > not going to acheive the accuracy you desire with a resistor
> divider.


=====
My software has no bugs. Only undocumented features.

__________________________________





The 2024 Embedded Online Conference