c ---------------------------------------------------------------------- c Test A/D converter directly from FORTRAN by manipulating the I/O ports c The main program is exactly the same as AD.FOR c Link with ASM.OBJ only (no ADDA.OBJ) c ---------------------------------------------------------------------- character text*10,ascii c Voltage limits = -10V -- +10V --> range=20. range = 20. factor = range/4096. c Reset the A/D converter CALL RESADC 5 call clrscr call output(4,5,'Hit any key to change channel.$') call output(5,5,'Enter channel # (0-15 for SE, or 0-7 for DI): $') read(*,501)ichan call output(6,5,'Enter gain (0=X1, 1=X2, 2=X4 3=X8): $') read(*,501)igain call output(7,5,'Voltage: $') 10 CALL ADIN00(ICHAN,IGAIN,IVALUE) voltage=float(ivalue-2048)*factor write(text,605)voltage,'$' call output(7,14,text) call askkey(iyesno) if(iyesno .eq. 0)goto 10 call readky(ascii,iscan) goto 5 501 format(i5) 502 format(f8.3) 605 format(f8.3,a1) end SUBROUTINE RESADC c Reset the A/D board directly from FORTRAN c dport ... Data port c cport ... Command port integer*2 chan,gain,value,dport,cport dport=#2EC cport=#2ED c Issue a Stop Command call outp(cport,15) c Kill some time (i.e. 9 ticks) call gettic(ihword,ilword) iold = ilword 5 call gettic(ihword,ilword) if(ilword .lt. iold+9)goto 5 c Take a look at at the Status bit 1: read from the Data Register c so that bit 1 can be cleared call inp(cport,iovalue) ibit0=mod(iovalue,2) if(ibit0 .eq. 1)call inp(dport,iovalue) c Check to make sure that bit 2 is set before writing to the Command Register c Bit 2 has a value of 4 10 call inp(cport,iovalue) ibit2=mod(iovalue/4,2) if(ibit2 .eq. 0)goto 10 c Select Function 1: Clear Error call outp(cport,1) return end SUBROUTINE ADIN00(CHAN,GAIN,VALUE) c Perform A/D conversion directly in FORTRAN c dport ... Data port c cport ... Command port integer*2 chan,gain,value,dport,cport dport=#2EC cport=#2ED value=0 c Check to make sure that bit 2 is set before writing to the Command Register c Bit 2 has a value of 4 10 call inp(cport,iovalue) ibit2=mod(iovalue/4,2) if(ibit2 .eq. 0)goto 10 c Select Function 12: Read A/D Immediate call outp(cport,12) c Check to make sure that bit 1 is 0 before writing to the Data Register 20 call inp(cport,iovalue) ibit1=mod(iovalue/2,2) if(ibit1 .eq. 1)goto 20 c Write GAIN to the Data Register call outp(dport,gain) c Check to make sure that bit 1 is 0 before writing to the Data Register 30 call inp(cport,iovalue) ibit1=mod(iovalue/2,2) if(ibit1 .eq. 1)goto 30 c Write CHAN to the Data Register call outp(dport,chan) c Check to make sure that bit 0 is set before reading from the Data Register 40 call inp(cport,iovalue) ibit0=mod(iovalue,2) if(ibit0 .eq. 0)goto 40 c Read the low byte from the Data Register call inp(dport,value) c Check to make sure that bit 0 is set before reading from the Data Register 50 call inp(cport,iovalue) ibit0=mod(iovalue,2) if(ibit0 .eq. 0)goto 50 c Read the hi byte from the Data Register call inp(dport,iovalue) value=iovalue*256 + value return end