Rpbasic-52 programming guide, On count – Remote Processing BASIC 52 User Manual
Page 86
RPBASIC-52 PROGRAMMING GUIDE
2-67
ON COUNT
Syntax:
ON COUNT number, line number, count, program line
ON COUNT number, line number
ON COUNT number
Where: number is 4 to 11. It represents a cou nter numbe r.
line number is 0-7 or 100-123 an d is the digital I/O line nu mber.
count is 1 to 65535. It is the num ber of pulses nee ded for an interrupt.
program line is the subroutine to execute when count is reached.
Function:
Enables count multi-tasking at a specific I/O line. Optionally generates a software interrupt when the
specified number of counts at an I/O line is reached.
Mode:
Run
Use:
ON CO UNT 10,7,200,5000
Executes a subroutine at line 50 00 when 2 00 counts are rea ched at I/O
line 7.
Cards:
RPC -320, R PC-3 30. line number is card depend ent. Refer to your h ardware m anual.
D E S C R IP T I ON
This command enables software counting. This command is not related to any hardware counters on the card.
The three syn taxes control cou nting as follows: T he first syntax with a ll parameters g enerates a softw are
interrupt when count is reached. The second syntax simply enables counting at the line number. The third
syntax turns off coun t multi-tasking for that number only.
A pulse is cou nted on a high to low transition. A line must be high and low for a m inimum of 5 ms to ensu re
detection. The RPBASIC-52 operating system scans the specified lines every 5 ms. Thus, maximum
counting frequency is 100 Hz. In practice, maximum is 95 Hz using a perfect square wave.
The current n umber of pu lses at a counter number is read using the COUNT function. To reset or zero a
count value, re-ex ecute ON COU NT aga in for that particular number.
number is from 4 to 11 to distinguish it from the other hardware counters on board.
R e v ie w HARDWAR E AND SOFTWARE INTERRU PTS in the first part of this manual for interrupt
handling and multitasking information. Read COUNT MULTITASKING earlier in this man ual for a summ ary
of operation.
RELATED
COUN T function
E R R O R
BAD A RGUM ENT when number is out of range.
EXAMPLE
The following example sets line 0 as a counter and branches to a subroutine when this line is brought low 10
times
10 ON COUNT 4,0,10,1000
20 IDLE
30 GOTO 20
.
.
.
1000 PRINT "Counter 4 interrupt"
1010 RETURN
This example makes line 3 a counter only input. Its value is printed every second using COUNT function.