[INTEL NAVIGATION HEADER]

Assembly Language A/D buffering routine

Assembly Language A/D buffering routine.

$pagelength(50)

A2D_Buffering_Utility module stacksize(12)
;
; Intel Corporation, July 16, 1985
; by Dave Ryan, Intel Applications Engineer
;
; This utility fills a memory buffer with A/D conversion results. The
; conversions are done under interrupt control, and are initiated when
; A2D_BUFF_Util is called. The results of the conversions are placed
; in one of two buffers, called BUFF0 and BUFF1.
;
; This utility provides options for the selection of the buffer lengths, data
; format, sample period, conversion channel and time base. The utility also
; has a donwload routine that will load either buffer into a register file
; buffer. Output formats can also be chosen for the downloaded buffer. The
; data can be formatted as signed or unsigned linear or paried arrays.
;
; RUN-TIME OPTIONS
;
; Rather than use the STACK to pass controls, this utility gets its directions
; from 2 control words in memory. The utility expects that its control words
; are valid at the time A2D_BUFF_Util is called and remain valid throughout
; A/D interrupt executions and downloads. The control words are:
;
; Sample_Period ; WORD ; The time between samples in timer counts
; ; where the timer used has been specified
;
;
; Control_A2D ; BYTE ; Control information for the utility:
; BIT#
;
; ; 0-2 ; Channel Number
;; ; 3 ; Signed Result/Unsigned Result#
; ; 4 ; Convert/Download#
; ; 5 ; BUFF1/BUFF0# for conversions
; ; BUFF0/BUFF1# for downloads
; ; 6 ; Linear/Paired#
; ; 7 ; Converter BUSY/IDLE#

$EJECT
;
; The following is a table of equates that can be used to simplify the
; bit diddling requirements. If you are not running conversions concurrently
; with downloads, always LDB Control_A2D with the following command then
; ORB Control_A2D with the channel number you wish to convert if you are
; starting a conversion.
;
; Once the utility is called, care must be taken when Control_A2d is
; modified. You can cause downloads to occur while conversions are running,
; but you cannot start conversions during a download. To do this, ORB to the
; control byte with the appropriate bits set. Do NOT change the BUFF bit or
; the BUSY bit. Just set the download bit and set the data format bits to the
; correct values.
;
; The BUFF bit has opposite definitions for conversions and downloads. This
; allows conversions to be done into BUFF0 while downloads come from BUFF1, and
; vice versa.
;
; A2D UTILITY COMMANDS_____________________________________________________
;
;con_b0 equ 00010000b;convert to BUFF0
;con_b1 equ 00110000b; " BUFF1
;
;dump_b0_l_u equ 01100000b; download BUFF0 as LINEAR USIGNED data
;dump_b1_l_u equ 01000000b; " BUFF1 " " " "
;dump_b0_p_u equ 00100000b; " BUFF0 " PAIRED " "
;dump_b1_p_u equ 00000000b; " BUFF1 " " " "
;dump_b0_l_s equ 01101000b; download BUFF0 as LINEAR SIGNED data
;dump_b1_l_s equ 01001000b; " BUFF1 " " " "
;dump_b0_p_s equ 00101000b; " BUFF0 " PAIRED " "
;dump_b1_p_s equ 00001000b; " BUFF1 " " " "
;__________________________________________________________________________
$eject
;
; ASSEMBLY-TIME OPTIONS
;
; The base addresses and length of each conversion buffer and the destination
; buffer are DECLARED EXTRNal in this utility. Other options such as selection
; of the timer used as a timebase, the length of the buffer, and the effective
; number of bits in the reported result are set at assembly time through use
; of EQUates in this module.
;
; The following parameters need to be provided at assembly or link time.
; The buffer bases are declared EXTRNal by this utility, while the buffer
; length shift count and HSO commands are EQUated.
;
; BUFF0_BASE ; The starting address of BUFF0
; BUFF1_BASE ; The starting address of BUFF1
; DEST_BUFF_BASE ; The starting address of the download
; ; target buffer.
;
; BUFF_LENGTH ; The number of SAMPLES that each
; ; buffer must hold. must be >1 and <256
;
; Shift_count ; The number of times that the conversion result is
; ; to be shifted right from its natural left justified
; ; position. Setting a shift count greater than 6 will
; ; result in lost bits to the right. Rounding is NOT
; ; done.
;
; CLOCK ; Specify as either TIMER1 or T2CLK. This is the
; ; timebase used for conversions.
;
; Samples are stored as words in the buffers. The program stores
; conversions linearly in BUFF0 and BUFF1, and linearly or paired in the
; destination buffer as selected. If the download is to be paired, the first
; sample is placed in location DEST_BUFF_BASE, the second sample is placed in
; location (DEST_BUFF_BASE + BUFF_LENGTH), the third in (DEST_BUFF_BASE + 2),
; the fourth in (DEST_BUFF_BASE + 2 + BUFF_LENGTH), etc.
;
$eject
;
;NOTES ON EXECUTION
;
; When a utility call directs the initiation of a set of A2D conversions, the
; first conversion is begun at approximately one sample time plus 50 state
; times from when the utility was called. This assumes that no interrupts are
; present.
;
; The conversion busy bit is set approximately 50 state times after a call
; to the utility, if the convert bit was set in the A2D_Control byte. The
; busy bit is cleared after all conversion results have been stored in the
; result buffer designated (BUFF0 or BUFF1).
;
; Take great care in modifying the A2D_Control byte to do a download while
; conversions are taking place. You can never download a buffer that is
; being converted into. The results would be invalid.
$eject

RSEG

EXTRN BUFF0_BASE, BUFF1_BASE, DEST_BUFF_BASE
EXTRN ad_command, ad_result_lo, ad_result_hi
EXTRN hso_command, hso_time,sp

BUFF_LENGTH EQU 64
Shift_Count EQU 1
CLOCK EQU TIMER1

; set up hso commands for correct timer **********************************

TIMER1 equ 0AH
T2CLK equ 0CH

MASK equ (10h*CLOCK)AND(40h)

Start_A2D equ (00001111b)OR(MASK)
;start a2d based on timer 1, no interrupt

HSO_0_Low equ (00000000b)OR(MASK)
; make hso.0 low based on timer1 no interrupt

HSO_0_High equ (00100000b)OR(MASK)
; make hso.0 hi based on timer1 no interrupt

; set up storage *******************************************************

adudtemp0: DSW 1; temp register for download calls

aductemp0: DSW 1; temp registers for conversion calls
aductemp1: DSW 1
top_of_buffer: DSW 1
sample_count: DSB 1

Control_A2D: DSB 1; the byte that controls the utility execution
DForm equ 3 ; Signed/Unsigned#
Con_Dwn equ 4 ; Convert/Download#
B0_B1 equ 5 ; Buff1/Buff0# for conversions
; Buff0/Buff1# for downloads
Lin_Par equ 6 ; Linear/Paired#
Busy equ 10000000B ; Bit 8
$eject

Sample_Period: DSW 1; the word that specifies the number of clock ticks
; that elapse between each sample

PUBLIC Control_A2D, Sample_Period

OSEG

src_ptr: DSW 1; some overlayable temp registers
temp set src_ptr:WORD
dest_ptr: DSW 1
loop_count: DSW 1

CSEG at 2002h

PUBLIC A2D_DONE_Vector

DCW A2D_DONE_Vector

CSEG

PUBLIC A2D_BUFF_Util

Load_HSO_Command MACRO var ; Macro to load HSO

LDB hso_command,#var
LD hso_time,aductemp0
ENDM
$eject

A2D_BUFF_Util:

JBS Control_A2D, Con_Dwn, Convert ; Select convert or download
Download:
LD src_ptr,#BUFF1_BASE
JBC Control_A2D, B0_B1, Set_Data_Format

Download_BUFF0:
LD src_ptr,#BUFF0_BASE

Set_Data_Format: ; Choose linear or paired
LD dest_ptr, #DEST_BUFF_BASE
LDB loop_count,#BUFF_LENGTH
JBS Control_A2D, Lin_Par, Linear_data_loop

PAIRED: SHRB loop_count,#1 ; The paired data routine uses 1/2
; as many loops as the unpaired
Paired_Data_loop:
LD adudtemp0,[src_ptr]+ ; Move even word
ST adudtemp0,[dest_ptr]
ADD dest_ptr,#BUFF_LENGTH ; Length = # of words = 1/2 # of bytes

LD adudtemp0,[src_ptr]+ ; Move odd word
ST adudtemp0,[dest_ptr]+
SUB dest_ptr,#BUFF_LENGTH

DJNZ loop_count, Paired_Data_loop ; Loop until done

CALL Convert_Data
RET

Linear_Data_loop: ; Move data linearly
LD adudtemp0,[src_ptr]+
ST adudtemp0,[dest_ptr]+

DJNZ loop_count, Linear_Data_loop ; Loop until done

CALL Convert_Data
RET
$eject

Convert_Data: ; Convert the data in the destination buffer

LD loop_count,#BUFF_LENGTH
LD src_ptr,#DEST_BUFF_BASE

Again: LD adudtemp0,[src_ptr]
ANDB adudtemp0,#11000000b
JBC Control_A2D, DForm, Unsigned_Result

Signed_Result:
SUB adudtemp0,#7fe0H
SHRA adudtemp0,#Shift_Count
BR Replace_Sample

Unsigned_Result:
SHR adudtemp0, #Shift_Count

Replace_Sample:
ST adudtemp0,[src_ptr]+
DJNZ loop_count,Again ; Loop until done

RET

Convert: ;; Prepare to Start Conversions

PUSHF

ORB Control_A2D, #Busy ; set converter busy bit

LDB sample_count,#BUFF_LENGTH - 1
LD top_of_buffer,#BUFF0_BASE
LD aductemp1,#(BUFF0_BASE + 2*BUFF_LENGTH)

JBC Control_A2D, B0_B1, Start_Conversions
LD top_of_buffer,#BUFF1_BASE
LD aductemp1,#(BUFF1_BASE + 2*BUFF_LENGTH)
$eject

Start_Conversions:

ANDB ad_command,Control_A2D,#00000111b ;load channel number

ADD aductemp0,CLOCK,Sample_Period ;start first conversion
;one sample time from
;now

Load_HSO_Command Start_A2D ; Start A2D at Time=aductemp0

POP temp ; get a copy of the psw

Load_HSO_Command HSO_0_high ; set hso.0 high at conversion
; start time for external S/H

OR temp,#202h ; enable a2d interrupts

ADD aductemp0,Sample_Period

Load_HSO_Command Start_A2D ; start second convertion one
; sample time from the first

PUSH temp ; put psw back on stack

Load_HSO_Command HSO_0_low ;lower hso.0 for external S/H

POPF
RET
$eject
CSEG

A2D_DONE_Vector: ; A/D INTERRUPT ROUTINE
PUSHF

STB ad_result_lo,[top_of_buffer]+
STB ad_result_hi,[top_of_buffer]+
ANDB ad_command,Control_A2D,#00000111b ;load channel number

DJNZ sample_count, Sample_Again
INCB sample_count

CMP top_of_buffer,aductemp1 ; Check top of buffer
BE Top_of_buffers
POPF
RET

Sample_Again:
ADD aductemp0,Sample_Period ; Set next sample time
CMP top_of_buffer,aductemp1 ; Check top of buffer
; for later jump
Load_HSO_Command Start_A2D

JBC sample_count,0,Make_HSO_High

Make_HSO_low:
nop ; wait 8 states after HSO load
Load_HSO_Command HSO_0_Low
; Load for change of HSO to trigger S/H
BE Top_of_buffers
POPF
RET

Make_HSO_high:
Load_HSO_Command HSO_0_High ; Load for change of HSO to trigger S/H

BE Top_of_buffers
POPF
RET

Top_of_buffers:
ANDB Control_A2D,#NOT(Busy) ; Clear converter BUSY bit
POPF
RET
END

Free Web Hosting



Legal Stuff © 1997 Intel Corporation