Monday, 25 April 2016

Lab Power Supply - Board Redesign

So in the last post I was at the point where I felt I had ironed all the faults out of the current design and felt it was time to go for a new board. Since then I rolled all the changes back into the schematics and designed a new board that integrates all those changes.

Schematic Changes

So I will go through each section of the schematic, list the changes and then include the updated schematic.

Power

In this section I made the following changes:
  1. I added a diode across the relay to suppress back-EMF when the relay is switched-off.
  2. I changed the 24V LM317 to be a TO-220 package as the surface-mount version was getting too hot.

Pre-Regulator

In this section I made the following changes:
  1. A buffer for the Ioutmon (U14) and Voutmon (U7D) signals to stop them affecting each other through the summing amplifier. This was causing the voltage to vary under load and causing incorrect current readings at low currents.
  2. A peak-detector (D12, C28, R52) to slow down the decrease in the pre-regulator when the voltage drops. This helps stabilize the output when a pulsed load is driving the system into current limit
  3. A minimum voltage of 0.6 + 3.3V to the pre-regulator (D13, D15, D14, R57). This prevents the pre-regulator going down to zero when the output voltage is very low (for example if you set the current limit to a very low value like 20mA)
  4. A bypass capacitor for U7 (was missing from previous schematic).

Post Regulator

In this section I made the following changes:
  1. The orientation of Q8 was corrected (collector and emitter where the wrong way round due to a footprint change when I changed the component model).
  2. The differential amplifier measuring the output voltage was changed to use 100K resistors and the compensation capacitor was reduced to 4.7pF. This increases the impedance of the amplifier inputs but then the compensation had to be reduced to maintain the same response time.
  3. I removed the four terminal voltage sensing. This wasn't stable and I didn't want to mess around to fix it so for now I am not supporting sense terminals. I will still sense the voltage at the output terminals but you can't connect sense wires to an external load.
  4. The MOV output protection was changed to just 2 MOVs. This is as a result of the change to only have two terminals instead of 4.
  5. The current sense resistor was changed to the Vishay VC1625. While the tempco and accuracy of the Welwyn OAR3 resistor was fine, the thermoelectric effect wasn't. I decided to go with a higher precision four terminal current sense resistor.

PCB Changes

I have been struggling to find a case that will house the project and then the recent discovery that I needed to put the bridge rectifier on the heatsink led me to re-think the problem. In addition to the bridge I need to include another TO-220 for the 24V supply which means I need to make the board much wider.

The heatsink I chose is 254mm wide (10") so there is no option to put three modules on one heatsink. I figured out that if I can reduce the length of the board to below 100mm the project will fit comfortably fit inside a 3U 19" rackmount case. 3U gives me 130mm of height for the Raspberry Pi touch screen which leaves around 30mm of height for binding posts.

The 19" case however is 480mm wide which gives me lots of space. I realized that if I got another heatsink and cut it in half (so 125mm wide) I could fit this in the case also and still get three channels.

Layout Changes

Having the bridge on the back edge makes some things a bit tricky. The bridge needs to be near the relay, the pre-regulator MOSFETs, the capacitors. The VCC bridge also needs to be nearby also but this creates a problem if the power connector is at the edge of the board as some traces would need to be router right over the other side to get to the internal voltage regulators.

Instead I put the internal regulators (for VCC, 5V, 24V) on the left side, the power connector, relay and bridge in the middle and then the pre-regulator MOSFETs and output MOSFET toward the right.

The pre-regulator circuit (except for the opamps) is at the top right near the pre-regulator MOSFETs. The bulk capacitors are between this and the output.

The analog section is at the front near the middle and then the digital section is to the left (section with ground plane). The USB section is below the internal regulators and behind the other digital sections. It wasn't practical to put the USB connector at the edge of the board so this too is in the middle nearer to the power input.

I also used 4mm traces for the heavy current tracks which allowed me to make the board quite compact. 

This worked quite well overall as none of the power traces are very long, the analog bits of the digital section are close to the analog section and the analog section is close to the negative output (which is the ground point for the circuit) and the sense resistor.

The layout is much more dense than before so there are a few more vias. The control lines for the relay transistor, the VCC voltage control and the signal that controls the pass transistor were particularly difficult to route.

I was able to fit nearly everything in with 80mm of width but I couldn't figure out how to rout the Vrelay and Vsetplus lines. I ended up adding an extra few mm of width so the board is 128mm instead of 125mm. This will have a negligible effect except that there will be a slight overhang off the ends of the heatsink.


Here is how the board looks in 3D - not all parts have models.


Other layout corrections:

  1. The ground routing for the analog and digital section all comes off one track that connects right at the sense resistor. Before some of the grounding came off an earlier point on the heavy-current ground path and this created some voltage differences.
  2. The PTC was placed further from the sense resistor to avoid temperature induced errors.
  3. The placement of the capacitors for the AD7705 crystal were too close so these were placed a bit further off.
  4. A bit more space was added between the pass transistor and the pre-regulator MOSFETs to allow the aluminium dioxide insulator pad to fit.

Footprint Changes

  1. The MOV footprint was mirrored before (made sense from bottom of board). This was corrected.
  2. The PTC footprint was mirrored before. This was corrected. Also the footprinted suggested by the manufacturer had the feet too far off the axis of the part so I reduced this a bit to make the part fit more comfortably.
  3. The MCP2200 footprint was the wrong width and this was corrected
  4. The AD7705 was changed to be the SOIC footprint as I got some of these cheaply off ebay.
  5. The pads for the main capacitors were too small. I added bigger pads for better mechanical strength.
  6. The LM317 used for 24V rail got too hot as a surface mount component so this was changed to a TO-220 part.

Next

So I have ordered more boards from Seeed studio and am waiting for these to be manufactured. Next step will be assembling and testing the channel on the new board.

Wednesday, 13 April 2016

Lab Power Supply - Pre-regulator re-visited

A while back I noted some odd behaviour in the pre-regulator when the load is current is switching at 10Hz or less and the power supply is going in and out of current limit. Then more recently I noted a fault with the summing amplifier where it was effecting the current measurement and voltage measurement. While working on the current measurement I noted another fault which is that if the output voltage is driven really low (say if you set the output current to 50mA and connect a dummy load trying to suck amps) the pre-regulator can drive the voltage right down to zero and lock-up the supply.

So I thought it was time to re-visit the pre-regulator design.

Current Affecting Voltage

For a while now I have been chasing problems where the output voltage would dip with the current increased. The problem is that there were multiple reasons for this. One reason is that the ground points were not correctly placed so the larger currents created voltage differences across some conductors which then lead to ground voltage differences across the circuit. I tracked down a few of these in the PCBs already.

I also had problems with poor connections between the sense and output voltage lines causing issues. On top of this there is a 1mV or so drop across the binding posts under more than 1.5A of load.

Earlier I realized that the input impedance of my differential voltage amplifier was too low and was affecting the readings.

The latest problem is that the summing amplifier in the pre-regulator ties together the Vout and Iout lines using 10K resistors. This is enough for the output voltage to affect the current reading by a few mV and for the current reading to affect the voltage reading by a few mV.

So now I have added buffers between the current monitor and the summing amplifier (I have a spare op amp in one of the chips). In the final design I will also add another op amp to the board for the second buffer.

Pulsed Current Limit Load

This was pretty hard to reproduce in the simulator but easy to see on the scope. Here is a shot of the output voltage and capacitor voltage that I took before:

You can see the capacitor voltage has dropped and so the output voltage can't get back to the set voltage before the load hits again (which drives the output voltage low again). The worst part of this is that the output will slowly slew from a state where it is outputting the set-voltage at the peaks then down again.

The problem is that the pre-regulator compares the output voltage with the capacitor voltage at the instant that the capacitor is charging (as the next 100Hz pulse from the bridge is coming in). If this happens to be at a point where the output voltage is low because the supply is in current limit then the capacitor won't be charged to a level sufficient to provide the set-voltage.

I was thinking that what I really want is for the desired capacitor voltage to increase quickly to meet demand but to decrease slowly. 

The solution was to add a peak-detect circuit to the output of the summing amplifier so the pre-regulator set-point moves down slowly enough that it won't get caught short when the load is switching on and off at a slow rate. The peak detect has to be fast enough that it will eventually bring the pre-regulator set-point back down to limit heat dissipation on the pass transistor. I chose to make the time constant about 1 second which seemed to work quite well. Here is what the pre-regulator looks like with this added
.
This worked very well. The pulsed load issue went away entirely with a 50Hz pulsed load (the lowest frequency I can do with my dummy load). 

The only issue is that under extreme conditions it will create a significant heat load. I set the output for 25V, the current limit for 2.5A and the dummy load to draw 3.9A in pulses at 50Hz. This creates a close to optimally bad load as the capacitor voltage is over 25V, the output voltage drops to a very small voltage but 2.5A is flowing. The pass transistor got pretty warm but was well within safe limits after a few minutes of operation (I still have problems with the bridge rectifier over-heating so can't test for too long).

Pre-Regulator Lock-up

I wanted to see how accurate the current measurement and current limiting was at very low currents. I set the current limit to 50mA and enabled my dummy load. The output voltage quickly fell down to somewhere in the mVs but then something odd happened - it fell to zero and so did the output current.

I tried this out in LTSPICE and I was able to reproduce it:

This took some time to figure out but the problem is that to keep the pre-regulator 4V above the output, it uses a zener diode to subtract this voltage from the capacitor voltage and compare the subtracted voltage with the output required. As the output drops below 4V (the zener voltage) the zener diode is no longer in breakdown and so the voltage is less than 4V below the output.

If the output voltage is very low then the pre-regulator can drive itself down to a point where the capacitor falls to zero and then the output is zero so it never turns back on!

Once I had a handle on what was going on I decided to peg the minimum voltage to something sensible. With the peak-detector in place I can add another diode to form a sort of diode-or with another voltage which will become the minimum pre-regulator voltage. To begin with I set the minimum to be 4V but then the pre-regulator will hold at 8V as it subtracts 4V from the output before comparing. In the end I added two diodes in series to create the minimum voltage (which gets droped to one diode voltage because of the diode-or) but this worked a treat. Now the minimum pre-regulator voltage is roughly 4V.

Here is the circuit with the minimum voltage setting.

This worked in simulation. The pre-regulator then behaved more like this:


When I tried this on the PCB it worked similarly. The new circuit had no effect at higher voltages and prevented the lock-up. I think this pretty much concludes my work on the pre-regulator! It works!

Next

At this point I think it is time to re-spin the board to fix all the issues I found. The next phase will be to re-integrate all of these changes into the KiCAD design and re-layout the board.

Friday, 8 April 2016

Lab Power Supply - Thermoelectric effect

Now that I sorted the problem with current measurement due to leakage from the voltage output, I wrote some code to enable me to calibrate the current control and the current measurement. The problem I found was that the current take a long time to settle and seems to drift by as much as a few mA - far more than the 1mA I was aiming for.

Current Drift

My home-made constant current load can (according to my Keysight 34461A) draw a constant current that varies by less than 1mA. At the moment the calibration is off so it always draws 1mA more than it should (but I don't care).

I noticed that when drawing 1A the reading taken by the lab supply varies by as much as 5mA, Similarly when the lab supply is in current limit, the output current will vary by the same amount roughly.

On my board I have the PTC fuse right next to the shunt. I thought this could be heating up the shunt and throwing the readings off. I attached a thermocouple to the shunt and the temperature did vary with load but by no more than a degree C. I removed the PTC and replaced it with a wire for now to see if this changed anything and it did a little although as the shunt resistor is rated at 20ppm/C it should effect it much at all.

With the dummy load set to draw 1A I measured the voltage on the shunt resistors and got this graph:
 
The 25uV variation equates to about 2.5mA on the reading and 250ppm if the temperature is only varying by 1 degree.

With the supply set to limit the output to 1.5A, here is the output current over time
So it is varying by 6mA which is way more than my 1mA budget.

Thermoelectric Effect

The thermoelectric effect is where a small voltage is generated across a metal junction as a result of the temperature of the metal. The heat is effectively converted directly into voltage.

I found out that for some metals this can be as much as 10uV/C. Given I am only seeing 25uV changes this could well be down to this effect.

The metal strip resistor I am using is a Welwyn OAR3 but unfortunately the datasheet doesn't specify the thermoelectric coefficient. 

Hunting for a Solution

My first thought was that if I increase the resistance from 10m Ohms to say 50m or 0.1 ohms then the thermoelectric effect will be greatly decreased as a proportion of the overall voltage. The downside is that then the resistor has a much greater voltage drop but also consumes much more power.

I ordered some other size resistors and began experimenting with the circuit in LTSPICE - mostly to ensure I had the calculations correct for the feedback resistors on the op amp that measure the current.

While fiddling around I noticed that with 50m or 0.1 ohm that when the system went into current limit the output would oscillate - in fact the current measurement would oscillate. I messed around trying to add compensation and slow things down but the only thing that would change the situation was to reduce the output capacitance but that effects the voltage stability.

I considered just living with the problem and calibrating the system for the steady state current with the assumption that it could take 20s to get there. This seemed a real shame as the rest of the system was just so precise. For example I measured the voltage on the current sense resistor in current limit mode and it varied by no more than 2 or 3 microvolt over a short period. The current control loop is *really* impressively good.

Better Shunt Resistors

So then I went looking for some better current sense resistors. There are four terminal surface mount ones but the ones with lower temperature co-efficients also tend to be lower power. Many of these specify a thermoelectric voltage of 2 or 3 uV per degree C.

I found these ones from Vishay which are outstandingly good but not cheap ($10USD from digikey in single quantity). They have 2ppm temperature co-efficient, less than 0.05uV/C thermoelectric voltage. They have 4 wire sensing and are generally totally kick-ass all round.

I will probably have to spin a new board before I can test these however.

Tuesday, 5 April 2016

Lab Power Supply - Raspbery Pi Control

So finally I got round to building some code to implement a basic GUI for the power supply. This showed up an anomaly in the current readings that lead me on a hunt to somewhere I didn't expect.

Control Interface

So a while back I bought a new Raspberry Pi (PI 2B) and the official Raspberry Pi touch screen. The plan has always been to make the Pi a touch based user interface for the power supply. I found a Python GUI library called Kivy that works on Windows. Mac and Raspberry Pi and which provides pretty much everything I might need to implement the user interface.

Kivy is really focused on 2D and 3D graphics more than user-interfaces but it does provide buttons and input fields. I am pretty sure that this is all I need plus some colour and maybe later I might use the 2D primitives to do some current graphs.

Being Python I started by writing the code on my Mac and then moved to the Raspberry Pi.

Kivy comes with its own language that you use to describe the graphical layout (in a .kv file). These then get bound to Python classes at runtime. 

Field Binding

You can bind fields in the display to data members in the classes and if the data member changes, the GUI value will be updated. You can even use conditional expressions in the kv language to control fields. For example in my application I use an expression to change the colour of the text to grey if the power supply channel is disabled or in current limit.

Initially I had some trouble with this as I set the value of fields based on regular functions or data in my class. The problem with this is that the Kivy runtime can't 'observe' those functions and so the values would not change in the GUI when they were updated in the class. Instead you have to create members that are of type ObjectProperty and set/get these.

Layout

So you can create a class that is essentially a canvas that you can compose into a bigger window. I created one panel for each power supply channel and then created an overall window that contained three instances of the channel (one for each PSU channel).

I used quite big text for everything as it had to be fat-finger driveable. I figured the most important things are
  • The output voltage (measured by the PSU)
  • The output current (ditto)
  • The set voltage
  • The current limit
  • Enabling/Disabling the channel
  • An indication of if the channel is enabled/disabled
  • An indication of if the channel is in current limit
  • (Nice to have) The output power
The output voltage, current and power are the biggest font. The text goes green if the channel is enabled, grey if disabled and red if in current limit. This is no good if you are colour blind so I may change this scheme to something else later.

The set voltage/current is in small text with a button to bring up a dialog to set it.

There is a big enable/disable button at the bottom for each channel. If I can I will align the binding posts for each channel with the screen and these buttons.

Here is how it looks running on the Raspberry Pi touchscreen and communicating with the lab supply. The numbers are a bit off as it needs to be calibrated.


Here is the dialog for editing the output voltage. The same dialog with different labels is used to set the current limit.


The dialog needs some work I think :
  • The buttons are too small for fingers
  • The V/mV buttons are not worth it. Just have V
  • You have to back-space to reset the value. If you miss the DEL button is dismisses the dialog and you have to start again.
  • Really need some mechanism to be able to slowly sweep the voltage up. For example either a physical dial or a dial/slider on the GUI somewhere (ideally without leaving the main screen).

Updating

The code uses the Kivy Clock class to schedule updating of the values. The first thing I noticed was how stuttery the dialog was when I enabled the updating. This was a simple fix as I just disable the scheduler when the dialog is open and re-enable it when the dialog is dismissed.

It quickly became apparent that the update rate is pretty slow when running at 9600 baud. I plugged the USB cable into a Windows machine where the MCP2200 utility was present and changed the baud rate to 115200.

I then went to change the baud rate in the firmware and remembered how much trouble I had setting this in the first place, The calculations for setting the baud were pretty far off. After some Googling I figured out that there is a fuse that is set by default and that sets the internal clock speed to the crystal frequency divided by 8. Not even sure why they do this.

This program has been interrupted to bring you this message...

And that's when everything went wrong. I have been having intermittent problems with programming the chip and at some point the device simply stopped responding. It could be that the fault meant the fuse bits got whacked to some bad value. The device was essentially bricked,

One thing I noticed was the output from the micro controller during programming (the MISO line) looked like it was fighting with some other voltage. I figured out the state of the chip select for the AD7705 was low which meant it could be trying to control the bus. I figured out that what I should have done is tied the reset line of the AD7705 (and the AD5689) to the microcontroller's reset line so that during programming they won't try and control the bus regardless of the state of their select lines. I hacked the board to make this the case but still it wouldn't go. The MISO line looked clean however.

I de-soldered the micro-controller and soldered a new one on. A task made much easier with the recent purchase of a new toy (more on this later).

This got me back on the road and I was able to program and communicate with the board again.

Python Serial

Up until this point I have been communicating with the board via Python by simply opening the device (/dev/ttyACM0) as a file. The default baud rate was 9600 baud so this worked fine but now that I changed the baud rate I needed to do a fcntl() on the file descriptor to change the baud when I open it. To make matters worse the fcntl() parameters are different between Mac and Linux (Raspberry Pi) and messy.

I found this cross platform library called pySerial that could do all this for me. Further more, it implemented a timeout mechanism in case the device doesn't respond (which was a problem I hadn't solved with the file interface). The library was available for all the platforms I wanted and this worked quite well.

Weird Current Readings

So with all the soldering/de-soldering, the calibration was a tiny bit off. Furthermore I haven't really tried to calibrate the current yet so I wasn't surprised to see the readings were wrong.

When the power supply was running with 10V output and zero output current the reading was around 22mA. I just assumed this was an offset error but I noticed that as the voltage increased so did the zero reading (pretty much linearly). Interestingly the current measured when a load was placed on the output looked pretty close.

I assumed that I had a current leak but I really couldn't find a possible current path. Sure the differential amplifier measuring the output voltage will take some current but it is tiny compared with this.

I found another small ground problem for the amplifier that measures the current but it was pretty small (few hundred micro-volts). I measured the voltage across the shunt and it was tiny - far smaller than the reported value.

Being quite stumped at this point I went back to the simulation and found that it too had a discrepancy. This was masked by the switch model I used for the output load as even when the switch was off a few mA flowed. When I disabled this I noticed that there was a discrepancy there too.

I was looking at the output of the amplifier that senses the voltage over the shunt. I realized this voltage was also used in the summing amplifier inside the pre-regulator. The summing amplifier boosts the bulk capacitor voltage when there is output load. The summing amplifier looks like this:

Then it clicked - as the resistor in this amplifier were only 10K, the Voutmon was affecting Ioutmon and this is why the current reading was high when the output current was low (or zero).

To test this I cut the track to R46 from Ioutmon and sure enough the offset went away.

I went back to the simulation and tried changing the 10K resistors to 100K and while this massively reduced the effect it created ringing and other dynamic stability problems in the summing amplifier.

I think to fix this I'd have to buffer the output with another amplifier. The current measurement is likely effecting the output voltage measurement when there is load on the supply. I probably need to buffer both.

I have one spare op-amp on one of the LT1639 chips. My plan is to swap the LTC2050 used to measure the output current for a dual opamp package (LTC2051). This unit has the same performance specifications but contains two amplifiers in the same footprint. Then I can use one of these to buffer the current and the spare LT1639 op amp to buffer the voltage and that should be that.

Next

There is still lots of work to do on the GUI but the board is getting to the point where I am not sure I want to hack it any more. It might be time to spin a new PCB to fix all the problems.