Remote-processing RPC-2350 Manuel d'utilisateur Page 60

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 83
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 59
CHAPTER 14 MULTI-MODE COUNTER
14-5
inputs to count
130 on tick 0,1 gosub 1000
140 c = 1 :'initialize loop counter
200 bit 0,0,0
210 bit 0,0,1 :'rising edge increments
count
220 a=count(8)
230 if a <> c then print "Count error"
: end
240 inc c
250 goto 200
1000 print count(8) :'show current
count
1010 return
The following example returns a frequency. Input signal
is at J2-9 (A input)
10 OUT &F1,32 :’RESET COUNTER
20 OUT &F1,72 :’ENABLE INPUTS
30 ON TICK 0,1 GOSUB 1000
40 GOTO 40 :’HANG OUT HERE
1000 A = COUNT(8) :’GET COUNT
1010 C = A-B :’FIGURE CHANGE FROM
LAST TIME
1020 PRINT “Frequency = “;a
1030 B = A
1040 RETURN
The first frequency read will be off, due to initialization.
Accuracy is increased by stretching reading to every 10
seconds. Other factors affecting accuracy include serial
communications and other interrupt processing.
The counter will not miss counts. Due to interrupt
latency, some counts will be lar ger than o thers. It is
several counts off at about 8 kHz. If you average the
counts it will be accurate.
Another problem with this routine is periodically, a large
negative number is returned. This is because the counter
has rolled over. This is cor rected by periodically
resetting the CNTR.
Program C NTR2. BAS sets up the LS7166 to cause an
interrupt when a preset number of counts is reached.
W7[2-3] is jumpered to interrupt on a borrow. To
reload the count, bring the LDCTR line (J10-6) low.
When the count is 0 again, another interru pt is
generated. You can also count up provided you bring
counter line ‘B’ (J10-8) low while counter line ‘A’ is
high.
CNTR3.BAS interfaces to a quadrature encoder in x1
mode. The counter is pre-loaded to 100.
NOTE: See CAMBASIC resolution limit below.
CAM BASIC resolution lim it
CAM BASIC stores num bers to 7 digits + exponent.
The counter outputs numbers to 8 digits. This means
that when the counter counts down from 0 to 1677215,
CAM BASIC will store it as 1.67721E+ 7. T he last digit
is dropped.
You can compensate for this easily by introducing an
offset. Preload the counter to some number, say
100,000. This becomes the zero point. W hen the count
is below this number, the counter is in “negative”
territory. See CNTR4.BAS
Program CNTR5.BAS r eads the counter in Basic (not
using CO UN T(8) and prints the value in hex for mat.
This routine can be useful when an external device
triggers the LCTR line (J10-6) to transfer the count to a
latch. The count at that time can be read.
MEASURING PULSE WIDTH
You can measure pulse widths with 217 nano-Second
precision. Widths can be as long as 3.64 Seconds using
the counter input at J10.
There are limitations to measuring pulse widths. Below
lists the major ones.
The pulse repetition r ate must be slower than the time it
takes CAMBASIC to respond to it. As a guide, the
pulse repetition rate should be less than 100 Hz.
Measuring a 50 micro-second signal every second is
easy. Measu ring a 500 micro-second signal every m illi-
second is difficult, if not impossible.
Only logic low pulses are measured. If a high pulse
width is desired, invert the input signal. See figure
below.
Vue de la page 59
1 2 ... 55 56 57 58 59 60 61 62 63 64 65 ... 82 83

Commentaires sur ces manuels

Pas de commentaire