beautypg.com

Section 8. processing and program control examples, 1 computation of running average – Campbell Scientific CR7 Measurement and Control System User Manual

Page 83

background image

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, 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).

Flags tests are used in the Running Average, Interrupt Subroutine, and Converting Wind Direction
examples (8.1, 8.4, and 8.6)

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 includes 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 one 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 i-5

2:10smpl av

16:Temp i-4

11:Temp i-9

17:Temp i-3

12:Temp i-8

18:Temp i-2

13:Temp i-7

19:Temp i-1

14:Temp i-6

20:Temp i

Where i is current reading,
i-1 is previous reading, etc.

*

1

Table 1 Programs

01:

1

Sec. Execution Interval

01:

P17

Panel Temperature

01:

1

IN Card

02:

1

Loc [:Panl Temp]

02:

P14

Thermocouple Temp (DIFF)

01:

1

Rep

02:

1

1500 uV slow Range

03:

1

IN Card

04:

1

IN Chan

05:

1

Type T (Copper-Constantan)

06:

1

Ref Temp Loc Panl Temp

07:

20

Loc [:Temp i ]

08:

1

Mult

09:

0.0000

Offset

03:

P51

Spatial Average

01:

10

Swath

02:

11

First Loc Temp i-9

03:

2

Avg Loc [:10smpl av]