Tuesday, October 27, 2015

SIMPL Revisited - Again, but this time it's personal

In May 2013, I learned about Ward Cunningham's Txtzyme language - a very simple serial command interpreter which allowed basic control of microcontroller function using a serial interface.

I wrote about it here:

Txtzyme - A minimal interpretive language and thoughts on simple extensions

Tytzyme was about as easy as a "language" could get, it offered digital input and output, analogue input, rudimentary timing in uS and mS and simple repetitive loops.  It was so simple, and offered so many opportunities for extension, that I decided to write some new functions - and called the extended language SIMPL  - serial interpreted minimal programming language.

In late May 2013, I described the extensions here:

SIMPL - A simple programming language based on Txtzyme

In the last 30 months I have ported SIMPL to Arduino,  ARM and FPGA soft core processors. I have also used the Txtzyme interpreter to help to create assembly language for an entirely new soft core FPGA cpu.

Very often, during initial deveopments, we need a low level human interaction with a new microcontroller, and SIMPL seems to provide that coding framework to allow more complicated applications to be tested and coded.

SIMPL is coded in C - which allows good portability between micros, but recently I have been wondering whether SIMPL would be better coded in Forth, and act as a human interface layer between a Forth virtual machine and the human programmer.

Forth can be a difficult language to master - partly because it involves considerable manipulation of the data stack, and the need to keep track of the stack presents quite a challenge to the new programmer.

Standard Forth consists of a vocabulary of about 180 compound words, which can be entirely synthesised from about 30 primitives.  When ported to a FPGA soft core CPU, optimised for Forth,  most of those 30 primitives are actual native instructions. That makes it fast in execution, but still not the easiest of languages to grasp.

Can we use SIMPL to access a sufficient subset of the Forth vocabulary to allow real programs to be written, but without having to tie our brains in knots over keeping track of the stack?

The beauty of Forth, is that you can compile a new word and give it any name you wish.  In SIMPL terms, this name would be a single alpha or punctuation character. Small alpha characters are reserved for the keywords, whilst capital letters can be used for User defined words.

This gives us access to

26 lower case primitives
26 Upper case User words
33 punctuation characters

This gives us a subset of 85 possible words - which has reduced the scope and complexity of the standard Forth language by a factor of 2.

Forth text entry consists solely of words and whitespace. This is intentional because it makes it more readable from a human point of view, and the spaces between words allows the compiler to know where one word ends and the next begins.  The carriage return is usually used to denote the end of a line, and thus signal the compiler to start compilation of the contents of the input buffer.

SIMPL borrows from these ideas, but attempts to simplify by removing the whitespace. In fact a space character (ascii 32) may have it's own unique meaning to the SIMPL interpreter.

Numbers also present a burden to the traditional Forth interpreter - which has to search the dictionary only to find that a number is not listed, and then assume that it is a number.  In SIMPL we assume that numbers are all decimal unless prefixed with a character that changes the base to hexadecimal.

As the compiler is only dealing with 85 possible input characters, the dictionary is simplified to an address lookup.  For example if the interpreter encounters the character J, it looks up the address associated with the function called J, executes that code and then returns so as to interpret the next character in the buffer.

There are only 85 characters to interpret - so only 85 action routes to execute.

Here are some of the primitives

+           ADD
-            SUB
*            MUL
/             DIV

&           AND
|              OR
^             XOR
~            INV

@           FETCH
!             STORE

<            LT
=            EQ
>            GT

j             JMP
z            JPZ
:             CALL
;             RET


#            LIT
%           MOD
£            DEC
$            HEX

(            Push R    >R
\             R@
)            Pop  R     R>

?            Query
_           Text String

a           ALLOT
b           BEGIN
c           CONSTANT
d           DO
e           ELSE
f           FOR
i          IF
l          LOOP
o         OVER
p         PRINT
r          REPEAT
s          SWAP
t          THEN
u          UNTIL
v          VARIABLE
w         WHILE

Tuesday, October 06, 2015

Open Inverter - Part 6 - Thinking Allowed

130 VA Toroidal Transformer Inverter using BTN8960 H-Bridge ICs

It's been a frenetic week of progress on the Open Inverter project. Both Trystan and I have managed to cobble together inverters from FETs, H-bridge ICs and other random, readily available modules - bought cheaply from China.

I have powered up the inverter with a DC input of 24V close to 5A and successfully powered a couple of 60W 230V lightbulbs.  The efficiency looks promising with neither the H-bridge nor the transformer getting anything more than warm.

In this post, I pause for thought to decide upon the future direction of the project based on our findings, so far in this week of discovery.

Here's the current wish-list:

1. An Open Source Inverter, of modular construction that is scalable in blocks of 125W or 250W.
2. Built from readily available, understandable, low cost electronics.
3. Rugged, robust, reliable - delivering reasonable efficiency and power quality.
4. Grid synchronisable - if required - will synchronise to external source.
5. Built in power monitoring, with wireless communications compatible with emonCMS monitoring
6. "Arduino" or similar microcontroller for hackability.
7. Supports a variety of power conversion topologies, including boost, buck, peak power tracking and split-pi.
8. Uses include micro-solar, LiPo4 battery charging, dc ring main schemes etc.
9. Under $20 for primary building block.
10. Easy to build, easy to repair, extendable, hackable.

Expanding on some of the above points.

The proposed inverter will be built from low cost modules that can be plugged together as required, depending on the application.

The basic design will consist of a microcontroller, one or more H-bridge power boards and a 125VA or 250VA torroidal transformer.

Choice of Microcontroller.

The microcontroller could be an Arduino or derivative, or one of the very low cost, easily breadboarded STM32F103 ARM boards - based on the Maple Mini - which can be programmed with Arduino code - using STM32-Duino.
The breadboardable Baite STM32F103 "Maple  Mini" 
The advantage of using the STM32F103 is that it has more I/O and Flash/RAM than the standard Arduino and runs at about 5 times the speed.  It has more versatile and numerous pwm outputs and higher resolution AD converters. Remarkably these little boards are available very cheaply (<£5) from numerous vendors on ebay.

Using STM32Duino, these boards can be programmed from the Arduino IDE - using an additional board file which caters for the STM32Fxxx range of ARM devices.  This allows sketches developed for Arduino to be readily easily converted so as to run on the much greater performance STM32 range.

Choice of H-Bridge.

This handy power board is one I designed earlier in the year to drive a 100W DC Motor, it uses 2 x BTN8960 ICs

The H-bridge board can either be based on standard n-type FETs with driver ICs, or using the more sophisticated BTN8960 H-bridge ICs.

The FET solution may be more hackable and appplicable to other projects, but the H-bridge based on the BTN8960 is a quick and cheap solution.  I had already designed a power board to drive a low voltage dc motor, and it was very easy to adapt it to drive the secondary of the 120VA toroidal transformer, using an Arduino-like mcu to generate the 50Hz sine waves.

I am currently testing both solutions so that I can give more informed advice based on my findings.

The BTN8960 power board runs very efficiently with a 120W load. However, the IC is limited to 25kHz switching frequency - and this is not an easy frequency to create using the fast pwm options on the standard Arduino - short of running it on an 8MHz or 12MHz crystal.

The tabs of the H- bridge ICs are soldered to large copper areas - approximately 30 square cm each. This allows them to run cool even at 120W power - without additional heatsinking.

Choice of Toroidal Transformer.

This can be any toroidal transformer in the 50VA to 250VA range - with the secondary voltage chosen to be approximately that expected from the solar panel, or the battery.  For convenience I use a 130VA toroid with a 24V secondary.

The toroidal transformer does two things for us, it conveniently steps-up the output voltage from the H-bridge to that of the ac mains, and  effectively isolates the low voltage power electronics from the high voltage mains - so that high voltages are contained in the transformer, and not on the H-bridge board - making for a much safer project.

The toroidal transformer is also fairly efficient at converting the low voltage to mains - depending on its VA rating about 91 - 95% is typical.

In the UK, a suitable Vigortronix  120VA transformer 0-12V 0-12V from Rapid Electronics (88-3814) is £15 or less, on ebay.

Putting it in a box.

As the inverter has mains voltages present, it is recommended that it is put into a plastic or metal enclosure.

The largest, heaviest component is the toroidal transformer, which should be securely mounted to the case.  The 120VA inverter should fit in a case about 100 x 160 x 50mm, some of those extrusions use for Eurocad sized pcbs could be used to advantage.  The Vero 14-1003 or the Hammond cases (Rapid 30-1574 or 30-1535) aluminium extrusion at 105 x 165 x 60 or similar would be ideal.

Using components sourced from the UK, a DIY 120VA inverter in a case could be made for about £50.

A few points on efficiency.

The losses in a toroidal transformer are the sum of the Iron Loss and the Copper Loss. The Iron loss is effectively the magnetising current required to set up the field in the core and lost in the eddy currents. For a 230V 120VA transformer, this magnetising current is about 9mA and the iron loss is 0.98W.  The iron loss remains constant at all loads.

The copper loss is the sum of the I2R losses in both the primary and secondary.

For a 2 x 12V  120VA transformer running with 5A secondary current and 0.5A primary current

Secondary loss = (5 x 5 x 0.24) = 6W

Primary loss  =    (0.5 x 0.5 x 14.6) = 3.65W

The copper losses will rise with temperature because of the increase in the resistance of the windings with temperature.

In total there will be about 11W lost in the transformer when working at its rated power.

Losses in the FETs.

These are outlines in the BTN8960 datasheet.  At 25C, the path loss is 14.2 milliOhms.  With a 5A drain current, the I2R losses in the FETs are (5 x 5 x 0.0142) = 0.355W. There wil also be some switching losses, plus powering of the remainder of the circuit.

I measured the input current to the H-bridge, which also includes the Arduino, a relay and a 24V to 5V simple switcher 5V voltage regulator.  When not driving the transformer the circuit consumed 50mA at 24.25V.  A loss of  1.21W

With no load on the transformer primary, the current into the inverter was 0.23A.  This puts the no load driver losses as (24.25 x 0.23) = 5.58W.

Adding all the losses, the best estimate (unconfirmed) for system losses is

No load losses     5.58   W
FET I2R losses    0.355 W
Iron losses           0.98   W
Copper Losses     9.65  W

Total                    16.565 W

Regarding overall efficiency

Inverter Efficiency   (120-16.565)/120  =  86.2%.

Room for Improvement

The proposed micro-inverter is intended to be used when there is no alternative to using ac mains - for certain low wattage devices.  The second part of this proposal is to use dc for direct charging of consumer electronics and mobile computing devices.

By increasing the system voltage, to say 48V, the currents switched in the FETs is halved, and so these I2R FET losses can be quartered, however a transformer with a 48V secondary will have more winding resistance.

The losses in the toroidal transformer are more or less fixed for a given core size,  however by using a larger core than is actually needed, it will have lower resistance windings in both the primary and secondary - and so the copper losses will be reduced, but the iron losses will be up a little.

For example using a 250VA toroid - but running it at 5A

Secondary loss = (5 x 5 x 0.08) = 2W   (previously 6W)

Primary loss  =    (0.5 x 0.5 x 6.1) = 1.525W  (previousy 3.65W)

Iron Loss      = 1.62W  (previously 0.98W)

No load losses     5.58   W
FET I2R losses    0.355 W
Iron losses           1.62  W
Copper Losses     3.525  W

Total                    11.08 W

Inverter Efficiency   (120-11.08)/120  =  90.76 %.

So a half loaded 250VA transformer will run cooler with about half the total losses of the fully loaded 120VA toroid.  This can increase the overall efficiency of the inverter by about 5%.  It also allows for some extra capacity when other loads are switched in, and the voltage droop, under load will be less.

Open Inverter - Part 5, More Experimentation

Today was a day in the lab to try out the various H-bridge modules I have access to, plus the toroidal transformers, which are more efficient than the E-core types that Trystan and I were using last week.

Low Cost IBT-2 Modules

Some months ago, I  bought a pair of the IBT-2  H-bridge modules from an ebay seller. These are advertised as 43A and 24V. They use the now obsolete Infineon BTS7960 half H-bridge IC, that I discussed in Part 3.

The IBT-2 Module uses the Infineon BTS7960 half-bridge module
These boards are 50mm x 50mm and the holes (3.2mm) are on 45mm centres - this is an ideal size to take advantage of the low cost 5 x 5 cm pcb services being offered.  I paid about £7 each for these - including free shipping from China!  There are several variants of this module around, as it has been widely copied in China by various manufacturers.

It uses two of the Infineon BTS7960 half bridge modules, and a 74HC244D buffer-driver IC to provide some isolation between the "Arduino" and the H-bridge.

Not entirely visible is the anodised aluminium heatsink that is screwed to the underside of this module - to take the heat from the BTS7960 devices.

The BTS7960 is quite easy to drive - it has a single PWM pin an an /INHibit pin - active low. Only 4 port lines are required from the Arduino to drive this module.

At first I was getting some very unusual waveforms from the output tab of the ICs.  I soon found out that they are limited to a 25kHz pwm signal - and I was using 62.5kHz. I made a quick change to the PWM timer control register - to reduce the PWM to 7.8125kHz and all was well - I was getting good clean sinusoidal signals from the IC tabs - with the scope set to 1kHz low pass filter mode

Connecting the Transformer

I happen to work for a company that uses a lot of toroidal transformers of various VA capacities. Today I selected our smallest and cheapest - which is 120VA with a nominal 24V rms secondary and 5A current.

Our standard 120VA toroidal transformer has a nominal 24Vrms secondary winding @ 5A
The transformer is intended for both 115V and 230V operation - so it is a case of connecting the split primary windings in series in order to get 230Vrms output.  If you get them the wrong way, the phases wil cancel out and you will see no output.  If you want 115V, you have to get the primaries the correct way around in parallel - otherwise you will short them out - which is bad   :-(

In initial tests, I found that the "Magnetising Current" for this particular transformer was 0.22A from a 24V dc supply.  So the inverter burns 5.28W when idle - before an ac load is attached.

The BTN8960 H-Bridge

My company makes products that uses brushed dc motor drives - between 100W and 600W.
Earlier this year I designed an experimental board o use the newer Infineon BTN8960 half-H driver IC. This replaces the BTS7960 - which is now end of life - and becoming harder to find.

On the left is an "Arduino" providing the pwm drive signals to the BTN8960 H-bridge board on the right.
The "Arduino" board is a ATmega328p-AU with 16MHz crystal, reset circuit and FTDI connection. Most of the I/O is brought out to connectors for easy plugging - this allows simple generation of 50Hz complimentary pwm sine waveforms using Timer 2.

The board on the right is an experimental motor drive board I cooked up earlier this year to evaluate the BTN8960 devices for dc motor control. The BTN8960 devices, IC1, IC2 are located in the middle of the upper and lower edges of the pcb - with the large dc-link capacitor located between them. A thermistor (thin yellow wires) allows the temperature of the upper BTN8960 to be measured.  This board has no external heatsinking -  but relies heavily on large "flag" copper areas both on the upper and lower surfaces of the pcb to dissipate the heat.

The 24V dc input to the board is on the lower left, and the output to the toroidal transformer is on the right edge of the pcb.  The orange device is a relay which allows the toroid to be disconnected from the transformer.  The board also includes a LM2576  5V "simple switcher"  voltage regulator - for powering the microcontroller.

Here we see the full set-up.

The Driver Board, Toroidal Transformer and switched socket outlet complete the prototype Inverter.

So that was the state of play at 6pm this evening. I had the opportunity to connect my Weller soldering iron station to the output of the transformer. Off load the mains ac output was 240V dropping to 238Vrms when the soldering iron was plugged in. It used 24V dc at 1.15A from the 24V bench supply to power the iron.

More Testing Tomorrow.

Today I was lacking in  suitable 230V loads to try. Tomorrow I have a bunch of 240V 60W incandescent lightbulbs to try out and slowly push this inverter up in power output to characterise its performance and efficiency.

Monday, October 05, 2015

Open Inverter Part 4 - Getting the Draft Design into eagleCAD.

Designing the H-Bridge

In today's post, the fourth in this series I start to look at some of the practical aspects of the Open Inverter design - starting with the proposed H-bridge and the choice of driver IC and heatsinks.

Sketching out the schematic, choosing the components and laying out the pcb is about 2 days work.

A typical N-FET H-Bridge with HIP4082 Driver IC and current sensing

The circuit above shows a typical H-bridge arrangement based on N type FETs and a readily available H-bridge driver IC - the HIP4082 from Intersil.

The circuit will fit easily on a 5 x 5cm pcb, and with the correct choice of FETs - and heatsinks will handle 50V and 50A .

The FETs are in standard TO220 packages, and there is a wide range of FETs that could be selected depending on application.

The 2 main parameters for FET selection are the maximum Drain-Source voltage Vds, and the maximum Drain Current Id.

For safe operation at 48V it would be worth using 100V FETS, and 70A current handling - such as the Infineon 70N10.

It should be noted that the gates of the FETs contain a pair of resistors and a diode. These components limit the current supplied to the gate, control the turn on time and the diode improves the turn-off time. They also help protect the driver IC from damage and oscillation of the gate drive outputs.

The bill of materials for this H-bridge will be around £10 in 1 off.

The Intersil HIP4082 is an economical way to drive an N FET, H-bridge
Above is the minimum circuit required for the HIP4082, this one with optional current sensing. The current sense resistor Rsh is typically 10 milliohm or even 1 mOhm - if you are working with high currents.

It should be a 1206 package or several resistors in parallel.  10A currents across 10 mOhm will dissipate 1W in the resistor. Special, precision metal current sense resistor links are available for this purpose.  The gain of the op-amp should be chosen to suit the full scale input of the ADC on the microcontroller (typically 3V3 or 5V).

Typically the FETs will have about 10mOhm drain-source resistance when turned on.  It is this RDSon that is the major dissipation of power in the FET.  Remember that the power dissipation in the FET is the product of the square of the drain current Id and RDSon.

For example 20A passing through 10 mOhm will dissipate 4W in that FET, but 50A will dissipate 25W - and also 25W in the FET that forms the other active device in the H-bridge.  The heatsink must me capable of removing this heat without the die of the FET overheating.  A heatsink of about 3 degrees C per watt will be needed to safely handle these levels of heat dissipation.

This one from Farnell (below) is fairly economical, and both the upper and lower FETs can be bolted to it - provided that they are insulated from each other and from the heatsink.  The thermal performance is 2.6C per Watt provided the heatsink is placed vertically.

The heatsinks are quite chunky, and I have had to exploit the 17.02mm wide channel for the placement of the gate drive and current sensing components. Placing the two mosfets back to back can make for a reasonably compact arrangement.

Heatsink Farnell 1699368 has 2.6 C/W 

Putting it into Practice

First draft pcb layout in eagleCAD Size is 50mm x 50mm
The circuit at the top of this post has now been laid out on a 50mm x 50mm 2 layer pcb.  Special attention was paid to maximising the copper areas that carry the high currents. These were laid out as polygons rather than traditional tracks.  There are partial  ground planes on both the top and bottom layers and these are "stitched" together with many vias which help carry the large currents - and in the case of the voltage regulator help dissipate the heat from the topside to the bottom.

The layout proved to be quite tight, and a dual op-amp such as an LM358 might be preferable to the quad LM324 making a bit more room in the centre of the pcb.

Two heatsinks like the one shown in the drawing above are fitted. The heatsinks overhang the top and bottom edges of the pcb by about 10mm.

The outputs of the inverter (to the 24V- 230V transformer) are on the left.  The battery or solar panel inputs are on the right.

A 10 way connector, PL1 allows the "Arduino" to be connected.

The connector in the centre of the right hand side is to accept an external capacitor C1, as only 1000uF at 50V will fit on the board.

As the driver chip runs on 12V, a 78M12 regulator in a TO252 package is included. Maximum voltage for this regulator is 35V.

Sunday, October 04, 2015

OpenInverter - An Open Source, Micro-Solar Inverter - Part 3

A 12A 24V motor drive H-bridge pcb repurposed into a 64W micro-solar inverter
Further Thoughts

Welcome to Part 3 of this series of posts regarding the Open Inverter - a micro-solar inverter.

The H-bridge is fundamentally a 2 port, power control device, similar to it's cousin the bridge rectifier. Instead of passive rectifiers the H-bridge consists of 4 semiconductor switches that can be controlled under firmware - and as such is much more versatile than the diode bridge. However, unike the diode bridge, it has electrical symmetry - and so power can flow in both directions - and we can use this unique ability to our advantage. The H-bridge becomes a versatile power transformation device.

Consider the H-bridge to be like a black box, that in it's simplest form has 2 ports A and B, to which power sources - or sinks, can be connected.

In the photo above, dc power  (15.949V 3.97A) from a 150W solar panel enters from the right hand side on the red and black wires.

It is then converted by the H-bridge under firmware control into a pwm 50Hz ac signal, that feeds the mains transformer - connected to the left hand side - by white and black wires, and is then transformed up into 230V ac mains .

Thus a board designed for dc motor control has been repurposed into being a micro-solar inverter.

Depending on how the H-bridge is controlled, it can:

1. Transfer power in either direction between ports A and B,
2. Rectify ac to dc
3. Synthesise ac from dc
4. Transform dc up and down in voltage and current
5. Provide a variable impedance load -  for load matching and peak power tracking.

All from a $20 module - Wow!

As I document the project so far and put my thoughts down into words it's becoming increasingly apparent that a versatile H-bridge controlled by a low cost microcontroller has a multitude of uses amongst the hobbyist community - a few here:

Solar Inverters
Step Up (Boost) dc/dc converters
Step Down (Buck) dc/dc converters
Boost-Buck Converters
Split Pi Converters
Synchronous rectifiers
Solar PV - peak power tracking
Battery chargers - high efficiency charging of consumer electronics and portable PCs
Load balancing
DC Motor Control for pumps, solar trackers, machine tools, vehicles (bikes etc)

However, the basic H-bridge design can then be further extended to 4 or more ports. By adding an extra half-H Bridge,  3 phase applications become practical:

3 phase ac or brushless dc motor drives
Solar boost peak power tracking inverter

Furthermore, each half-bridge can be regarded as a power port - where power may be supplied or removed to/from the system.  This means that the H-bridge can be seen as a 3 port device - and in this mode it has applications in some bi-directional boost-buck dc/dc converter topologies - such as the split-pi converter. 

If it is made in a modular fashion that can be extended to cope with more sophisticated or power hungry applications - then it will be a lot more versatile.

So it sounds like the world is in need of a low cost, open source, versatile H-bridge power converter. If it can be made for under $20, it can appeal to a whole variety of price sensitive applications.

A Modular Approach

An H-Bridge Module like this, connected to an Arduino is very versatile

Today it is time to make some fundamental design decisions regarding the inverter power stage.

There are 2 main options:

1.  Traditional N-FETs with driver ICs.
2.  Half-Bridge ICs - such as the Infineon BTN8962

Whilst there are many mosfet driver ICs, only a few work at 30V, which is essential for a nominal 24V battery supply. - eg Microchip TC4431/32

These are available in DIP for easy self-assembly.  The advantage with option 1 is that you can fit whatever FETs you have available - depending on your maximum voltage and current requirements.

Option 2 uses the BTN8962 or BTS7960 integrated driver and half-bridge ICs from Infineon.  These are available as ready made modules from China, at a price cheaper than they could be made here - and might appeal to some experimenters.

So in order to make a design decision, to further the project- I am going to suggest is a traditional  FET board which is footprint compatible with the Chinese module. 

Regarding the "Arduino" part of the design, this could be built on stripboard sized approximately 5cm x 5cm which is then stacked underneath the FET power module on hexagonal spacers.  Header connectors would connect up to the power module.  I believe that this would be a suitable option for home construction.

Additionally, I am looking at a pcb layout for the inverter's mcu section.  This would use the ATmega328 on a pcb sized about 5cm x 5cm so that it stacks below either the discrete FET board or the Chinese BTS7960 motor drive module.

5 x 5 cm is a good size as it allows for additional circuitry & connectors, a 5V regulator and 5x5 boards are very cheap from dirty-pcbs.com. Using the standard 5 x 5 or 10 x 10cm boards - these can be made stackable with as many power stages as required. In theory, an inverter could be built up, stage by stage, to allow for possibly 1000W.

Wireless Control and Monitoring.

For several years I have been using designs that incorporate a RFM 12B or RFM 69 wireless module. These modules make use of Jean Claude Wippler's Jee Libs - a wireless protocol devised for communication between low cost wireless nodes.

Jeeibs has been adopted by my friends at Open Energy Monitor - for communication between their wireless sensors and energy monitors - and a base station - often web conected, to their cloud based analysis and energy visualisation package, emonCMS.

By including a wireless module on the Open Inverter MCU board - it ensures emonCMS compatibility - allowing remote monitoring and control of the power transferred by the inverter -  using emonCMS.

As well as the micro-solar inverter, the Open Inverter boards could be used for pv peak power tracking, LiPo battery charging/monitoring, and dc/dc conversion for the various voltage outlets of the "dc ring main". They can be used anywhere that power is generated or converted and report back the individual power transfers to emonCMS. 

Saturday, October 03, 2015

An Open Source, Micro Solar Inverter - based on Arduino - Part 2

In the first part of this "Open Inverter" series, I described how Trystan and I had cooked-up a simple inverter based on a mosfet H-bridge, an "Arduino" and a 12V-230V mains transformer.

Before going into too much technical detail, (as I am still documenting it),  I first wish to explain why I think that the combination of microcontroller and H-bridge is an essential building block in modern power electronics, and the ability to efficiently transform ac to dc, dc to dc, and dc to ac are paramount to the renewable energy sector.

FETs capable of switching moderate power levels are available surprisingly cheaply. The ones we used in our inverter were under £1 each.  The driver ICs (IRF2110 or similar) are a couple of quid each.

So, it's possible to make up the H-bridge stage and drivers for under £10 - and that includes some heatsinks.

However, the ubiquitous H-bridge is also available in the form of an IC - or rather 2 ICs - as most implementations appear to use half H-bridges.

Infineon make a range of these - intended for automotive motor control, and so can handle high currents, but generally at 28V maximum.  This makes them suitable for 24V battery systems.

The BTS7960 is typical of the Infineon range.  It has a maximum voltage of 28V, but with correct heatsinking can switch up to 43A.  Theoretically, a pair of these devices would be capable of running a 1kW inverter - but I would be happier in the 250W to 500W range.

It includes over-temperature, over-voltage and current limiting built in. It also outputs an anaogue signal proportional to the drive current - which can be used to monitor the performance.

Ebay is a good source for ready built modules containing a pair of BTS7960 devices.  I bought a pair of these for about £8 each.

A low cost BTS7960 H-bridge module from Ebay or TaoBao

The BTS7960 is also available as an Arduino shield - called the MegaMoto shield, which holds a pair of BTS7960 plus jumpers for easy selection of which pwm to drive them from. At £32 its a bit overpriced, but handy if you are already working with an Arduino platform.

Other BTS7960 boards are availabe from Taobao - of varying design and quality - with or without heatsinks - but I consider adequate heatsinking to be essential. 

This application note for the BTN8962 - a newer, related family member - gives good details on how to get the best from these devices.

Making the H-Bridge Work for Us.

If you look at a typical FET H-bridge, you will see that each FET is bypassed with a reverse biased diode. This is sometimes called the body-diode, and it comes for free, as part of the process of implementing a  FET on the silicon substrate.  It is tremendously important in protecting the FET from inductive switching over voltage spikes - as it returns them safely to the supply rails, but can also work in our favour in allowing easy implementation of rectifier and boost converter topologies.

A half bridge like this one may easily be turned into a boost converter by supplying dc power into the terminal marked OUT, via a series inductor, and extracting the boosted voltage from the terminal marked VS.

Conversely, a buck converter can be made by applying power between VS and GND, and extracting a reduced voltage between OUT and GND - again through a series inductor.

So two of these half bridges, a couple of inductors and you have all the makings of a boost- buck dc/dc converter.

Why would you first boost a voltage, only to buck it down again?  Well if it was the varying output voltage of a solar panel which drifted depending on clouds - it would be handy to boost it so as to properly charge a battery pack at the correct charge voltage.  Then you might want a stable 12V or 5V supply for powering some equipment - in which case you would buck the voltage down again.  

This ability to transform dc power up and down, with high efficiency, or match the varying dc output of a pv panel - so as to capture peak power, is very important - and it can all be done with the H-bridge controlled by an 8-bit Arduino. 

The Tasks of the Arduino.

In the 10 years,  Arduino has become a familiar and accessible microcontroller platform.  Even though it is only an 8-bit, 16MHz device, it can still be used to great effect in power electronic applications.

We built up "breadboard Arduinos" which closely follow Cefn Hoile's Shrimp design. Essentialy a ATmega328 IC with crystal, reset and FTDI cable header.

Shrimp - a minimal breadboard "Arduino" - by Cefn Hoile

The Arduino has to generate complimentary PWM in order to drive the H bridge. In some applications independent PWM channels may be needed to control each side of the H-bridge separately.

In addition to pwm generation, the Arduino should also monitor current, voltage and load regulation.

By making use of "Fast PWM" and "Fast ADC" on the Arduino, the ATmega328 can achieve quite a lot of control whilst generating the sinusoidal pwm.

Our first task on the Arduino is to generate a sinusoidal signal using "Fast PWM".  

For those who are eager to experiment, I have created a Github Gist containing the sinusoid pwm generation sketch.  This produces complimentary pwm on digital pins 3 and 11 - just what you need for driving H-bridges.

To test this routine, make a low pass filter from a 10K resistor and 100nF capacitor and attach to either digital Pin 3 or 11. This will reconstruct the sine wave from the digital pwm waveform - and give you a scope trace similar to that at the start of this post.

In the next part - I will have the schematics for the FET version of the inverter for eagleCAD. In the meantime I encourage readers to try and get the Arduino or Shrimp to produce a 50Hz sine waveform.


A Micro Solar Inverter - based on Arduino - Part 1

Bothy-Hack - A Micro-solar inverter based on Arduino

About once a year, I get the opportunity to spend some time with my friends from @openenergymon in North Wales.  This year, having attended the oshCamp in Heben Bridge last weekend, I took advantage of the glorious late September sunshine to cross over to southern Snowdonia, to a rural bothy outside the village of Llanfrothen, to spend a few days working on some new projects with Trystan Lea.

Trystan had expressed an interest in building from scratch, a low power inverter.  This would take the dc output from a low-wattage solar pv panel and create a stable 50Hz, 230Vac mains - suitable for powering small items of equipment. So after a couple of beers and some tech discussion over a pub meal on Monday evening we set about beginning our micro-solar inverter project.

Open Source - Easily Built, Easily Repaired

There have been several inverter designs published on the web, but they are either crude, square wave or modified square wave and based on beefy bipolar transistors.

The intention was to make the design easily accessible to others, with the intention of using familiar and easily sourced components - available to hobbyists everywhere. The project was going to be open sourced, hopefuly with professional pcbs coming a bit later - so that others could follow our work.

We wanted to make a design that uses readily obtainable N-type FETS and an Arduino (more strictly a ATmega328P-PU on a breadboard) to generate the PWM signals and provide simple circuit protection, and load sensing.  With the PWM signals generated in firmware it can easily be modified for 50Hz or 60Hz operation, either 115V or 230V operation and a wide range of battery input voltages.

We imagined that the final design could consist of an Arduino, an "Inverter Shield"  containing FETs and driver ICs configued in a H-bridge and some voltage and current monitoring circuits.  To make the inverter a 12V or 24V battery (or PV panel) and a 12V (or 24V) torroidal transformer would be added.

As we really only had 2 days to work on the design, we decided to make a simple proof of concept prototype, which could later be refined.

We are happy to receive suggestions from the wider community  - in the hope that the basic design will evolve into an efficient unit.


The steps of the primary project were planned as follows, the time available was about two and a half days:

1.  Use a breadboard "Arduino" to generate the 50Hz sinusoidal pwm waveforms needed to drive the FETs.

2.  Breadboard the FET driver ICs and the 40A  55V FETs for ininial testing with a 4VA step up transformer.

3.  Build up the FETs on stripboard - with substantial current handling tracks and heatsinks.

4.  A series of tests with different ac loads, with both 12V battery and pv input power.

5. Documentation and blogposts.

A secondary project was to build a simple energy monitor - again using a "breadboard Arduino" which would measure the dc output of the pv panel, and allow us to perform efficiency tests on the micro-solar inverter.

As a fall-back position, I had brought along a dc motor driver board I have been developing at work that uses an ARM Cortex M4 processor and a 12A  24V H-bridge.  I wanted to have a go at repurposing this board to make a simple 50Hz inverter (and succeeded!).


Step 1 was fairly quick to achieve, because I already had some Arduino code to generate an 8-bit sine waveform, using "Fast-PWM" - which appears as complementary pwm outputs on Arduino Digital Pins 3 and 11.

Trystan had already built up a "breadboard Arduino" - so it was relatively simple to program this with a FTDI cable, and then test the outputs for frequency, using a low pass filter to reconstitute the sine waveform for the oscilloscope.

The next task was to build up the 4 FETs that form the H-bridge onto a breadboard, and wire them up to the IR2110 driver ICs.  These ICs produce a level shifted drive waveform, so that N-FETs can be used in the upper arms of the H-bridge - with reduced on resistance and therefore improved switching efficiency.  The driver ICs are designed to supply the high currents - both source and sink, required to turn the FETs on and off - quickly.

Breadboard construction is not ideal for building fast switching power electronics, and getting the driver ICs to work reliably was probably the biggest challenge of the project.

However, by 9:45pm on the first night, Trystan had the inverter running and lighting an ac powered LED bulb.

The LED lamp in Trystan's right hand was first signs of a working inverter!

The ac waveforms on the scope were not in great shape, so we added a couple of 0.33uF 250V capacitors, connected in series across the ac output - that cleaned things up a lot!
Scope waveform  - not great at first
Until we added 0.33uF capaciors across the mains output
Even with a 4VA step up transformer - the LED lamp was ultrabright!

So we retired at the end of Day One - with a working inverter, and the plan to characterise it and improve it on Day Two.

In the next part, I look in more detail at the design and performance.  Later there will be links to the schematics,  pcb layout and the Arduino code used to drive the FETs.

Micro Solar - The Future is Bright

Micro-Solar - A New Approach to Increasing the Installed PV Capacity


Recent changes in the solar grant scheme have had a very negative effect on the UK's fledgling solar pv industry. The rug has been pulled out from under the feet of all those that set up installation businesses. The FITs have been decimated - and so now there is virtually no reason why anyone would make a large, long term investment in a permanent pv installation.

Feed in tariffs (FITs) have been reduced to the point where there is no longer an incentive to invest in a photovoltaic solar installation.  Our current Government seem to be more interested in kickstarting the UK fracking industry and selling off large sections of our critical electricity generation infrastructure to the Chinese.

The reduction in FITs to just 1.63p/kWh in January 2016 is going beyond miserly, and at such levels completely removes any economic reason to export to the grid.

Without the grid export option, the pv output can only be used locally, and if used efficiently will help reduce the amount of power consumed from the grid.

In this post, I propose a new way to look at solar pv, in a way that could appeal to a much greater customer base, and at a price that is much more affordable.

A single 250 W pv panel, could reduce your electricity bills by up to 10%, and if repeated by millions, rather than 10's of thousands of consumers around the country, it would significantly increase the installed solar capacity.

There are many potential customers for micro-solar. Those who can afford an expenditure of up to £1000,  but not the £6K - £10K for a full system.  With the FITs gone, the market for larger systems will have evaporated.

Sources of PV Panels

A recent web-search revealed small solar systems being made and marked in China for about £750, complete with inverter, battery and controller.

If you choose to shop around on Taobao (Chinese ebay) you can find 250W panels for about £60 each. Even if these prices doubled by the time you had shipped to the UK.

If you want to search for your own panels - the Chinese term is 250W 太阳能板  - Happy Hunting!


A unit from the grid (Southern Electric October 2015) is currently 14.0385p (incl VAT). My annual consumption is approximately 2400 kWh.

A small system consisting of 4 x 250Wp panels would yield between 850 and 900kWh per annum, displacing about 35% of my grid consumption.

If we think that 800kWh of this can be used in the home, it could reduce the incoming electricity bill by
£112 per year.

Importing 250W panels from China at £0.50 per peak watt, means that the system could recover its costs in 5 years - without a grant or FITs, nor the additional expense of a grid-tied inverter and professional MCS installation.

The Case for Microsolar

I will define a Micro-Solar system as an installed system of 1000Wp or less.  With currently available panels this would consist of up to 4, 250Wp panels.  These panels are typically 1.6m x 1m and weigh about 21kg.

The emphasis being that microsolar should be small, cheap and portable.  Portable in the sense that it's not a permanent installation, can be deployed on a wall mounted bracket, especially if roof access is not available, and can be moved from property to property a required - a benefit for young adults in the rented sector. As it is a small system, typically it would be a DIY installation, not requiring specialist tools or equipment. One attractive use would be on a south facing balcony, with the panel securely clamped to the balcony rail.

As the system is small, it is essential to get the best use from it, and the best conversion efficiency. This will entail the use of high efficiency dc/dc converters and LiFePO4 batteries used for energy storage.

Whilst we are all familiar with ac mains electricity, and almost all of our appliances and consumer electronics products are intended for ac plug in use - for some products the ac is an inconvenience, and a huge source of inefficiency. With the rise of portable computing products, smart phones and other mobile gadgets - these increasingly require a 5V charge - from a standard "USB" style charger.

If you are interested in USB chargers - this excellent post covers them in great detail, in terms of efficiency, power quality and safety.

The underlying message is that small ac powered USB chargers are at best only 65 to 80% efficient, and this is a figure that has a lot of room for improvement.  Direct dc/dc conversion could improve this considerably.  Starting with a 12V input, this can be converted with 92% efficiency to 5V using a synchronous switching converter - such as this one from ON Semiconductor.

With the increase in electric bike technology - LiPo battery packs are available with high capacities and low cost.  The real benefit of Lithium battery chemistry is that it has a very high charge efficiency. Packs of welded lithium cells are typically available in 350W to 1kWh capacities.

What can you power with 1kWh per day?

Several years ago, when I was working from home, I mused on the idea of a home-office workspace that ran on just 200W. At the end of that post, I speculated that perhaps even 100W was possible. In the 10 years since that post we have had the benefit of  more power efficient laptops and netbooks, LCD monitors, LiPo batteries and LED lighting. I now believe that I can run the same work environment on an average power budget of  just 100W - and that puts home working well within the reach of a microsolar installation.

Whilst thinking about the e-bike battery packs, it occurred to me that a lot more people are cycling these days, particularly within our urban cities.  An e-bike consumes typically about 20Wh per mile, and so a 36V 10A pack could offer a range of about 15 to 18 miles between charges - depending on terrain and how much you pedal.  By using several e-bike battery packs as the basis of the modular battery store, it is possible to have a freshly charged pack every morning. Three or four interchangeable packs would form the system, so on any day there is always about 1kWh of storage.

Having arrived back home after a day at the office, the battery is fully charged and ready for the evenings use.  This would involve recharging of portable computing devices, smart phones and LED lighting in the evening.

A quick check on the specs of a 43" Samsung smart tv - showed a 51W consumption - so 6 hours of TV gaming or web-browsing in the evening is going to be well within the capability of a microsolar system.

What about the Winter?

Microsolar systems will run at much reduced capacity during the Winter months.

The graph below shows monthly output, for south facing panels, in southern England, averaged over 3 years (2012-2014) - scaled to reflect the output of a single 250 Wp panel.
Normalised output for a 250Wp panel
It shows that useful output is available from March until September - approaching 1kWh per day, but for 4 months of the year, you are getting only about a third of the summer peak.  If you are reliant on the solar contribution to charge your bike pack, then you will need to find an efficient means to recharge your pack from the ac mains during the winter months.

Fortunately, the designers of switched mode power supplies have made significant advances over the years in improving power supply efficiency. This is particularly important in the server farm and telecoms applications where efficiency and reliability is paramount.  These efficiency improvements have filtered down to the PC power supplies - and you can now buy a desktop PC supply with better than 95% efficiency.

Combining a high efficiency psu with a LiPo battery bank, means that you can top up your store when required, at maximum efficiency. It also helps maintain your output on cloudy days.

In summary, all the components for a high efficiency microsolar system are available and affordable.

In the next post I will go into some more detail of the proposed system.

Thursday, October 01, 2015

A Glorious Week in September

The First Rays of October Sunshine Bathe The Llanfrothen Bothy

This week I have been off work and attending various events around the country.

The weather has been exceptional - i am so lucky to have picked a week off work with such fine sunny autumnal weather

Last Thursday I went to an ARM Cortex M7 programming course near Cambridge.

On Friday, I hung out with Andrew Back and Omer Killic in Hebden Bridge and discussed plans for a new video frame store and imaging system for his 1985 Cambridge Instruments Scanning Electron Microscope.

Saturday was oshCamp 2015 (Open Source Hardware Camp)  - 2 days of tech talks and workshop sessions at Hebden Bridge Town Hall. This was the first event of the week long @wutheringbytes Digital Festival held in Hebden Bridge.

On Monday I attended the morning session of "Open  for Business" and then spent the early afternoon teaching a 75 year old pensioner the basics of programming Arduino.

In the late afternoon I drove to North Wales to a remote rural bothy near the village of Llanfrothen.  I then spent nearly 3 days developing a micro solar inverter with good friend Trystan Lea of @openenergymon.

I have returned to Redhill, Surrey and expect to return to work tomorrow for a well deserved rest.

More posts about the above to follow.