Section 8. processing and program control examples, 1 computation of running maximum – Campbell Scientific CR23X Micrologger User Manual
Page 111

8-1
SECTION 8. PROCESSING AND PROGRAM CONTROL EXAMPLES
The following examples are intended to illustrate the use of Processing and Program Control
Instructions, flags, dual Final Storage, and the capability to direct the results of Output Processing
Instructions to Input Storage.
The specific examples may not be as important as some of the techniques employed, for example:
Directing Output Processing to Input Storage is used in the Running Average and Rainfall Intensity
examples (8.1 and 8.2).
Flag tests are used in the Running Average, Interrupt Subroutine, Converting Wind Direction, and
Saving Data Prior to Event examples (8.1, 8.5, 8.7 and 8.8).
Control ports and the Loop are illustrated in the AM32 example (8.3).
An algorithm for a down counter is used in the Saving Data Prior to Event example (8.8).
Powering 12 V sensors with the switched 12 V port (8.12).
As in Section 7 these examples are not complete programs to be taken verbatim. They need to be
altered to fit specific needs.
8.1 COMPUTATION OF RUNNING
MAXIMUM
It is sometimes necessary to compute a running
maximum (i.e., the maximum covers a fixed
number of samples and is continuously updated
as new samples are taken). Because the
output interval is shorter than the period over
which the maximum is determined, Instruction
71 cannot be used; the algorithm for computing
this maximum must be programmed by the
user. The following example demonstrates a
program for computing a running maximum.
In this example, each time a new measurement
is made (in this case a thermocouple
temperature) a maximum is determined and
computed for the 10 most recent samples. This
is done by saving all 10 temperatures in
contiguous input locations and using the Spatial
Maximum Instruction (49) to determine the
maximum. The temperatures are stored in
locations 11 through 20. Each time the table is
executed, the new measurement is stored in
location 20 and the maximum is stored in
location 2. The Block Move Instruction (54) is
then used to move the temperatures from
locations 12 through 20 down by 1 location; the
oldest measurement (in location 11) is lost
when the temperature from location 12 is
written over it.
PROGRAM
*
Table 1 Program
01:
10.0
Execution Interval (seconds)
01:
Panel Temperature (P17)
1:
1
Loc [ Panl_Temp ]
02:
Thermocouple Temp (DIFF) (P14)
1:
1
Reps
2:
1
±10 mV Slow Range
3:
1
DIFF Channel
4:
1
Type T (Copper-Constantan)
5:
1
Ref Temp Loc [ Panl_Temp ]
6: 20
Loc [ Temp_i ]
7:
1
Mult
8:
0
Offset
03:
Spatial Maximum (P49)
1: 10
Swath
2: 11
First Loc [ Temp_i_9 ]
3:
2
Avg Loc [ 10smpl_av ]
04:
Block Move (P54)
1:
9
No. of Values
2: 12
First Source Loc [ Temp_i_8 ]
3:
1
Source Step
4: 11
First Destination Loc [ Temp_i_9 ]
5:
1
Destination Step
05:
Do (P86)
1: 10
Set Output Flag High