| Home |
Last Modified: 21 November 2000 |
6172 CAN Micro Controller Module AN005
This application example is not yet completely tested
64 bit input with CD 4021
This application example enables the user to use 64 CMOS digital inputs.
Eight pieces CD 4021 are used for this example.
This example uses the maximum capacity of one CANopen PDO, it can easily be expanded to 256 inputs, using 4 PDO's.
header "64 digital inputs AN005"
inputs: equ 16 ;64 inputs memory location (8 bytes)
strobe: equ 0 ;bitnummer of strobe of 4021's (OUT9)
;initialization sequence
sequence seq_0
resb strobe ;strobe inactive
shspd 1 ;SPI shifter at 1.1 µS/bit
shpat 0 ;normal data, no shifted clock
srdy ;READY output active
enasq 0 ;enable sequences
endsq
;read memory location 16..23 from 4021's
sequence seq_3,1 ;executed every 10 mS
seta strobe ;STROBE high for 7 µS
resa strobe
shom inputs+7 ;first inputs 57-64
shom inputs+6 ; inputs 49-56
shom inputs+5
shom inputs+4
shom inputs+3
shom inputs+2
shom inputs+1 ; inputs 9-16
shom inputs ; inputs 1-8
endsq
end
Assuming that all 6172 objects are in their default state, the following objects need to be adjusted (if a PDO is used):
|
1 |
Subindex |
Value |
Description |
|---|---|---|---|
|
PDO mapping of transmit PDO 1 |
|||
|
1A00h |
0 |
2 |
2 objects in transmit PDO 1 |
|
1A00h |
1 |
61200520h |
memory location 16-19 |
|
1A00h |
2 |
61200620h |
memory location 20-23 |
|
Enable PDO transmission on any change of memory location 16-23 |
|||
|
6006 |
17 |
255 |
memory location 16 |
|
6006 |
18 |
255 |
memory location 17 |
|
6006 |
19 |
255 |
memory location 18 |
|
6006 |
20 |
255 |
memory location 19 |
|
6006 |
21 |
255 |
memory location 20 |
|
6006 |
22 |
255 |
memory location 21 |
|
6006 |
23 |
255 |
memory location 22 |
|
6006 |
24 |
255 |
memory location 23 |
The 64 digital inputs now can be read by:
Copy and Paste this part direct after the declarations in the
canappl.bas program
this program can be found on the 6197 designers kit diskette or
ordered separately as service part together with one of our CAN products.
APPLICATION:
'This simple program is made for one 6172 and a 6390 as CAN bus interface
'the following assumptions are done:
'- 6390 is connected to COM2
'- 6172 ID = 1, CANbus speed = 50 kBAUD
'- assembled sequence file is "AN005.seq"
'The 64 digital inputs are read using the PDO, if the PDO isn't received
'within 5 seconds, it is requested.
'The results are displayed as a 64 bit binary string
'this continues until the user presses enter
CLS
PRINT "CD Systems 6172 AN005 DEMO program"
PRINT
Activate6390 2, 19200 '6390 works at COM2, 19200 BAUD
SetCANBUSSpeed 50 'CAN BUS at 50 kBAUD
C% = CheckSequence%(1, "AN005.seq") 'download sequence if not already done
C% = PutU8% (1, &h1A00, 0, 2) '2 objects in transmit PDO1
C% = PutU32% (1, &h1A00, 1, &h61200520) 'transmit PDO1 from memory 16-19
C% = PutU32% (1, &h1A00, 2, &h61200620) 'transmit PDO1 from memory 20-23
C% = PutU8% (1, &h6006, 16, 255) 'enable transmit PDO on any change
C% = PutU8% (1, &h6006, 17, 255)
C% = PutU8% (1, &h6006, 18, 255)
C% = PutU8% (1, &h6006, 19, 255)
C% = PutU8% (1, &h6006, 20, 255)
C% = PutU8% (1, &h6006, 21, 255)
C% = PutU8% (1, &h6006, 22, 255)
C% = PutU8% (1, &h6006, 23, 255)
SendNMTCommand (1, 1) 'node in operational state
BT = TIMER - 6 'force immediate request
PDOCOB% = (1 + 384) * 32 'tx PDO1 COB ID shifted left 5 bits
DO
' send a transmit PDO1 remote request if nothing received after 5 seconds
IF (BT + 5) < TIMER THEN
SendToCAN (CANIDS$ (PDOCOB% + &h10))
BT = TIMER
END IF
' check if the transmit PDO is received
R$ = ReceiveFromCAN$
IF LEN (R$) > 1 THEN 'anything received?
IF (CANIDR% (R$) AND &hFFE0) = PDOCOB% THEN 'PDO1 tx received?
LOCATE 10,1
FOR I% = 3 TO 10: M% = 1 '8 bytes in PDO
FOR B% = 1 TO 8 '8 inputs in a byte
IF (ASC(MID$(R$,I%)) AND M%) THEN PRINT "1"; ELSE PRINT "0";
M% = M% * 2
NEXT B%
NEXT I%
BT = TIMER
END IF
END IF
LOOP UNTIL INKEY$ = CHR$(13)
SendNMTCommand (1, 2) 'stop node
DO 'clear & ignore any received message
R$ = ReceiveFromCAN$
LOOP UNTIL R$ = ""
END