ENPM808B Instructor: Nam Sun Wang Page 1 ================================================================================ 2 Registers (DATA IN-OUT and COMMAND-STATUS) used in DT2801 (Default BASE address for the I/O ports: 2EC) |------------BASE-----------| |----------BASE+1-----------| ...Address +----------------+----------------+----------------+----------------+ |DATA IN (WRITE) |DATA OUT (READ) |COMMAND (WRITE) | STATUS (READ) |...Register +----------------+----------------+----------------+----------------+ STATUS REGISTER Description ------------------------------------------------------------------------------ bit 0: Data Out Ready (Check this bit for 1 before reading from DATA OUT Register) bit 1: Data In Full (Check this bit for 0 before writing to DATA IN Register) bit 2: Ready (Check for 1 before issuing a new command to COMMAND Register) bit 3: Command (The last byte was written to COMMNAD Register) bit 4: Not Used bit 5: Not Used bit 6: Not Used bit 7: Composite Error (Check for 0 to ensure a successful completion) COMMAND REGISTER Description ---------------------------- bit 0: OPCODE bit 1: OPCODE bit 2: OPCODE bit 3: OPCODE bit 4: DMA bit 5: Continuous bit 6: External Clock bit 7: External Trigger General Rules for Reading and Writing: * Wait for STATUS REGISTER to turn to 5 before reading from DATA * Wait for STATUS REGISTER to turn away from 2 before writing to DATA * Wait for STATUS REGISTER to turn to 4 before writing to COMMAND ENPM808B Instructor: Nam Sun Wang Page 2 ================================================================================ FUNCTION R/W PARAMETER REGISTER -------------------------------------------------------------------------------- Read A/D Immediate W X0001100 (CHex, 12Dec) C W gain Din W channel Din R L byte Dout R H byte Dout Set A/D Parameters (Block) W 00001101 (DHex, 13Dec) C W gain Din W start channel Din W end channel Din W # conversitons, L byte Din W # conversitons, H byte Din Read A/D (Block) W XXXX1110 (EHex, 14Dec) C R L byte Dout R H byte Dout (R L byte Dout) (R H byte Dout) .... Repeat .... Write D/A Immediate W X0001000 (8Hex, 8Dec) C W channel Din W L byte Din W H byte Din (W L byte Din) if channel=2 (W H byte Din) Set D/A Parameters (Block) W 00001001 (9Hex, 9Dec) C W channel Din W # conversitons, L byte Din W # conversitons, H byte Din Write D/A (Block) W XXXX1010 (AHex, 10Dec) C W L byte Din W H byte Din (W L byte Din) if channel=2 (W H byte Din) -------------------------------------------------------------------------------- Set Digital Port for Input W X0000100 (4Hex, 4Dec) C W port Din Set Digital Port for Output W X0000101 (5Hex, 5Dec) C W port Din Read Digital Port Immediate W X0000110 (6Hex, 6Dec) C W port Din R DIO data Dout (R DIO data Dout) if port=2 Write Digital Port Immediate W X0000111 (7Hex, 7Dec) C W port Din W DIO data Din (W DIO data Din) if port=2 -------------------------------------------------------------------------------- Set Internal Clock Period W 00000011 (3Hex, 3Dec) C W period, L byte Din W period, H byte Din Read Error Register W 00000010 (2Hex, 2Dec) C R error register, L byte Dout R error register, H byte Dout Reset W 00000000 (0Hex, 0Dec) C Clear Error W 00000001 (1Hex, 1Dec) C Stop W 00001111 (FHex, 15Dec) C Test W X0001011 (BHex, 11Dec) C -------------------------------------------------------------------------------- ENPM808B Instructor: Nam Sun Wang Page 3 ================================================================================ Parameter Definitions: ================================================================================ Gain Byte Value A/D, D/A, and DIO Channel Range ----------------- ------------------------------- # Conversions: 3-65535 1 0 0-15 ... SE A/D Clock Period: 2-65535 2 1 0-7 ... DI A/D Byte value=2.5us 4 2 0-2 ... D/A (2 means 0&1) Recommended=100us 8 3 0-2 ... DIO (2 means 0&1) Default=1000us Bit Read Error Register (COMMAND #: 02Hex) -------------------------------------------- 0 Reserved 1 Command Overwrite Error 2 Clock Set Error 3 Digital Port Select Error 4 Digital Port Set Error 5 DAC Select Error 6 DAC Clock Error 7 DAC # Conversions Value Error 8 A/D Channel Error 9 A/D Gain Error 10 A/D Clock Error 11 A/D Multiplexer Error 12 A/D # Conversions Value Error 13 Data Where Command Expected Error 14 Reserved 15 Reserved Divide a DEC value into H and L bytes: HIGH = INT(VALUE/256) LOW = VALUE - HIGH*256 Combine H and L bytes into a DEC value: VALUE = HIGH*256 + LOW ENPM808B Instructor: Nam Sun Wang Page 1 ================================================================================ A/D CONVERSION SUBROUTINES FOR DT2801 (ADDA.ASM & ADDA.OBJ) ================================================================================ --------------------------------------------------------------------------- ADIN00(CHAN,GAIN,VALUE) INTEGER*2 CHAN,GAIN,VALUE Read A/D one time from channel number CHAN and put the readout into VALUE. CHAN is in the range 0-15 for Single-End and 0-7 for Double-End. GAIN is 0, 1, 2, or 3 (corresponding to 10,5,2.5,1.25 volts full scale reading). VALUE will be from 0 to 4095 depending on the input voltage. Time needed to execute the subroutine is about 1 millisec. --------------------------------------------------------------------------- ADIN01(NUM,CHAN,GAIN,VALUE) INTEGER*2 CHAN,GAIN INTEGER*4 VALUE Same as ADIN00 but read the channel NUM times and put the total into VALUE. --------------------------------------------------------------------------- ADIN02(CHAN1,CHAN2,GAIN,VALUES) INTEGER*2 VALUES(*) Read a range of channels (from CHAN1 TO CHAN2) and put the values into VALUES. --------------------------------------------------------------------------- RESADC Reset the data translation board and set digital port zero for output. --------------------------------------------------------------------------- DAOUT0(CHAN,VALUE) INTEGER*2 CHAN,VALUE Output a voltage to D/A channel number CHAN. CHAN is 0 or 1. --------------------------------------------------------------------------- DAOUT1(VALUE0,VALUE1) INTEGER*2 VALUE0,VALUE1 Output voltages VALUE0 to channel #0 and VALUE1 to channel #1 simultaneously ENPM808B Instructor: Nam Sun Wang Page 2 ================================================================================ A/D CONVERSION SUBROUTINES FOR DT2801 IN BLOCK MODE ================================================================================ --------------------------------------------------------------------------- SETCLK(NUM) INTEGER*2 NUM Set the clock of the DT2801 board. NUM is the time between ticks in 2.5 microsec units. (e.g. 400 means one millisec rate.) The slowest rate is .1638375 second, which corresponds to NUM=65535. --------------------------------------------------------------------------- SETAD0(NUMB,CHAN1,CHAN2,GAIN) INTEGER*2 NUMB, CHAN1, CHAN2, GAIN Set A/D board for block mode operation. Set starting channel to scan (CHAN1) Set ending channel to scan (CHAN2). CHAN1 and CHAN2 are from 0 to 15. GAIN ... 0,1,2,or 3 NUMB=0 ... continuous & DMA operation =1 ... continuous operation =2 ... DMA operation =3--65535 ... number of conversions --------------------------------------------------------------------------- ADIN03(NUM1,NUM2,VALUES) INTEGER*2 NUM1, NUM2, VALUES(*) Must be used with SETAD0 to do block mode conversions. NUM1 is the number of channels that are scanned. NUM2 is the number of conversions in one cycle, if NUM2 equals to NUM1, then each conversion value is used and put into the VALUES array. If NUM2 is two times NUM1, then each second reading is put into VALUES and so on. --------------------------------------------------------------------------- ADIN04(NUM1,NUM2,VALUES) INTEGER*2 NUM1, NUM2 INTEGER*4 VALUES(*) Must be used with SETAD0 to do block mode conversions. NUM1 is the number of channels scanned. NUM2 is the number of conversions in one cycle. If NUM2=NUM1, then each value is used and put into VALUES. IF NUM2=K*NUM1, then K number of samples are totaled and the sum is put into VALUES. ENPM808B Instructor: Nam Sun Wang Page 3 ================================================================================ A/D CONVERSION SUBROUTINES FOR DT2801 IN BLOCK MODE ================================================================================ --------------------------------------------------------------------------- ADINC3(LENGTH,NUM1,NUM2,VALUES) INTEGER*2 NUM1, NUM2 INTEGER*4 LENGTH, VALUES(*) Same as ADIN03 but must be used with SETADC for continous block mode operation. LENGTH is the number of conversions to perform. It is recommended to call RESADC again after using this subroutine because at returning this routine leaves the DT2801 board in an error condition. --------------------------------------------------------------------------- ADINC4(LENGTH,NUM1,NUM2,VALUES) INTEGER*2 NUM1, NUM2 INTEGER*4 LENGTH, VALUES(*) Same as ADIN04 but must be used with SETADC for continuos block mode operation. LENGTH is the number of conversions to perform. It is recommended to call RESADC again after using this subroutine because at returning this routine leaves the DT2801 board in an error condition.