Section 8. processing and program control examples, 1 computation of running average – Campbell Scientific TD Operating System Addendum for CR510, CR10X, and CR23X User Manual

Page 31

Advertising
background image

THIS SECTION ENTIRELY REPLACES THE CR10X MANUAL SECTION 8.

AD-8-1

SECTION 8. PROCESSING AND PROGRAM CONTROL EXAMPLES

This section contains examples for the CR10X. The appropriate voltage range codes would have to be
selected for the CR23X (see CR23X Manual Section 8 for the measurement instructions). The CR510-
TD may not support all the examples.

The following examples are intended to illustrate the use of Processing and Program Control
Instructions, flags, 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, and Converting Wind Direction
(8.1, 8.5, and 8.7).

Control ports and the Loop are illustrated in the AM32 example (8.3).

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

AVERAGE

It is sometimes necessary to compute a running
average (i.e., the average covers a fixed
number of samples and is continuously updated
as new samples are taken). Because the
output interval is shorter than the averaging
period, Instruction 71 cannot be used; the
algorithm for computing this average must be
programmed by the user. The following
example demonstrates a program for
computing a running average.

In this example, each time a new measurement
is made (in this case a thermocouple
temperature) an average is computed for the 10
most recent samples. This is done by saving all
10 temperatures in contiguous input locations
and using the Spatial Average Instruction (51)
to compute the average. 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 average 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.

Input Location Labels:

1:Panl Temp

15:Temp_i5

2:smpl10av

16:Temp_i4

11:Temp_i9

17:Temp_i3

12:Temp_i8

18:Temp_i2

13:Temp_i7

19:Temp_i1

14:Temp_i6

20:Temp_i

Where i is current reading, i1 is previous
reading, etc.

*

1

Table 1 Programs

01:

10

Sec. Execution Interval

01:

P17

Module Temperature

01:

1

Loc [:Panl_Temp]

02:

P14

Thermocouple Temp (DIFF)

01:

1

Rep

02:

1

2.5 mV slow Range

03:

1

IN Chan

04:

1

Type T (Copper-Constantan)

05:

1

Ref Temp Loc Panl_Temp

06:

20

Loc [:Tempi ]

07:

1

Mult

08:

0

Offset

03:

P51

Spatial Average

01:

10

Swath

02:

11

First Loc Temp_i9

03:

2

Avg Loc [:smpl10avg]

04:

P54

Block Move

01:

9

No. of Values

02:

12

First Source Loc Temp_i8

03:

1

Source Step

04:

11

First Destination Loc
[:Temp_i9 ]

05:

1

Destination Step

Advertising