Statement: ontime [expr],[ ln num – Rockwell Automation 1771-DB Basic Module User Manual - Series A User Manual

Page 68

Advertising
background image

Operating Functions

Chapter 5

5–31

Mode: RUN
Type: CONTROL

Your BASIC Module can process a line in milliseconds while the
timer/counters on the microprocessor operate in microseconds. You must
use the ONTIME [expr], [In num] statement because of this
incompatibility between the timer/counters on the microprocessor and the
BASIC Module. The ONTIME statement generates an interrupt every time
the special function operator, TIME, is equal to or greater than the
expression following the ON TIME statement. Only the integer portion of
TIME is compared to the integer portion of the expression. This
comparison is performed at the end (CR or:) of each line of BASIC. The
interrupt forces a GOSUB to the line number [ln num] ) following the
expression ([expr]) in the ONTIME statement.

Important: The ONTIME statement does not interrupt an input
command or a CALL routine. Since the ONTIME statement uses the
special function operator, TIME, you must execute the CLOCK1 statement
for ONTIME to operate. If CLOCK1 is not executed the special function
operator, TIME, does not increment.

You can generate periodic interrupts by executing the ONTIME statement
again in the interrupt routine:

Example:

u10 TIME=0 : CLOCK1 : ONTIME 2,100: DO

u20 WHILE TIMEt10 : END

u100 PRINT “TIMER INTERRUPT AT –”,TIME,“SECONDS”

u110 ONTIME TIME+2,100 : RETI

uRUN

TIMER INTERRUPT AT – 2.045 SECONDS
TIMER INTERRUPT AT – 4.045 SECONDS
TIMER INTERRUPT AT – 6.045 SECONDS
TIMER INTERRUPT AT – 8.045 SECONDS
TIMER INTERRUPT AT – 10.045 SECONDS

READY

The terminal used in this example runs at 4800 baud. This baud rate allows
about 45 milliseconds to print the message TIMER INTERRUPT AT –“ ”.
The resulting printed time is 45 milliseconds greater than the planned time.

5.4.20
Statement: ONTIME
[expr],[ln num]

Advertising