Arduino Forum

Using Arduino => Microcontrollers => Topic started by: cameronasmith on Apr 07, 2014, 07:54 pm

Title: AnalogRead - readings are erratic
Post by: cameronasmith on Apr 07, 2014, 07:54 pm
Hi Guys,

I have an INA125 plugged into a breadboard (i read that this might be a problem) with a strain gauge connected to an Arduino analog pin.

When I take readings it seems to jump around. For example:

101, 102, 101, 101, 102, 101, 101, 101.

Is this normal for a strain gauge? And can anyone recommend a way to not make the signals so erratic.

Thanks,

Cameron.
Title: Re: AnalogRead - readings are erratic
Post by: (deleted) on Apr 07, 2014, 09:06 pm
(deleted)
Title: Re: AnalogRead - readings are erratic
Post by: cameronasmith on Apr 07, 2014, 09:16 pm
Hi spycatcher2k,

Thank you for the advice :). I'm going to give it a try tonight. But my question is why i'm I getting those strange values?

Thanks,

Cameron.
Title: Re: AnalogRead - readings are erratic
Post by: pito on Apr 07, 2014, 09:34 pm
Quote
101, 102, 101, 101, 102, 101, 101, 101.
Is this normal for a strain gauge?

That is normal with ADC.
Title: Re: AnalogRead - readings are erratic
Post by: fungus on Apr 07, 2014, 09:38 pm

Thank you for the advice :). I'm going to give it a try tonight. But my question is why i'm I getting those strange values?


There's nothing strange about it, it's just electronic  noise.

"Strange" would be 101, 102, 101, 303, 302, 101, 101, 101.
Title: Re: AnalogRead - readings are erratic
Post by: CrossRoads on Apr 07, 2014, 09:43 pm
I'm with the other folks on this one.
You could try putting a low pass filter on the INA125 output, could smooth the output some. 101 to 102 represents ~4.88mV of difference if Aref is using 5V.
Could also try adding some more caps to the Aref pin to make that cleaner.
Title: Re: AnalogRead - readings are erratic
Post by: cameronasmith on Apr 07, 2014, 09:48 pm
Hi CrossRoads,

Please could you provide more information on how you would add a low pass filter on:

Quote
You could try putting a low pass filter on the INA125 output


and how you would add capacitors on the Aref pin.

Quote
Could also try adding some more caps to the Aref pin to make that cleaner.


BTW. I'm not using the Aref pin for anything at the moment.
Title: Re: AnalogRead - readings are erratic
Post by: dave-in-nj on Apr 07, 2014, 09:49 pm
I am doing temperature with a LM34

I need to get that to degress.

input is between 0 and 1024 for the ADC, with a 5V supply that is about 10mV per step.
need to divide by the per step value
need to multiply that to get to degrees

I used an integer as a variable and got huge jumps of temperature.

what I wound up doing was to print each value along the way.
once I realized most of my math was after diving the input by 1024.... and then putting that into an integer.
well, it was a wonder I got any readings !

since then, I make sure the values are in the sweet spots of calculations.  multiplying by 10 or 100 to raise the value has made some numbers easier.

also, eliminate any delays in the program.  they seem to accentuate errors.
and lastly, remember, the ADC is using the power as a reference voltage.  either make the power smooth, or use a precision power supply for the sensors.



Title: Re: AnalogRead - readings are erratic
Post by: cameronasmith on Apr 07, 2014, 10:12 pm
Hi dave,

Please can you go into more description on:

Quote
since then, I make sure the values are in the sweet spots of calculations.  multiplying by 10 or 100 to raise the value has made some numbers easier.


Thanks,

Cameron.
Title: Re: AnalogRead - readings are erratic
Post by: CrossRoads on Apr 08, 2014, 02:36 am
Lowpass filter:
http://sim.okawa-denshi.jp/en/CRlowkeisan.htm
Pick an R and a C, try it out.

Caps on Aref - Put a cap between Aref and Gnd right next to it on the header.
Title: Re: AnalogRead - readings are erratic
Post by: Docedison on Apr 08, 2014, 06:47 am
Smoothing is always in order... and the Arduino unfortunately doesn't have a separate ground plane. ?The other unfortunate thing is the fact that the LSB is not something to really count on because the ADC is a SAR? (sp?) or uses successive approximation as the conversion method..
The addition of an analog ground plane that is connected to the lowest impedance point relative to the power return connection. Or both the analog and the digital ground planes must connect at the same point and close as possible to the PSU ground terminal.

Doc
Title: Re: AnalogRead - readings are erratic
Post by: dlloyd on Apr 08, 2014, 07:41 am
Quote
When I take readings it seems to jump around. For example:
101, 102, 101, 101, 102, 101, 101, 101.


Even though a "jump" from 101 to 102 is almost a 1% change (in code), the signal may in fact be so stable that it would take high precision equipment to measure the change.

For instance, if the true signal is:
0.493164 volts for code 101
0.495605 volts (1/2 way between 101 and 102)
0.498046 volts for code 102

Above, it would only need to change by 0.000001 volts (0.495604 to 0.495605) to cause the ADC to output to change by 1 count.

ADDENDUM:
As CrossRoads pointed out, the change in code represents ~4.88mV.
Consider this:
If the signal is changing by 4.879mV exactly between what represents code 101 and 102,
the DAC's output would be stable.
Or, as shown above, it might be only 1 microvolt (or even 1 nanovolt) that causes the code change.
Title: Re: AnalogRead - readings are erratic
Post by: CrossRoads on Apr 08, 2014, 07:57 am
With Aref of 5V, the difference between 101 and 102 is 0.004887V.
Would seem a change of much more than 1uV would be needed to be recognized as one level or the other. I would say more on the order of 0.0024 to 0.0025V.
Datasheet says:
• 0.5 LSB Integral Non-linearity
• ± 2 LSB Absolute Accuracy

Section 24 of the datasheet has more details.
Title: Re: AnalogRead - readings are erratic
Post by: dlloyd on Apr 08, 2014, 09:21 am
Quote
Would seem a change of much more than 1uV would be needed to be recognized as one level or the other. I would say more on the order of 0.0024 to 0.0025V.
Datasheet says:
• 0.5 LSB Integral Non-linearity
• ± 2 LSB Absolute Accuracy


The INL is expressed for the full range of the DAC so it may not factor in to much for small code changes. The accuracy wouldn't be the issue - it would more likely be the resolution or precision of reading.

I agree it could be in the order of 0.0024 to 0.0025V because, of course there's noise to contend with that's probably higher.
Title: Re: AnalogRead - readings are erratic
Post by: Grumpy_Mike on Apr 08, 2014, 09:31 am
Any A/D converter will always give a reading that can change by the least significant bit, that is perficatly normal. What is not normal is expecting a stable unchanging reading from a A/D.
Title: Re: AnalogRead - readings are erratic
Post by: cameronasmith on Apr 08, 2014, 07:26 pm
Thanks Guys,

So what do you recommend in this situation? Should I increase the gain of the INA125?

Thanks,

Cameron.
Title: Re: AnalogRead - readings are erratic
Post by: Grumpy_Mike on Apr 08, 2014, 07:37 pm
No the point was that it is all working as it should be and you should expect no better results. In fact you can not get any better results in terms of stability of reading, no matter what you do. It is how electronics works.
Title: Re: AnalogRead - readings are erratic
Post by: cameronasmith on Apr 08, 2014, 08:34 pm
So, how do people use these weights to measure 1 gram increments?

It came out of a unit that does this feature.

Is it that I just have to do some crazy programming?
Title: Re: AnalogRead - readings are erratic
Post by: dlloyd on Apr 08, 2014, 09:04 pm
Check the datasheet.

It says a single external resistor sets any gain from 4 to 10,000.

You'll need to set the gain so that you get full ADC code swing
for the measurement range you require.

That way when you take a reading, +/- 1 gram will give maximum response.
Title: Re: AnalogRead - readings are erratic
Post by: cameronasmith on Apr 08, 2014, 09:48 pm
Hi dlloyd,

When I try increasing the gain to reasonable readings I can only measure 44 grams, and I need to measure around 200 grams.

What would you suggest?

Thanks,

Cameron.
Title: Re: AnalogRead - readings are erratic
Post by: dlloyd on Apr 08, 2014, 10:02 pm
It would be great if you had posted a schematic, however:

If 200 grams is the maximum you'll ever need to measure,
and 44 grams gives code 1023,
then your gain is set too high.

In this case, you would need to lower the gain so that 200 grams gives code 1023.
Then you could measure any change of 0.2 grams with 0 to 200 gram range.
Title: Re: AnalogRead - readings are erratic
Post by: cameronasmith on Apr 08, 2014, 10:18 pm
Hi dlloyd,

I don't have the schematic in front of me right now, but when I get home i'll send it.

The problem is, that when I lower the the gain the readings of the grams is too close to the drift values from the Analog sensor to get a good reading.

Oh, and the readings are *something* like this:

600 to 860 when the gain is set high

200 to 860 when the gain is set low.

Thanks,

Cam
Title: Re: AnalogRead - readings are erratic
Post by: Grumpy_Mike on Apr 08, 2014, 10:22 pm
Quote
In this case, you would need to lower the gain so that 200 grams gives code 1023.
Then you could measure any change of 0.2 grams with 0 to 200 gram range.

That would only work if the response of the strain gauge were linear. Maybe you need a linearisation amplifier.
Title: Re: AnalogRead - readings are erratic
Post by: cameronasmith on Apr 08, 2014, 10:33 pm
Do you think if I get an ADC with a higher bits like 16 bit it might work better?

Also, what is linearisation amplifier?

Thanks
Title: Re: AnalogRead - readings are erratic
Post by: dlloyd on Apr 08, 2014, 10:34 pm
Quote
The problem is, that when I lower the the gain the readings of the grams is too close to the drift values from the Analog sensor to get a good reading.


Make sure you apply the maximum weight you'll ever need to measure prior to setting the gain.

This procedure sets the span.
Title: Re: AnalogRead - readings are erratic
Post by: cameronasmith on Apr 08, 2014, 10:38 pm
Hi dlloyd,

That's super interesting :

Quote

Make sure you apply the maximum weight you'll ever need to measure prior to setting the gain.
This procedure sets the span.


I've never heard that before? So depending on the weight I have on the scale will adjust my reading when I change the gain?

Title: Re: AnalogRead - readings are erratic
Post by: Grumpy_Mike on Apr 08, 2014, 11:01 pm

what is linearisation amplifier?

See attached, it applies to strain gauges as well:-
Title: Re: AnalogRead - readings are erratic
Post by: dlloyd on Apr 08, 2014, 11:07 pm
Also look at this from the datasheet:

Connecting VREFOUT (pin 4) to one of the four available
reference voltage pins (VREFBG, VREF2.5, VREF5, or VREF10)
provides an accurate voltage source for bridge applications.


The datasheet shows pins 4&16 shorted (VREF10).
I think you should try VREF5 (jumper pins 4&15) after reading this (http://www.edaboard.com/thread280860.html):

I have 2 load cell parts, one for 1kg and the other for 200kg. The 1kg load cell works good with pins 4&15 shorted, but the 200kg load cell gets the precision reference to drop a little.
Title: Re: AnalogRead - readings are erratic
Post by: dlloyd on Apr 08, 2014, 11:23 pm
Quote
I've never heard that before? So depending on the weight I have on the scale will adjust my reading when I change the gain?

That's what the stain gauge is doing - varying it's output resistance which varies the analog voltage.
You need to adjust the gain with maximum weight (max voltage) to set the full scale reading.
Otherwise,  you're adjusting full scale reading with 0 gram (minimum voltage).
Title: Re: AnalogRead - readings are erratic
Post by: cameronasmith on Apr 09, 2014, 03:07 am
Quote
I think you should try VREF5 (jumper pins 4&15) after reading


Hi dlloyd,

Thank you for the suggestion. I have the pin connected to 15 because:

Pin 16 is for 10 volts

and Pin16 is for 5 volts.

Do you think if I get a ADC with higher bits I would get better readings? More gain and more results or do you think the drift would just match the increase?

Thanks,

Cameron.
Title: Re: AnalogRead - readings are erratic
Post by: dlloyd on Apr 09, 2014, 03:30 am
Quote
Thank you for the suggestion. I have the pin connected to 15 because:
Pin 16 is for 10 volts
and Pin16 is for 5 volts.


Just noticed this in the datasheet (http://www.ti.com/lit/ds/symlink/ina125.pdf), pg11.

Positive supply voltage must be 1.25V above the desired
reference voltage.


So it looks like you need to use VREF2.5 (jumper 4 & 14).
Title: Re: AnalogRead - readings are erratic
Post by: cameronasmith on Apr 09, 2014, 08:00 pm
Hi dlloyd,

Thanks for your post. Yeap, that improved things, but I think I just need a higher resolution ADC to get more accurate results. I guess I have to wait for a week while it comes in the mail.

The only other thing I thought about was maybe there was some calculation I could do:

For example:

834 = 500 grams
133  = 0 grams

When I increase the gain the 500 grams goes over the scale:
834 = Unknown weight
526 = 0 grams

Can anyone think of a way to calculate what the weight might be here? That way I could adjust the sensitivity with the previous 500 gram reference.


Title: Re: AnalogRead - readings are erratic
Post by: dlloyd on Apr 09, 2014, 08:17 pm
If you try (jumper 3 & 13), VREFBG (1.24V) it would probably give you further improvement but limit the high end. It might be OK because 200g max is all you want to measure.

Start out by using the min gain of 4 (remove the gain resistor between pins 8 and 9).
Title: Re: AnalogRead - readings are erratic
Post by: cameronasmith on Apr 09, 2014, 08:30 pm
Hi dlloyd.

Do you mean jumper 3 & 13 or jumper 4 & 13

BEcause i have been so far:

jumper 4 - 16
jumper 4 - 15
jumper 4 - 14
Title: Re: AnalogRead - readings are erratic
Post by: dlloyd on Apr 09, 2014, 08:33 pm
Oops...4 & 13
Title: Re: AnalogRead - readings are erratic
Post by: cameronasmith on Apr 10, 2014, 02:39 am
Thanks, dlloyd,

You have been a great help. The suggestion you made did make an improvement, but I think I still need an ADC with more bits.

I'm not really sure how the INA125 pins 4 & 13 really work. Please could you explain it to me.

Thanks,

Cameron.
Title: Re: AnalogRead - readings are erratic
Post by: dlloyd on Apr 10, 2014, 04:27 am
Quote
I'm not really sure how the INA125 pins 4 & 13 really work. Please could you explain it to me.


It sets the reference voltage...its effect can be seen in the formula below.

I think the main difficulty here in being able to use the full range of Arduino's ADC, is that there is no -5V supply, so you need to make single supply connections as in figure 6. In this diagram, they are connecting pins 4 & 14 for 2.5V reference. Note that (load -) is also Vref, so the maximum linear range (I think) would be from code 512 to 1023.

So, by lowering Vref to 1.24V you could achieve maximum linear range of code 256 to 1023.
With a -5V supply and figure 1 diagram, you could achieve full range (0 to 1023).

The formula here tells all:
(http://i62.tinypic.com/2i0g86o.jpg)
Title: Re: AnalogRead - readings are erratic
Post by: dlloyd on Apr 10, 2014, 04:56 am
Forgot to mention, with 767 steps in code (1023-256) and 200 grams max weight,
you would get 200/767 = 0.26 grams per step.

To calibrate, you would need to use a 200g weight, then adjust gain for maximum code. If your zero gram reading is at 256, then the formula to calculate any weight from 0-200g would be ((code reading - 256)/767)*200 grams.
Title: Re: AnalogRead - readings are erratic
Post by: cameronasmith on Apr 10, 2014, 03:04 pm
Thanks dlloyd,

You've helped a lot! I'll let you know when I get a 16bit ADC :) Hopefully, that will improve things.