Saturday, 21 March 2015

Dummy Load

I actually finished the dummy load a while ago but have been a bit lax in writing it all up. I wrote about the design including compensating the control loop (to stop it oscillating) in a previous post here.

To complete my dummy load I did a few things:


  1. Found a suitable heat-sink
  2. Ordered a low tempco, 20W 1Ohm resistor
  3. Switched to a precision op amp
  4. Added a LCD screen and an AVR micro-controller. 
  5. I added a voltage reference and used a DAC to drive the opamp.

Heatsink

I ended up going with the flanged version of this heat sink from Jaycar. It's a bit of a beast and appears to be a half-kilo lump of cast aluminium. It claims to have only a 0.78 degree C per watt temperature increase which seems pretty good. The MOSFET I used has a 1 degree per watt temp rise between the case and the die and is capable of withstanding 175 degrees. So the maximum power dissipation if the ambient temperature is say 35 degrees is (175-35)/1.78 = 78W. So at 25V that is over 3A or at 20V it is just under 4A. Pretty good! 

Power Resistor

I ended up buying one of these Bourns 100ppm 1 Ohm resistors. The thing is capable of 20W which means over 4A of load. Under test I found this thing pretty steady. I had trouble at first as I mounted it on an insulating pad and didn't bolt it down tight enough. Once I realized it's metal tag is well insulated (electrically) I mounted it with heat grease tightly onto the heat sink and it performed well outside its specs.

Precision Op amp

I bought one of these LT1006 op amps that have a really low offset voltage, low drift and low noise. Also you can zero out the input offset but in the end I didn't need to do this as it was so small it didn't matter.

Voltage Reference and DAC

I bought a 4.096 voltage reference (LM4040C41IDBZR). This thing is pretty amazing in that it has a 100ppm tempco and even though it is only accurate to 0.5% was dead on 4.096 (according to my multimeters - one of which is in calibration).

I bought a 12 bit DAC (MCP4921) to go with this. This isn't a great unit but I figured it would do. It boasts an integral non-linearity of 0.5 LSBs but when I tested this in the complete system I found it to be a bit worse. To begin with I thought this was the resistor or the wiring losses but I can't see how this would add a non-linear response. See below for details on how I got around this.

I found an Arduino library to make driving the DAC easy here. The DAC interfaces via SPI which makes life pretty easy.

Initially I was aiming for 10mA resolution but when I found the reference was so stable and accurate I thought I'd go for 1mA. Because of the error in the DAC I didn't quite make it but it's pretty close (less than a 1mA off across the full range).

I ended up using a surface mount adapter board to rig these into the final circuit as both parts were only available in this form.

The Brains

So then my plan was to be able to control the thing from a uController. I found one of these cheap encoders and a simple circuit to read them. There is an Arduino library for reading encoders here that works with this. The circuit for reading these is pretty straight forward - the main objective of the circuit is to debounce the switching of the encoder to avoid jumps. The circuit is on the Arduino site here.

I already had one of these Hitachi compatible LCD screens and again there is an Arduino library for writing to them. I hooked this up as per the instructions here and used the Arduino library to write to it.

I added two buttons so I could have one to change the mode and one to enable/disable the output.

Construction

The whole dummy load was built on a piece of matrix board. The matrix board was screwed to the heatsink. Initially I planned to run the load off a 9V battery but I found the LCD backlighting would drain the battery in a very short time. I changed the circuit to have a power socket for an old plug-pack from a junk box and added a 7812 and 7805 regulator to provide power to the circuit.

The back-lighting is still not right. Initially it was quite bright but it made the regulators far too hot. I reduced the intensity but now it is too dim. I might have to re-visit this.


The dummy load sinks current from the red/black terminals on the right hand side. You can see the DAC and the reference on their adapter boards. The tactile switches and rotary encoder are to the right of the LCD screen.

I added a ICSP header next to the Atmega so I could upload the firmware onto the micro controller.

Software

I had been writing bits of code to drive the DAC, read encoders and drive the display but now it was time to put it together. The functions I wanted were:
  1. To be able to set the current down to the milliamp.
  2. Constant current mode where the load extracts a controlled current.
  3. Pulse mode where the load oscillates from zero to the configured current. I wasn't sure what speed would be most useful so decided to support 50Hz, 100Hz and 1kHz
  4. Ramp mode. Note sure how useful this is but after some testing I decided to support only 50 Hz and 100Hz operation for this mode. More on this later.
  5. Single button output activation/disablement.
  6. Shaft encoder to select from ranges of values. Button to switch between the settings being modified.
After developing GUIs for thick client apps as my day-job I found two lines of 16 characters quite limiting. I decided that I wanted four basic fields on the display to be:
  1. The output mode (constant current, pulse, sawtooth)
  2. The mode qualifier (none for constant current mode) which is the frequency of the output for whatever mode is selected
  3. An indicator showing if the output is enabled or not.
  4. The output current.


I wanted to make the field you are currently editing to blink. I couldn't figure out how to make the LCD blink some text. It is likely the LCD can do it but I don't think it can be done if you access  LCD using only a 4 bit wide interface. After some head scratching I figured out I could just get the micro controller to do the blinking by re-displaying the LCD contents with the field blank.

So the basic interface is you hit the mode button (top right) and you can move between fields. The field being edited blinks to show that it is being edited and if you turn the encoder the field cycles through the possible values. At any time if you hit the bottom button (enable/disable) it turns on the output and blinks the 'Enabled' field. When the output is enabled you can't edit anything but you can hit the enable/disable button again to disable the output.

Also the code saves whatever the settings are in NVRAM so if you power cycle the device it comes back up in the mode where you left it (but with the output disabled).

Initially I split the current field into amps and mili-amps (so you could edit the whole number of amps with the encoder, hit mode and then edit the number of mili-amps) but I found that cycling through 999 values in the mili-amps field was too slow. Instead it now is split into amps, 0.1 amps and then mili-amps.

Software Design

At this point I realized this is no longer a trivial application. Ok it isn't that complicated but it isn't ten minutes of coding either.

Working in the Arduino dev studio, I started create classes to model the components;
  1. LoadControl models the DAC and analog electronics and implements setting the output current and output mode etc.
  2. Display manages the display of the LCD fields including blinking fields.
  3. Controller sits between the display, the input devices and the LoadControl and manages the device based on the user's inputs.
Then I needed a few more things:
  1. ButtonMonitor automates interfacing with buttons and provides a function to tell you if the button was clicked. There is one button monitor for each button.
  2. PersistentSettings saves the current user selection in the NVRAM and is used to load the last used settings at startup
  3. Splitting up, updating and re-combining the output current from fields became a bit of a mess so I moved this out into an AmpsSplitter class that handled it all.
The main module simply calls the Controller::update() method in the loop method. The controller:
  • Checks if a the enabled button was pressed and if so switches between enabled/disabled mode.
  • If enabled. checks if the mode button was clicked and if so cycles to the next field
  • Otherwise the code checks if the shaft encoder was changed and if so it cycles the current field by the number of clicks the shaft encoder was turned.
  • Updates the display. This is where the display writes the fields into the LCD. The display also knows which field is blinking and will check the time (using getMilis()) so it can blink the current field every 200ms

Timing


Initially I had the code also calling LoadControl::update() every time round so that if the output is enabled it will update the DAC. The problem is the timing was all over the place and generated unusable amounts of jitter.

The processor has timers you can use to generate interrupts so the processor can act at specific times. There are two timers but I quickly figured out the first timer is used by the getMilis() system call and was too low-resolution for what I wanted.

Using AVR manual and this guide I  set about updating the LoadControl code so that when the output is enabled and not in constant current mode it will use a timer interrupt to time updates to the DAC. This worked very well and could handle updates as fast as 10kHz. Much faster than this it would slow the user interface down so much that it became unusable.

The basic idea is there is a register that counts each CPU clock cycle. You can set a value so that when the counter equals the value an interrupt is generated. The counter is only 16 bit however and the clock speed is 16MHz so they add a pre-scaler which has the effect of counting only ever two, four, eight, sixteen etc clocks. The code needs to figure out the best pre-scaler to use and calculate the right comparison value.

This worked pretty well and even at 1kHz generated negligible jitter. The trace below shows the voltage on the load resistor at 0.2V/division and 0.2ms/division.


Linearity and Calibration

So now I actually want the device to sink the amount of current you asked it to sink. As the DAC is a 12 bit device and the reference is a 4.096V voltage, each step of the DAC is 1mV. So ideally if you ant 1A you set the DAC for 1V (1000).

Not surprisingly it doesn't work that way. The DAC is not completely linear, the resistor isn't exactly 1 Ohm and the wiring between the terminals and GND and between the terminals and the MOSFET have some small resistance.

Initially I thought the DAC would be near enough to linear and took accurate measurement of the output current for a range of settings using my 5.5 digit HP3478A bench meter so I could put these into a spreadsheet and use linear regression to calculate the slope/intercept. This did improve the accuracy but not nearly enough and it got worse at higher currents. You could really see it in sawtooth mode as there was a definite curve to the voltage ramp.

I found this description of a simple technique for getting around this where you apply different slopes for different segments of the DAC's output. The way it works is you take a series of measurements at different DAC output levels and then you measure the slope of the line segment between each measurement. The slope gives you the increment per step of the values in that segment. Then, when you want to output a particular value you find the segment the value falls within and you use a simple linear equation to calculate the DAC value to get that.

It isn't perfect of course as the DAC isn't linear within those regions but it does greatly reduce the error and is quick to calculate.

This got my output pretty much to the nearest miliamp across the range (at least across the range I could measure as my power supply can only deliver 2.6A!).

Software


The source code is up on github here (or will be soon).

I hope it is useful for somebody!



No comments:

Post a Comment