Remote-processing BASIC 52 Instrukcja Użytkownika Strona 11

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 163
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 10
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 during each system tick time (every 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 hard war e section of t he card's
manual.
Just about any valid digital I/O line can be designated
as a counter input. Exceptions are interrupt inputs,
keypad, and display lines. Even if a digital line is an
output, it can be 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 using 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 before it can be counted again.
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 Hz. However, 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 COUNT. Notice
there are two COUNT commands. One is a function,
which returns a value. This is the one used by the
software counters. The other COUN T command is a
statement, which writes a value to a hardware
counter. This is not used by the software co unters.
Software counters canno t be preset.
ON COU NT declares or clears a multitasking
process. T here are thre e variations of this command.
Referring to the ON C OUN T command in this
manual, the first syntax defines the digital line to
count, number of pulses to count before executing a
subroutine. When the specified number of pulses is
reached, the counter resets and a count interrupt flag
is set. Should a higher priority interrupt be executing,
the count subroutine is delayed until the higher one is
finished. The COUNT func tion is not usually used 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 count,
simply re-declare the ON COUNT statement for that
line.
The third syntax shuts off multitasking for that
counter.
The ON COUNT command can be used to expand
the number of lines used as an ON LINE command.
The limitation here is an interrupt is generated only
when a line goes low. Set the count to 1 in the ON
COUNT declaration.
Serial Communication Multitasking
ON COM $ defines a program branch when either a
specific character or number of characters is met.
Criteria are specified in the O N COM$ statement.
When the criteria is met, the incoming data is referred
to as a packet.
This statement is especially useful in a networking
application using the RS-485 serial port. Other
devices, such as modems or scales can be used to
generate an interrupt using RS-232. A ll serial ports
can use ON COM$.
Data packets are retrieved using the COM $ function.
In RS-485 networking applications, the STR (8,...)
function is useful for determining its address.
Two serial application program s are in this manu al.
The first program is a simple RS-485 network
communication handler, shown in Appendix A. The
second uses a modem to auto receive and is in
Appendix B.
The RS-485 network handler is set up as a master-
slave protocol. Slaves "do not talk unless spoken to".
The host transmits to all receivers. All receivers
transmitters go to the hosts receive line. The host
does not transmit until it receives a response from a
node or a timeout is reached.
Przeglądanie stron 10
1 2 ... 6 7 8 9 10 11 12 13 14 15 16 ... 162 163

Komentarze do niniejszej Instrukcji

Brak uwag