I also have an 80mm fan cooling the heatsink, but i took the lazy route; the fan are connected to the fet output, so it varies according to the load.
Here's my complete current code.:
Start:
setfreq m4
SYMBOL Volt = w0
SYMBOL Mode = b15
Symbol Temp = w1
Symbol TempLow = b16
Symbol TempComp = b17
Symbol PrevTemp = b18
Symbol Counter = b19
Symbol CompTempBoost = w2
Symbol CompTempMaint = w3
Symbol Duty = w4
Symbol BulkDone = b20
Symbol Elapsed = w5
Symbol ManualOverride = b21
Duty = 0 'Set initial Maintenance duty cycle to 0%.
Mode = 0 'Set initial Mode to off/Battery Ok.
BulkDone = 0
Elapsed = 0
ManualOverride = 0
ReadTemp 4, TempLow
PrevTemp = 120 'Set PrevTemp to very high to force a tempcomp
'pin1 = Volt
'pin2 = Output (MosFet)
'pin3 = Manual On/Dumpload off
'pin4 = Temperature
Main:
ReadADC10 1,Volt
If TempLow <> PrevTemp Then 'A weakness here; if Templow are 0C at startup,
GoSub SetTempComp 'variables will not be set...
EndIf
If Time = 5 Then
SerTXD("V:", #volt, " D:", #duty, " M:", #Mode, " TL:", #TempLow, 13, 10)
Time = 6
EndIf
If Time = 10 Then
ReadTemp 4, TempLow
SerTXD("V:", #volt, " D:", #duty, " M:", #Mode, " TL:", #TempLow, 13, 10)
If BulkDone = 0 AND Mode = 1 Then
Let Elapsed = Elapsed + Time
EndIf
Let Time = 0
EndIf
If Pin3 = 1 AND ManualOverride = 0 Then
BulkDone = 1
ManualOverride = 1
Pause 500 'Pause here to avoid on/off in one go.
Goto Main
ElseIf Pin3 = 1 AND ManualOverride = 1 Then
BulkDone = 0
ManualOverride = 0
GoSub DumpOff
EndIf
If Mode = 1 AND BulkDone = 0 Then
If Elapsed >= 3600 Then '1 Hour
BulkDone = 1
Let Elapsed = 0
EndIf
EndIf
If Volt <= 540 AND BulkDone = 1 Then
BulkDone = 0
ManualOverride = 0
EndIf
If BulkDone = 0 Then
If Volt >= CompTempBoost AND Mode = 0 Then
GoSub BoostDump
EndIf
ElseIf BulkDone = 1 AND Mode <> 2 Then
If Volt >= CompTempMaint AND Mode = 0 Then
GoSub MaintDump
ElseIf Mode = 1 Then
GoSub MaintDump
EndIf
EndIf
If Volt <= 563 AND Mode > 0 AND Duty <= 202 Then ' 13,20V
GoSub DumpOff
EndIf
If Volt > CompTempMaint AND Mode = 2 AND Duty < 1015 Then
Gosub PwmUp
EndIf
If Volt < CompTempMaint AND Mode = 2 AND Duty > 202 Then
GoSub PwmDown
EndIf
If Volt > CompTempBoost AND Mode = 1 AND Duty < 1015 Then
Gosub PwmUp
EndIf
If Volt < CompTempBoost AND Mode = 1 AND Duty > 202 Then
GoSub PwmDown
EndIf
Goto Main
SetTempComp: 'Find TempComp Voltage
If TempLow >= 25 And TempLow <= 29 Then '0,0V comp @ 25-29c
TempComp = 0 '14,4V, 13,2V
EndIf
If TempLow >= 20 And TempLow <= 24 Then '0,15V comp @ 19-24c
TempComp = 6 '14,55V, 13,35V
EndIf
If TempLow >= 15 And TempLow <= 19 Then '0,30V comp @ 15-19c
TempComp = 12 '14,7V, 13,5V
EndIf
If TempLow >= 10 And TempLow <= 14 Then '0,45V comp @ 10-14c
TempComp = 19 '14,85V, 13,65V
EndIf
If TempLow >= 5 And TempLow <= 9 Then '0,60V comp @ 5-9c
TempComp = 25 '15,0V, 13,8V
EndIf
If TempLow >= 0 And TempLow <= 4 Then '0,75V comp @ 0-4c
TempComp = 31 '15,15V, 13,95V
EndIf
If TempLow >= 129 And TempLow <= 134 Then '0,90V comp @ -5--1c
TempComp = 38 '15,3V, 14,1V
EndIf
If TempLow >= 135 And TempLow <= 140 Then '1,05V comp @ -10--5c
TempComp = 44 '15,45V, 14,25V
EndIf
PrevTemp = TempLow
CompTempBoost = 616 + TempComp '14,4V baseline.
CompTempMaint = 581 + TempComp '13,6V baseline.
Return
PwmUp:
Duty = Duty + 1 Max 1015
PwmDuty 2, duty
Return
PwmDown:
Duty = Duty - 1 Min 202
PwmDuty 2, duty
Return
MaintDump:
If Mode <> 1 Then
pwmout 2, 255, 202
Duty = 202
EndIf
Mode = 2
Return
BoostDump:
pwmout 2, 255, 202
Mode = 1
Duty = 202
Let Elapsed = 0
Return
DumpOff:
pwmout 2, Off
Mode = 0
Duty = 0
Return
The code - as is, are not suitable for a windgen because it's not fast enough; i use it with solar.
The reason it's not fast now, are that i run it at 4MHz, and the ReadTemp command uses up to 750mS to execute (to communicate to the Dallas 18b20 temp sensor). In addition, the SerTxd command also uses some time, even when limited to every 5 sec. (ReadTemp are executed every 10sec.)
The function of the code are as follows:
If Voltage are below 12.7V the output are off, and a flag for bulk charge are set.
As long as the voltage are under 14.4V +/- temperature compensation, the code keeps the voltage at 14.4V for an hour before switching to maintenance mode at 13.6V.
If the voltage drops below 13.2V, it turns off the dumpload, and turns it on again at 13.6V.
It sends a log line every 5 sec., and reads the temp every 10 sec.
It checks pin 3 for manual override, forcing bulk charge on or forcing it into maintenance charge.
I'm sure the code can be optimalized, so everyone; feel free to comment...
Edit:
The voltages are temperature compensated in 5 deg. celsius step. (0.15V/5deg. for 12V battery.)