beautypg.com

Campbell Scientific PS200/CH200 12 V Charging Regulators User Manual

Page 87

background image

Appendix A. Advanced Programming Techniques

If TestBatt = Off AND (ManualTest = On OR XDays <= DayCntr) Then
ManualTest=Off

TestBatt = On
DayCntr = 0
Timer (1,Hr,0)

EndIf

'Battery test command will be sent every 30 seconds. Must send it

'at least every 90 seconds or the PS/CH200 will automatically reset!
If TestBatt=On AND ElapsedHrs <= TestLengthHrs AND VBatt >= 11.7 Then
'Call WAKEUP to wake up the PS/CH200.

Call WAKEUP
'Send out the PS/CH200 command followed by a carriage return.

SerialOut (COMPRT,BATTEST_CMD,"",1,3)
SerialOut (COMPRT,CR,"",1,3)
'Bring in the result from either command and process it.

'Discard characters in the receiver buffer up to and including asterisks "*"
SerialIn (xmit_str,COMPRT,50,"*",40)
'Capture the PS/CH200 response string after the asterisks and including the

'string terminator hexadecimal zero (&H00).
SerialIn (CH200string,COMPRT,50,&H00,140)
'Return strings are different for both instructions. Have to process them

'different as well.
OK_Loc = InStr(1,xmit_str,"O",2)
ReturnStr = Mid (xmit_str,OK_Loc,2)

Else
'When the test is over reset the timer and turn of the TestBatt flag.

Timer (1,Hr,3)
TestBatt = Off
EndIf


'Get the PS/CH200 status information.
'Call WAKEUP to wake up the PS/CH200.

Call WAKEUP
'Send "read status" command to PS200 followed by a carriage return.
SerialOut (COMPRT,CH200STATS_CMD,"",1,3)

SerialOut (COMPRT,CR,"",1,3)
'Discard characters in the receiver buffer up to and including asterisks "*"
SerialIn (xmit_str,COMPRT,50,"*",40)

'Capture the PS/CH200 response string after the asterisks and including the
'string terminator hexadecimal zero (&H00).

SerialIn (CH200string,COMPRT,50,&H00,140)
Check_sum = CheckSum (CH200string,5,0 )
'For the string to be correct the check sum must be zero.

If Check_sum = 0 Then
'Split up the main string from PS/CH200 into separate components.
SplitStr (CH200_M0(),CH200string,COMMA,9,4)

'Sort out the components to specific variables.
VBatt = CH200_M0(1)
IBatt = CH200_M0(2)

ILoad = CH200_M0(3)
V_in_chg = CH200_M0(4)

I_in_chg = CH200_M0(5)
Chg_TmpC = CH200_M0(6)
ChargeState = CH200_M0(7)

ChargeSource = CH200_M0(8)
Ck_Batt = CH200_M0(9)
'Values for check battery start with zero. Have to shift the value

'by one to line it up with the correct words in the array.
CheckBattery = CheckBatteryArr(Ck_Batt + 1)
EndIf


'Get the PS/CH200 extended status information.
'Call WAKEUP to wake up the PS/CH200.

Call WAKEUP
'Send "read extended status" command to PS/CH200 followed by a carriage return.

SerialOut (COMPRT,EXTSTATS_CMD,"",1,3)
SerialOut (COMPRT,CR,"",1,3)

A-25