Home

Last Modified: 21 November 2000

6172 CAN Micro Controller Module AN003


This application example is not yet completely tested

24 bit analog input with AD7712

This application example enables the user to use a -10...10Volt analog input with a resolution of 1.2µV.

The AD7712 is configured to use its 10V input, it is default set to a sample rate of 10 Hz (recommended for highest precision).

By tying the DRDY output of the 7712 to (level sensitive) IN8 of the 6172, this application will automatically transmit a PDO every 100 mS (if the analog input value has changed).


Schematic diagram

  


Sequence assembler source code
        header  "AD7712 A/D converter AN003"
 
advalue:equ     0               ;A/D value memory location 
config: equ     4               ;A/D converter configuration value
 
a0bit:  equ     1               ;A0  (AD7712) input bit number (OUT10)
tfsbit: equ     2               ;TFS (AD7712) input bit number (OUT11)
rfsbit: equ     3               ;RFS (AD7712) input bit number (OUT12)
rdybit: equ     7               ;DRDY (AD7712) output bit number (IN8)
 
;default configuration (a 24 bit number) will select:
;bit
;23-21: operating mode   = %001: active self calibration, normal mode when
;                                finished (after 9 sample cycles)
;20-18: gain             = %000: gain = 1 (full scale = 10V)
;   17: channel          =    1: select AIN2 input
;   16: power down       =    0: normal operation
;   15: word length      =    1: output word is 24 bits
;   14: unused
;   13: burnout current  =    0: no burnout current (AIN1 input)
;   12: bipolar/unipolar =    0: -10...10V input
;11- 0: filter selection = $7A1: filter/sample rate = 10Hz
 
configh:equ     %00100010
configm:equ     %1000 shl 4 + $7
configl:equ     $A1
 
;initialization sequence 
 
        sequence seq_0 
 
        setb    tfsbit          ;TFS inactive state
        setb    rfsbit          ;RFS inactive state
        shspd   1               ;SPI shifter at 1.1 µS/bit 
        shpat   0               ;normal data, no shifted clock 
        srdy                    ;READY output active 
 
        ldwc    configh         ;set default config value in
        stwm    config + 1      ;lower 3 bytes of the config location
        ldwc    configm
        stwm    config + 2
        ldwc    configl
        stwm    config + 3
        
        call    seq_3           ;write config to AD7712, start self-calibration
        
        seqcl   seq_4,0,rdybit  ;activate sequence 2 on low level of IN8
        enasq   0               ;enable sequences
        endsq
 
;write config to AD7712
 
        sequence seq_3,,config+3 ;start on write of config+3
 
        resb    a0bit            ;A0 low to access control register
        resb    tfsbit           ;TFS active
        shom    config+1         ;write current config to AD7712
        shom    config+2
        shom    config+3
        setb    tfsbit           ;TFS inactive, calibration now starts
        endsq
 
;read sample from AD7712, this sequence is started when IN8 (DRDY) is low
 
        sequence seq_4
        
        setb    a0bit           ;A0 high to access data register
        resb    rfsbit          ;RFS active
        shim    advalue         ;read 24 bit result into advalue
        shim    advalue+1
        shim    advalue+2
        setb    rfsbit          ;RFS inactive, DRDY (IN8) will go high
        endsq
        
        end

CANopen object dictionary configuration

Assuming that all 6172 objects are in their default state, the following objects need to be adjusted.

 

Index

Subindex

Value

Description

Receive PDO 1 is set for a 32 bits unsigned integer with the AD7712 configuration in the lower 24 bits

1600h

0

1

1 object in receive PDO 1

1600h

1

63200220h

memory location 4 - 7

Transmit PDO 1 should be treated as a signed 32 bits integer with the A/D value in the higher 24 bits

1A00h

0

1

1 object in transmit PDO 1

1A00h

1

61200120h

memory location 0 - 3

Enable interrupt on change of memory locations 0 - 2

6006h

1

255

enable interrupt on any change of location 0

6006h

2

255

enable interrupt on any change of location 1

6006h

3

255

enable interrupt on any change of location 2

The AD7712 configuration can be changed by:

The AD7712 sample can be read by:


Example BASIC program

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 "AN002.seq"
 
'The 6172 will be enabled to send its PDO on any change, the PDO will be
'requested if no PDO was received within 5 seconds.
 
'pressing ENTER exits the program
 
CLS
PRINT "CD Systems 6172 AN003 DEMO program"
PRINT
 
Activate6390 2, 19200                   '6390 works at COM2, 19200 BAUD
SetCANBUSSpeed 50                       'CAN BUS at 50 kBAUD
 
C% = CheckSequence%(1, "AN003.seq")     'download sequence if not already done
 
C% = PutU8% (1, &h1600, 0, 1)           '1 object in receive PDO1
C% = PutU32% (1, &h1600, 1, &h63200220) 'receive PDO1 to memory 4..7
 
C% = PutU8% (1, &h1A00, 0, 1)           '1 object in transmit PDO1
C% = PutU32% (1, &h1A00, 1, &h61200120) 'transmit PDO1 from memory 0..3
 
C% = PutU8% (1, &h6006, 1, 255)         'enable transmit PDO on any change
C% = PutU8% (1, &h6006, 2, 255)
C% = PutU8% (1, &h6006, 3, 255)
 
SendNMTCommand (1, 1)                   'node in operational state
 
BT = TIMER
 
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?
       AD& = CVL (MID$(R$, 3, 4))                 'get signed AD value
       AD& = AD& / 256                            'shift right 8 bits
       V#  = AD& / 2^23 * 10                      'convert to voltage
 
       PRINT USING "D/A value: ########  = ##.######Volt"; AD&, V#
       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