Continue to Site

# A pic based Charge Controller

Status
Not open for further replies.

#### bryan1

##### Well-Known Member
Hi Guys,

I would like to put forward a proposal where fellow members of the forum can join in and design a pic based charge controller for solar/wind/hydro.

The concept will be it can be used for different input voltages as the input signal will just be a voltage divider and with a few tweaks in the software. Once finished a new thread will be made and placed in the RE projects section. The whole idea of starting this is in the spirit of open source I feel we can create a great database of RE related projects.

Initial Suggestions
The lcd will show the voltage and input current from the RE array. A preset voltage will either setup to short the PV panels or divert the load to another source(ie: dumpload). Datalogging is also a great idea to incorporate.

OK I'll leave things at that and wait to see the feedback on this proposal.

Regards Bryan

#### Pommie

##### Well-Known Member
OK, I'll start, how about I knock up a circuit with a 16F886, an LCD and keypad on Portb 0-6 and Porta 5-7. This will keep the analogue pins, the ccp modules, the uart, the MSSP and the ICSP pins free. I could then write some basic menu stuff as a place to start. Anyone any preference on language? I suggest BoostC as I have most of it already written (and it's free).

Mike.

#### Mr RB

##### Well-Known Member
Sounds cool!

One thing I would suggest would be to keep the C to the simplest C expressions possible, so it can easily be converted to other C compilers, BASIC, ASM etc.

Like instead of large compound expressions you could split it into small single-line expressions, that is much easier to convert (especially to ASM).

for(x=0; x<16; x++) blah

you can do;
x=0;
while(x<16)
{
blah
x++;
}

I think a menu button system might be more user friendly (more attractive too?) than a numeric keypad, not sure what you had in mind there.

#### nickelflippr

##### Member
Very interesting, have been wanting to do this for a while for a single 75W solar panel. A Microchip app note AN1211a has a maximum power point algorithm. Although that appnote is for a boost topology, I think it has some good ideas.

Would like to do a 10A (solar) prototype. Although I am sure that others would want something much larger, or have more diverse interests. One could use #ifdef to add options for energy type, current ratings, etc. at compile time.

These are some parts on hand, for current sense, the Allegro Hall effect ACS712ELCTR-20A-T or the Maxim 4081. And a large Bourns inductor.

Using Mclr as a menu button sounds good. Key pad could work, if explained a little more.

Might follow along with GCBasic port, and learn something about C in the process.

#### smanches

##### New Member
I'll help. Done projects similar to this before.

Although I'm going to be too busy until October.

Vacation!!!

#### Pommie

##### Well-Known Member
Well, I've put together a little circuit, with a 16F886 (could be a 16F88), a 16*2 LCD and 4 push buttons. It only used 7 I/O pins and keeps all the multi use pins free.

I've also written a simple menu system in BoostC. It is not very elegant due to some (newly discovered) limitations of BoostC. Namely, no ROM pointers. It mimics the early mobile phone menus with "back up down enter" buttons and can handle 255 entries and up to 8 levels. I'll tidy it up over the next few days and post it as it will probably be useful for other projects.

Now, what to do next? Anyone any suggestions?

Can anyone suggest a menu structure that I could implement as a test. I always find a real world example the best test.

Mike.

#### bryan1

##### Well-Known Member
Hi Pommie,
Great mate, that your starting on the project, I have plenty of pic's here but not boostC, I do have Oshonsoft Basic both the 16f IDE and the 18f IDE with all the bells and whistles. I have tried to learn C for the pic's but I always stumble on the simple things. Time for me doing electronics is very limited due to my work, the family and running the farm.

Lots of people just go 12 volts with RE for the first time but don't realize the benefits of going for a higher voltage like 24 or 48 volts.

With solar as the only RE input 99.9% of charge controllers simply short the PV panels. As an example that shunt controller schematic I put in the projects section just diverts the input power away from the batteries to a dumpload for a preset period. My dumpload is set for a 19 amp dump which can make my analogue voltage gauge bounce then when the dump switch's off the voltage rises quickly again turning the dumpload on. Now the main bank I have connected is 24 volts @ 500ah so when the batteries are fully charged I do waste the dumpload in heating air.

A good thought for dumploads is stepped switching to multi dumploads depending on the input current that needs to be diverted. The main reason I went with a 19 amp one was the I have have full sun and it's windy I could be getting around 12-14 amps from the PV array and a further 5-20 amps from my 2hp motor conversion wind genny and I am only in the shed briefly at night after work and on weekends.

I do intend to make some new dumploads using nichrome wire and I'll take a heap of pic's and make a thread in the projects section.

More discussion from other members on the design will be welcome as I feel the needs of my system is very different to others.

Regards Bryan

#### smanches

##### New Member
Why are you dumping the load on PV panels? Or is that the only type of charger controller you have right now?

#### Nigel Goodwin

##### Super Moderator
Why are you dumping the load on PV panels? Or is that the only type of charger controller you have right now?

What would you suggest he does with it?.

#### smanches

##### New Member
Nothing. Unless I missed something huge, PV panels can be in the sun open circuit.

#### Nigel Goodwin

##### Super Moderator
Nothing. Unless I missed something huge, PV panels can be in the sun open circuit.

It's for wind and hydro as well.

#### nickelflippr

##### Member
Two position dip switch for selecting hydro, solar, or wind power?

Code:
(LEVEL ONE)--POWER TYPE--
|--HYDRO POWER
|--WIND POWER
|--SOLAR POWER---(LEVEL TWO)--SYSTEM VOLTAGE--
|--48v
|--24v
|--12v--(LEVEL THREE)--BATTERY CHEMISTRY
|--CUSTOM
|--AGM
|--GEL
|--CURRENT LIMIT  xx A
|--BULK ?
|--ABSORB  xx.x V
|--FLOAT xx.x V

EDIT: O.K. see there is a combo system of wind and solar in use, so possible to have a Hybrid system setup or menu choice.

Last edited:

#### Mr RB

##### Well-Known Member
Just a thought; change the menu for more "human" feel as the thing you will probably want to do most is just view the data, and maybe some simple control functions;
Code:
DISPLAY
volts amps in
volts amps out
power generated today
power dumped today
stats for this day/week (etc)
CONTROL
set charging on/off
force dump off/auto/on
send data out RS232 to PC
SET OPTIONS
solar/wind/hydro
battery 12/24/48 etc
battery charging full limits/profile/time etc
set alarm limits

obviously some would have sub menus but the basic control is more user friendly, normally you want switch between displaying stats, then sometimes control stuff, then very rarely chaneg the setup options.

#### bryan1

##### Well-Known Member
Hi Guys,
Good to see some great idea's coming in with the menu system. The idea of dumping the stored data to a PC is one of my goals but I thought it would be a bit audacious of me to suggest it.

For the amount of data suggested I feel a 18f pic say a 18f2550 USB would be perfect for the job. I have the USB addon for OS basic so by using the ready available USB routine would make a HID device easy. Now I did suggest basic for this project, Pommie has suggested using 'C' so whynot make this project code in basic, 'C' and asm to suit everyones flavor of coding. I'm sure with the knowledge of our forum members this can be accomplished so any member that wants to build the project can choose the coding language they are familiar with.

I will have a big think over the next few days with some thoughts on a menu system and post them in here.

It is really great to see this first RE project coming to life and I really hope we can make this project a reality. I feel then the RE section of this forum will bring in a heap more RE people who will help out with questions posted.

Regards Bryan

#### nickelflippr

##### Member
Had thought about the USB question too. If you keep to the RS232 side of things then a lot more options are available to the end user.
1) More devices available, and pin for pin compatibility (e.g. 16f886_887 is same as 18f2620_4620).
2) More compiler options available, as most free versions will not support USB?
3) As an option one could burn a USB PIC with Microchip precompiled hex demo to make a \$2-3 serial to USB device, or just use a cable converter.

Good question on what data logging medium to use; eeprom, flash, sd card? Like the idea of eeprom(s), as it would fit with the I2C rtc (DS1307) library that I have. In the end, the control software will be most important, and the interface could be a user definable issue.

Haven't fooled with switchmode stuff before, but willing to learn. Is it right to think this will be a buck regulator/converter? Also that the current control part of the charge profile is likely to use mppt (i.e. check current, test current for max/min boundary, vary PWM up/down to find max reading within boundary). And, that the voltage control part will use a PID algorithm to feed the PWM duty cycle to keep the voltage constant during load swings.

#### Mr RB

##### Well-Known Member
Well i would go RS232 over USB any day. You don't need the high data transfer rates of USB and RS232 will run hundreds of metres over cheap cable, and it's easier because you don't need a USB PIC. RS232 also leaves open an option of using any cheap old PC as a dedicated solar display terminal you can have in the house and leave it running.

For data storage I think simple is best, like just using the PIC internal eeprom. You only need to record min/max and 24 hourly averages, so the 256 bytes of eeprom in a 16F886 should be plenty. You might even be able to record 15 minute averages.

A potential killer for this project would be feature blow-out, ie trying to make it do way too much and/or too perfect at the start then it just gets too hard and stalls.

I think pommie was on the right track, a minimal setup with a PIC 16F886 and a display and 4 buttons, then make it display volts/amps and turn the load on and off. And see where it goes after that.

#### john warfin

##### New Member
Hi,

I am new to this forum and decided to jump in when the subject of micro based controller design cropped up. I've built a few MPPT and array trackers for my off grid summer house using Atmel AVR and the current project involves combining the two.

I agree "creeping featurism" is the number one fatal disease these type efforts succumb to so struggle to keep mine as simple as possible. Limited pin count of my Mega8/328 platform helps in this respect.

At present I have rs232 interface in lieu of display/kbd but that may change if pins are left over once basic functions are implemented. Flash is used for logging because there's just so much more available (20-30k/1-2yrs) compared to EE.

I look forward to seeing how this PIC based design evolves, specially regarding feature selection. Thanks for listening.

#### bryan1

##### Well-Known Member
Hi John,
Welcome to the forum mate, I'm sure with this project you'll be keen to share some of your expertise with your past knowledge of RE stuff.

Anyway I've setup my big breadboard with a 16f886, lcd, 4 buttons and a 4:1 voltage divider.

The input voltage will come thru AN0
The LCD is hooked up as upper portB bits for data in 4 bit mode, RA4 is the RS pin RA5 is the 'E' pin. I haven't worried about the RW pin.

I did get my ICD2 clone to see the pic on the breadboard OK, so the software I'll be using is Oshonsoft Basic and hopefully I can get Eric to chime in as the man IS the guru with this basic software.

As this project is for my son for his caravan he is going to learn along side with me. I will be setting up a 12 volt array using 4 of my 6 volt 105AH AGM's and the PV input will be 2 off 12 volt 45 watt panels. With all the rain we've had this week I'll be digging a trench from the van to the shed and when my shed array's are full and dump the load I'll setup that power to go in for extra charge.

As the batteries are well over 6 years old and I have a few fail in my shed array, I will setup individual monitoring of each battery. Then if one fails it will give an alert and that will make it easier to find the suspect one.

I will be doing several of these charge controllers to suit my RE needs and I'll log each one in this thread. When other members get started on theirs feel free to add them in this thread also.

Hopefully we can make this charge controller project thread a good resource for anyone that is keen to learn and make their own. In the spirit of open source and member support I'm sure we can make this project a top resource for RE and a valued addition to this great forum.

Regards Bryan

#### Pommie

##### Well-Known Member
As promised, here is a menu system in BoostC. The example menu that is implemented is,
Code:
Main Menu
Display
volts amps in
In from panel
8.1V 2.3A
volts amps out
Out to Battery
12.2V 1.5A
Generated Today
Generated Today
123456W
Dumped Today
Dumped Today
4321W
Weekly Stats
Today   37kWh
Today-1 43kWh
Today-2 41kWh
Today-3 45kWh
Today-4 34kWh
Today-5 50kWh
Today-6 27kWh
Control
Charging on/off
Charging on/off
on
Allow Dump
Allow Dump
True
Options
Set Baud Rate
2400
4800
9600
19200
Set voltage
Voltage 12V
Voltage 24V
Voltage 36V
Voltage 48V

It is a data driven menu but is a little messy in it's implementation.

BoostC does not have ROM pointers or ROM structures greater than 256 long and so I implemented the menu data as a memory object using pragma data directives. All menu variables are held in EEPROM so they are persistent.

The hardware details are,
16F886, 16*2 LCD, 4 push buttons and 4 diodes.
LCD connections, data to b6-b2, RW to gnd, EN to b1 and RS to A7 - this is to keep the ICP pins (b6,7) and Int0 (b0) free.
The diodes connect to the data pins (anode) and then to the push buttons. Other side of the push buttons goes to A6.

At the moment, it is still compilable with the free version of BoostC and there is a whole 50 words of program space free. The full version of BoostC would allow the other 6K (of 8k) to be used.

In it's current form it is not really usable but could be chopped down to implement a programmable battery charger.

If anyone could put this circuit together in Proteus or some other simulator and get the code running that would be fantastic. A video (like AtomSoft's here) would be awesome.

I may convert this to Swordfish Basic over the next few days as I think this would be easier for people to use. What do people think?

Mike.

Bryan, if you need me to make a hex file for your board let me know your layout.

#### Attachments

• Bat Charge.zip
10.6 KB · Views: 1,242
Last edited:

#### nickelflippr

##### Member
Started in with a 16F887 because that was on hand. 16F, 18F no diff to me.

Have tested part of the program, mainly the voltage control mode of the charger. The hardware PWM (CCP1/RC2) is used to generate a programmable voltage reference. The PWM voltage reference is then fed into the C1IN+/RA3 pin of the C1 comparator. A pot working between Vdd (4.85V in my case) and Vss simulates a voltage output (Vout) from a supposed 4x divider from the charger output. The Vout is fed into the C1IN-/RA1 pin. The C1OUT/RA4 pin then outputs the setpoint to the, yet to be determined, switching transistor.

I realize that this is only a small part of the scheme. Hopefully I'm on the right track. May need some boundary checks or clamps in there, as the voltage output misbehaves near the top and bottom rails. Also a bit of a glitch, or bounce? on the rising and falling edges.

May keep the OSC1/RA7 and OSC2/RA6 pins handy if more PWM resolution is required through an external crystal.

Code:
'GCBasic Program for solar powered swithmode battery charger
'Test Voltage control mode
'with programmable PWM voltage reference as C1IN+
'and simulated voltage out 4 x divider output as C1IN-
'Tested 9/26/2009

'Chip model
#chip 16F887, 8
#config  _INTRC_OSC_NOCLKOUT

'setup lcd
#define LCD_NO_RW	;tied to gnd
#define LCD_IO 4
#define LCD_DB4 PORTB.3
#define LCD_DB5 PORTB.2
#define LCD_DB6 PORTB.1
#define LCD_DB7 PORTB.0
#define LCD_RS PORTB.5
'No #define LCD_RW PORTC.6
#define LCD_Enable PORTB.4
#define led1 PortE.0
#define led2 PortE.1
#define led3 PortE.2

'Set the pin directions
dir led1 out
dir led2 out
dir led3 out
'dir portA.0 in

'setup comparator C1IN+/RA3 for programmable PWM reference voltage
'and C1IN1-/RA1 from charger output voltage divider
'C1OUT/RA4 sent to switch mosfet transistor gate
Set C1ON On    'set comparator C1 enable bit
Set C1OE On     'set output to C1OUT pin (RA4)/clear bit if internal only
Set C1CH.1 Off:Set C1CH.0 OFF    'select C12IN1- (RA1) to C1Vin-
dir PortA.4 out    'Enable C1OUT comparator output

dim count as word

Main:
Count = 0
Do while Count <= 5000
HPWM 1, 8, 191    'measured 3.6V by DVM (i.e. 4 x 3.6V = 14.4V)
count += 1
Loop

Count = 0
Do while Count <= 5000
HPWM 1, 8, 175     'measured 3.3V by DVM (i.e. 4 x 3.3 = 13.2V)
count += 1
Loop
goto Main

Status
Not open for further replies.

Replies
5
Views
348
Replies
5
Views
4K
Replies
23
Views
6K
Replies
0
Views
3K
Replies
8
Views
6K