Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
' Solar charger
' Olivier de Broqueville. Version 3.3 Feb.2003
' Written and compiled using PROTON+ version 2.00
'
' Use Watchdog, Low power detection and internal OSC with NO clock out
'
' Use of ADIN
Device = 12f675
REMARKS ON
CONFIG WDT_ON ,INTRC_OSC_NOCLKOUT,PWRTE_ON, BODEN_ON,MCLRE_OFF
DECLARE WATCHDOG ON
XTAL = 4
'-------[DEFINE PIN SYMBOLS]---------------------------------------------
Symbol Panneau = GPIO.5 'Trigger for the MOSFET controling the Solar Pannel
Symbol Charge = GPIO.4 'Trigger for the MOSFET controling the 'Load'
Symbol Test = GPIO.3 'Test pin: If enabled, enter adjustement procedure
'-------[ASSIGN VARIABLEs]-----------------------------------------------
Dim AD_RESULT as ADRESL.WORD ' Convert the ADRESL register into a WORD variable
DIM Surcharge as WORD ' Overload value at which the solar pannel is desactivated
DIM Decharge as WORD ' LowBat value at which the 'load' is desactivated
DIM Tension as WORD ' Actual voltage level we monitor
DIM FL_BAS as BYTE ' Flag used to introduce an hysteresis in 'load' switching
'-------[ START SERIOUS THINGS...]---------------------------------------
Delayms 500 ' Wait for the PICmicro to stabilise
'-------[INITIALISATION OF GPIO,AD CONVERTERS, ETC.]----------------------
Initialisation:
FL_BAS=0
TRISIO = %11111111 ' All pins set for input
ANSEL=%00110111 ' Set AN0-AN1-AN2 as analogue input / AN3 as digital input and ADC"s clock for FRC
ADCON0=%10000000 ' Set Right justification of ADC result and VREF to VDD
'-------[MAIN PROGRAM. LOOP FOREVER]---------------------------------------
Principal:
While 1 = 1 ' Create an infinite loop
Acquisition:
Surcharge=ADIN 0 ' Perform ADC conversion of Overload reference
Surcharge = AD_RESULT
Decharge=ADIN 1 ' Perform ADC conversion of Lowbatt reference
Decharge = AD_RESULT
Tension=ADIN 2 ' Perform ADC conversion of monitored voltage
Tension = AD_RESULT
If TEST=0 THEN
' Are we in normal condition (TEST not activated)
' If YES, then control the Panel and the load with delays, histeresis
If Tension > Surcharge THEN ' Are we in overload condition (+- 14 volts)?
LOW Panneau ' Yes: Disconnect solar pannel
ELSE
HIGH Panneau ' No: Connect solar pannel
ENDIF
IF FL_BAS=0 then ' Was the load already connected? (Hysteresis)
IF Tension > Decharge THEN ' Yes. Then is the battery voltage above minimum?
HIGH Charge ' Yes: Connect the 'Load'
ELSE
LOW CHARGE ' No: Disconnect the 'Load'
FL_BAS=1 ' And prepare for hysteresis
ENDIF
ELSE
IF Tension> (Decharge+40) THEN '"Histeresis" active: are we above the limit (1volt)
HIGH Charge ' YES: Let's connect the 'Load'
FL_BAS=0 ' and clear the flag
ELSE
LOW Charge ' NO: Stay disconnected
ENDIF
ENDIF
IF Tension > (Surcharge+40) THEN
LOW Charge ' By the way, are we not overloading the 'Load'?(Above Overload limit + 1volt)
ENDIF
SNOOZE 6 ' Wait for half a second
' If NO then skip all delays to facilitate adjustements
ELSE
If Tension > Surcharge THEN ' Are we in overload condition (+- 14 volts)?
LOW Panneau ' Yes: Disconnect solar pannel
ELSE
HIGH Panneau ' No: Connect solar pannel
ENDIF
IF Tension > Decharge THEN ' Is the battery voltage above minimum?
HIGH Charge ' Yes: Connect the 'Load'
ELSE
LOW CHARGE ' No: Disconnect the 'Load'
ENDIF
IF Tension > (Surcharge+40) THEN
LOW Charge ' By the way, are we not overloading the 'Load'?(Above Overload limit + 1volt)
ENDIF '
ENDIF
Wend ' Do another control cycle
'--------------------------------------------------------------------------
END