Using the LTC1298 or SP8538 A/D
Converters to Measure Voltage

; program to read an LTC1298
DEF tic62_c
LIB fbasic.lib


DEF ltc_cs pin_a1
DEF ltc_clk pin_a3
DEF ltc_data pin_a4


LIB ltc1298.lib


FUNC none main
BEGIN
   rs_param_set( debug_pin )
   pin_high( ltc_cs )
   pin_low( ltc_clk )

   rep
      con_out( read_ltc1298( 1b ))
      con_out_char( 13b )
   loop
ENDFUN
; Functions to control A/D 
; These functions rely on three defines to work properly
;       cs   =  Chip Select pin    'Must have a separate line  '
;       clk  =  Clock control pin  'Can share a data line with other device '
;       data =  data pin           'Can share a data line I.E. a LCD'


; Routine to read a data from an LTC1298 or LTC1288 A/D chip

FUNC word read_ltc1298
    PARAM byte config           ; This value indicates mode and channel
                                ; for the A/D chip.
                                ; bit 7 = mode ( 0=single end, 1=differential)
                                ; bit 1-6 = channel select
                                ; bit 0 = polarity for differential or lsb
                                ;         channel select for single ended
    LOCAL byte count 0b
BEGIN
    pin_low( ltc_clk )
    pin_low( ltc_cs )
    pin_high( ltc_data )                ; start bit
    pulse_out_high( ltc_clk, 10w )
    IF b_and( config, 0y10000000b )       ; do we want a differential conversion
        pin_low( ltc_data )
    ELSE
        pin_high( ltc_data )
    ENDIF

    pulse_out_high( ltc_clk, 10w )
    IF b_and( config, 1b )                ; select channel or polarity
        pin_high( ltc_data )
    ELSE
        pin_low( ltc_data )
    ENDIF

    pulse_out_high( ltc_clk, 10w )
    pin_high( ltc_data )                ; use msb first format
    pin_high( ltc_clk )                 ; clock in the msbf bit
    =( count, pin_in( ltc_data ))       ; make data line an input
    pin_low( ltc_clk )                  ; return clock to low state

;    delay( 10w )                        ; settling delay

    =( count, 0b )
    =( exit_value, 0w )                 ; get data loop ready
    REP
        pulse_out_high( ltc_clk, 10w )  ; clock for next data bit
        =( exit_value, <<( exit_value )); shift exit word to the left
        IF pin_in( ltc_data )
            ++( exit_value )
        ENDIF

        ++( count )
    UNTIL ==( count, 12b )

    pin_high( ltc_cs )
ENDFUN

 

Protean Logic Inc. Copyright 05/06/04         Top of Page