Offline
Jr. Member
Karma: 0
Posts: 76
|
 |
« on: February 02, 2013, 02:12:47 pm » |
Where to begin...
I have been working on a project and one part is to control a DC motor so on and so forth... not the problem.
I have one pot for feedback from the motor and one pot for control. My problem is as one pot changes, it influences the values of the other pot. Ive tried adding more pots and one always affects the other reading. Ive checked all voltages going in and they are constant even as the values change.
We did find a Mcgyverish solution to it.
Suppose I am reading two pots. I must attach one to A1, and one to A3. A0 and A2 must be grounded... and that's not all I need to read A0 and A2, but just ignore the values and then read the values of A1 and A3 I actually want. If this is done, one pot does not affect another. Due to this I am fairly confident it is internal to the Atmega
This works, but I can only use half of my analog pins, but ill need more than that in the end (Im already using a mega).
Does anyone know how this is happening/ how to fix it.
I would be happy to post more information if this isn't enough.
-Nick
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15314
Measurement changes behavior
|
 |
« Reply #1 on: February 02, 2013, 02:21:10 pm » |
What value pots are you using. The arduino analog input pins like to 'see' 10k ohms or lower of source impedance for best results.
Lefty
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 76
|
 |
« Reply #2 on: February 02, 2013, 02:24:33 pm » |
Both are 10K linear taper
|
|
|
|
|
Logged
|
|
|
|
|
the land of sun+snow
Offline
Edison Member
Karma: 81
Posts: 2134
|
 |
« Reply #3 on: February 02, 2013, 02:26:29 pm » |
There can be several problems.
First, if some ADC channels are floating, they will read spurious values which are related to the fact the sampling cap is still holding some remnant of the value from the previous channel read.
Secondly, if the source-impedances to the ADC are > 10K or so, you don't get accurate readings, as the sampling cap does not have time for full-settling.
Thirdly, you might try doing 2 ADC reads in a row on a channel, and see if the 2nd read is more accurate.
Fourthly, if you have a signal coming from a motor, you might want to low-pass filter it with a cap, and smooth out any motor noise. Eg, if you have a current-sensing R in the motor line, you can tap off of it with a 10K, 0.1uF RC filter, etc.
|
|
|
|
|
Logged
|
|
|
|
|
Montreal
Offline
Edison Member
Karma: 17
Posts: 2207
Per aspera ad astra.
|
 |
« Reply #4 on: February 02, 2013, 02:36:43 pm » |
I agree with that: Thirdly, you might try doing 2 ADC reads in a row on a channel, and see if the 2nd read is more accurate. You may increase accuracy taking more readings, than take average: uint16_t summ = 0; for( uint8_t k = 0; k < 64; k++ ) { summ += analogRead(adc_InPin); } summ /= 64; adc_Input = summ;
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 76
|
 |
« Reply #5 on: February 02, 2013, 02:49:22 pm » |
First, if some ADC channels are floating, they will read spurious values which are related to the fact the sampling cap is still holding some remnant of the value from the previous channel read.
Then why does grounding the channels near it and reading them fix that?
|
|
|
|
|
Logged
|
|
|
|
|
the land of sun+snow
Offline
Edison Member
Karma: 81
Posts: 2134
|
 |
« Reply #6 on: February 02, 2013, 02:58:02 pm » |
First, if some ADC channels are floating, they will read spurious values which are related to the fact the sampling cap is still holding some remnant of the value from the previous channel read.
Then why does grounding the channels near it and reading them fix that? Because now you have a hard voltage [0V] on the grounded pins, and a firm ADC reading.
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Online
Brattain Member
Karma: 277
Posts: 25546
Solder is electric glue
|
 |
« Reply #7 on: February 02, 2013, 03:00:37 pm » |
Then why does grounding the channels near it and reading them fix that? Because the zero volts discharges the sample and hold capacitor. If you are using 10K pots and get this effect you have something else wrong, maybe the pot value is not what you think, maybe the wiring is wrong, like a ground is not connected correctly.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 76
|
 |
« Reply #8 on: February 02, 2013, 03:31:47 pm » |
So if I were to read a pot, then read a grounded pin, another pot, and then the same grounded pin, [so on and so forth] would that discharge the cap each time?
-Nick
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Online
Brattain Member
Karma: 277
Posts: 25546
Solder is electric glue
|
 |
« Reply #9 on: February 02, 2013, 03:35:06 pm » |
So if I were to read a pot, then read a grounded pin, another pot, and then the same grounded pin, [so on and so forth] would that discharge the cap each time?
-Nick
Yes
|
|
|
|
|
Logged
|
|
|
|
|
the land of sun+snow
Offline
Edison Member
Karma: 81
Posts: 2134
|
 |
« Reply #10 on: February 02, 2013, 05:14:34 pm » |
If you have a hard voltage on the pin, then the sampling cap will charge to that value. If the pin is floating, then the charge on the sampling cap will not change, or will change in some indeterminate way, and the reading will be irrelevant. Take a look at the ADC input cktry in the ATmega datasheet.
|
|
|
|
|
Logged
|
|
|
|
|
United Kingdom
Offline
Faraday Member
Karma: 131
Posts: 4681
|
 |
« Reply #11 on: February 02, 2013, 05:53:19 pm » |
There are at least three simple solutions for avoiding crosstalk between analog inputs:
1. Patch wiring_analog.c to insert a few microseconds delay in the analogRead code between setting the multiplexer to the desired channel and starting a conversion. The delay you need is about 1us per 10K of source resistance.
2. Equivalent to (1) but less invasive, write your own function to set the multiplexer to the correct channel, delay a few microseconds then then call analogRead. Use this as a replacement for analogRead.
3. Connect a 0.01uF or 0.1uF capacitor between each analog input and ground.
Taking multiple readings from the same pin and discarding all but the last one works in a similar way to solutions (1) and (2) but is slower and less effective, especially when the source resistance is high.
However, you should not be getting crosstalk between analog inputs if they are all fed directly from 10K pots, since the source resistance will be 2.5K at worst. Are you certain the pots are 10K? Do you see the same problem when the motors are disconnected?
|
|
|
|
|
Logged
|
Formal verification of safety-critical software, software development, and electronic design and prototyping. http://www.eschertech.com
|
|
|
|
0
Offline
Tesla Member
Karma: 73
Posts: 6631
Arduino rocks
|
 |
« Reply #12 on: February 02, 2013, 05:58:42 pm » |
Something a bit odd is happening - do you have a schematic of your circuit? You are running a standard Arduino setup with a standard Arduino board? Using Vcc as the reference for analogRead(). You shouldn't see more than a fraction of 1LSB cross-channel interference in those circumstances as I understand it (unless you tinker with the ADC clock settings).
How big an effect is it?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 76
|
 |
« Reply #13 on: February 02, 2013, 06:47:39 pm » |
Normal arduino board.
No shift at the edges, but up to 100 on a 10 bit read at its worst.
Ive had someone else check the circuit and pots and they're fine.
-Nick
|
|
|
|
|
Logged
|
|
|
|
|
Anaheim CA.
Offline
Edison Member
Karma: 31
Posts: 2311
Experienced old Whitebeard with a Full head of Hair...
|
 |
« Reply #14 on: February 02, 2013, 07:04:52 pm » |
Normal arduino board.
No shift at the edges, but up to 100 on a 10 bit read at its worst.
Ive had someone else check the circuit and pots and they're fine.
-Nick Yeah but there's no such thing as magic either and that is next... Bob
|
|
|
|
|
Logged
|
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
|
|
|
|
|