v0.2 bringup

electronics, usbpwr

I’ve started soldering the v0.2 board, testing and porting the v0.1 software as I go along.  The LED, button, and ADC channels all moved, which required adjustment of a couple of header files.  Two minor wire mods were required, but so far everything tested is working.  There is a tiny bit of coupling between the PWM signal and the ADC feedback signal, but I suspect a well placed capacitor will clean the line up.

From here, I have to do the following:

  1. Populate the auxiliary transformer and generate a sane voltage rail for the opamps on the secondary side.
  2. Populate the feedback circuitry.
  3. Adjust the ADC driver to use the new configuration.
  4. Calibrate.

And then I can test my primary side current monitoring.

Advertisements

Layout rev 0.2

electronics, usbpwr

Layout for rev 0.2 is complete, it’s PCBtrain time again.  I should get the boards before the bank holiday season starts next week.

Key changes to rev 0.2:

  • Improved voltage and current monitoring on the isolated side
  • Fixed Atmega PWM pin.
  • Improved filtering on voltage rails – there is space for play here, with an excessive number of cap footprints.
  • Different inductor – higher peak current, smaller package, lower price. Also lower isolation.
  • Size is now 75mm x 50mm (was 60mm x 50mm)

Layout rev 0.2

Closing the loop

usbpwr

It’s time to think about closed loop control.  The control loops exists mostly in software, but uses values scaled and shifted in hardware to minimise the error – in this post I describe how it all fits together.   I’m not planning a particularly complicated feedback scheme – PI or PID should be enough.  The part that did require extensive thinking, was to keep track of the different units in the system and managing all this within the constraints of an 8 bit micro.

Voltage feedback block diagram

Starting on the left, the user specifies a target voltage V.  This is converted to a target ADC value by the VtoADC function.  This gives the setpoint for the control loop – we will try to get the feedback ADC value to match the target ADC value.  The actual ADC value is subtracted from the setpoint to give the error that we are trying to minimise.

I first limit the size of the error to fit in an 8 bit value (i.e. between -128 and 127), then this value goes into the low-pass filter.  By restricting the magnitude of the error, I only have to store 8-bit values in my filter, thus conserving precious RAM.  This also limits the rate of change of the output voltage, which dampens overshoot by slowing down the control loop. I found that adjusting the output too quickly can cause the host computer to detect a short circuit – limiting the magnitude here helps to avoid that problem.

The output of the low-pass filter (vaguely labeled ε here) now represents a smoothed error term.  This goes into the PID section of the loop, to find the desired duty cycle (D) for the PWM module.  Note that I’m currently only using the proportional term of the PID controller, with the other terms set to 0.  When the rest of the circuit stabilises, I’ll improve the controller response by tuning these.

Here we cross from software into hardware.  The duty cycle value determines the shape of the PWM wave, which in turn drives the MOSFET to switch the current in the transformer.  On the secondary side of the transformer, after the rectifying diode and output filters, we find the output voltage.

However, this voltage is determined by the load resistance, so we have to measure the voltage and return a value to the primary side.  We can measure the voltage connecting the output to the optocoupler diode through a resistor.  Back on the primary side, the diode current flows through a resistor to generate a voltage. This voltage is in turn measured by the AVR’s ADC.  This complicated is a fairly complicated conversion from out voltage to ADC value – I represent it in the lower block labeled VtoADC. The original VtoADC function (top left) converts the desired input voltage to the ADC setpoint by mimicking this hardware conversion – just how well it can replicate it will determine how accurately the setpoint voltage can be tracked.  Finally, it is likely that the measured value will contain some noise too, so that adds into the control loop just before conversion.

We can track this feedback value back around the control loop now: an error is calculated, then filtered, and the used result to adjust the PWM duty cycle according to the PID controller.  And that is closed loop control.

Another constraint, which is not shown on this diagram, is that the PWM duty cycle is also limited.  This limits the average of power delivered to the transformer to safe levels (<2.5W), and also limits the peak transformer current to stay within the allowed range.

Note the five scratches in the lower righthand corner – I’m counting the number of times I’ve managed to crash my laptop.

Bootstrapping rev0.2

usbpwr

My current monitoring on rev0.1 was a bit optimistic, so I’m complicating the isolated side by adding more opamps. Half an LM358 is used to sense the return current, the other half acts as V-I converter, driving a BJT through the optocoupler, here simulated with an LED.

To test it, I need a variable voltage source –  rev0.1 is already useful enough.

Testing current measurement

I have since simplified this design – LM358 can supply enough output current – no BJT is required.

USB working

electronics, usbpwr

USB connection to ATmega16u4 is working: serial for controlling the main application, and USB DFU (device firmware upgrade) to load the bootloader.

I’m using Dean Camera’s LUFA library for the main program – it was quick to adapt to my application, and so far it is working well.

The bootloader is the default Atmel bootloader.  By pulling the !HWBL pin low at startup, execution jumps to the bootloader, allowing off-the-shelf software to be used for updating the device.  One less thing to manage.

Minimal USB board

Feasibility

electronics, usbpwr

While the design process is lots of fun, it is important to keep track of how feasible the final design is in terms of usability and production.  I’ve therefore come up with the following requirements – if they can’t be met, there is no point in me turning this into a product.

At least 2W output

I can calculate the theoretical losses to some extent, but until I build and measure it, I don’t really know how efficient it is.  I feel 2W is an attainable figure, and it is enough to be useful.

BOM cost < $25

Officially, I’d like the BOM to be as cheap as possible, but designing becomes a lot easier if you have some budget you are working from.  $25 sounds like a lot, right? I thought so too when I only looked at ICs, but when I added a connector or two, and then the transformers, then considered dials and a display, the budget looked much less forgiving.