MPPT Solar Charger Rev C Design

Over the last year or so I’ve designed, built and tested a standalone solar charger. It performed quite well but as with any complex design there were a number of things that needed to be improved.  So I eventually reached the point where I decided to design a revised version. And this is what this post is all about.

Things to improve

Here’s a list of things that I wanted to improve besides fixing the design errors of the old design:

  • Downsize the board and give some thought to how to put the whole thing into a case. Consider carefully where to put screw holes, connectors and the like.
  • Reduce complexity wherever possible. Reduce the number of distinct components.
  • Reduce total component cost without sacrificing performance.
  • Reduce height of the assembled board so that it can ship in a padded envelope.
  • Turn user interface on by means of a logic signal as opposed to turning its power supply on and off. Ability to control the display entirely via I2C, including backlight brightness and reset.

Let’s look at these points one by one.

Downsize the board

I looked around for a suitable case for my solar charger and finally decided on a 90x115mm cast aluminium case. The specific model chosen is available from Farnell at around 10 bucks which I found very reasonable. With the case chosen the size of the board was pretty much given. The inside shape of the case is rather special since there are also mounting holes for the case itself that take away space for the board. However, I decided to keep the board rectangular so it stays universal and is not just made to fit that particular case. That left me with a board of 85x78mm as opposed to 90x140mm of the last version. That’s about half the size in terms of board area so fitting everything on the new board was really a challenge.

The main space saving came from using much smaller mosfets. The model previously used was rather huge in physical size. I’m now using NXP PSMN6R0-30YL in a LFPAK package that is much smaller while delivering similar if not better performance.

The main inductor is also somewhat smaller. I found that the Coilcraft MSS1210 series delivers pretty much the same performance as the MSS1583 while saving some space.

Apart from that I didn’t downsize any of the components in order to keep everything hand-solderable  and hobbyist-friendly. Particularly, all the resistors and ceramic capacitors are at least 0805 in size.

Getting the board made from dirtypcbs.com also allowed me to do a denser layout, mainly by using smaller vias. But I didn’t push it to the limit, all traces are still at least 12 mils (0.3mm) wide with 0.4mm vias and 6 mils clearance.

Now all the power connectors are located at the top of the board with a single 12-pin 200-mil connector. USB is still located at the front and the programming header is at the right edge of the board. External temperature sensors and fan output are now on the left side. The header for the user interface is now located so that the user interface can just be stacked on top of the charger and sits precisely in the middle. There are also mounting holes for the user interface on the charger board.

Reduce complexity

The obvious place to start was the combination of PIC18F26J50 microcontroller with a I2C multiplexer and a port extender. The same PIC family also includes a 44-pin version that allows replacing all 3 chips with a single chip.  I’m now using the top-of-the-line PIC18F46J50. That not only simplifies the board but also the software since we no longer need to care about the mux and which pins are on the PIC and which are on the port extender.

The 4 mosfet drivers for the power outputs have been replaced by 2 MCP14A0153 dual mosfet drivers that also don’t require a reference voltage signal which further reduces complexity somewhat.

The 5V switching converter for USB charging on the last version needed quite a few external components to function. Besides that it got rather hot at 2 amps. I’ve replaced it with a Texas TPS54428 synchronous switcher that is more efficient, uses less external components, delivers up to 4 amps and has a thermal pad at the bottom which helps keeping it cool. The new Coilcraft MSS1048 coil is slightly higher but otherwise the same size and helps keeping power dissipation low.

I’ve tried quite hard to keep the number of distinct capacitor and resistor values to a minimum. You can easily see that the same values such as 10k, 300k and 680k appear over and over again. The only point where there are still a lot of distinct resistor values are the USB charging ports where I’ve tried to emulate an Apple and Samsung charger, respectively. I’m not sure to what extent one can cut corners here without risking that certain devices don’t charge properly.

Overall, the number of distinct components has been reduced from 60 to 47 despite some added features.

Reduce cost

Getting rid of the I2C mux and the port extender already saves some cost. The same goes for the dual mosfet drivers and the downsized inductor. There were some unnecessarily expensive components on the last version. There was an 18-bit ADC that we didn’t really need. The Microchip MCP3428 is a very similar model that only has a maximum resolution of 16 bits and is quite a bit cheaper without making any difference to our application. Another component that was somewhat of an overkill was the voltage reference. Note that the voltage reference is only needed for the temperature measurements. The voltage and current measurements are done by the external ADC that comes with a precise on-board voltage reference. I found the Silicon Labs TS6001 which provides a sufficiently precise 2.5V reference.
I’ve also replaced the large and relatively expensive EEPROM with a much smaller 16kbit Microchip 24AA16 EEPROM in combination with a cost-effective serial Flash (Spansion S25FL208K) with 8Mbit of capacity. This way we get much more storage at a similar total cost while still keeping some easy-to-use EEPROM for configurations and the like.

Reducing height

Since the only overly high components on the last version were the input and output capacitors this was an easy task. I decided that I want to use the same model for both input and output which meant that I needed a 25 volt rating. Maintaining the 10mm diameter and limiting the height to 12.5mm left me with a maximum available capacity of 470uF. The ripple current rating of the new caps is also lower so I now have to use 2 caps in parallel at the input to not exceed this rating at 75 watts.
The caps are still the highest components on the board but only slightly higher than the USB connector, the main inductor and the 200-mil connector. The resulting total height of about 15mm is low enough to comfortably ship the assembled board in a padded envelope which is much cheaper than a small parcel.

User interface

I’ve already presented a user interface that fulfills most requirements listed. However, I still needed to again revise the user interface for two reasons. First, the previous version would not physically fit inside the cast aluminium case. So I had to somewhat taper off the board towards the side so it would fit. I also had to re-locate the mounting holes inward so that they lay on the charger board. Secondly, I need to be able to shut down the user interface without blocking the I2C interface. This was not an issue with the last version where I had a I2C mux in between. So the new  interface now includes a 2-channel bi-directional switch that is controlled via the same signal that turns the interface on and off.

Next steps

I’m looking forward to my ReflowR hopefullly arriving soon so I can build up the board in an efficient way.  As you can see below I have already prepared a setup to apply the solder paste to the board. I have glued three faulty user interface boards to a piece of coated plywood to repeatedly align the board. I have limited experience with reflow soldering but I will hopefully learn quickly and report my progress and lessons learned here.

As you can see from all the photos here the boards have already arrived and I’m excited to try them out. All the eagle files as well as the Gerbers and everything are on github: github.com/soldernerd/SolarChargerHardware.

C# USB HID Utility

Have you ever tried to write a program that connects to some device via USB? I have done so a few years ago and was shocked how much of a pain that is (at least on a Windows plattform). I always thought there should be a nice little library that wraps all those uggly DLL imports, marshalling and COM API calls and offers a nice and clean C# interface to the outside world.

Much to my surprise I found nothing that really did what I was looking for. Now I finally sat down and wrote my own. It’s on github.com under GNU GPLv3 license for anyone to modify and use.

My starting point was the Microchip PIC18F46J50 FS USB Demo Board. This nice little board comes pre-programmed as a HID (Human Interface Device) / MSD (Mass Storage Device) USB composite device and is a great starting point for anyone interested in building a USB device based on a PIC.

Once uppon a time, Microchip also wrote a WindowsForms application to showcase the USB functionality of their microcontrollers and that application (in various versions) can still be found here. It lets you read an analog voltage from the board, tells you if a pushbutton is pressed or not and lets you toggle an LED. Very simple but all you need to get started with your own device and application.

Unfortunately, that code no longer gets maintained and is quite outdated by now. It was created with VisualStudio2010 and .NET 2.0.  And all USB and WindowsForms code is mixed up in a single file which makes it difficult to re-use. It also lacks some functionality such as the ability to list available devices. Apart from that it works very well and stable so I used it as a starting point.

My solution is now based on VisualStudio Community 2015 (which is available for free) and .NET framework 4.6. So you can just download VisualStudio and open the HidUtilityDemo.sln file.

There are 3 projects inside the solution:

  • A WindowsForms application named HidDemoWindowsForms
  • A WPF application named HidDemoWpf
  • A console application named HidDemoConsole

All projects use a common file named hid.cs. This file is what this is all about. The applications mainly just show how to use it and give you a starting point for your own application.

hid.cs is not pretty. 900 something lines of DLL imports, COM object calls and marshalling. It’s C# but it doesn’t look and feel like C#. But it does all the heavy lifting for you and offers a nice, clean, truely C# interface for you to work with HID devices.

You add it to your namespace, create an instance of HidUtility, tell it what device to connect to  and subscribe to the events you are interested in:

// Get an instance of HidUtility
HidUtility HidUtil = new HidUtility();
// Connect to device with Vid=0x1234 and Pid=0x5678
HidUtil.SelectDevice(new hid.Device(0x1234, 0x5678));
// Subscribe to the events you care about
HidUtil.RaiseDeviceRemovedEvent += DeviceRemovedHandler;
HidUtil.RaiseDeviceAddedEvent += DeviceAddedHandler;
HidUtil.RaiseConnectionStatusChangedEvent += ConnectionStatusChangedHandler;
HidUtil.RaiseSendPacketEvent += SendPacketHandler;
HidUtil.RaisePacketSentEvent += PacketSentHandler;
HidUtil.RaiseReceivePacketEvent += ReceivePacketHandler;
HidUtil.RaisePacketReceivedEvent += PacketReceivedHandler;

You can also obtain a list of all available HID devices at any time:

foreach (Device dev in HidUtil.DeviceList)
{
Console.WriteLine(dev.ToString());
}

As the three projects demonstrate, the very same hid.cs file can be included in just about any C# project. There is not a single API call or anything in the remaining files.

Just register some event handlers and your application will be informed whenever a device has been added or removed, when a package of data has been received from the device, when the connection status has changed or whatever else.

So you don’t have to re-invent the wheel every time and can fully concentrate on the application you have in mind, not the details of USB communication.

A word of caution: I am by no means an expert C# programmer. I have tried the applications on 3 different PCs running Win7 and Win10, respectively. They seem to work reliably on any of these. Apart from that the code has not yet been productively deployed and there may well be some bugs and issues. If you find anything that doesn’t work, please let me know and I will do my best to get things fixed and updated on github. Also, please comment on this post if anything needs clarification.

So once again, the code is available for download from github.com/soldernerd/HID_Utility.

Ultrasonic Anemometer Part 30: Downsized Hardware

In my last post of this series I’ve looked at different transducers and finally decided on a entirely waterproof 14mm model. The much lower signal level from those kind of transducers makes it  necessary to reduce the distance between the transducers in order to still receive a reasonable signal amplitude.
So I took my previous lasercut design and reduced it in size so that the distance between the transducers is only 120mm. I went to the local FabLab and and lasered two copies of the downsized design.

Since the new transducers are only 14mm in diameter but those plastic pipes are only available in 16mm I had to pad the transducers with short sections of aluminium tube with an outer and inner diameter of 16 and 14mm, respectively.
I previsously connected the wind meter to an Arduino with a LCD display to test the I2C functionality as well as to read the wind speed and direction without having to connect the anemometer to a PC. Now I have used my I2C user interface for that purpose. It is powered from the wind meter’s 3.3 volt rail and is controlled via I2C including the backlight brightness and display reset. The user interface usually also includes a rotary encoder with push-button not present in this application.

In an attempt to boost signal amplitude I’ve also changed the first stage op amp’s gain from 11 to 31 by replacing the 10k resistor with a 30k one. I’ve argued in my last post that this is probably about as far as you can safely push it.
Even with the lowered transducer distance and increased gain the signal amplitude after the first stage is less than impressive. But we knew that already. And we have a second variable-gain stage at our disposal. Setting the second stage’s gain sufficiently high we hopefully get the 3 volts peak-to-peak amplitude we are aiming for.

By the way, I’ll started from scratch with the firmware. The reason for that is mainly USB. Currently, the anemometer acts as a HID device. While working on my solar charger I started to play around with HID / MSD (human interface device / mass storage device) composite devices. They still act as HIDs with all the functionality just like before. But when you plug it into a PC it also enumerates as a mass storage device, i.e. it behaves just like a memory stick. You can read and write the files on it from any computer, irrespective of the operating system and without needing any particular softwar or driver installed. So you can put all the configuration parameters in a text file that resides on what looks like a memory stick. I guess that’s the most user friendly way of dealing with those user-specific configuration parameters. Just plug it in, open a text file, change what you need, save the file and you’re done. This is how the solar charger will operate and  I’ve decided to implement the same here.
Microchip’s Harmony library includes all that functionality so I have no doubt it’s doable. But I’ve figured that it’s likely easier to do this as a new project and then add the previously implemented functionality step-by-step.

And then there’s another USB-related feature that I had in mind right from the start but which I haven’t event started to implement so far: A USB boot loader. That would enable people to do a firmware update without needing a in-circuit programmer such as the PICKit 3. Users could just download a new HEX file and upgrade the firmware without needing any special hardware or even skills.
USB boot loaders come in various flavours. The Harmony library includes support for an HID boot loader. But that’s not really ideal if you ask me. It means that you need to run some software on your PC that communicates with the anemometer and sends the new firmware via USB. The need for software means that it matters what kind of operating system you run. And needing additional software is undesirable in the first place.

There are also MSD bootloaders which do not have all those downsides. The device acts as a memory stick to the PC. The user then just copies the HEX file to that memory stick and that’s it. Just drag-and-drop, no extra software, no matter what OS.

The problem is that the Harmony library does not support that out of the box. Indeed, Microchip doesn’t seem to have implemented that for any of their chips. That’s kind of strange because other chip manufacturers have done so long time since. There is at least one implementation for PICs out there in the web but I haven’t looked at it yet because the website it was hosted on no longer exists it seems. Probably I’ll have to implement this myself but the Harmony support for MSD will hopefully do much of the heavy lifting.

So that’s the plan. Implement a bootloader, preferably of the MSD variety. And then run the anemometer appliction as a HID/MSD composite device. You may say that I set the wrong priorities given the fact that the actual measuring is not yet as good as it needs to be. But this kind of fundamental architecture is easier to get right from the very beginning. So that’s why.
If you’re interested in this lasercut design you can find iton github.com or more precisely on https://github.com/soldernerd/AnemometerLasercut. This version is called Anemometer_03.scad and the PDF that was used for the actual laser cutting is Anemometer_03.pdf.