I have a project where I use a variable dc voltage (0 to 3v) into an analog pin, to be output to a digital potentiometer (x9c103) to provide 0-10k resistance. I am getting a strange lagging effect. I do an analogRead() on an analog pin, covert the supplied 0-3v to a 0-100 value and provide that value to the digital pot. I use DigiPotX9Cxxx as the library to control the x9c103 (with pot.set(x);), and it works. The 0-3v supply feeding the analog pin is just a 3v battery and a physical 500k potentiometer.
What I am experiencing is a strange ramping up of values, so instead of it being a realtime "turn this knob, see the digital pot react", I'll get a weird latency which isn't just a delay but a ramping up/down in values.
I provide 0v, the digital pot immediately provides 0k output.
I provide 3v, the digital pot immediately provides 10k output.
But if I turn the physical pot from zero to halfway quickly, I'll get increases step by step and after a few seconds it'll reach the correct amount. It's like a slow portamento of inbetween values rather than jumping to wherever the pot is set.
I do not think this is related to the x9c103 as I can set random values and have it respond really quickly.
Am I missing something obvious? Is it the 500k+3v battery has too much impedance? I tried a 100nf to ground on the analog pin and no improvement. I tried setting the prescaler to 16. I tried a few faster analogRead libraries. I've tried various delay times, I've tried calling analogRead twice. Would love some help from smarter folks.
To me it sounds like a grounding problem and this can happen if things are not connected correctly so it is vital we can see a schematic.
This sort of thing can happen because the sample and hold capacitor on the A/D converter is not being fully discharged like this plot I made of a disconnected input.
Sorry it's a bare ATMEGA328PU chip. I program it through the ide with an uno (with a zif socket) and then load it into my own pcb which provides the power and clock and all that. It's working and very stable except for this lag.
I do "need" to use a 500k pot as it's dual purpose (in a guitar) so would a buffer work to get this down to 10k before the analog pin? I'll test with a 10k to see if the problem goes away though, thank you.
Yes, the ADC on the 328P is optimized for an input impedance of 10K or less (see the datasheet for details). A voltage follower on the input would likely do the trick.
Thank you. I'll upload the schematic soon. The other analog pins are being used but they are all grounded or with a voltage, only one is "floating" (used as a switch) but has the input_pullup designated. Should I not use the internal pullup maybe?
Apologies, I'm an idiot. I had used a 100uf cap between the voltage and ground (I used as it's what was on hand at the time to kill wiper noise and never bothered changing it), swapped for 0.1uf, problem solved. I guess I forgot how capacitors worked haha.