Remote-processing RPC-330 Manuel d'utilisateur Page 44

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 48
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 43
MULTI-MODE COUNTER SECTION 13
Page 13-2 RPC-330
short pulse is generated. The latch captures it captures
it. A latch is cleared using LINEB function.
500 A = LINEB(6,5) :REM clear counter 0 latch
510 A = LINEB(6,7) :REM clear counter 1 latch
Clear a latch befor e it is used as an inter rupt.
Program examples
This code resets counter 0 and enables its inputs. The
count is printed once a second. To see the count change,
momentarily bring "A0 IN" or "B0 IN" on P2 to ground.
When "B0 IN" is gr ounded, the count decrem ents.
10 LINEB 6,1,32
20 LINEB 6,1,64+8
30 ONTICK 1,500
40 GOTO 40
500 PRINT COUNT(0)
510 RETI
Line 20 can be shortened somewhat. 64 selects the ICR
(Input control register ) and 8 enables inputs. 72 could
have been used.
The following program example returns a frequency.
Input signal is at "A0 IN".
100 LINEB 6,1,32
110 LINEB 6,1,72 : REM enable inputs
120 ONTICK 1,500
130 IDLE
140 GOTO 130
500 A=COUNT(0) : REM get count
510 C=A-B : REM figure change from last time
520 PRINT "Frequency = ",A
530 B=A
530 RETI
The first frequency read will always be a bit off. This is
because of the time required to initialize ONTICK.
Subsequent readings are more accurate.
Accuracy is increased by stretching ONTICK to every
10 seconds. This is necessary when higher accura cy is
needed.
Other factors affecting accurate readings in this program
include serial comm unications and ONIT R statement.
A problem with this routine is periodically, a large
negative number is returned. This is because the
multimode counter has rolled over. This is corrected by
periodically resetting the CNTR or transfer ring P R to
CNTR. Refer to the data sheet, Appendix A for counter
operating modes.
The next program sets up the LS7166 to cause an
interrupt when a preset number of counts (100) is
reached. H2[3-4] is jumpered to interrupt on a borrow.
10 LINEB 6,1,132
20 COUNT 0,100 : REM write to CNTR
30 LINEB 6,1,8 : REM transfer PR to CNTR
40 LINEB 6,1,72 : REM enable A/B counters
50 ONITR 0,500
100 PRINT COUNT(0) : REM print progress
110 GOTO 100
500 PRINT "In Interrupt"
510 RETI
Line 10 sets OCCR to divide by N. Line 50 enables
INT 0 interrupt. Line 100 prints the counter. W hen
pulses are applied to the A input, the count will go
down. W hen 100 pulses are detected at A input, the
message in line 500 is printed.
To use INT 1, jumper H3[3-4] and change the LINEB
address to 3. Change references to count and INT to 1.
This next example interfaces to a quadrature encoder in
x1 mode. An interrupt is generated when the counter
crosses 0. Jumper H2[9-10] for INT0 and H3[9-10] for
INT1. The program below is for counter 0. Set
variable B to 3 and C to 1 for counter 1 in line 5.
The counter is pre-loaded to 150. W hen the enco der is
turned so the count goes down to 0, an interr upt is
generated.
5 B = 1 : C=0
10 LINEB6,B,32 : REM master counter reset
20 LINEB6,B,128 : REM set CYBW active
30 LINEB6,B,193 : REM enable quadrature x1 mode
40 LINEB6,B,72 : REM enable a/b counters
60 COUNTC,150 : REM load PR with 150
70 LINEB 6,B,8 : REM load PR into count reg
80 A=LINEB(6,B+4) : REM reset interrupt latch
100 ONITR C,500 : REM set up interrupt
110 ONTICK .5,1000 : REM print out COUNT
120 GOTO 120
500 PRINT "Interrupt count",COUNT(C)
510 A = LINEB(6,B+4) :REM Reset int. latch
520 RETI
1000 PRINT COUNT(C)
1010 RETI
Vue de la page 43
1 2 ... 39 40 41 42 43 44 45 46 47 48

Commentaires sur ces manuels

Pas de commentaire