Programmable voltage source with digital potentiometer - Page 1
Forum section: electronics / projects

author: BlvckBytes
author_rank: Newbie
timestamp: March 13, 2024, 08:13:53 pm
content: Hey there!I'm trying to build something very simple, which has consumed more time already than it ever should have... I'm at my wits end and hope to get some advice or debug inspiration on here.In essence, I need a constant current driver which operates between roughly 10V and 30V and can drive anything from 1-2mA to 300mA, which offers remote control functionality and runs off of any old 5V 2A USB charger.What came to mind was using an ESP8266-12F I had laying around, running a web-server with the web-socket handler, hosting it's own little application specific website: a simple slider with tap for on/off and slide for 0-255 "dimming". So far, so good, that all works out.Next up, I've used a 1/100 Ohm shunt, along with an LM324D op-amp I also had around, going into a ADS1115 16 Bit ADC, as that one on the ESP didn't quite suffice for my application (and has a bad reputation, as far as I could read up online). I can now measure the current any given load draws quite accurately, so that all works out too.Next up, I've ordered some XL6009 boost-converter boards from amazon, and bought a few MCP41HV51-10K digital potentiometers, which can handle up to 36V, if I understood the datasheet correctly. My idea was, as I've seen done countless times online already, to use the digi-pot as a rheostat and just substitute it into the place of the on-board 10k potentiometer. The XL6009's regulates V_out based on the resistor divider attached to the feedback-pin between V_out and GND as: V_out = 1.25 * (1 + R2/R1), where R1 is the fixed resistor on-board and R2 is the digi-pot in rheostat mode. R1 = 425 Ohm in my case.Since I've lost an IC due to a "race condition" between the digi-pot getting set up and the XL6009 starting up, I've added a high-side mosfet as a switch before the boost-converter, to only enable it from software once the XL6009 is in a known state. I read back the wiper register after each write, to ensure functionality, or otherwise put the device into a boot-loop, trying over and over again.Anyways, I haven't yet fully understood the purpose of V+ and V- on the digi-pot, seems to me that they should be applied with the potential that is used on A, W and B? I've tied V- to GND. When tying V+ to 5V, A-B measures roughly 10k, and W-B is a resistor value directly proportional to the wiper register: 0 -> 395 Ohm (weirdly high), 128 -> 5.19k Ohm, 255 -> 9.93k Ohm.To try and regulate the feedback pin's voltage, I've tied V+ to V_out of the regulator, tied V+ to the wiper, and tied B to the feedback pin of the regulator, where there's also that 425 Ohm resistor to ground, making up the voltage divider. For safety, I've added a 33V zener diode to V+ against GND, as to clamp its voltage in case V_out spikes for whatever reason.So far, so good, no smoke or heat, but V_out just doesn't work as intended. If I set the wiper to 20, I'd expect(9930 - 395)/255 * 20 + 395 ~= 1143 Ohmand thus1.25 * (1 + 1143/425) ~= 4,6Vbut instead, I get 31V. With a wiper of 16, it's at 30V, at 12 it's roughly 28.2V. I have no idea as to why this weird behavior happens, and would be very appreciative of any ideas on how to debug the circuit. Also, I know that this might not be the smartest approach of what I'm trying to build, and I'd also love to hear about alternative approaches, but now I really want to know why this idea doesn't just work as intended, as I've seen it done before with other regulators.(I don't think that sharing any code will help, as this is a hardware issue, and I'm 100% sure that I set the wiper register correctly.)

author: PCB.Wiz
author_rank: Super Contributor
timestamp: March 13, 2024, 09:36:02 pm
content: Try and get it working 'as expected' first, with a very simple 0-5V setup.Notice that digital pots have worse precision and tempcos when used as rheostats, rather than as ratiometric dividers.Usually, you try to have no current through the wiper, to reduce the wiper variation effects. Your setup does not do that.Ideally, you also want to use the full range of the pot, for best control.If you know you want 10-30V, you could set up two divider legs from V_out, one for 10V and one for 30V, and then the pot spans between those, giving a percentage of both.The pot ratio to voltage is not linear, so you need a simple table or calculation.The 10V and 30V points are now very precise, and the absolute resistance variation matters far less.Or, you can set up a pot as a (eg) 5V DAC, and use that to adjust current into the reference pin, to give 10-30V out.That is 'almost linear', the pot equivalent source impedance causes a slight S bend.That also allows you to use a lower voltage Digital POT, which are cheaper.