skip to main content
Historic District, Mount Dora, FL
Using Other H-Bridges

DAC Controlled DC-DC Converter

The next logical step in our motor controller evolution is digitally controlled DC using a Digital to Analog Converter (DAC) to adjust the output of a DC to DC converter. In our case, we use a buck converter to reduce the maximum voltage of 24V to the desired value. It took some doing to come up with a viable design, but it works like a charm! Now that it's done that is...

To get to this point took some detective work, reverse engineering the LM2596 based buck converter, and experimenting with "external control" we'll call it. These modules are available everywhere, and at 8 for $12, they're a bargain. Feed in 3V - 40V and it puts out 1.5V - 35V @ 3A. The output is adjustable via an onboard 10KΩ multi-turn potentiometer. The plan is to move that potentiometer control to an external one mounted on a panel. The concern is noise picked up along those long leads negatively affecting operation.

Many times the feedback circuits used to regulate the output employ a low pass filter to avoid oscillation, but it's uncertain whether these have any filtering, or whether they can effectively "squelch" any noise introduced on the leads. There's one way to find out. Try it. Getting that onboard pot unsoldered took way too much doing. The extended time with the soldering iron let it get too hot, which damaged one of the plate-throughs or traces on the PC board.

Using an external analog potentiometer doesn't sound much like digital control, granted, but the thought is to use up the surplus of digital potentiometers just sitting and waiting to be useful. Unfortunately, they aren't suitable for the voltages present in the feedback loop. That would have been too easy! But for now, analog pots will do just fine to help better characterize the behavior of the buck converter under external control.

The first discovery is the range of the 10KΩ pot isn't entirely utilized. Too low a value and the controller goes berserk! Once past 6KΩ, the changes to the output tail off. Changing to a 5KΩ pot with another small resistor in series to provide a suitable minimum value doesn't quite have enough range to totally shut off the output. This is all well and good, but it quickly becomes apparent what is needed is a way to leave that onboard pot in place and just inject an external influence.

While searching for more information online, an application note written by Maxim pops up. It's the rosetta stone! Not only does it contain the circuit configuration, but it also includes the formulas to calculate the values for a resistive divider to inject an external current. It's a lot of math, and still includes some guess work, but it provides the path forward.

Now all that's needed is a DAC. After scouring through the parts "junkbox", the results are discouraging. The few archaic finds are from the late '70s, modular, and as big as one of the analog panel meters. Time to order some more modern ones, barely a half an inch square. Talk about miniaturization! They're also higher resolution. All that matters is how to connect it to, and control it with, an Arduino.

It uses the Inter-Integrated Circuit (I2C) interface to interact with the Arduino. There are Adafruit libraries that do it all for you, except these are "knock offs". The provided code doesn't detect the DAC on the I2C bus at the Adafruit device address. Time to write our own wrapper around their libraries that uses the correct address. Other pieces of the puzzle are missing too, like storing the current setting so it's used at next startup.

We'll get to why storing that value is important soon enough. For now, just the ability to control the DAC with a slider on the user interface is good enough to move forward. The circuit is laid out across an experimenter board and our NW switcher engine is dedicated to testing. It's lying on its side on a chunk of foam to keep it from getting damaged and allow the wheels to turn freely. The power pickup shoes make for a sturdy connecton point for those test leads with the alligators clip ends.

It takes some tinkering and tweaking to get the whole thing working, but it works! The onboard pot must be adjusted for the maximum output and no more for the circuit arrangement to work. Adjusting the DAC output is backwards of the desired buck convert output, i.e. the higher the output of the DAC, the lower the output of the converter. Once the DAC is set higher enough to minimize the output of the converter, that onboard pot needs to be adjusted such that the DAC can totally shut off the output.

As with the DAC's analog counterpart, there are minimum and maximum value. Outside that range the output of the converter no longer changes. The lesson learned is the need for three DAC absolute setting parameters, not just two. They are min, max, and OFF. The min value maps to the highest value of the DAC where the converter output is just enough to start the wheels turning. The max maps the lowest value that affects that converter output near maximum speed. The OFF value is guaranteed to turn off the output.

The extra time spent solving the current sensor problem pays off now. Current readings are updated every tenth of a second and reported back to the user interface D3 graph. It was noted that unless the OFF value was set, the output of the converter is still enough for current to flow, just not enough the turn the wheels. The OFF value ensures that the output is zero. Zero volts. Zero amps.

More code changes to integrate the DAC with the speed control hides the internal workings from the user behind a more familiar 0 to 100% slider. Other enhancements include the addition of an external, 16 bit, four channel I2C Analog to Digital Converter (ADC) in addition to a digital encoder for local, manual input. Using a browser or even a smart phone to control the output when testing outside in real world conditions on the Barkyard was cumbersome. The manual input and a 3D printed case solved that problem.

The built in push switch was mapped to change the direction when idle, or initiate a "quick stop" if the train is moving as a sort of "panic button". Push it again and it becomes an emergency stop! While the ADC isn't necessary in this application, it provided more data points during the current sensing investigation, and provides the extra current sense sampling both H-Bridges in the dual units are used. More 3D printed cases were fitted with the different PWM motor controller versions using the encoder as input.

News
October 25, 2025
July 15, 2025
June 21, 2025

Join our newsletter!

There was a problem with your submission. Please correct the issues below