beautypg.com

Rpbasic-52 programming guide – Remote Processing BASIC 52 User Manual

Page 11

background image

RPBASIC-52 PROGRAMMING GUIDE

1-8

MULTITASKING CONSTRUCTS

COUNT M ultitasking

RPBASIC-52 on the RPC-3XX series of cards can
count pulses while a program is running. Checking
and counting is performed at assembly language
speed d uring each syste m tick time (eve ry 5 ms).
This capability effectively speeds up program
performance and simplifies programming.

This section describes only software counters on the
card. Hardware counters are in a separate category
are disc usse d in the h ard war e se ctio n of t he c ard 's
manual.

Just about any valid digital I/O line can be designated
as a counter input. Excep tions are interrupt inputs,
keypad, and display lines. Even if a digital line is an
output, it can b e designated as a counter input. This
is useful in situation where you may want to limit or
keep track of the number of pulses to a motor,
solenoid, or lamp.

Eight software counters are available. They are
numbered 4-11. Counters 0-3 are reserved for any
hardware ones that may or may not be on your board.

Counting is enabled as soon as a line is designated as
a counter us ing ON C OUN T. The digital line is
sampled every 5 ms. When it goes from a high to low
state, its counter is incremented. A line must be
sampled at a high state be fore it can be counted a gain.
A line must be at a high and low state for a minimum
of 5 ms each to ensure detection. In theory the
maximum counting rate is 100 H z. Howe ver, due to
other multitasking events (mainly serial ports),
effective maximum rate is about 95 Hz assuming a
perfect square wave.

There are two commands used in COUNT
multitasking: COUNT and ON CO UNT. Notice
there are two COUNT commands. One is a function,
which returns a value. This is the one used by the
software counters. The o ther COUN T comm and is a
statement, which writes a value to a hardware
counter. T his is not used b y the software co unters.
Software co unters canno t be preset.

ON COU NT declares or clears a multitasking
process. T here are thre e variations o f this comma nd.
Referring to the ON C OUN T com mand in this
manual, the first synta x defines the d igital line to
count, number of pulses to count before executing a

subroutine . When th e specified n umber o f pulses is
reached, the counter resets and a count interrupt flag
is set. Should a higher priority interrupt be executing,
the count sub routine is dela yed until the highe r one is
finished. The COU NT func tion is not usually use d in
conjunction with this version.

The second syntax simply declares a line for
counting. Use the COUNT function to return the
number of pulses at the line. When the count reaches
65,535 it rolls over to 0 . To reset o r clear a cou nt,
simply re-declare the ON COUNT statement for that
line.

The third syntax shuts off multitasking for that
counter.

The ON C OUNT command can be used to expand
the numbe r of lines used a s an ON LINE c omman d.
The limitatio n here is an interr upt is generate d only
when a line goes low. Set the count to 1 in the ON
COUN T declaration.

Serial Communication Multitasking

ON COM $ defines a program branch when either a
specific char acter or num ber of char acters is met.
Criteria are sp ecified in the O N CO M$ state ment.
When the criteria is met, the incoming data is referred
to as a pack et.

This statement is especially useful in a networking
application using the RS-485 serial port. Other
devices, suc h as mode ms or scales can be use d to
generate an interrupt using R S-232. A ll serial ports
can use ON COM$.

Data pa ckets are retrie ved using the COM $ function.
In RS-48 5 network ing applicatio ns, the STR (8,...)
function is useful for determining its address.
Two ser ial applicatio n program s are in this manu al.
The first program is a simple RS-485 network
communication handler, shown in Appendix A. The
second u ses a mod em to auto receive and is in
Appendix B.

The RS-485 network handler is set up as a master-
slave proto col. Slaves " do not talk u nless spoke n to".
The host transmits to all receivers. All receivers
transmitters go to the hosts receive line. The ho st
does not transmit until it receives a response from a
node or a timeout is reached.