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.

Don't understand what is happening (program Pulse Count)


Otemohu Feb 15, 2018 04:09 PM

Hello,

I have a program that I changed the code recently. Now, and I do not know why, the pulse count instruction (or its totalize instruction in datatable) seems to act twice. As a consequence, I have two more precipitations than another station located nearby.

Here is the program:

'Variables and Table definitions

' Time and filename variables
Public Outstat As Boolean
Public Outstat2 As Boolean
Public Lastfilename As String *50
Public Lastfilename2 As String *50
Public Lastfiletime As String *50
Public Lastfiletime2 As String *50
Public Newfilename As String *50
Public Newfilename2 As String *50
Public timearray(7) As String
Public timearray2(7) As String
Public Desiredtime As String *50
Public Desiredtime2 As String *50

'CMP6 variable
Public CMP6_V : Units CMP6_V = mV
Public CMP6_SW_IN : Units CMP6_SW_IN = W/m2
Const CMP6_sens = 12.17
Const CMP6_mult = 1000/CMP6_sens
Const CMP6_off = 0

'HMP155 variables
Public HMP155_Tair_V : Units HMP155_Tair_V = mV
Public HMP155_Tair : Units HMP155_Tair = degC
Const HMP155_Tair_mult = 0.14
Const HMP155_Tair_off = -80
Public HMP155_RHair_V : Units HMP155_RHair_V = mV
Public HMP155_RHair : Units HMP155_RHair = %
Const HMP155_RHair_mult = 0.1
Const HMP155_RHair_off = 0

'ARG100 Rainfall variables
Public ARG100_Rain : Units ARG100_Rain = mmeters
Const ARG100_Rain_mult = 0.201

'Geonor T200BM rainfall variables
Const Geonor_f0 = 1072.9
Const Geonor_A = 2.20218E-2
Const Geonor_B = 1.22522E-5
Public Geonor_Prec : Units Geonor_Prec = mmeters
Public Geonor_Depth_Raw : Units Geonor_Depth_Raw = mmeters
Public Latest_Geonor_Depth_Raw : Units Latest_Geonor_Depth_Raw = mmeters
Public Geonor_Freq : Units Geonor_Freq = Hz
Public Geonor_BackRecs(12)

'WindSonic1 variables
Dim WSStr As String * 21
Dim ByteRet
Dim ChkSumF As Boolean
Public WSData(3)
Public N(9)
Alias WSData(1)=WindDir : Units WindDir =deg
Alias WSData(2)=WS_ms : Units WS_ms = m/s
Alias WSData(3)=WSDiag : Units WSDiag = unitless
Alias N(1)=SmplsF
Alias N(2)=Diag1F
Alias N(3)=Diag2F
Alias N(4)=Diag4F
Alias N(5)=Diag8F
Alias N(6)=Diag9F
Alias N(7)=Diag10F
Alias N(8)=NNDF
Alias N(9)=CSEF

'Other variables
Public Batt_V : Units Batt_V = Volts
Public PTemp : Units PTemp=degC

'Definition of DataTables
DataTable(FRFonBS01,True,-1)
TableFile ("USR:FRFonBS01.dat",11,7,0,1,Day,Outstat,Lastfilename)
Sample (1,TimeStamps,String)
Sample(1,CMP6_V,IEEE4) 'SW_IN_IU_2_1_1
Sample(1,CMP6_SW_IN,IEEE4) 'SW_IN_2_1_1
EndTable

DataTable(FRFonBS02,True,-1)
TableFile ("USR:FRFonBS02.dat",11,7,0,1,Day,Outstat2,Lastfilename2)
Sample (1,TimeStamps,String)
Sample(1,HMP155_Tair_V,IEEE4) 'TA_IU_2_1_1
Sample(1,HMP155_Tair,IEEE4) 'TA_2_1_1
Sample(1,HMP155_RHair_V,IEEE4) 'RH_IU_2_1_1
Sample(1,HMP155_RHair,IEEE4) 'RH_2_1_1
Sample(1,Geonor_Freq,IEEE4) 'P_IU_1_1_1
Sample(1,Geonor_Prec,FP2) 'P_1_1_1
Totalize(1,ARG100_Rain,FP2,False) 'P_1_1_2
WindVector (1,WS_ms,WindDir,FP2,False,0,0,1) 'WS_4_1_1
FieldNames("WS_ms_S_WVT,WindDir_D1_WVT") 'WD_4_1_1
EndTable

DataTable(Meteo,True,-1)
DataInterval(0,30,Min,10)
Average(1,CMP6_SW_IN,IEEE4,False)
Average(1,HMP155_Tair,FP2,False)
Average(1,HMP155_RHair,FP2,False)
Totalize(1,ARG100_Rain,FP2,False)
Totalize(1,Geonor_Prec,FP2,False)
Sample(1,Geonor_Depth_Raw,IEEE4)
Sample(1,Geonor_Freq,IEEE4)
WindVector(1,WS_ms,WindDir,FP2,False,10,0,0)
FieldNames("WS_ms_S_WVT,WindDir_D1_WVT,WindDir_SD1_WVT")
Maximum (1,WS_ms,FP2,False,True)
Totalize(1,NNDF,FP2,False)
Average (1,Batt_V,FP2,False)
EndTable

DataTable(Wind_Diag,True,-1)
DataInterval(0,30,Min,10)
Totalize(1,SmplsF,FP2,False)
Totalize(1,Diag1F,FP2,False)
Totalize(1,Diag2F,FP2,False)
Totalize(1,Diag4F,FP2,False)
Totalize(1,Diag8F,FP2,False)
Totalize(1,Diag9F,FP2,False)
Totalize(1,Diag10F,FP2,False)
Totalize(1,CSEF,FP2,False)
EndTable

DataTable(Batterie,True,-1)
DataInterval(0,1,Day,10)
Minimum(1,Batt_V,FP2,False,False)
EndTable

'SubRoutines
Sub TimeFormat
Public TimeStamps As String *17
Public rTime(9)
Public YYYY As String *4
Public MM As String *2
Public DD As String *2
Public hh As String *2
Public mn As String *2
Public ss As String *2
RealTime(rTime)
YYYY = rTime(1)
'forcage du zero devant l'unite a un chiffre (ex quand 8 --> 08)
If rTime(2)<10 Then MM ="0"&rTime(2) Else MM = rTime(2)
If rTime(3)<10 Then DD ="0"&rTime(3) Else DD = rTime(3)
If rTime(4)<10 Then hh ="0"&rTime(4) Else hh = rTime(4)
If rTime(5)<10 Then mn ="0"&rTime(5) Else mn = rTime(5)
If rTime(6)<10 Then ss ="0"&rTime(6) Else ss = rTime(6)
TimeStamps = YYYY&MM&DD&hh&mn&ss
EndSub

'Main Program
BeginProg
SerialOpen(Com1,38400,3,0,985)
SetStatus("USRDriveSize",1500000)

' Scan (2,Sec,1,0)
' 'Mesure de la freq du capteur du Geonor T200BM
' PeriodAvg (Geonor_Freq,1,mV250,5,0,1,1000,1000,1,0) 'mesure de la freq sur 1000 cycles
' AvgRun(Geonor_Freq_Avg,1,Geonor_Freq,5) 'calcul moy mobile sur les 5 dernieres valeurs
' 'Mesure des precipitations sur l'ARG100
' PulseCount(ARG100_Rain,1,1,2,0,ARG100_Rain_mult,0)
' 'Call Data Tables and Store Data
' CallTable(Meteo)
' NextScan
'
' SlowSequence
Scan(20,Sec,1,0)
'Mesure du rayonnement global sur le CMP6
VoltDiff (CMP6_V,1,mV25C,2,True,10000,_50Hz,1,0)
CMP6_SW_IN = CMP6_V * CMP6_mult + CMP6_off
'Mesure des precipitations sur l'ARG100
PulseCount(ARG100_Rain,1,1,2,0,ARG100_Rain_mult,0)
'Configuration du Timestamps au format YYYYMMDDhhmmss
Call TimeFormat
'Appel des tables
CallTable(FRFonBS01)
CallTable(Meteo)
'File timing
If Outstat Then
Lastfiletime = FRFonBS01.Timestamp(3,5)
SplitStr(timearray(),Lastfiletime,"",6,0)
Desiredtime = timearray(3)&timearray(2)&timearray(1)
Newfilename = "USR:FR-Fon_BM_"+Desiredtime+"_L10_F01.dat"
FileRename(Lastfilename,Newfilename)
EndIf
NextScan

SlowSequence
Scan(30,Sec,1,0)
'HMP155 (panel switched power) Temperature & Relative Humidity Sensor measurements 'TempAir' and 'RHair'
PortSet(9,1)
Delay(0,5,Sec)
VoltSe(HMP155_Tair_V,1,mV2500,1,0,0,_50Hz,1,0)
HMP155_Tair = HMP155_Tair_V * HMP155_Tair_mult + HMP155_Tair_off
VoltSe(HMP155_RHair_V,1,mV2500,2,0,0,_50Hz,1,0)
HMP155_RHair = HMP155_RHair_V * HMP155_RHair_mult + HMP155_RHair_off
PortSet(9,0)
If HMP155_RHair>100 AND HMP155_RHair<108 Then HMP155_RHair=100
'Mesure des precipitations sur le Geonor T200BM
PeriodAvg (Geonor_Freq,1,mV250,5,0,1,1000,1000,1,0) 'mesure de la freq sur 1000 cycles
Geonor_Depth_Raw = (Geonor_A * (Geonor_Freq - Geonor_f0) + Geonor_B * (Geonor_Freq -Geonor_f0) ^2 ) * 10
GetRecord(Geonor_BackRecs,FRFonBS02,1)
Latest_Geonor_Depth_Raw = (Geonor_A * (Geonor_BackRecs(6) - Geonor_f0) + Geonor_B * (Geonor_BackRecs(6) -Geonor_f0) ^2 ) * 10
Geonor_Prec = Geonor_Depth_Raw - Latest_Geonor_Depth_Raw
If Geonor_Prec < 0.02 Then Geonor_Prec = 0 'elimination du bruit de fond

'WindSonic1 Two Dimensional Sonic Wind Speed & Direction Sensor measurements 'WindDir', 'WS_ms', and 'WSDiag'
'Get data from WindSonic1
SerialInRecord(Com1,WSStr,&h02,0,&h0D0A,ByteRet,00)
WindDir=Mid(WSStr,3,3)
WS_ms=Mid(WSStr,7,6)
WSDiag=Mid(WSStr,16,2)
ChkSumF=HexToDec(Mid(WSStr,20,2)) Eqv CheckSum(WSStr,9,18)
'Set diagnostic variables as needed
If ByteRet=0 Then WSDiag=NAN
Move(SmplsF,9,0,1)
Select Case WSDiag
Case=0
SmplsF=1
Case=1
Diag1F=1
Case=2
Diag2F=1
Case=4
Diag4F=1
Case=8
Diag8F=1
Case=9
Diag9F=1
Case=10
Diag10F=1
Else
NNDF=1
EndSelect
If NOT (ByteRet<>0 IMP ChkSumF) Then CSEF=1
'Configuration du TimeStamps au format YYYYMMDDhhmmss
Call TimeFormat
'Default Datalogger Battery Voltage measurement 'BattV'
Battery(Batt_V)
'Default Wiring Panel Temperature measurement 'PTemp_C'
PanelTemp(PTemp,_50Hz)
'Appel des tables
CallTable(FRFonBS02)
CallTable(Meteo)
CallTable(Wind_Diag)
CallTable(Batterie)


'File timing
If Outstat2 Then
Lastfiletime2 = FRFonBS02.Timestamp(3,5)
SplitStr(timearray2(),Lastfiletime2,"",6,0)
Desiredtime2 = timearray2(3)&timearray2(2)&timearray2(1)
Newfilename2 = "USR:FR-Fon_BM_"+Desiredtime2+"_L10_F02.dat"
FileRename(Lastfilename2,Newfilename2)
EndIf
NextScan
EndProg


smh Feb 15, 2018 04:18 PM

You are calling the Meteo table twice in the program, once in each scan!


Otemohu Feb 15, 2018 05:38 PM

Ok, I thought about that but how log the other variables without calling the meteo table a second time ?

Can I call the meteo table at the very end of the program, just once?


Otemohu Feb 15, 2018 05:40 PM

The pulsecount is called twice: at the 2sec scanrate and at the 20sec scanrate. Sorry i did not see that.


Otemohu Feb 15, 2018 08:17 PM

Ok no, I know why I did that. First the pusle count instruction was included in the 20sec scan but it did not work cause I had to move it into the fastest scanrate. At the end of this scanrate, I needed to call the meteo table to have the totalize in the 30 min datatable.
In addition with this halfhourly file (meteo datatable), I had to create a daily file with 20sec samples so I needed to pulse count again the raingauge to get the data every 20sec. Since the other variable CMP6 has to be scanned every 20sec too, I had to call again the meteo datatable.

How can I manage this to avoid the error in precipitations ...


nsw Feb 19, 2018 04:30 PM

Simplest way to do this os just create a new 24 hour table, Call this table from your 20s scan and Totalise the rain in that table. You then have a separate table just with the 24 hour rain. If this is adequate as it is, then that is fine.

If you really need the 24hour rain total in the FRFonBS02 table, then after you have called the 24hour rain table, then set a variable to this total field in the table and sample that value. Extras as follows :-

Public TotalRain : Units TotalRain=MM

DataTable(FRFonBS02,True,-1)
  TableFile ("USR:FRFonBS02.dat",11,7,0,1,Day,Outstat2,Lastfilename2)
  Sample (1,TimeStamps,String)
  Sample(1,HMP155_Tair_V,IEEE4) 'TA_IU_2_1_1
  Sample(1,HMP155_Tair,IEEE4) 'TA_2_1_1
  Sample(1,HMP155_RHair_V,IEEE4) 'RH_IU_2_1_1
  Sample(1,HMP155_RHair,IEEE4) 'RH_2_1_1
  Sample(1,Geonor_Freq,IEEE4) 'P_IU_1_1_1
  Sample(1,Geonor_Prec,FP2) 'P_1_1_1
  'Totalize(1,ARG100_Rain,FP2,False) 'P_1_1_2
  Sample(1,TotalRain,FP2)
  WindVector (1,WS_ms,WindDir,FP2,False,0,0,1) 'WS_4_1_1
  FieldNames("WS_ms_S_WVT,WindDir_D1_WVT") 'WD_4_1_1
EndTable

DataTable(TempRainTot,True,5)
  DataInterval(0,1440,Min,10)
  Totalize(1,ARG100_Rain,FP2,False)
EndTable

.....

    CallTable(FRFonBS01)
    CallTable(Meteo)
    CallTable(TempRainTot)
    'Take total from 24hour temp table of rain
    If TimeIntoInterval(0,1440,min) Then TotalRain = TempRainTot.ARG100_Rain_Tot(1,1)

.....

Haven't tested this, but it should work or at least give you the details you need to make it work.

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