Remote Processing CAMBASIC User Manual

Page 193

Advertising
background image

Event Multitasking - 4

Theoretically, a 100 Hz square wave can be counted. However, due to sample timing variations (dependent upon other
multitasking events), the maximum square wave frequency rate should be 80 Hz. To obtain the full frequency response,
the minimum time the signal is low or high is 8 mS. The software is written to reject high frequency noise.

Defining a Counter

Setting up a counter is done w ith the CON FIG C OUN T statement. The syntax is:

CONFIG COUNT counter, address, bit [,preset] [,AUTO]

Where:
counter is the counter number which may be 0 through 7.

address is the I/O address o f the port (of 8 bits) that you w ant to use for the input. This will
typically be an 8 2C55 po rt.

bit is the particular bit or line of the port addressed. The range is 0 through 7.

preset is an optional parameter that tells the counter to notify the system when a preset count has
been reached. The program will branch if an ON CO UNT statement has been executed. The value
may range from 1 to 65,656.

AUTO is an optional parameter. W ithout AUTO, the counter will continue to increment after the
preset count is reached. W hen AUTO is specified, the counter will reset to zero after reacting the
preset count. This way no counts are m issed while the subroutine branch is executing.

Background Tasking is Much Faster

The data that you enter with the CONF IG COU NT and ON COU NT statements is compiled into object code. Thus, the
execution time on the 200 Hz (100 times in 9 MHz systems) clock tick is only microseconds, rather than the milliseconds
t ha t i t w o ul d t ak e in BA S IC .

Modes of Oper ation

At there are tw o modes of opera tion. T he first is the po lled mode in which cou nts are ac cumulate d and re ad from time to
time by the program. When the counter reaches 65, 535, the next count will roll the counter over to zero. This mode
requires only that CONF IG COUN T and START C OUNT be executed in that order. A short example would be:

10 CONFIG COUNT 5,0,1,2000,AUTO
20 START COUNT 5
.
.

Line 10 configures counter 5 to read bit 1 of address 0 as an input. When the count reaches 2000,
the counter will autom atically rese t.

L i ne 2 0 s ta r ts c ou n te r o pe r a ti on . T h es e tw o li ne s do n ot ne e d t o b e ad ja c en t i n t he p r og r a m .
However , line 20 must be executed after line 10.

Advertising