Project: Solar/Wind PIC controlled battery array

Thread Starter

nsaspook

Joined Aug 27, 2009
13,086
My "work in progress" software update for this project. It's not pretty but is mainly a testbed for some ideas about a larger system sometime in the future.
 
Last edited:

Kermit2

Joined Feb 5, 2010
4,162
Having a closet full of batteries myself, I'm impressed with your project.

I would like to suggest some rubber insulation for those copper pipe battery interconnects. I've seen a socket wrench 'evaporate' when it was dropped across a 48 volt battery bus bar. Such accidents aren't supposed to happen, but if it's exposed and there are things above it, then you really should protect it from that happenstance.
 

Thread Starter

nsaspook

Joined Aug 27, 2009
13,086
Having a closet full of batteries myself, I'm impressed with your project.

I would like to suggest some rubber insulation for those copper pipe battery interconnects. I've seen a socket wrench 'evaporate' when it was dropped across a 48 volt battery bus bar. Such accidents aren't supposed to happen, but if it's exposed and there are things above it, then you really should protect it from that happenstance.
They have been covered for a while using copper pipe insulation but thanks, after rechecking I see a few missing spots.

 
Last edited:

Thread Starter

nsaspook

Joined Aug 27, 2009
13,086
Nice! How many separate pieces of data are you sampling?
Most are listed in the source code header below. I'm in the process of adding a thermistor adc channel so I can account for sensor temp drift and battery SOC changes. Both the hardware and software are works in process so things are still changing. The current software lacks a clear design process but should be the basis for a much larger scale system I plan to build in a few years.

The system uses the PIC18 high and low priority interrupt heardware to provide for a master 1 second clock/comm interface on the high ISR and a worker thread on the low ISR that runs as a background process updating the system database from the inputs.
These processes communicate with a set of data structures that control what cell gets charged or how power is to be used using a weight factor. This weight factor is generated in a routine that looks at the current system data and any history that has been stored to make a decision on who should be connected to a energy source.
When all batteries are charged and there is excess power a diversion relay can send a signal to switch external AC loads to PV off-grid power.

Rich (BB code):
/*
 * This program controls and monitors solar power battery arrays on a 12vdc system
 * MBMC
 * standard program units:
 * Voltage  in (unsigned long) millivolts, current in (long) tenths of amps
 * power in (unsigned long) Watts, battery capacity in (long) tenths of Ah
 *
 * USART2               is the host comm port 38400
 * USART1               SD card dump comm port 115200
 * Timer0               1 second clock
 * Timer1               work thread , background I/O clock ~20HZ
 * Timer2
 * PORTA                analog inputs
 * adc0 vbatol                                  PIC Controller supply voltage to 5VDC regulator
 * adc1 solar                                   Charging voltage at battery from CC
 * adc2 currentin                               50A AMPLOC sensor input from PV array
 * adc3 rawp1/inputvoltage              Voltage from PV array
 * adc4 rawp2/primarypower[B1]  Voltage a primary inverter battery
 * PORTF                                                analog inputs
 * adc5 current                                 300A AMPLOC sensor battery output to inverter
 * adc6 rawp3/primarypower[B2]  Voltage for backup battery
 * adc8 currentcharger                  50A AMPLOC sensor on 15vdc 10A ps for external charger.
 * adc_cal[10-13]                               current sensors zero offset stored in eeprom 10=a50, 11=a50c, 12=a300, 14=future
 * cal table 98,123,127,161,119,127,127,127,127
 * currentload                                  The current going the power the inverter or other load.
 *
 * PORTD                switch input
 * PORTE                battery/charge relays
 * PORTJ                load/input relays
 * PORTB                external control i/o
 * PORTH0               run flasher led on-board.
 * PORTC0               C40 charge controller led input
 * 4x20 LCD status panel and led status lights.
 *
 * nsaspook@nsaspook.com Copyright 2011
 * Fairview, Oregon
 * MMC-SD card routines from ELM-CHAN,www.captain.at,www.microchipc.com and others
 */
Rich (BB code):
unsigned char pick_batt ( unsigned char choice, unsigned char bn )
{
        static unsigned char z, pick, boi = 0, D_ON = 0, D_OFF = 0;
        static long iweight, vloaded;
        static float weight;

        /*      look at cell and history data for next battery to charge or if all are good float on primary battery
         *      choice is 0 for normal logic or 1-4 for battery to switch float to
         *      bn      = battery c40 is currently connected to, or 0
         *      0       = float charge on primary if all charged
         *      1-4     = battery to run full C40 charge sequence on
         *      return  codes -1 = error, 0 = float, 1-4 charge this battery
         */
 
Last edited:

Thread Starter

nsaspook

Joined Aug 27, 2009
13,086
Awesome! What do you use the power for exactly?
I have an isolated power system that runs a outdoor media room with a small TV, music system and lighting.

The diversion signal is sent to a relay based transfer box that mainly feeds outdoor/garage lighting. Switching motor/sensitive circuits will need something more complex with zero-cross and phase detection.



The run-time data for loads is displayed on the front LCD panel.


Line 1: Bulk mode, Efficiency of charge controller, Battery number, Max time if not fully charged.
Line 2: Voltage from PV, Voltage to battery, Charge current.
Line 3: Battery 1 voltage, Run-time at current load, State Of Charge, Ah used
Line 4: Data for Battery 2.
 

russpatterson

Joined Feb 1, 2010
353
That's really cool. I've had the same daydreams but haven't taken it nearly that far. I got sidetracked with the make it run outdoors in an isolated spot, solar stuff. It seems like you're ready to share the code and designs. Have you considered posting the files up on git hub or somewhere similar? https://github.com/

Maybe it will take off and you'll help make a dent in gazillion barrels of oil we buy each year.
 

Thread Starter

nsaspook

Joined Aug 27, 2009
13,086
That's really cool. I've had the same daydreams but haven't taken it nearly that far. I got sidetracked with the make it run outdoors in an isolated spot, solar stuff. It seems like you're ready to share the code and designs. Have you considered posting the files up on git hub or somewhere similar? https://github.com/

Maybe it will take off and you'll help make a dent in gazillion barrels of oil we buy each year.
I will take a look at github. There's nothing new or special being used or programmed by me on this project but the long term plan is to have a 4KW off-grid system for my retirement home on a plot of land I own in central Texas.
http://maps.google.com/maps?hl=en&q...code_result&ct=title&resnum=1&ved=0CB0Q8gEwAA
A large part of my retirement is in oil stocks now, so I hope that won't happen anytime soon.
 

russpatterson

Joined Feb 1, 2010
353
Even though there's no ground breaking technology. The fact that you've figured out what parts, relays, etc to use, how to hook them up, and all the code to monitor it is pretty useful. Git is an open source code repository. It works but it's all command line, no bells and whistles. There are good tuturials on it. You can then commit your local git repository to somewhere like github, it's free if you allow public access to your repository.

4Kw off grid sounds pretty cool. Will you have grid power available there at all?

On your current system. If you run out of battery power does it automatically switch over to grid power?
 

Thread Starter

nsaspook

Joined Aug 27, 2009
13,086
The diversion logic will run the battery down to a preset SOC level then transfer the AC load circuits back to grid power. There is a fail-safe option that will run the system down to nothing in a emergency but that's a battery killer. The media room is hardwired only to the inverter but I've got 450 Ah of battery and should generate 2.4kW on a good day in the summer with the current array.

The location is next to the old family farm with grid power about 1/2 mile away. I would have to pay the cost of the line extension of at least $5,000 so if I invest $10,000 on solar instead it's a good deal plus I get to deduct 30% of the expense off the tax bill.
I'm looking at a 10 year time frame to get things running so technology should be a at a mature level then for renewable energy.
 

russpatterson

Joined Feb 1, 2010
353
When it switches from the battery to the grid does it power down and switch or is it seamless and not noticeable in the media room? What do you use for the switch? Relays?
 

Thread Starter

nsaspook

Joined Aug 27, 2009
13,086
The media room is always on the inverter and never switches to grid power. The max load is about 400W with everything including a small AC unit going but usually it's under a 100W. The off/on grid switched circuits uses a 12vdc 20A relay. I have some zero-crossing ssr modules to upgrade it later but because it only has lights on it for now that's really not needed yet.

Relay Box http://flic.kr/p/9wBJBY
SSR http://flic.kr/p/9wBJDu
Inverter http://flic.kr/p/7FT8Q1
 

russpatterson

Joined Feb 1, 2010
353
So you'll replace the 20A relay with the zero-crossing SSR modules? The ssr modules are new to me. So they are used to cleanly switch under load? So you could switch power to your Computer from the inverter to the grid power and not miss a beat?

On the current setup for your relay box. Does the relay just interrupt one side of the AC? I don't know much about the 110VAC house current either. Does it matter if you switch the black or white wire with the relay?
 

Thread Starter

nsaspook

Joined Aug 27, 2009
13,086
So you'll replace the 20A relay with the zero-crossing SSR modules? The ssr modules are new to me. So they are used to cleanly switch under load? So you could switch power to your Computer from the inverter to the grid power and not miss a beat?

On the current setup for your relay box. Does the relay just interrupt one side of the AC? I don't know much about the 110VAC house current either. Does it matter if you switch the black or white wire with the relay?
If my inverter and the grid power frequency and phase were locked it would be that easy. In my case they are not, so I would have to use two module sets with a XOR lockout so both can't be enabled at the same time by accident. To switch over power sources when not in sync you have to command the online SSR set to off, wait at least 1 full cycle, then switch the other SSR set on to reduce a DC offset power surge. Most consumer electronics won't see less than 10 missing cycles but a good online UPS might.

In my case with the relay I switch both the hot and neutral wires to totally isolate my power from the utility. My inverter ground is connected to the utility ground at the main panel per the NEC for a Separately derived system.
http://www.iaei.org/magazine/2009/11/separately-derived-systems/
http://ecmweb.com/mag/electric_separately_derived_system/
 

Thread Starter

nsaspook

Joined Aug 27, 2009
13,086
Now that the solar controller code is pretty stable, it's time to work on the host controller.

I'm using a PIC32 Ethernet demo board and i/o expander to talk to the controller for control and status using the web server. The Microchip demo app is being modified to use a rs-232 port for the data link. It's mostly just a mockup for now until I build a interface card for the PIC32 using a MAX235 chip on a PICtail prototype board.





 
Last edited:

Thread Starter

nsaspook

Joined Aug 27, 2009
13,086
I finished building the serial interface on the PICtail prototype board. The plan is to run the usarts on both controllers in 9 bit mode and to use the ninth bit as a flag for commands or data so I can send binary data without re-encoding or escaping command bytes. If bit 9 is clear (0) it's a network command, (1) is binary data sorta like RS-485 addressing.


 

Thread Starter

nsaspook

Joined Aug 27, 2009
13,086
Basic networking is running using a simple master/slave comm protocol that can transfer binary blobs (C data structures) directly from one processor to the other.

The PIC32 is running a test program that just moves the data for now so I can add CRC checks and cleanup the network code.

Short video: http://flic.kr/p/9z7hYU

It's just a modded version of the uart demo. The structure types have to be defined with variable types that both the PIC18 and PIC32 C versions know the exact size of in mbmc.h
 
Last edited:

Thread Starter

nsaspook

Joined Aug 27, 2009
13,086
I've finished the basic PIC18/PIC32 serial network drivers /API and coded most of the basic callback functions for the web server on the Microchip TCPIP stack app.

The only real problem was getting the structure defines and alignments correct for both controllers. The PIC32 wants data on 4 byte hunks but the PIC18 packs structures to 1 byte. A few tricks with the GCC __attribute__ pragma fixed that.

Short Video: http://flic.kr/p/9ALee7
http://code.google.com/p/solar-monitor/downloads/list
 

Attachments

Top