I have put small caps across the analog input and ground before to try and smooth out readings, it seemed to work. This was for a thermistor voltage dividing circuit. I have read that this is not a good practice, however I'm not sure it matters as long a your sampling rate is low. I can't remember what value of cap I used. If I recall correctly the cap was between .1uf and 10uf.
Did you try putting a capacitor between the input and ground like Shawn suggested? You should also have a bypass cap between power and ground on the ADC chip.
Yes, I added a .1 uf cap between the pot wiper and ground.
Is it possible that all of these problems are due to me working on a breadboard with jumper wires?
Perhaps it's doing its job the better as it could, while being pushed to its specc'd limits, for sure, and the use of a breadboard would certainly pose further concerns, due stray capacitances, lack of proper shielding against noise coupling and detrimental/unwanted feedback paths, just to name a few.
Better keep off them for a while, untill you feel confortable with your results, at least.
If you want to spare the operational amplifier from being damaged, while doing direct solder joints at its pins, just select a suitable dip socket to insert it, after all the soldering stuff is completed; machined-pin ones seems to be a better option, for contact reliability and ease of access, though they would demmand better alignement and straightening of the component pins, and also a bit of extra force, when it comes for insertion and extraction of the dip-packaged part.
In order to get some inspiration, just take a look at the Computer History Museum exhibition of Jim Willians' preserved workspace, at Linear Tech. Flying components, wireframes and solder spots did never looked that better, anyway.
I don't mind soldering the opamp. I have several of the chips and each chip has four opamps so I have plenty of spares! Maybe I'll try directly soldering everything. I was about to do that anyway except that I wanted to verify that the circuit worked before I did it. Thanks everyone for your help. So far I've been pretty successful getting digital circuits to work but it seems I have a long way to go before I'm comfortable with analog circuits.
The cap should be right at the input to the ADC. However, you need to add a resistor between the opamp and the ADC to create an RC filter. With a 0.1uf cap and a 10k resistor you'll have a time constant of 1 msec. You might try a larger cap, such as 1 uf. If that works, then you might be able to eliminate the opamp.
I almost invariably hook up pots as part of an RC timing circuit with a single I/O. You just use it as a series resistor with an arm and the wiper. So much simpler and you can flatten the reading in software if need be as well. The cap automatically "filters" the noise too. Use a series resistor to limit the current when the pot resistance is zero (the pot is in parallel with the cap).
Basically you charge the cap for a few tens of microseconds or so, float the I/O, read the CNT and WAITPNE etc or some other similar method.
I didn't have any 1uf caps so I tried a 10uf cap and it didn't work any better. Maybe I'll take the opamp out of the circuit to see if just the cap works.
Looking at your breadboard it is a mess of "antennas" and no supply bypass caps in sight. Any analog circuit used with RF or digital needs a tight layout that isn't possible with breadboards. Alternatively you can put the analog stuff on a small matrix board and plug it into your breadboard.
The MCP3208 needs a really clean supply and ground. I can't see how it can on with this layout.
Looking at your breadboard it is a mess of "antennas" and no supply bypass caps in sight. Any analog circuit used with RF or digital needs a tight layout that isn't possible with breadboards. Alternatively you can put the analog stuff on a small matrix board and plug it into your breadboard.
Yeah, I think all of the long wires are likely the problem. The ADC module has its own bypass cap but I should add one near the I/O expander chip. Maybe I'll hardwire all of this stuff on a protoboard to see if that helps.
Ok, I see the circuit a bit better now and the I/O expander (I thought it was the A/D) and the opamps etc. If you bring the power in on the right side where the A/D is you might find it will reduce the noise since at present it is on a long ground and supply rail and subject to noise from that end.
I would like to suggest something, just a little bit more "radical"...
You said you have at least another LM324 in hand, so my first advice would be not too simple, but I suggest you "copy/paste" the whole analog stuff to an isolated segment at the protoboard, as follows (sorry by doing some "graffiti" stuff, over the picture of your project)...
Addendum: If you feel that as an attack on your copyright privileges, I'm all for eraseing it, promptly. Henrique
- as much as possible (and whenever possible), keep analog stuff apparted from digital paths;
- keep things as streamlined: signal-source-paths, them amplification/conditioning, them conversion;
- (*) star-wise supply connections do ever shine;
- unless you're using pcb layers as power planes, or connecting all power paths into central points (as star-wise ones, like an "*"), any of "H, X or *"-wise connections, in the middle of straight-lined power supply routes are prone to create loops (either GND ones, or any other voltage potential), causing many "stubs", each one a potential pick-up/source of noise and signal reflections on its own;
Thanks for the suggestions. I will separate the analog stuff to see if that helps. In fact, maybe I'll just remove the port expander and OLED display entirely to see if just the analog stuff by itself will work. I was really hoping I could replace the ADC chip and the port expander with a P1 but someone suggested against that.
In thinking about this, I'm wondering which long wires I need to avoid. It occurs to me that for my project I'd probably like to have the potentiometer mounted separately from the PCB with a three-wire harness connecting it. Do I need to make sure that is shielded?
Personally I would avoid using an ADC just to read a pot, it's such an overkill. However just to check to see where the noise is coming from why don't you hook up a resistor divider, say two 1k resistors, to the supply and ground and feed the middle of that to the A/D as if it were the pot at half position. Just put the resistors as close to the A/D as possible. Now check the readings. If they are all over the shop then your noise is probably from the supply and ground etc. Progressively you can narrow down the source of the noise rather than focusing too much on the pot. btw, what value is the pot? A lower value is better in that it will be less affected by noise due to the loading effect of lower resistance.
Personally I would avoid using an ADC just to read a pot, it's such an overkill. However just to check to see where the noise is coming from why don't you hook up a resistor divider, say two 1k resistors, to the supply and ground and feed the middle of that to the A/D as if it were the pot at half position. Just put the resistors as close to the A/D as possible. Now check the readings. If they are all over the shop then your noise is probably from the supply and ground etc. Progressively you can narrow down the source of the noise rather than focusing too much on the pot. btw, what value is the pot? A lower value is better in that it will be less affected by noise due to the loading effect of lower resistance.
I started using the ADC because the one analog input on the ESP8266 was noisy and I thought using an ADC would help. When it didn't, I stuck with the ADC because I need to be able to measure both the pot and the battery charge level so I figured I'd need more than the one ADC that the ESP offers. If I switch to using a P1, I guess I can have as many ADCs as I want and the P1 can also handle the buttons and any LEDs I might need. The only thing I'm a bit worried about is that the P1 probably draws more power than the port expander and ADC chips.
I tried using the LM324N opamp and it didn't help. Also, I notice that the noise increases if I touch the pot. Not sure where to go from here.
That the noise increased when you touched the pot suggests that the pot may be the source of the noise. That was a very common problem with early analytic instruments that used potentiometers to adjust gains and threshold levels.
If I switch to a P1 for handling the pot and buttons what is the recommended way of establishing communications between the ESP8266 and the P1? I know the Parallax module uses a UART connection but I kind of liked using the i2c connection with the port expander and ADC chips. Has anyone written an i2c slave object for P1?
If I switch to a P1 for handling the pot and buttons what is the recommended way of establishing communications between the ESP8266 and the P1? I know the Parallax module uses a UART connection but I kind of liked using the i2c connection with the port expander and ADC chips. Has anyone written an i2c slave object for P1?
IIRC there should be several I2C objects around. If not I have some spin code somewhere that sent out 32 bit chunks of data using the same clock and data signalling as a starting point. Ask and I will dig it out and post it.
If I switch to a P1 for handling the pot and buttons what is the recommended way of establishing communications between the ESP8266 and the P1? I know the Parallax module uses a UART connection but I kind of liked using the i2c connection with the port expander and ADC chips. Has anyone written an i2c slave object for P1?
IIRC there should be several I2C objects around. If not I have some spin code somewhere that sent out 32 bit chunks of data using the same clock and data signalling as a starting point. Ask and I will dig it out and post it.
I know there are lots of I2C objects that an allow the P1 to act as master. I wasn't sure about ones that supported slave operation. I think the ESP8266 is going to be the master in my system.
I just found a dumb mistake that I made that has the effect of amplifying the noise I'm seeing. I remember wrong which ADC module I purchased. I had thought I purchase the 16-bit ADS1115 module but I actually purchased the 12-bit ADS1015 module. In the 12-bit module, the low order four bits in the 16-bit data register are always zero. This had the effect of multiplying any error I was seeing by 16. I shifted the ADC value to the right by four bits and now the values don't jump around as much. I also moved the analog circuit on the breadboard so it isn't right next to the digital components. That may have helped a bit as well. I'm still playing with the opamp and filter circuits though.
If so, I agree. The 10-bit MCP3002 seems to work better with potentiometers than the 12-bit chips. It's not as accurate as the 12-bit ADCs but it is more tolerate of high impedance inputs.
Comments
Please, don't blame that poor LM324N, alone!
Perhaps it's doing its job the better as it could, while being pushed to its specc'd limits, for sure, and the use of a breadboard would certainly pose further concerns, due stray capacitances, lack of proper shielding against noise coupling and detrimental/unwanted feedback paths, just to name a few.
Better keep off them for a while, untill you feel confortable with your results, at least.
If you want to spare the operational amplifier from being damaged, while doing direct solder joints at its pins, just select a suitable dip socket to insert it, after all the soldering stuff is completed; machined-pin ones seems to be a better option, for contact reliability and ease of access, though they would demmand better alignement and straightening of the component pins, and also a bit of extra force, when it comes for insertion and extraction of the dip-packaged part.
In order to get some inspiration, just take a look at the Computer History Museum exhibition of Jim Willians' preserved workspace, at Linear Tech. Flying components, wireframes and solder spots did never looked that better, anyway.
https://computerhistory.org/blog/an-analog-life-remembering-jim-williams/
Basically you charge the cap for a few tens of microseconds or so, float the I/O, read the CNT and WAITPNE etc or some other similar method.
The MCP3208 needs a really clean supply and ground. I can't see how it can on with this layout.
Yeah, I think all of the long wires are likely the problem. The ADC module has its own bypass cap but I should add one near the I/O expander chip. Maybe I'll hardwire all of this stuff on a protoboard to see if that helps.
You said you have at least another LM324 in hand, so my first advice would be not too simple, but I suggest you "copy/paste" the whole analog stuff to an isolated segment at the protoboard, as follows (sorry by doing some "graffiti" stuff, over the picture of your project)...
Addendum: If you feel that as an attack on your copyright privileges, I'm all for eraseing it, promptly. Henrique
- as much as possible (and whenever possible), keep analog stuff apparted from digital paths;
- keep things as streamlined: signal-source-paths, them amplification/conditioning, them conversion;
- (*) star-wise supply connections do ever shine;
- unless you're using pcb layers as power planes, or connecting all power paths into central points (as star-wise ones, like an "*"), any of "H, X or *"-wise connections, in the middle of straight-lined power supply routes are prone to create loops (either GND ones, or any other voltage potential), causing many "stubs", each one a potential pick-up/source of noise and signal reflections on its own;
Hope it helps
Henrique
https://analog.com/en/products/lt1677.html#product-samplebuy
There is a PDIP 8-pin version (at least), but it's not cheap (~US$ 5.85/ each).
All the specs seem to be very good, near TI's SMD alternatives.
Hope the LM324 could do it, in order to spare your credit card for Christmas season...
That the noise increased when you touched the pot suggests that the pot may be the source of the noise. That was a very common problem with early analytic instruments that used potentiometers to adjust gains and threshold levels.
IIRC there should be several I2C objects around. If not I have some spin code somewhere that sent out 32 bit chunks of data using the same clock and data signalling as a starting point. Ask and I will dig it out and post it.
Mike
Do you mean a MCP3002?
If so, I agree. The 10-bit MCP3002 seems to work better with potentiometers than the 12-bit chips. It's not as accurate as the 12-bit ADCs but it is more tolerate of high impedance inputs.