Use Time Intervals for More than Storing Data: Decisions and Control

by Janet Albers | Updated: 12/30/2015 | Comments: 2

Search the Blog


Subscribe to the Blog

Set up your preferences for receiving email notifications when new blog articles are posted that match your areas of interest.


Area / Application

Product Category

Activity

Corporate / News

Enter your email address:



Suggest an Article

Is there a topic you would like to learn more about? Let us know. Please be as specific as possible.

Leave this field empty

Clock with modem on/off indicators

We all know that Campbell Scientific data loggers are really good at taking measurements and storing data. But did you know that they can also make decisions and control other devices? Often, device control is done based on a time interval. This article briefly illustrates how you can set time intervals using the TimeIsBetween() and TimeIntoInterval() instructions.

As a CRBasic programmer, you may already be using the DataInterval() instruction to store data on a specific interval, such as every hour at the top of the hour, like this:

DataInterval() instruction

Other things, besides storing data, can be done on an interval. For example, you can use the TimeIsBetween() instruction or the TimeIntoInterval() instruction within a logic statement to turn a device on or off, take a measurement, or perform a calculation.

Both instructions return the values of TRUE or FALSE depending on the data logger’s real-time clock.

  • Use the TimeIsBetween() instruction to determine if the data logger's real-time clock falls within a range of time. If so, the instruction returns TRUE. The instruction returns TRUE for the entire interval specified.
  • Use the TimeIntoInterval() instruction to determine if the data logger’s real-time clock matches the time specified in the program at the start of a scan. If so, the instruction returns TRUE. The instruction only returns TRUE for the one scan that matches the interval specified.
TimeIsBetween() instruction TimeIntoInterval() instruction

In this example, a modem is set to turn on between the hours of 9:00 a.m. and 5:00 p.m.

In this example, a modem is set to turn on at 9:00 a.m. and turn off at 5:00 p.m.

Program code examples for TimeIsBetween() and TimeIntoInterval() instructions

Tip: Notice that in both programs, when you turn a device on, you also need to turn the device off. If you try to rely on a condition being FALSE to turn off a device, the FALSE condition will not change the state of the port, and your device will remain turned on.

The nuances between the two programs above matter the most if your program misses an exact time. In this first instance, because the program is sent at 8:20 a.m. (prior to the 9:00 a.m. start time), both instructions return TRUE at 9 a.m. and remain TRUE until 5 p.m.

TimeIsBetween() Modem TimeIntoInterval() Modem

8:00 AM

  Off

  Off

8:20 AM send program 

  Off

  Off

9:00 AM

  On

  On

...

  On

  On

5:00 PM

  Off

  Off

In this second instance, because the program is sent at 9:20 a.m. (after the 9:00 a.m. start time), the first scan returns FALSE for the TimeIntoInterval() instruction, and the instruction remains FALSE until 9:00 a.m. the next day.

TimeIsBetween() Modem TimeIntoInterval() Modem

8:00 AM

  Off

  Off

9:00 AM

  On

  On

9:20 AM send program 

  On

  Off

10:00 AM 

  On

  Off

...

  On

  Off

5:00 PM

  Off

  Off

Note: The TimeIsBetween() instruction was introduced with the release of OS 28 for the CR3000, CR1000, and CR800-series dataloggers, and with the release of OS 01 for the CR6.

Recommended for You: For more information about the TimeIsBetween() instruction, read the “Tips and Tricks: More Decisions, Decisions, Decisions…” newsletter article.

How have you used the TimeIsBetween() and TimeIntoInterval() instructions in your CRBasic programs? Share your story below.


Share This Article


About the Author

janet albers Janet Albers was a Senior Technical Writer. She enjoyed sharing tips, simplifying concepts, and guiding our clients to a successful project. She had been with Campbell Scientific, Inc. longer than the CR1000, but not quite as long as the CR10X. After work hours, Janet enjoyed the outdoors with her boys and dogs.

View all articles by this author.


Comments

dpatino | 09/05/2017 at 03:14 PM

Hi

it is possible to set hour and minute for SW12 control

jra | 09/06/2017 at 09:35 AM

dpatino - Sure! Use units of Min(utes) instead of Hours. There are 1440 minutes/day.

For example, to do something between 9:30AM and 4:30PM your instruction would look like: TimeIsBetween (570,990,1440,Min). 

Please log in or register to comment.

We're active on social media!
Stay informed with our latest updates by following us on these platforms: