SPI-controlled adjustable voltage power supply

Posted on
  • Using one of these DC-DC converters:


    The Voltage adjust pot has been removed, and replaced with pinheader. The pot is used as a rheostat, between the output voltage and the voltage sense, which is also connected to ground with a 500 ohm resistor. The power supply tries to keep the voltage on that sense line at 1.2 volts.

    The original plan was to simply replace that pot with an MCP41HV51-103. Those seem to be unobtainium at the moment, so I had to settle for an MCP41HV31-103. This is a high voltage digital potentiometer (up to 36 volts on the analog pins), with 128 taps.

    Unfortunately, when this is at it's lowest setting, it's resistance is still close to 500 ohms, preventing the supply from being set to a low voltage. I needed a way to raise or lower the value of that 500 ohm resistor between sense and ground. Enter an MCP4131-502 SPI digital potentiometer. Since this is just between the sense and ground, we didn't need a high voltage pot. It has 129 taps (not 128).

    The MCP41HV31 pot between Out+ and sense will be hereafter known as the "upstairs" pot.
    The MCP4131 pot between sense and gnd will hereafter be known as the "downstairs" pot.


    +12v from external PSU -> In+ on DC-DC converter
    GND from external PSU -> In- on DC-DC converter, V- and DGnd on upstairs pot, GND on Espruino, P0B, Vss on downstairs pot.

    Out+ (from header where pot was) on DC-DC converter to V+, P0B, and P0W on upstairs pot.

    +3.3v on espruino to VL on upstairs pot, Vdd on downstairs pot.

    B13,B14,B15 -> SCK,SDO,SDI on upstairs and downstairs pots

    SDWN on upstairs pot to +3.3v
    WLAT on upstairs pot to GND

    var us=require("MCP4xxx").connectSPI(SPI2,C4­,1,128);
    var ds=require("MCP4xxx").connectSPI(SPI2,C5­,1,129);

    It works!

    I can change the voltage over the whole range, and get decent resolution over all of that range by adjusting the upstairs and downstairs pots. The next step is to write an algorithm to choose the right settings on the two pots, and maybe add some sort of feedback to the espruino so it can nudge the pots a bit up or down if the voltage isn't right.


    The next steps:
    Order the MCP4231-103 to replace the constant current adjustment pot.
    Some way for the Espruino to read the voltage (maybe just a voltage divider)
    Make a PCB to hold everything
    Find something to do with this thing.

  • @DrAzzy I've been wanting to control the speed of a ventilation fan based in how hot the room is. Will your project work on controlling a fan? The fan I would like to control can be found here.

  • This controls a DC-DC converter, with max output voltage of around 30v at a few amps.

    That fan is a 120VAC fan - so no, it can't be adjusted by powering it from an adjustable voltage DC power supply. I'm not sure how I'd adjust the speed of a line voltage fan. I've done it for a few 120vac fans with some old variacs I had sitting around, but that's not electronically controlled anyway. Of course, you could turn the fan on and off under electronic control easily enough.

  • Bringing 120V AC and a 3.3..5V DC thing together - without either smokeless death of the 3.3..5V device or/and jolt-fully death of you - needs some serious separation elements. But it can be done. How depends on the type of fan motor, of course. Assuming, the motor can be controlled by a #triac, you need two optocouplers for the safety of the Espruino board:

    1. one #optocoupler to detect the #zerocrossing of the AC - connected to an input pin watched by a #setWatch
    2. one optocoupler to drive or 'fire' the triac - connected to an output pin controlled by a #digitalPulse.

    Search on the internet for microcontroller controlled ac fan. A straight forward solution approach is shown in this (Arduino) post: http://www.instructables.com/id/Arduino-­controlled-light-dimmer-The-circuit/. Note the cautions at the end of the post!

    Note also that the circuitry shown is built for driving a resistive load - such as an incandescent bulb - where the filament is the resistor. Resistive loads have a decently nice behavior when switched on and off. In electro motors, the inductive loads are coils that build up and change polarity of magnetic fields in defined (times and) spaces. Switching on and off inductive loads need some extra attention and element. The application section of any data sheet about triac and triac driving optocoupler will show you basic circuitry for resistive and inductive loads. For example, see http://pdf.datasheetcatalog.com/datashee­t/motorola/MOC3010.pdf.

    So (little) much to hardware. Now for the software:

    With 60 Hz AC power (as common in US, 50 Hz in Europe), every 8.333[ms] milliseconds (= 1 / 60[Hz] / 2, with 50 Hz every 10[ms]) an AC zero-crossing happens, and you get an interrupt that invokes the function as you pass as callback in setWatch(). Within the next 8.333[ms] you have to switch on the triac with a digitalPulse() that must NOT last beyond the 8.333[ms] period - or in other words - a pulse that has to end decently before the next zero crossing - in order to enable the triac to switch off as well at the zero crossing. The later in the of 8.333[ms] you switch on the triac with the digitalPulse(), the shorter the triac, lesser energy is passed to the motor, and the slower is the motor.

    I have no figures how much of these 8.333[ms] you have to deduct for overhead before your function is called, for the measuring the temperature, calculating the time for the time out for the digitalPulse(). If sure there is plenty time left for the triac to actually be switched on and switched off timely. @Gordon for sure will have some information what the timings are.

    I know for a fact that Espruino has a powerful mechanism to catch interrupts, queue them in order to not loose any during limited time of interrupt rush hours. With each #interrupt, Espruino also captures the time and passes it to the callback function. With that interrupt time it is possible for the software to detect if there is still enough time for the digitalPulse() to switch on the triac. If not, switching on is skip for the current cycle in favor of prepare for a compensated next one.

    This describes so far the software for a complete software controlled switching. To offload ESPRUINO from the actual switching every 8.333[ms] period, an external circuitry can be put in place that handles just the timed switching based on digital or analogue value given by Espruino. A smartly connected #555 #timer circuit can do that. See for example, http://pcbheaven.com/circuitpages/Voltag­e_Controlled_AC_Light_Dimmer/. The zero crossing detection will now be fed to the 555 timer's TRG trigger input pin, and the an Espruino analog output pin will be connected to the CNTR control input pin. Such a delegation of the switching frees up Espruino to just do the sensing and math 'once in a while' - may be every minute - and set the new analogue value.

    A similar approach has been taken in this post at http://www.alfadex.com/dimming-230v-ac-w­ith-arduino-2/. It contains also information about driving resistive and inductive loads.

  • The power supply looks great! I'm quite tempted to give it a go - one of those Nokia LCDs and a rotary encoder would make a really nice compact variable voltage supply :) Also I reckon you could connect GND via a 1 Ohm (or less!) resistor, and could then measure and display the current drawn....

    As for fan control, triacs are probably best as @allObjects says. You could use something like this which has the opto-coupler for driving built-in, which makes everything much safer.

    You've then got to detect zero-crossings, but if you used an old-style (transformer-based) AC wall-wart power supply you get a lower voltage and can detect it quite safely. For low-noise switching, as the fan has quite a bit of mass, you could simply choose either to power the fan or not power it every 50Hz (during the zero crossing). It's nice and easy and avoids all the timing issues (although those can be overcome if needed ;).

  • Well, the supply supports current limiting, so once I add another pot for that (got em in the mail today, but i'll have to etch a board for the whole mess - As you might have noticed, it's currently a bit of a nightmare to handle, and adding a naked SOP-14 part dangling off it wouldn't make that any easier.

    They have a LED that lights up when current limiting is engaged, so I could take off that to see when it's limiting current.

  • There is a simpler way. Use one of the two DAC outputs and connect a resistor to the Feedback pin of the voltage regulator. Keep the resistor divider that determines the output voltage. if you set the DAC output at the same voltage as the Feedback pin, the output voltage is unchanged. if you set the DAC voltage higher there will be a small current flowing into the Feedback node. so the current in the top feedback resistor must decrease by the same amount. That means that the output voltage must decrease. and the other way around.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

SPI-controlled adjustable voltage power supply

Posted by Avatar for DrAzzy @DrAzzy