'***************************************************************
'**  BIOLUME_PLAN.TTB - Data Aq. program used for August 2002 ** 
'**                     Biolume Missions                      **  
'**                                                           **  
'**  LISST Particle Size Analyzer Data Aquisition Code        **
'**   Sequoia Scientific, Inc.                                **  
'**   SW_START Version 1.00      Last Revision : May 1999     **
'**    Written by : H. C. Pottsmith                           **
'**                                                           **  
'**   Updated and renamed as CTD_PLAN July 2002               **  
'**    Run data acquisition loop at 4Hz                       ** 
'**    Updates commented with BIOLUME                         **  
'***************************************************************
'**  Notes:
'**          Analog Channel        Use                  Notes
'**                0           Mux 1 Output
'**                1           Mux 2 Output
'**                2           Transmission Sensor
'**                3           Battery Voltage        Aprox. 200 counts/volt
'**                4           Aux Input 1
'**                5           Laser power sensor
'**                6           Depth Sensor        Aprox  18.7 counts/meter
'**                7           Thermistor
'**
'**           Digital Channel        Use                  Notes
'**                0,1,2,3        Mux Channel Address
'**                  10           Main Power           PSET 10 turns on power
'**                  12,13        Aux Digital Channels 1, and 2
'**
'**     variables
'**             D               Datafile counter
'**             I,J             General loop counters
'**
'**       Note: for 512kb systems change line after the NEW command 
'****************************************************************
NEW
REM ASM &H9A, DW 16, 0 : REM  SET MEMORY TO 512kB 
ASM &H9A, DW 32, 0 : REM  SET MEMORY TO 2mB


 5 D=0 : F=0

'** LISST 100 Particle Size Analyzer Data Aquisition Code
'** SW_START Version 1.10   June 1999
'** BIOLUME_PLAN Updated code July 2002 for Biolume Cruise

30 PRINT
31 PRINT "*********************************
35 PRINT "*  LISST DATA ACQUISITION CODE  *"
40 PRINT "*     MBARI Biolume Cruise      *"
41 PRINT "*         August 2002           *"
45 PRINT "*********************************
50 PRINT
60 RTIME         : REM load ? array with current date and time

200 REM wait for switch before taking data
210 IF PIN(5)=1 GOTO 1000
220 PRINT " Waiting for ON switch signal"
230 SLEEP 100
240 GOTO 210

1000 REM  Initialization Section
1020 PSET 10,7           :REM turn on main power
1021 PSET 12             :REM turn off water pump - using Aux1 input (digital channel 12)

1030 PRINT "POWERING UP...."
1040 SLEEP 0 : SLEEP 20 : REM sleep 0.2 seconds
1050 A=CHAN(3)/16/2+20 
1055 IF A<1500 F=1   : REM set flag if battery is low  
1056 IF F=1 PRINT 'Low Battery Voltage: ', A/100,'.',A%100 

'**
'** BIOLUME update - Main menu
'**
1060 INPUT "   WHAT DO YOU WISH TO DO (0=STOP, 1=COLLECT DATA NOW, 2=SET TIME) > "I
1061 IF I=0 STOP      : REM user chose to stop 
1062 IF I=1 GOTO 1170 : REM skip time setting and start collecting
1063 IF I=2 GOTO 1070 : REM Set time
1064 GOTO 1060        : REM Invalid entry

1070 REM ** Get the MVC Date/Time from the driver
1071 INPUT "YYYY> "I
1072 IF I<1980 I=1980
1073 IF I<2000 ?(5)=I-1900
1074 IF I>1999 ?(5)=I-2000
1075 INPUT "MM> "I
1076 IF I<1 I=1
1077 IF I>12 I=12
1078 ?(4)=I
1079 INPUT "DD> "I
1080 IF I<1 I=1
1081 IF I>31 I=30
1082 ?(3)=I
1083 INPUT "HH> "I
1084 IF I<0 I=0
1085 IF I>23 I=23
1086 ?(2)=I
1087 INPUT "MIN> "I
1088 IF I<0 I=0
1089 IF I>59 I=59
1090 ?(1)=I
1091 INPUT "SS> "I
1092 IF I<0 I=0
1093 IF I>59 I=59
1094 ?(0)=I
1095 STIME         : REM set real time clock with values in ? array
1096 GOTO 1060     : Go back to menu

'***********************************
'**  Main Control Loop (4Hz)
'**
'**    while (true) {
'**      Get data;
'**      Write data out serial port;
'**      If (power switch is off)
'**        break;
'**    }
'**    shutdown;
'***********************************

1170 REM take data
1171 REM Start Pump and Data Aquisition
1172 PCLR 12        : REM Turn on pump switch
1180 SLEEP 0                    : REM  reset timer 
1210 SLEEP 25                   : REM 4 Hz data
1220 GOSUB 10000 : REM take data 

1240 REM **
1241 REM ** BIOLUME update - write data record out to serial port (2 long prints faster than loop)
1242 REM **
1245 PRINT #6,@(1),#6,@(2),#6,@(3),#6,@(4),#6,@(5),#6,@(6),#6,@(7),#6,@(8),#6,@(9),#6,@(10),#6,@(11),#6,@(12),#6,@(13),#6,@(14),#6,@(15),#6,@(16),#6,@(17),#6,@(18),#6,@(19),#6,@(20);
1246 PRINT #6,@(21),#6,@(22),#6,@(23),#6,@(24),#6,@(25),#6,@(26),#6,@(27),#6,@(28),#6,@(29),#6,@(30),#6,@(31),#6,@(32),#6,@(33),#6,@(34),#6,@(35),#6,@(36),#6,@(37),#6,@(38),#6,@(39),#6,@(40)

1270 IF PIN(5)=0 GOTO 1300      : REM check switch status
1280 GOTO 1210


1300 PRINT "PROFILE COMPLETED:  SHUTTING DOWN MAIN POWER"
1310 PCLR 10 : PRINT " Power is off"
1320 PSET 12 : PRINT " Pump is off"
1399 GOTO 210     : REM return to pressure testing section

'-----------------------------------------------------------------
9000 REM     Battery testing subroutine   May 1997
9010 REM     Assumes that Main Power (PSET 10) is on
9020 REM     Modifies value of A and I
9030 I=1
9100 A=CHAN(3)/16/2+20 : REM read battery voltage and convert to volts
9110 PRINT 'Battery Voltage is ', A/100,'.',A%100
9120 IF A<1500 PRINT "*** WARNING BATTERY VOLTAGE IS BELOW RECOMMENDED LEVELS ***"      
9121 REM **
9122 REM ** BIOLUME update - do not ask to continue (REM next 2 lines)
9123 REM **
9124 REM 9130 IF A<1500 INPUT "     DO YOU WISH TO CONTINUE?  (1=YES, 0=NO)  "I
9125 REM 9140 IF I=0 PCLR 7,10: STOP : REM user chose to stop after low battery warning
9199 RETURN

10000 REM**************************************************************************
10001 REM Main Data Aquistion Routine for LISST 100    June 1999 Single scan
10005 REM    Assumes main power is on,  D is data file pointer
10010 REM      uses @ array from @(1) to @(40)
10050  PSET 6 : REM turn on LED on endcap
10095 @(33)=CHAN(2)/16,@(36)=CHAN(5)/16 :REM store laser pwr and ref
10100 PSET 1 : PCLR 0,2,3    : REM 0100
10110 @(1) = CHAN(0)/16 : @(31)=CHAN(1)/16
10120 PSET 0   : REM 1100
10130 @(2) = CHAN(0)/16 : @(32)=CHAN(1)/16
10140 PCLR 0,1   : REM 0000
10150 @(3) = CHAN(0)/16 : @(29)=CHAN(1)/16
10160 PSET 0   : REM 1000
10170 @(4) = CHAN(0)/16 : @(30)=CHAN(1)/16
10180 PCLR 0 : PSET 1,2   : REM 0110
10190 @(5) = CHAN(0)/16 : @(27)=CHAN(1)/16
10200 PSET 0   : REM 1110
10210 @(6) = CHAN(0)/16 : @(28)=CHAN(1)/16
10220 PCLR 0,1   : REM 0010
10230 @(7) = CHAN(0)/16 : @(25)=CHAN(1)/16
10240 PSET 0   : REM 1010
10250 @(8) = CHAN(0)/16 : @(26)=CHAN(1)/16
10260 PSET 1,3 : PCLR 0,2   : REM 0101
10270 @(9) = CHAN(0)/16 : @(23)=CHAN(1)/16
10280 PSET 0   : REM 1101
10290 @(10) = CHAN(0)/16 : @(24)=CHAN(1)/16
10300 PCLR 0,1   : REM 0001
10310 @(11) = CHAN(0)/16 : @(21)=CHAN(1)/16
10320 PSET 0   : REM 1001
10330 @(12) = CHAN(0)/16 : @(22)=CHAN(1)/16
10340 PSET 1,2 : PCLR 0   : REM 0111
10350 @(13) = CHAN(0)/16 : @(19)=CHAN(1)/16
10360 PSET 0   : REM 1111
10370 @(14) = CHAN(0)/16 : @(20)=CHAN(1)/16
10380 PCLR 0,1   : REM 0011
10390 @(15) = CHAN(0)/16 : @(17)=CHAN(1)/16
10400 PSET 0   : REM 1011
10410 @(16) = CHAN(0)/16 : @(18)=CHAN(1)/16
10500 REM Store Battery voltage,Laser power ref, Pressure, Temp
10510 @(34)=CHAN(3)/16,@(35)=CHAN(4)/16
10520 @(37)=CHAN(6)/16,@(38)=TEMP(CHAN(7))
10530 RTIME  : REM read and store time to data file

10535 REM User selectable time stamp options. Modify by moving REM from begining of line
REM 10540 @(39)=?(1) : @(40)=?(0)  : REM store minutes and seconds
REM 10540 @(39)=?(2) : @(40)=?(1)  : REM store hour and minutes
REM 10540 @(39)=?(3) : @(40)=?(2)  : REM store day and hour
10540 @(39)=?(3)*100+?(2) : @(40)=?(1)*100+?(0)  : REM store Day*100+hour and minutes*100+seconds

10550 PCLR 0,1,2,3
10800 FOR J=1 TO 40
10810  STORE D,#2,@(J)
10820 NEXT J
10900 PCLR 6 : REM turn off led on endcap
10999 RETURN    : REM return to call section of code

