| Home |
Last Modified: 21 November 2000 |
6172 CAN Micro Controller Module AN002
This application example is not yet completely tested
14 bit analog output with AD7840
This application example enables the user to set a -3 ... 3 Volt analog output with a resolution of 0.37 mV.
The AD7840 is configured to use the 14 most significant bits of the 16 bits
it receives.
This example can be used to implement other (16 bit) D/A converters.

header "6172-AN002, 7840 D/A converter"
davalue:equ 2 ;D/A value memory location
lsbit: equ 0 ;OUT1 bit number in port A
;-------------------------------------------------------------------
initialisation sequence
sequence seq_0
seta lsbit ;ldac/sync high
shspd 1 ;SPI shifter at 1.1 µS/bit
shpat 1 ;normal data, phase shifted clock
srdy ;READY output active
;write zero to the D/A converter (sets output at 0 Volt)
ldwm 0 ;clear working register
resa lsbit ;ldac/sync low
stwm spiout ;high byte
stwm spiout ;low byte
seta lsbit ;ldac/sync high
enasq 3 ;enable sequence 3
endsq
;-------------------------------------------------------------------
;update D/A converter sequence, after a write to address DAVALUE + 1
sequence seq_3,,davalue+1
resa lsbit ;ldac/sync low
shom davalue ;msb to D/A converter
shom davalue+1 ;lsb to D/A converter
seta lsbit ;ldac/sync high
endsq ;done
;-------------------------------------------------------------------
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 |
62000208h |
memory location 2 |
|
1600h |
2 |
62000308h |
memory location 3 |
The DAVALUE can now 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 our 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 "AN002.seq"
'As long as the user enters a number, the programs sends this to the 6172
'using a 32 bit SDO write
'entering nothing (just pressing ENTER) exits the program
CLS
PRINT "CD Systems 6172 AN002 DEMO program"
PRINT
Activate6390 2, 19200 '6390 works at COM2, 19200 BAUD
SetCANBUSSpeed 50 'CAN BUS at 50 kBAUD
C% = CheckSequence%(1, "AN002.seq") 'download sequence if not already done
'because the D/A value is set with a SDO command, the node doesn't have
'to be put in operational state (NMT command)
DO
INPUT "Enter a integer value (-31768 ... 31767)"; DAVAL$
IF DAVAL$ <> "" THEN
DAVAL& = VAL(DAVAL$)
PRINT
PRINT "Transfer ";
IF PutSDOObject(1, &H6320, 1, MKL$(DAVAL&)) = 0 THEN PRINT "un";
PRINT "succesfull"
PRINT
END IF
LOOP UNTIL DAVAL$ = ""
END