| Home |
Last Modified: 21 November 2000 |
6172 CAN Micro Controller Module AN004
This application example is not yet completely tested
64 bit digital output with CD 4094
This application example enables the user to use 64 CMOS digital outputs.
Eight pieces CD 4094 are used for this example. These standard CMOS devices can deliver a maximum of 1mA per output.
This example uses the maximum capacity of one CANopen PDO, it can easily be expanded to 256 outputs, using 4 PDO's.
header "64 digital outputs AN004"
outputs:equ 32 ;64 outputs memory location (8 bytes)
enable: equ 7 ;output enable of 4094's (OUT8)
strobe: equ 3 ;strobe of 4094's (OUT4)
;initialization sequence
sequence seq_0
resa enable ;output enable inactive
resa strobe ;strobe inactive
shspd 1 ;SPI shifter at 1.1 µS/bit
shpat 0 ;normal data, no shifted clock
srdy ;READY output active
call seq_3 ;write memory location 32-39 to 4094's
seta enable ;enable outputs
enasq 0 ;enable sequences
endsq
;write memory location 32..39 to 4094's
sequence seq_3,,outputs+7 ;start on write of location 39
shom outputs+7 ;first outputs 57-64
shom outputs+6 ; outputs 49-56
shom outputs+5
shom outputs+4
shom outputs+3
shom outputs+2
shom outputs+1 ; outputs 9-16
shom outputs ; outputs 1-8
seta strobe ;STROBE high for 7 µS
resa strobe
endsq
end
Assuming that all 6172 objects are in their default state, the following objects need to be adjusted (if a PDO is used):
|
Index |
Subindex |
Value |
Description |
|---|---|---|---|
|
1600h |
0 |
2 |
2 objects in receive PDO 1 |
|
1600h |
1 |
63200920h |
memory location 32-35 |
|
1600h |
2 |
63200A20h |
memory location 36-39 |
The 64 digital outputs now can be set 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 "AN004.seq"
'the 64 digital output values are stored in the DIG% table
'all digital outputs are randomly set to 1 or 0 and then
'send to the 6172 (via one PDO)
'this continues until the user presses enter
DIM DIG%(64)
RANDOMIZE (-TIMER)
CLS
PRINT "CD Systems 6172 AN004 DEMO program"
PRINT
Activate6390 2, 19200 '6390 works at COM2, 19200 BAUD
SetCANBUSSpeed 50 'CAN BUS at 50 kBAUD
C% = CheckSequence%(1, "AN004.seq") 'download sequence if not already done
C% = PutU8% (1, &h1600, 0, 2) '2 objects in receive PDO1
C% = PutU32% (1, &h1600, 1, &h63200920) 'receive PDO1 to memory 32-35
C% = PutU32% (1, &h1600, 2, &h63200A20) 'receive PDO1 to memory 36-39
SendNMTCommand (1, 1) 'node in operational state
DO
' random values to DIG% and print them
LOCATE 10, 1
FOR I% = 1 TO 64
DIG%(I%) = CINT(RND(1))
PRINT HEX$(DIG%(I%));
NEXT
' accumulate 64 digital values into 8 byte string
PDO$ = ""
FOR I% = 1 to 56 step 8: P% = 0: B% = 0
FOR J% = 1 to 8
IF DIG% (I% + J% - 1) = 1 then P% = P% + B%
B% = B% * 2
NEXT J%
PDO$ = PDO$ + CHR$(P%)
NEXT I%
' send PDO to 6172
PDOCOB% = (1 + 512) * 32 'rx PDO1 COB ID
SendToCAN (CANIDS$ (PDOCOB% + 8) + PDO$)
R$ = ReceiveFromCAN$ 'ignore any CAN message
LOOP UNTIL INKEY$ = CHR$(13)
SendNMTCommand (1, 2) 'stop node
END