Background

I wrote about Texas Instruments’(TI) Launchpad line of micro controllers (uC) about a year ago in this post. . Finally it is time to use it in a project.

In the MSP430 Launchpad family of uCs there are seemingly infinite number of choices. The part number I am using is M430G2513, I ordered them from http://www.mouser.com for less than $2 each. To be able to use them in bread board circuits, I chose 20 pin DIP package (IN20 extension).

Project Description

If you remember the home made solar power project, 65 Watt experimental solar panel charged up a car battery, and this power was used for things like lighting, etc.

In a situation like this, the load is pretty much constant from day to day. However, the source of the power varies depending upon the seasons or the weather conditions. If a cloud passes by or if it rains or snows the power source is diminished.

So, what we need is a circuit that will measure the battery voltage periodically (say every 5 minutes) and check if it is below a threshold (say 12 Volts). If it is higher, this means there is enough power and it will do nothing. If the voltage is lower, it will turn on the relay to connect the battery charger to the grid (a plug on the wall) for a period of time (say one hour).

It is important to note that the battery will be charged independently by either the solar panel, the charger, or maybe both at the same time.

We will use the AD converter and the Timer A features of the uC for measuring the voltage and the timing, and we will use several output pins to turn on the LEDs and the relay.

Relay Control

M430G2513IN20 works with 3.3 DC Volts. The circuit below uses this low level signal and controls the relay, which in turn controls the power to a standard AC plug.

Relay Circuit

The schematic shows 5 Volts, but you need to use the voltage that the relay requires. Generic diode suppresses the spikes when the coil is turned off. R1 and R2 are both 1K, but again the resistor here depends on the gain of the transistor. The relay contacts controls the power to the plug. The signal from pin 15 of the uC is connected to the free end of the R1.

Note that this part of the project is generic enough that it could be used for other purposes.

You need to adjust the R2 resistor to set the battery limit voltage such that when the mid leg of the R2 is below 1 Volts, the relay will be activated.

Here is the bread board view.

Bread board view

Software

TI provides Code Composer Studio (CCS) to develop software for MSP430 uC. I will not go through the steps of installing this software because it is already documented in the TI’s website. Likewise, creating a new project in the workspace.

Once you create the project, you can copy the C program provided below over the sample main program that is created automatically.

Download
Most of this code is self explanatory, but here are several points.

We turn off the CPU in the main loop (line 49), because we are not using polling. This saves battery life. When the timer interrupts, the CPU will be activated and the interrupt service routine will run.

It is important to set meas_time and chrg_time to meaningful values (line 45 and 46). For testing purposes they are set to 1 and 2 here, but in real life you would want to set them to more meaningful values like 5 minutes and 60 minutes.

That’s about it as far as the code goes. You can compile and download it onto the uC with the LaunchPad development kit.

Finished Project

Here is a picture of the finished project. Granted, needs to be packaged better, but see it works great!

A Different Approach

Another approach to this project is that instead of charging the battery for a fixed amount of time, we measure the voltage as the battery is charging, and stop the charging when the voltage goes above the higher limit (maybe 14 Volts). It is very easy to make this change to the program listed above.