'Test file to read A/D ports on CIO-DAS08/JR I/O board. ' by Michael Krabach ' Compiled with Power Basic 3.2 for 80286 with no coprocessor 'rev 4-21-02 'Revised for five different calibrated LM335 temperature ic's on ' A/D channels 0, 1, 2, 3, and 4. Channels 5 thru 7 open. DEFINT a-s 'integer variables DIM degf(8) ON KEY (10) GOSUB stop_pgm KEY (10) ON CLS COLOR 14 PRINT "Exit program with F10." COLOR 7 PRINT "Output file 'logfile' saves screen output." PRINT "Output file 'datafile' saves A/D channel temperature data." INPUT "Input the base address as hex &h___ number (default is &h330)"; ans IF ans = 0 THEN bbase=&h330 ELSE bbase=ans END IF INPUT "What reading frequency in seconds"; interval OPEN "logfile" FOR APPEND AS #1 OPEN "datafile" FOR APPEND AS #2 CLS PRINT #1, "========== Test Board CIO-DAS08/JR ============" PRINT #1, TIME$;" "DATE$ PRINT #1, "" PRINT "A/D chan","msb","lsb","ad_counts","deg F" 'print to screen PRINT #1, "A/D chan","msb","lsb","ad_counts","deg F" 'print to logfile label_1: FOR n = 1 TO 8 'read n A/D channels with LM335 sensors attached OUT bbase+2,n-1 'starting with channel 0, MUX write control byte DELAY 0.05 'required for A/D channel to settle OUT bbase+1,0 'any write to this address causes A/D conversion scount=0 label_2: statusreg=INP(bbase+2) 'check to see if A/D conversion is done eoc=BIT(statusreg,7) 'check bit 7 for end of conversion IF scount=10 THEN GOTO label_5 ELSE INCR scount 'prevent hanging if no A/D card IF eoc=1 THEN 'if 1, A/D is busy, if 0 is done PRINT "."; 'print a dot on screen GOTO label_2 END IF lsb=INP(bbase) 'read lower byte value msb=INP(bbase+1) 'read upper byte value bitpattern$=BIN$(lsb) 'give it an alpha pattern bitpattern2$=BIN$(msb) ad_channel=statusreg AND &b111 'read lower 3 bits to identify A/D channel msb=msb*16 'shift msb to left 0000 bits SHIFT RIGHT lsb, 4 'read left nibble of bbase+1 ad_counts=msb+lsb 'add bytes to get word SELECT CASE ad_channel 'calibrations using 5v regulated supply CASE=0 degf(n)=(ad_counts-3087)/2.260 'cal for #1 CASE=1 degf(n)=(ad_counts-3084)/2.300 'cal for #2 CASE=2 degf(n)=(ad_counts-3090)/2.310 'cal for #3 CASE=3 degf(n)=(ad_counts-3092)/2.280 'cal for #4 CASE ELSE degf(n)=(ad_counts-3088)/2.290 'cal for any others END SELECT PRINT ad_channel, bitpattern2$, bitpattern$, ad_counts, degf(n) PRINT #1, ad_channel, bitpattern2$, bitpattern$, ad_counts, degf(n) NEXT n WRITE #2, TIME$, degf(1),degf(2),degf(3),degf(4),degf(5),degf(6),degf(7),degf(8) DELAY interval PRINT PRINT #1, "" GOTO label_1 'continue until F10 label_5: CLS PRINT "No A/D card found." END stop_pgm: CLOSE #1 CLOSE #2 END RETURN