'CR800/850 and CR1000 (run with CR800 wiring) Campbell Dataloggers 'TTS turbidity testing program 'Turbidity sensor read every 60 sec. 'See the TTS wiring table for wiring information 'SDI-12 sensors onnected to port 1 (C1), address 0 'OBS-3 or OBS-3+ (1X or 4X) connected to differential channel DIFF2, or 'OBS-3 turbidity sensor connected to SE3 , power to SW12 or 'Analite NEP395 connected to port 1 (C1) 'YOU MUST SET THE VARIABLES IN SUBROUNTINE Initialie BEFORE STARTING THE PROGRAM, THEN ' SAVE & COMPILE THE PROGRAM, THEN SEND THE PROGRAM TO THE DATA LOGGER 'Any of the variables in subroutine Initialize can be reset on the fly from the Numeric window 'Water temperature (waterTemp) is set to 991 if not activated or OBS-3 connected 'Output: median turbidity "medianTurb" and SDI-12 sensor water temperature "waterTemp" 'Paste the variable names with (Paste) after the declaration from the Add window into the Numeric window 'Date: 04/27/2007 'Program authors: R. Eads, RiverMetrics LLC, J. Lewis Redwood Sciences Lab '\\\\\\\\\\\\\\\\\\\\\\\\\ DECLARATIONS ///////////////////////// PreserveVariables 'Variables are listed in alphabetic order Public dtsArray(7) Public dtsTemp public i Public inArrayBounds as boolean Public index Public insert as boolean Public interval Public j Public k Public medianMv Public medianTurb '(Paste) Public midpoint Public mv(60) Public n Public nepArray(3) Public nepTemp Public nepWipeCode Public nextIndex Public rawMv Public turbC0 '(Paste) Public turbC1 '(Paste) Public turbC2 '(Paste) Public turbDevice '(Paste) Public waterTemp '(Paste) Public waterTempDevice '(Paste) public wipeStage '(Paste) Public stage '(Paste) '\\\\\\\\\\\\\\\\\\\\\\\\ OUTPUT SECTION //////////////////////// DataTable(OutTable,1,-1) Sample(1, medianTurb, FP2) Sample(1, waterTemp, FP2) EndTable '\\\\\\\\\\\\\\\\\\\\\\\\\ SUBROUTINES ////////////////////////// Sub Initialize stage = 0.3 '<======== Enter fake stage (SDI-12 sensors) stage = 0.2 '<======== Enter fake wipeStage (SDI-12 sensors) turbC0 = 0 '<======== Enter turbidity offset (intercept) turbC1 = 0.8 '<======== Enter coefficient of x (multiplier) for OBS-3 or OBS-3+, ' for linear equation c1 = 0.8, enter value for poly. turbC2 = 0 '<======== Enter coefficient of x^2 for OBS-3 or OBS-3+, ' for linear equation c2 = 0, enter value for poly. turbDevice = 1 '<======== Select turbidity sensor & (type of connection): ' 1 = DTS-12 (SDI-12) ' 2 = OBS-3 or OBS-3+ (differential connection DIFF2), 3+ wired 1X or 4X ' 3 = OBS-3 ' 4 = Analite NEP 395 (SDI-12) waterTempDevice = 2 '<======== Select water temperature device, requires uncommenting Output statement if selected ' 0 = None ' 1 = Campbell temperature sensor 107 ' 2 = DTS-12's on-board temperature sensor ' 3 = NEP395's on-board temperature sensor EndSub Sub SortTurbidity 'Sorts turbidity mV values into ascending order (OBS-3) k = k + 1 j = k insert = False 'Loop for inserting new values Do While (j<>1 And insert = False) If (rawMv >= mv(j-1)) Then insert = True 'will get us out of loop Else mv(j) = mv(j-1) j = j - 1 EndIf Loop 'Insert (rawMv) intoto array mv(j) = rawMv EndSub Sub ExtractMedian 'Find median turbidity (millivolts) -- OBS-3 'If k is odd If (k MOD 2 <> 0) Then k = k + 1 'Divide k in half to find the location for the median value 'Add .5 and truncate to round correctly in case of floating point error midpoint = INT(0.5*k + 0.5) 'Save middle value as median medianMv = mv(midpoint) 'Else [k is even] Else 'Take the average of the 2 middle values midpoint = INT(0.5*k + 0.5) medianMv = 0.5 * (mv(midpoint) + mv(midpoint+1)) EndIf EndSub Sub ReadTurbidity 'If DTS-12 selected If (turbDevice = 1) Then 'If measuring DTS-12 water temperature If (waterTempDevice = 2) Then 'Get water temp, mean turbidity and variance from SDI address 0 SDI12Recorder(dtsArray, 1, "0", "M!", 1, 0) dtsTemp = dtsArray(1) 'If invalid temperature, set to error code 991 If (dtsTemp < -100) Then waterTemp = 991 Else waterTemp = dtsTemp EndIf EndIf 'If submerged and above freezing, wipe before measuring 'Store mean, variance, median, BES, min, max, and temperature If (stage >= wipeStage And waterTemp >= 0.5) Then SDI12Recorder(dtsArray, 1, "0", "M2!", 1, 0) Else 'just measure SDI12Recorder(dtsArray, 1, "0", "M1!", 1, 0) EndIf 'Add turbidity offset to 3rd value collected (median) medianTurb = dtsArray(3) + turbC0 'If OBS-3 or OBS-3+ differential connection DIFF2, 1X (0-2000)or 4X (0-4000) ElseIf (turbDevice = 2) Then k = 0 'Switch 12V power on PortSet (9 ,1 ) 'Wait 3 seconds for sensor warm-up Delay(0,3,sec) 'Loop to read 60 turbidity values (mV) For i = 1 to 60 'Read differential voltage on DIFF2 VoltDiff (rawMv,1,mV2500,2,True,0,_60Hz,1.0,0) 'Delay each reading so 60 measurements takes 30 sec Delay(1,460,mSec) 'Insert rawMv at proper location in sorted mv array SortTurbidity Next i 'Switch 12V power off PortSet (9 ,0) 'Extract the median mV value from the sorted array ExtractMedian 'Convert millivolts to NTUs (both linear & polynomial) medianTurb = turbC0 + turbC1*medianMv + turbC2*medianMv^2 'If OBS-3 single-ended connection (SE3) ElseIf (turbDevice = 3) Then k = 0 'Switch 12V power on PortSet (9 ,1 ) 'Wait 3 seconds for sensor warm-up Delay(0,3,sec) 'Loop to read 60 turbidity values (mV) For i = 1 to 60 'Assigns OBS-3 (mV) on channel 3 to rawMv VoltSe (rawMv,1,mV2500,3,0,0,_60Hz,1.0,0) 'Delay each reading so loop takes 30 sec Delay(1,460,mSec) 'Insert rawMv at proper location in sorted mv array SortTurbidity Next i 'Switch 12V power off PortSet (9 ,0) 'Extract the median mV value from the sorted array ExtractMedian 'Convert millivolts to turbidity units (both linear & polynomial) medianTurb = turbC0 + turbC1*medianMv + turbC2*medianMv^2 Else 'device must be NEP395 by default 'If measuring NEP395 water temperature If (waterTempDevice = 3) Then 'Get water temp from SDI address 0; M7 returns a single value SDI12Recorder(nepTemp, 1, "0", "M7!", 1, 0) 'If invalid temperature, set to error code 991 If (nepTemp < -100) Then waterTemp = 991 Else waterTemp = nepTemp EndIf EndIf 'If submerged and above freezing, wipe NEP395 optics 'Status code is stored in nepWipeCode variable If (stage >= wipeStage And waterTemp >= 0.5) Then SDI12Recorder(nepWipeCode, 1, "0", "M8!", 1, 0) EndIf 'Measure median, min, and max turbidity with NEP395 SDI12Recorder(nepArray, 1, "0", "M2!", 1, 0) 'Add turbidity offset to 1st value collected (median) medianTurb = nepArray(1) + turbC0 EndIf EndSub '\\\\\\\\\\\\\\\\\\\\\\\\\\\ MAIN PROGRAM //////////////////////////// BeginProg SequentialMode Initialize Scan(60,Sec, 3, 0) ReadTurbidity CallTable OutTable NextScan EndProg '\\\\\\\\\\\\\\\\\\\\\\\\\\\ END MAIN PROGRAM ////////////////////////////