FET on the high side
Driving the FET is easy when it’s source pin is connected to 0 volts, not so straightforward in the circuit shown.
It’s conventional for circuits to have a common ground, so making and breaking the connection between solar panel and battery is achieved with the FET connected between the two positive terminals. This means that the FET’s source pin is connected to battery positive, not ground.
This is a problem because our logic circuit (PIC microcontroller) will be toggling it’s PWM output pin between 0 volts and 5 volts. To turn the FET on, it’s gate terminal needs to be raised to at least 10 volts above the source pin, that’s about 24 volts above ground (battery 14 volts, gate/source 10 volts).
Clearly we can’t connect the FET’s gate directly to the PIC’s output. An interface circuit (a level shifter) is required. Driving FETs in this configuration is a common problem. The circuit we require is known as a high-side driver because the FET is on the high side of the load (the battery is the load in our case).
Also, where are we going to get a voltage 24 volts above ground to drive the gate? We’ll have to generate it using a charge pump voltage multiplier.

More Solar Panels on the Toolshed
I’ve added a few more solar panels to my system. All the panels on the toolshed are amorphous types; four 12 watt panels on the top and three 4.8 watt panels at the front. That adds up to 62.4 watts in theory although much less power than this is actually realised. I’ve measured the current reaching the battery on a sunny day at 2.7 amps which equates to 37.8 watts when the battery is at 14 volts.
The shed is effectively empty (there’s just a load of junk inside), the batteries are some distance away on the side of the house. The cables running between the panels and battery are not very substantial (heavy cables are costly), so some power is lost there. Also, these panels generate maximum power at around 17.5 volts across the load. Using a 14 volt battery as the load makes the panels operate well off their maximum power point.
What’s important is that the battery is fully charged at the end of each day so that power is available after dark. That works for most of the year.

Road Sign
Spotted this street sign near to where I work. A couple of observations.
This is far from optimal siting for a wind turbine - it really can’t be generating much power here. Having said that, it was turning, so it must be generating something.
This is a non-critical piece of signage, just advising that the speed limit is 30 (if it detects that you’re going faster than that). It would be of little consequence if it stopped working for a few days (which may well happen during long overcast calm periods. The box behind the sign (which presumably contains the battery) is quite small. I don’t suppose there’s much more than about 20 amp hours of storage here.
I can’t imagine this power source being used on a set of traffic lights without mains backup.
Nevertheless, it’s encouraging that local councils are keen to try the technology.

Batteries
This is where I store power generated by the solar panels. Currently I have two car batteries, neither of which is brand new - in fact I found the smaller one dumped at the side of the road. If you’re thinking these should be deep-cycle batteries, you’re probably right, although I want to use components that readily available. Car batteries are fine as long as they’re not allowed to discharge too deeply.
The little white box (bottom right) is the charge controller - a MorningStar SunGuard-4. This keeps the batteries at a steady 14.1 volts by partially disconnecting the solar panels (using PWM).

Solar Cells
I was wondering whether it would be possible to make solar panels. There are a number of people selling individual solar cells on ebay, and the price seems attractive at around 1 pound a watt. Problem is you don’t get the glass, aluminium frame or the plastic back sheet. You would also need to source the connector block and cabling.
In commercially available panels, it seems the cells are first strung together in a suitable series/parallel arrangement, then encapsulated between layers of EVA (the stuff glue sticks are made of?). On the back is a white plastic layer and on the front glass (special solar glass with a high solar transmissivity). The whole thing is heated in an oven in a vacuum to remove all the air.
Of course the heating and vacuum processes couldn’t really be done at home, but it should be possible to use two sheets of glass with sealant round the edge to keep out moisture. The cells could be kept in place using those little plastic things used to keep tiles apart in the bathroom.
The finished panels could be used in place of the glass in a green house. Batteries could be housed in the greenhouse too.
It does seem feasible.
Not a part of the design that requires a huge amount of thought, but the PIC microcontroller needs a 5 volt supply and we have to work out where it’s going to come from. In theory it would be possible to derive this supply from the solar panel, which would have the advantage that current would only be drawn when there was solar power available and there would be no draw on the battery at all. However, it’s likely there would be all manner of problems associated with the slow rise and fall of solar panel voltage.
There are benefits in deriving power from the battery and no significant downsides as long as the current draw is kept low. One is that the regulator can perform tasks even when there is no power coming from the solar panels. One such task may be indicating battery voltage. A more advanced controller may need to communicate with other devices, control loads and so on.
Having made the decision to derive 5 volts from the battery, the required circuitry is simple - a 5 volt fixed voltage regulator. However, the older varieties (7805) have a rather high quiescent current in the order of a few milliamps, so we need to select one of the newer types which consume only a few tens of microamps internally.
The microcontroller itself can be made to use less power by running the clock at a lower frequency. This leads to the question of what frequency the pulse width modulation should be set to.
The PIC microcontroller has a 10-bit A/D converter on board, so accurately measuring battery voltage should be straightforward enough. However, there are a few issues that need to be considered. Firstly, the A/D converter’s voltage range is 0 volts to 5 volts, whereas the battery can go as high as 15 volts, so a simple potential divider with a 3:1 ratio could be used to connect the two. However, we’re not really interested in battery voltages below 10 volts, so the 5 volt range between 10 volts and 15 volts would map conveniently onto the A/D converter. By spreading the 1,024 bits of A/D resolution over just a third of the battery voltage range, we can achieve 3 times better measurement accuracy.
What’s needed is a level shifter, which can be implemented using a zener diode. The zener drops a constant amount of voltage off the battery voltage, so the A/D converter sees the battery voltage minus the zener voltage. A 10 volt zener would be ideal, but the nearest commonly available component value is 9.1 volts. Actually, this isn’t such a problem since we can use a potential divider to further reduce the voltage and at the same time provide us with a known ratio between battery volts and A/D converter steps (e.g. 16 steps per tenth of a volt).
Zener diodes aren’t very precise components, often having a voltage tolerance of plus or minus 10%. Fixed voltage regulators may be more accurate, but aren’t really suitable because of their high quiescent current consumption (up to 6mA). It may be necessary to select diodes from a larger stock to find accurate examples, or alternatively program a calibration value into each individual regulator.
This program flashes LED D6 on the PICkit1 programmer board using the PWM hardware. The microcontroller’s clock is set to 125kHz to make the pulse frequency low enough to see the LED turning on and off.
;12F683 Flashing LED using PWM
list p=12F683
#include "p12f683.inc"
__CONFIG _INTRC_OSC_NOCLKOUT & _WDT_OFF
org 0x00
init
clrf GPIO ;initialise all outputs
movlw 0x0c
movwf CCP1CON ;select PWM mode (active high)
movlw 0x80
movwf CCPR1L ;set PWM duty cycle to 50%
movlw 0x06
movwf T2CON ;enable timer2 with max prescale
banksel 0x80 ;select upper register bank
movlw 0x10
movwf OSCCON ;set clock to 125kHz
movlw 0xff
movwf PR2 ;set PWM max period
movlw 0x39
movwf TRISIO ;make GP2 and GP1 outputs
banksel 0x00 ;select lower register bank
flash
goto flash
end
This program flashes LED D0 on the PICkit1 programmer board using software delays. Two general purpose registers, del_lo and del_hi form a 16 bit counter (65,536 counts). The delay subroutine is called between each change of state of the LED.
;12F683 Flashing LED using software delay
list p=12F683
#include "p12f683.inc"
__CONFIG _INTRC_OSC_NOCLKOUT & _WDT_OFF
del_lo equ 0x20
del_hi equ 0x21
org 0x00
init
clrf GPIO ;initialise all outputs
banksel 0x80 ;select upper register bank
movlw 0x0f
movwf TRISIO ;make GP4 and GP5 outputs
banksel 0x00 ;select lower register bank
flash
bsf GPIO,4 ;set output GP4 high
call delay ;call the delay subroutine
bcf GPIO,4 ;set output GP4 low
call delay ;call the delay subroutine
goto flash ;go back and do it again
delay
decfsz del_lo,f ;decrement the low order delay register
goto delay ;go back if it hasn't reached zero
decfsz del_hi,f ;decrement the high order delay register
goto delay ;go back if it hasn't reached zero
return ;return to where the subroutine was called
end
-

Microchip PICkit1 Programmer
I’ll be using the Microchip PIC12F683 for this design as it has both an A/D converter and a PWM module. Since I have a couple of PICkit1 programmers available, that’ll be used to prototype the firmware.
The starting point for anyone new to programming microcontrollers is to get an LED to flash on and off. There are several ways to accomplish this. One simple technique is to turn the LED on, then keep the microcontroller busy with a long repetitive task, then turn the LED off then repeat the repetitive task.
It turns out that counting from zero to 255 (the maximum count in an 8 bit register) doesn’t take long enough to result in a pulse rate slow enough for the eye to see. 65,536 (the maximum count in a 16 bit register) is just about right. Here’s the program.
;12F683 PWM Control via ADC
list p=12F683
#include "p12f683.inc"
__CONFIG _INTRC_OSC_NOCLKOUT & _WDT_OFF
org 0x00
init
clrf GPIO ;initialise all outputs
movlw 0x0c
movwf CCP1CON ;select PWM mode (active high)
movlw 0x80
movwf CCPR1L ;set PWM duty cycle to 50%
movlw 0x06
movwf T2CON ;enable timer2 with max prescale
banksel 0x80 ;select upper register bank
movlw 0x11
movwf ANSEL ;set GP0 to analogue. set A/D clock
movlw 0x20
movwf OSCCON ;set clock to 250kHz
movlw 0xff
movwf PR2 ;set PWM max period
movlw 0x39
movwf TRISIO ;make GP2 and GP1 outputs
banksel 0x00 ;select lower register bank
movlw 0x01
movwf ADCON0 ;switch on A/D converter channel 0
bsf ADCON0,1 ;start first A/D conversion
dim
btfsc ADCON0,1 ;check if A/D conversion completed
goto dim
movf ADRESH,w ;get upper 8 bits of conversion value
movwf CCPR1L ;copy it to PWM duty cycle
bsf ADCON0,1 ;start another conversion
goto dim
end