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.

Best Practices for CR1000 Programming, Multiple Scan Intervals


Terrapin Jun 16, 2016 09:17 PM

I have a CR1000 program that has a 5-minute scan interval and a data table that is called hourly.  I have a snow depth sensor that will be turned on and read once every two hours.  The snow depth value must be outputted with all the other hourly data, but I need snow depth to show NAN those hours when no measurement was made.  

I'm trying to get some ideas about best practices for dealing with this type of situation. The best solution I've come up with is as follows.  Not sure this is the most efficient or elegant way to accomplish this task.  I would appreciate any feedback or ideas regarding this.

DataTable(Data,True,-1)

   DataInterval(0,1,Hr,10)

   Sample(1,SnowDepth,FP2)

   Process other data 

EndTable

'' ***************************************************************

BeginProg

   Scan(5,Min,3,0)

      Various Program Instructions

      If TimeIntoInterval(1,2,Hr) Then  

         SnowDepth = NAN

      EndIF

      CallTable Data

   NextScan

'' ***************************************************************

   SlowSequence

   Scan(2,Hr,3,0)

      If TimeIntoInterval(0,2,Hr) Then  

        Snow sensor instructions

      EndIf

   NextScan

EndProg

'' ***************************************************************

The end result for the data table should look like this

even hour datetime, #.#

odd hour datetime, NAN

even hour datetime, #.#

odd hour datetime, NAN


Ken Conner Jun 21, 2016 11:12 PM

You could do something fairly simple like this:

Public Logger_Battery
Public Logger_Temperature
Public Snow_Depth


DataTable (Hourly_Data,True,-1 )
DataInterval (0,1,hr,10)
Minimum (1,Logger_Battery,FP2,False,False)
Average (1,Logger_Temperature,IEEE4,False)
Sample (1,Snow_Depth,IEEE4)
EndTable


BeginProg
Scan (5,Min,3,0)
Battery (Logger_Battery)
PanelTemp (Logger_Temperature,_60Hz)

If IfTime (0,60,min)
'turn sensor on
'delay - let sensor warm up
'measure snow depth sensor
Snow_Depth = Logger_Battery 'create dummy data for snow depth value
Else
Snow_Depth = NAN
EndIf

CallTable Hourly_Data
NextScan
EndProg

Essentially, whenever your not at the top of a two hour interval you don't measure the snow depth sensor and you force its value to be NAN.


Terrapin Jun 23, 2016 09:44 PM

Hi Ken,

Thanks for your reply and suggestion.  I originally wrote a similar program but wasn't getting the proper data output (i.e., data in even hours and NAN values in odd hours).  After playing around with your code I realized it was because I was Averaging the data instead of Sampling and the Averaging included NAN values collected every scan interval. 

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