' Solar charger ' Olivier de Broqueville. Version 3.1 Feb.2003 ' Written and compiled using PROTON+ version 2 ' ' Use Watchdog, Low power detection and internal OSC with NO clock out ' ' Exhausted version. Do not use 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' '-------[DEFINE SOME ALIAS'S TO ADC REGISTERS]--------------------------- ' ANSEL register's bits Symbol ANS0 = ANSEL.0 Symbol ANS1 = ANSEL.1 Symbol ANS2 = ANSEL.2 Symbol ANS3 = ANSEL.3 Symbol ADCS0 = ANSEL.4 ' ADC conversion clock select bit Symbol ADCS1 = ANSEL.5 ' ADC conversion clock select bit Symbol ADCS2 = ANSEL.6 ' ADC conversion clock select bit ' ADCON0 register's bits Symbol ADFM = ADCON0.7 Symbol VCFG = ADCON0.6 Symbol CHS1 = ADCON0.3 ' ADC channel select bit Symbol CHS0 = ADCON0.2 ' ADC channel select bit Symbol GO_DONE = ADCON0.1 ' ADC Conversion status/ plus enable conversion-bit Symbol ADON = ADCON0.0 ' ADC Enable bit: 1 = enabled, 0 = disabled. '-------[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 Goto Initialisation ' Jump over the subroutines '-------[SUBROUTINE REPLACING ADIN (NOT WORKING FOR 12F675 IN PBP1.24j)]- GET_ADC: ADON = 1 ' Enable the ADC Delayus 100 ' Wait for sample/hold capacitors to charge GO_DONE = 1 ' Start conversion While GO_DONE = 1 : Wend ' Poll the GO_DONE flag for completion of conversion ADON = 0 ' Disable the ADC, to save power Return '-------[INITIALISATION OF GPIO,AD CONVERTERS, ETC.]---------------------- Initialisation: FL_BAS=0 TRISIO = %11111111 ' All pins set for input ADCS0 = 1 ' \ ADCS1 = 1 ' Setup ADC's clock for FRC ADCS2 = 0 ' / VCFG = 0 ' VREF is set to VDD of PICmicro ADFM = 1 ' Right justify the ADC result ANS0 = 1 ' Set AN0 (GPIO.0) as Analogue input (Overload limit) ANS1 = 1 ' Set AN1 (GPIO.1) as Analogue input (LowBatt limit) ANS2 = 1 ' Set AN2 (GPIO.2) as Analogue input (Monitoring) ANS3 = 0 ' Set AN3 (GPIO.3) as Digital input (Not used here) '-------[MAIN PROGRAM. LOOP FOREVER]--------------------------------------- Principal: While 1 = 1 ' Create an infinite loop Acquisition: CHS0=0 ' Choose A/D 0 (GPIO.0) CHS1=0 Gosub GET_ADC ' Perform ADC conversion of Overload reference Surcharge = AD_RESULT CHS0=1 ' Choose A/D 1 (GPIO.1) CHS1=0 Gosub GET_ADC ' Perform ADC conversion of Lowbatt reference Decharge = AD_RESULT CHS0=0 ' Choose A/D 2 (GPIO.2) CHS1=1 Gosub GET_ADC ' Perform ADC conversion of monitored voltage Tension = AD_RESULT Exploitation: 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) SNOOZE 6 ' Wait for half a second Wend ' Do another control cycle '-------------------------------------------------------------------------- END