Campbell Scientific TD Operating System Addendum for CR510, CR10X, and CR23X User Manual

Page 35

Advertising
background image

TD ADDENDUM—SECTION 8. PROCESSING AND PROGRAM CONTROL EXAMPLES

AD-8-5

8.4 INTERRUPT SUBROUTINE USED

TO COUNT SWITCH CLOSURES
(RAIN GAGE)

Subroutines given the label of 97 or 98 will be
executed when control ports 7 or 8,
respectively, go high (5 V, see Instruction 85,
Section 12). In this example, Subroutine 98 and
control port 8 are substituted for a pulse
counting channel to count switch closures on a
tipping bucket rain gage.

The subroutine adds 0.254 (mm, bucket
calibrated for 0.01 inch tip) to an input location
and uses Instruction 22 to delay 0.2 seconds.

The delay is to insure that any switch bouncing
(when closing, the contacts actually bounce off
each other, making and breaking the circuit
several times) has died out before the
subroutine is completed. (The pulse count
inputs do this automatically.) Without the delay,
the subroutine could be completed and called
again by a bounce, causing false counts. The
interrupt has no effect while the subroutine is
still being executed.

Subroutine 98 is in effect keeping a running
total in Input Storage. On the output interval,
this total is sampled to Final Storage and
zeroed by the program in Program Table 1.

To provide comparison, this example has the 2
pulse inputs also reading rain gages. (In a real
situation, it is more likely that the pulse counters
would be used for 2 wind speeds.) In Program
Table 1, the 2 normal pulse inputs are read and
the hourly totals output to Final Storage with
Instruction 72.

The rain gage is connected as diagrammed
below. When the switch closes, 5 volts is
applied to port 8 which causes the subroutine to
be executed.

FIGURE 8.4-1. Connections for Rain Gage

Input location Assignments:

10:Rain_1

(from Pulse count)

11:Rain_2

(from Pulse count)

12:Rain_3

(from subroutine 98 while

Output Flag is low)

*

1

Table 1 Programs

01:

10

Sec. Execution Interval

01:

P3

Pulse

01:

2

Reps

02:

1

Pulse Input Chan

03:

2

Switch closure

04:

10

Loc [:Rain_1 ]

05:

.254

Mult

06:

0

Offset

02:

P84

Data Table

01:

0

Seconds into interval

02: 3600

Seconds interval

03:

0

Records (0=auto; -=redirect)

03:

P72

Totalize

01:

2

Reps

02:

10

Loc Rain_1

04:

P70

Sample

01:

1

Reps

02:

12

Loc Rain_3

05:

P92

If time is

01:

0

seconds into a

02: 3600

second interval

03:

30

Then Do

06:

P30

Z=F

01:

0

F

02:

0

Exponent of 10

03:

12

Z Loc [:Rain_3 ]

07:

P95

End

08:

P

End Table 1

*

3

Table 3 Subroutines

01:

P85

Beginning of Subroutine

01:

98

Subroutine Number

02:

P

34 Z=X+F

01:

12

X Loc Rain_3

02:

.254

F

03:

12

Z Loc [:Rain_3 ]

03:

P22

Excitation with Delay

01:

1

EX Chan

02:

0

Delay w/EX (units=.01sec)

03:

20

Delay after EX (units=.01sec)

04:

0

mV Excitation

04:

P95

End

05:

P

End Table 3

Advertising