Hi,
I woud like to have just my windspeed and direction sensor in 0.250 seconds scan, while all other sensors has to be in 1 second scan interval.
One of the 1 second sensors is the precipitation sensor, which is pulsecount.
But thats not going to work in slowsequence.
And subscan isnt working..
Any idea how to overcome this situation?
With kind regards.
Put the PulseCount in the Main 0.25s scan. PulseCount instructions should be in the main scan.
The following is copied formt he CRBasic Help on PulseCount instruction :-
Note: This instruction should NOT be placed inside a conditional statement, subroutine, subscan, or SlowSequence scan. To ensure all pulses are detected and the counter does not overflow, it must be executed each time the main program is executed.
All the other instructions can go in the SlowSequence scan.
Hi nsw,
Thanks for the reply.
Ive now got it working in the main 0.250s scan.
But the pulsecount is related to count occurrences in seconds.
So is it possible to have the duration of the occurrences in seconds within the 0.250s main scan?
Its a precipitation sensor which detects 5 forms of precipitation.
And the most occurred precipitationtype is used as source.
Its kind of the same with my sunhours calculation, which is running now in the 0.250s mainscan and so not showing the correct duration in seconds but updated every 0.250s.
Ive attatched my program currently in use below:
'CR1000
'Created by Short Cut (4.1)
PreserveVariables
PipeLineMode
'Declare Variables and Units
Dim AirTC_2
Dim SPkPa
Dim Twg
Dim Twpg
Dim Vpg
Dim Vp
Dim SVp
Dim Twch
Dim VpgVpd
Dim Top
Dim Bottom
Dim SVpW
Dim N
Dim WCTF
Dim WCWSMPH
Dim HITF
Dim AirTC_3
Public BattV
Public PTemp_C
Public WS_kph
Public WS_kph_3S
Public WindDir
Public AirTC
Public RH
Public BP_mbar
Public SlrW
Public SlrkJ
Public Rain_mm
Public Precepitation_type
Public SunHrs
Public PotSlrW
Public RTime(9)
Public SolPos(5)
Public TdC
Public TwC
Public Tot24
Public WC_C
Public HI_C
Public SVPWPa
Alias RTime(1)=Year
Alias RTime(2)=Month
Alias RTime(3)=DayOfMonth
Alias RTime(4)=HourOfDay
Alias RTime(5)=Minutes
Alias RTime(6)=Seconds
Alias RTime(7)=Microseconds
Alias RTime(8)=DayOfWeek
Alias RTime(9)=DayOfYear
Alias SolPos(1)=SolarAzimuth
Alias SolPos(2)=SunElevation
Alias SolPos(3)=HourAngle
Alias SolPos(4)=Declination
Alias SolPos(5)=AirMass
Units BattV=Volts
Units PTemp_C=Deg C
Units WS_kph=kilometers/hour
Units WindDir=degrees
Units AirTC=Deg C
Units RH=%
Units BP_mbar=mbar
Units SlrW=W/m^2
Units SlrkJ=kJ/m^2
Units Rain_mm=mm
Units SunHrs=hours
Units PotSlrW=W/m^2
Units TdC=Deg C
Units TwC=Deg C
Units WC_C=Deg C
Units HI_C=Deg C
Units SVPWPa=Pa
Units Year=years
Units Month=months
Units DayOfMonth=days
Units HourOfDay=hours
Units Minutes=minutes
Units Seconds=seconds
Units Microseconds=microseconds
Units DayOfWeek=days
Units DayOfYear=days
Units SolarAzimuth=degrees
Units SunElevation=degrees
Units HourAngle=radians
Units Declination=radians
Units AirMass=unitless
'Define Data Tables
DataTable(Table1,True,-1)
DataInterval(0,1,Min,10)
Average(1,WS_kph,FP2,False)
WindVector(1,WS_kph,WindDir,FP2,False,0,0,0)
FieldNames("WS_kph_S_WVT,WindDir_D1_WVT,WindDir_SD1_WVT")
Maximum(1,WS_kph,FP2,False,False)
SampleMaxMin(1,WindDir,FP2,False)
Average(1,AirTC,FP2,False)
Minimum(1,AirTC,FP2,False,False)
Maximum(1,AirTC,FP2,False,False)
Average(1,RH,FP2,False)
Minimum(1,RH,FP2,False,False)
Maximum(1,RH,FP2,False,False)
Average(1,BP_mbar,IEEE4,False)
Minimum(1,BP_mbar,IEEE4,False,False)
Maximum(1,BP_mbar,IEEE4,False,False)
Average(1,SlrW,FP2,False)
Totalize(1,Rain_mm,FP2,False)
Sample(1,Lufft_R2S_Mode,IEEE4,False)
Totalize(1,SunHrs,FP2,False)
Average(1,PotSlrW,FP2,False)
Average(1,TdC,FP2,False)
Minimum(1,TdC,FP2,False,False)
Maximum(1,TdC,FP2,False,False)
Average(1,TwC,FP2,False)
Minimum(1,TwC,FP2,False,False)
Maximum(1,TwC,FP2,False,False)
Sample(1,Tot24,FP2)
Average(1,WC_C,FP2,False)
Minimum(1,WC_C,FP2,False,False)
Average(1,HI_C,FP2,False)
Maximum(1,HI_C,FP2,False,False)
Average(1,SVPWPa,FP2,False)
Minimum(1,SVPWPa,FP2,False,False)
Maximum(1,SVPWPa,FP2,False,False)
EndTable
DataTable(Table2,True,-1)
DataInterval(0,1440,Min,10)
Minimum(1,BattV,FP2,False,False)
Average(1,WS_kph,FP2,False)
WindVector(1,WS_kph,WindDir,FP2,False,0,0,0)
FieldNames("WS_kph_S_WVT,WindDir_D1_WVT,WindDir_SD1_WVT")
Average(1,AirTC,FP2,False)
Minimum(1,AirTC,FP2,False,False)
Maximum(1,AirTC,FP2,False,False)
Average(1,RH,FP2,False)
Minimum(1,RH,FP2,False,False)
Maximum(1,RH,FP2,False,False)
Average(1,BP_mbar,IEEE4,False)
Minimum(1,BP_mbar,IEEE4,False,False)
Maximum(1,BP_mbar,IEEE4,False,False)
Average(1,SlrW,FP2,False)
Totalize(1,Rain_mm,FP2,False)
Totalize(1,SunHrs,FP2,False)
Average(1,PotSlrW,FP2,False)
Average(1,TdC,FP2,False)
Minimum(1,TdC,FP2,False,False)
Maximum(1,TdC,FP2,False,False)
Average(1,TwC,FP2,False)
Minimum(1,TwC,FP2,False,False)
Maximum(1,TwC,FP2,False,False)
Sample(1,Tot24,FP2)
Average(1,WC_C,FP2,False)
Minimum(1,WC_C,FP2,False,False)
Average(1,HI_C,FP2,False)
Maximum(1,HI_C,FP2,False,False)
Average(1,SVPWPa,FP2,False)
Minimum(1,SVPWPa,FP2,False,False)
Maximum(1,SVPWPa,FP2,False,False)
EndTable
AngleDegrees
'Main Program
BeginProg
'Main Scan
Scan(250,mSec,8,0)
'Default CR1000 Datalogger Battery Voltage measurement 'BattV'
Battery(BattV)
'Default CR1000 Datalogger Wiring Panel Temperature measurement 'PTemp_C'
PanelTemp(PTemp_C,_60Hz)
'05106 Wind Speed & Direction Sensor measurements 'WS_kph' and 'WindDir'
VoltDiff(WS_kph,1,mV2500,1,True,0,_60Hz,0.081035,-39.9875)
VoltDiff(WindDir,1,mV2500,2,True,0,_60Hz,0.18,-0)
WindDir = WindDir + 140
If WindDir > 360 Then WindDir = WindDir - 360
If WindDir < 0 Then WindDir = WindDir + 360
If WindDir>=360 Then WindDir=0
AvgRun (WS_kph_3S,1,WS_kph,12)
'Met One 083E Temperature and Relative Humidity Sensor measurements 'AirTC' and 'RH'
VoltDiff(AirTC,1,mV2500,3,True,0,_60Hz,0.05,-65)
VoltDiff(RH,1,mV2500,4,True,0,_60Hz,0.05,-25)
If (RH>100) AND (RH<108) Then RH=100
'CS105 Barometric Pressure Sensor measurement 'BP_mbar'
VoltDiff(BP_mbar,1,mV2500,6,1,0,_60Hz,0.184,600)
'CM3 Pyranometer measurements 'SlrkJ' and 'SlrW'
VoltDiff(SlrW,1,mV250,7,True,0,250,1,0)
If SlrW<0 Then SlrW=0
'Calculate total flux
'The multiplier to calculate total flux was calculated by Short Cut
'and based on a program execution rate (scan rate) of 250 Milliseconds.
'If you change the program execution rate outside of Short Cut with the CRBasic Editor
'you will need to recalculate this multiplier. See the sensor manual for more details.
'Calculate flux density
SlrW=SlrW*43.30879
'52202 Rain Gauge measurement 'Rain_mm'
PulseCount(Rain_mm,1,1,0,0,0.01,0)
PulseCount(Precepitation_type,1,2,0,1,1,0)
If Precepitation_type >7 AND Precepitation_type <13 Then Precepitation_type=10
'Calculate Sunshine Hours
'Get current time
RealTime(RTime(1))
'Calculate solar position
SolarPosition(SolPos(),RTime(),0*3600,0,0,0,-1,AirTC)
'Calculate potential radiation for time & position (multiply sine of solar elevation angle by solar constant 1373)
PotSlrW=SIN(SunElevation*3.141593/180)*1373
'If the measured value (W/m^2) is greater than 0.4 * the potential solar radiation (W/m^2)
'and the sine of the sun elevation angle (degrees) is great than 0.1 (elevation angle of 6 degrees)
'than it has been sunny for the current scan.
If SlrW>0.4*PotSlrW And SIN(SunElevation)>0.1 Then
'Calculate sun hours for scan time in seconds
SunHrs=1/3600*0
Else
'Set sun hours for scan time in seconds to 0
SunHrs=0
EndIf
'Dew Point and Wet-Bulb calculation prep
AirTC_2=AirTC
SPkPa=101.325
SatVP(SVp,AirTC_2)
Vp=RH*SVp/100
'Dew Point calculation 'TdC'
DewPoint(TdC,AirTC_2,RH)
If TdC>AirTC_2 Or TdC=NAN Then TdC=AirTC_2
'Find Wet-Bulb 'TwC'
Top=AirTC_2
Bottom=TdC
For N = 1 To 25
Twpg=Twg
Twg=((Top-Bottom)/2)+Bottom
WetDryBulb(Vpg,AirTC_2,Twg,SPkPa)
VpgVpd=Vpg-Vp
Twch=ABS(Twpg-Twg)
If VpgVpd>0 Then
Top=Twg
Else
Bottom=Twg
EndIf
If Twch<0.01 Or N=25 Then ExitFor
Next
TwC=Twg
'24 hour running total calculation 'Tot24'
Tot24=Tot24+Rain_mm
If TimeIntoInterval(0,1440,Min) Then Tot24=0
'Wind Chill calculation 'WC_C'
WCTF=1.8*AirTC+32
WCWSMPH=WS_kph*0.621371
WC_C=35.74+0.6215*WCTF-35.75*WCWSMPH^0.16+0.4275*WCTF*WCWSMPH^0.16
If WC_C>WCTF Or WC_C=NAN Then WC_C=WCTF
If WCTF>50 Or WCWSMPH<3 Then WC_C=WCTF
WC_C=(5/9)*(WC_C-32)
'Heat Index calculation 'HI_C'
HITF=1.8*AirTC+32
HI_C=-42.379+2.04901523*HITF+10.14333127*RH-0.22475541*HITF*RH-6.83783*10^-3*HITF^2-5.481717*10^-2*RH^2+1.22874*10^-3*HITF^2*RH+8.5282*10^-4*HITF*RH^2-1.99*10^-6*HITF^2*RH^2
If HITF<80 Or RH<40 Or HI_C<HITF Or HI_C=NAN Then HI_C=HITF
HI_C=(5/9)*(HI_C-32)
'Saturation vapor pressure calculation 'SVPWPa'
AirTC_3=AirTC
SatVP(SVPWPa,AirTC_3)
SVPWPa=SVPWPa*1000
'Call Data Tables and Store Data
CallTable Table1
CallTable Table2
NextScan
SlowSequence
Scan (1,Sec,0,0)
Public Mode(6)
Public DestMaxSpa(2)
Public Lufft_R2S_Mode
'count the occurrences of each mode and put the counts into
'an array
If Precepitation_type = -10 Then Mode(1) = Mode(1) + 1
If Precepitation_type = 10 Then Mode(2) = Mode(2) + 1
If Precepitation_type = 20 Then Mode(3) = Mode(3) + 1
If Precepitation_type = 30 Then Mode(4) = Mode(4) + 1
If Precepitation_type = 40 Then Mode(5) = Mode(5) + 1
If Precepitation_type = 50 Then Mode(6) = Mode(6) + 1
'use MaxSpa to find the maximum of the Mode array
'the second destination variable is the Location
'within the array where the Max occurs
MaxSpa (DestMaxSpa, 6, Mode(1))
'Return a mode, based on which index in Mode() holds the max
If DestMaxSpa(2)= 1 Then Lufft_R2S_Mode = 0
If DestMaxSpa(2)= 2 Then Lufft_R2S_Mode = 10
If DestMaxSpa(2)= 3 Then Lufft_R2S_Mode = 20
If DestMaxSpa(2)= 4 Then Lufft_R2S_Mode = 30
If DestMaxSpa(2)= 5 Then Lufft_R2S_Mode = 40
If DestMaxSpa(2)= 6 Then Lufft_R2S_Mode = 50
If TimeIntoInterval(0,1,Min) Then Mode(1)=0
If TimeIntoInterval(0,1,Min) Then Mode(2)=0
If TimeIntoInterval(0,1,Min) Then Mode(3)=0
If TimeIntoInterval(0,1,Min) Then Mode(4)=0
If TimeIntoInterval(0,1,Min) Then Mode(5)=0
If TimeIntoInterval(0,1,Min) Then Mode(6)=0
If TimeIntoInterval(0,1,Min) Then Lufft_R2S_Mode=0
If TimeIntoInterval(0,1,Min) Then DestMaxSpa(2)=0
NextScan
EndProg
Have a look at the "TimerIO" instruction which can be used to give durations between pulses.