Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Programming issues CR1000


hopesci Aug 13, 2013 03:47 PM

Good afternoon, I am very new to programming and am having issues with data we are collecting not being reliable or consistently accurate.
Some background, I am a student and my group is monitoring water quality samples, and have received the some of the sensors and the program 2nd hand. However the specific sensor calibration numbers have been changed to match the specific sensor. We currently have a CR1000, an automatic water sampler, a acculevel Keller America Pressure transducer, turbidity sensor (OBS3+), and a Geo-tivity velocity sensor. Each of the sensors have been individually tested for general soundness and accuracy, and give reliable results when tested individually in the lab. However, when all are configured together out in the field we are getting data that is not consistent. The wiring is as it should be, and the only conclusion left is the programing. An example of the program is below.. if anyone would pick apart programming commands or find irregularities or any advice you would be willing to share, I would appreciate it. Thank you...

'CR1000 Series Datalogger

'Wiring
'Geotivity Flow Meter
'Red = SW Battery
'Bare = G (next to SW Battery)
'Black = G (next to SW Battery)
'White = SE4
'Green = Earth Ground
'Keller Acculevel Pt
'Red = SE6
'White = Earth Ground
'Black = Battery +
'Bare = G
'Yellow = not used
'Blue = not used
'Turbidity Sensor
'Red = SW Battery
'White = DIFF 1H
'Green = DIFF 1L
'Black = G
'Bare = Earth Ground
'Sampler
'-----Sampler Control Cable-----
'Patch Panel to CR1000 Sample Control Cable
'White = C1 (Blue)
'Orange = C2 (Orange)
'Green = C3 (Green)
'-----Sampler Power Cable-------
'Red (fuse) = Battery +
'Black = Battery -
'Precipitation (Not Installed)
'Green = Ground
'White = P1


Public batt_volt
Public depth, testdepth, tdepth, readdepth, tread, treadV
Public turbidityH, turbidityL, tturbH, tturbL, turbreadH, turbreadL
Public velocity, vread,tvel
Public rain_in
Public pulse
Public flow
Public load
Public loadrate
Public sampleflow
Public flowrate
Public counter
Public PTemp, veg1, veg2
Public veg1Volts, veg1WaterCon, veg2Volts, veg2WaterCon
Public radius = 20.32
Public TriggerDepth = 3 'Trigger depth in cm
Public samplecriteria = 100 'Volume to measure before sending sampler pulse to collect sample
Public depthslope = 0.0506 'converts milivolts to cm
Public caldepthoffset = 0.5177 ' depth calibration value
Public verticaloffset = 0.5' height above bottom of pipe
Public depthoffset
'Public turbslope = 3.2 'milivolt to concentration, based on DCDC values 3.2 ppm per milivolt
'Public turboffset = 0
Public velslope = 0.8898 'milivolt to volt for 1 m/s
Public veloffset = 0.0561 'adjust to set zero in still water
Public sampnum = 100 ' number of readings to average
Public Event1
Public Event2
Dim area, beta, i, go, gotwo
Units velocity = M/sec
Units turbidityH = Volts
Units turbidityL = Volts
Units rain_in = inches
Units flow = M^3
Units flowrate = M^3/sec


'Define Data Tables
DataTable (rain,rain_in <> 0,10000)
Sample (1,rain_in,FP2)
EndTable

DataTable (daily,1,-1)
DataInterval (0,6,hr,0)
Minimum (1,batt_volt,FP2,0,0)
Sample (1,flow,FP2)
Sample (1,turbidityH,FP2)
Sample (1,turbidityL,FP2)
EndTable

DataTable (Field,1,-1)
DataInterval (0,15,Min,0)
Sample (1,depth,FP2)
Average (1,depth,FP2,0)
Average (1,(tdepth/sampnum),FP2,0)
FieldNames ("SmpAvgDepth:Volts")
Sample (1,velocity,FP2)
Average (1,velocity,FP2,0)
Average (1,(tvel/sampnum),FP2,0)
FieldNames ("SmpAvgVelocity:Volts")
Sample (1,flowrate,FP2) '1 minute value, not totaled for 15 minutes
Average (1,flowrate,FP2,0)
Sample (1,turbidityH,FP2)
Average (1, turbidityH, FP2,0)
Sample (1,turbidityL,FP2)
Average (1, turbidityL, FP2,0)
EndTable

DataTable (event,go,-1)
DataInterval (0,1,min,0)
Sample (1,depth,FP2)
Sample (1,tread/sampnum),FP2)
FieldNames ("SmpAvgDepth:Volts")
Sample (1,velocity,FP2)
Sample (1,(tvel/sampnum),FP2)
FieldNames ("SmpAvgVelocity:Volts")
Sample (1, area,FP2)
Sample (1,flowrate,FP2)
Sample (1,turbidityH,FP2)
Sample (1,turbidityL,FP2)
Sample (1,pulse,FP2)
Totalize (1, Event1, FP2, False)
Totalize (1, Event2, FP2, False)
EndTable

Sub power
SW12(1)
Delay (1,1,sec)
EndSub

Sub Read
counter =0
tread =0
tturbH =0
tturbL = 0
tvel =0

Do While counter <sampnum
counter= counter+1
VoltSe (readdepth,1,mV5000,6,1,0,_60Hz,1.0,1)
tread =tread+readdepth
'VoltDiff (turbread,1,mV5000,1,True ,0,_60Hz,1.0,0) 'Must determine multiplier value to get correct turbidity
VoltSe (vread,1,mV5000,4,1,0,_60Hz,1.0,1)
tvel=tvel+vread
VoltSe (turbreadH,1,mV5000,2,1,0,_60Hz,1.0,0)
tturbH = tturbH+turbreadH
VoltSe (turbreadL,1,mV5000,2,1,0,_60Hz,1.0,0)
tturbL = tturbL+turbreadL
Loop
EndSub

Sub portoff
SW12(0)
EndSub

Sub sendpulse
PortSet (1,1)
Delay (1,100,msec)
PortSet (1,0)
EndSub

'Main Program
BeginProg
depthoffset = caldepthoffset + verticaloffset
Scan (1,Min,0,0)
Battery (batt_volt)
PulseCount(rain_in,1,1,2,0,0.01,0)
PulseCount (Event1,1,12,0,0,1.0,0)
PulseCount (Event2,1,13,0,0,1.0,0)
go = 0
pulse = 0
tdepth = 0
VoltSe(testdepth,1,mV5000,6,1,0,_60Hz,1.0,0)
treadV = testdepth
testdepth=testdepth*depthslope+ depthoffset
If testdepth > TriggerDepth Then
go = 1
gotwo = 1
EndIf


If testdepth <= TriggerDepth Then
If gotwo > 0 Then
go = 1
gotwo=gotwo-1
EndIf
EndIf

If go = 1 Then
Call power
Call Read

depth = (tread/sampnum)*depthslope + depthoffset
If depth <0 Then depth = 0
If depth > radius*2 Then depth = (radius * 2) 'diameter of pipe
beta = ACOS(1-depth/radius)
area = (radius^2 * (beta-COS(beta)*SIN(beta))*0.0001) 'area in cm^2 to M^2

velocity = ((((tvel/sampnum)*0.0033)*velslope + veloffset)*0.3048) ' Convert millivolts -> ft/s -> m/sec
'If velocity < .0022 Then velocity = 0
If velocity > 2.5 Then velocity = 0
If velocity = NaN Then velocity = 0
flowrate = velocity * area
sampleflow = sampleflow + flowrate * 60
flow = flow + flowrate*60 * 60

' turbidity = -1224.4*(tturb/sampnum/1000)^2+4475*(tturb/sampnum/1000)-86.04 'Turbidity Sensor #5
' concentration = (tturb/sampnum/1000)* turbslope + turboffset
' loadrate = flowrate * concentration * 0.001
' load = load + loadrate *60
turbidityH = tturbH
turbidityL = tturbL

If sampleflow > samplecriteria Then
pulse = 1
Call sendpulse
sampleflow= sampleflow - samplecriteria
EndIf

CallTable event


EndIf

If go = 0 Then
Call portoff
EndIf


CallTable daily
CallTable Field
CallTable rain
tread =0
tturbH =0
tturbL = 0
tvel =0
NextScan
EndProg


kirving Aug 14, 2013 06:04 AM

I'd be suspicious mostly of the power control, to make sure that 1 second is sufficient for the instrument(s) being controlled. A simple check would be to leave the power on and compare the results.


hopesci Aug 19, 2013 07:10 PM

Thank you for your response,

I will look into that and let you know what I have found.


User0618 Aug 19, 2013 07:41 PM

I would recommend talking with your group members and setting up a test unit in the lab, that will help you trace out and understand the program and hardware in real-time. It will help you track down if there are any hardware AND programming issues. Break down the program block by block. One other thing that can be difficult is the nomenclature of your variable names. Tracing those out and renaming them so they are more descriptive will help you trace out what is happening in the program as it executes. There is a lot of things going on and it can be overwhelming, but breaking things down and testing is the best place to start.


kirving Aug 19, 2013 08:55 PM

I made a pass through the program you posted, mostly changed some variables to constants where it seemed appropriate, and have put the program at this url: http://werc.engr.uaf.edu/~ken/misc/csiforum/hopecsi-program.cr1

Log in or register to post/reply in the forum.