by Janet Albers | Updated: 10/25/2017 | Comments: 2
Have you ever noticed a message saying that your CRBasic program compiled in PipelineMode or SequentialMode? What does it mean? And, when does it matter? In this article, we’ll look at these two modes.
Let’s start with the more straightforward mode: SequentialMode. The CRBasic Editor Help offers this description: “In sequential mode, instructions are executed by the data logger sequentially as they occur in the program.” In other words, your program runs from top to bottom. You can also think of sequential mode like this, with one instruction being executed after another:
Sequential mode gives you control over the order in which instructions are executed, and it makes your program easy to follow. Sequential mode can be especially useful when you are powering sensors under program control to ensure your sensor is turned on at the correct time.
In sequential mode, each measurement is followed by the processing tasks it requires. In other words, measurements and processing do not occur concurrently. Instead, processing always follows the measurement. Because measurements and processing are carried out in sequential order, there is no buffer for processing.
In the figure below, there are three measurements: A, B, and C. Each measurement needs processing—denoted by PA, PB, and PC, respectively. In this simple example, processing includes applying multipliers and offsets, and performing output calculations. We also see that there is some idle time in the scan, which is denoted by the unlabeled squares.
Click above for a larger image.
I’ll use seconds as the unit of measurement for the scan rate to make the figures easier to understand. (In practice, Campbell Scientific measurements and processing happen much faster.) In the figure above, we could say that the scan rate is 10 seconds.
In the next figure, we have removed the idle time in the scan. In sequential mode, the fastest this set of measurements and processing could run would be a scan rate of six seconds.
Click above for a larger image.
Trying to run the scan any faster in sequential mode would result in skipped scans. At this rate, you might still get a skipped scan if the occasional processing task takes longer than you’ve accounted for.
To better understand skipped scans, watch the illustrative video below.
(Note: There is no audio for this video.)
Note: CR300-series dataloggers always run in sequential mode.
Now, what’s PipelineMode? The CRBasic Editor Help offers this description: “In pipeline mode, measurement tasks and processing tasks are handled separately and executed concurrently.” In pipeline mode, measurement tasks are given the highest priority so that they execute first with precise timing in each scan. Processing tasks can lag and may be completed later—even during a different scan if the data logger has a tight time schedule. These simultaneous tasks are completed using scan buffers that allow processing tasks to queue up and occur in the background while measurements are being made.
In the figure below, the same program that we looked at in the sequential mode example is run in pipeline mode instead. Once again, there are three measurements (A, B, and C) with the processing of the measurements (denoted by PA, PB, and PC, respectively). Because we’re using pipeline mode, the measurement and processing tasks are handled separately, but can occur concurrently.
Click above for a larger image.
Now, let’s speed things up. In sequential mode, the fastest we could run the program without getting skipped scans was six seconds. In pipeline mode, measurements and processing happen concurrently, as needed, allowing us to increase the scan rate to five seconds.
Click above for a larger image.
Question: What is the fastest that this program could run in pipeline mode? Answer: By removing all idle time, it could run every three seconds. |
Processing tasks that take a variable amount of time, require retries, or only happen occasionally can increase the required scan time, which could result in skipped scans. The scan buffer (set in the CRBasic Scan() instruction) allows processing tasks to be stored in a queue and then processed when the processor becomes available.
Caution: If the data logger doesn’t complete the tasks and the buffer overflows, it will drop all the tasks in the buffer at once, which will cause a skipped scan for every buffer. If you see your skipped scans increase by the same number regularly, you are likely experiencing this. To eliminate skipped scans, you can increase the number of buffers, increase the scan rate, or change the structure of the program.
For help understanding skipped scans and buffers, watch the short video below.
For optimal viewing, click the full-screen button on the right of the video controls.
In the video example, using two buffers instead of one would have eliminated the skipped scans.
Note: In PipelineMode, the data logger uses a minimum of two buffers.
The MaxBuffDepth value in the data logger’s Status table can be monitored to help understand the optimum number of buffers to allocate for a program.
Recommended for You: For more information about the Status table, watch the “Connect – Station Status” video. |
By default, your CRBasic program will try to compile in pipeline mode. That gives you the most precise measurement timing and usually more efficient processing and power consumption. CRBasic will automatically switch to sequential mode when necessary. Most notably, a program will compile in sequential mode when measurements will not be made every scan (for example, in an If… Then statement) or when measurements need to be set up externally (for example, the sensor needs to be powered by the SW12 port).
See the CRBasic Editor Help for PipelineMode or SequentialMode for more details. To access this resource, follow these steps:
Recommended for You: For more information about CRBasic Editor Help, watch the “CRBasic | Help System” video. |
Credits: John Markham, Product Test Engineer at Campbell Scientific, Inc., contributed to this article.
If you have any questions about how to use PipelineMode or SequentialMode, please post them below.
Comments
Minh T. | 12/05/2018 at 08:29 AM
Hi Janet, how do users determine whether a built-in (or user-defined) CRBasic subroutine or function is a `Measurement` or `Processing` task? Is it possible to view the buffer contents?
jra | 12/05/2018 at 08:41 AM
Thanks for your question Minh.
In the CRBasic editor select PipeLineMode from the instruction list, click the Help button. In the first paragraph under Remarks there is a link to a list of instructions that run as measurement or processing tasks.
No - it is not possible to view the buffer contents.
I hope that helps. Let me know if you need more informations.
Please log in or register to comment.