read_lm335: FOR n = 1 TO 4 'read 4 of 8 A/D channels with LM335 sensors attached OUT bbase_ad+2,n-1 'starting with channel 0, MUX write control byte DELAY 0.05 'small delay needed between writes to converter OUT bbase_ad+1,0 'any write to this address causes A/D conversion scount=0 label_3: statusreg=INP(bbase_ad+2) 'check to see if A/D conversion is done eoc=BIT(statusreg,7) 'check bit 7 for end of conversion INCR scount IF scount=10 GOTO label_5 'prevent hanging if no A/D card IF eoc=1 THEN GOTO label_3 'if eoc=1 A/D is busy, if 0 is done lsb=INP(bbase_ad) 'read lower byte value msb=INP(bbase_ad+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(r,n)=(ad_counts-3087.96)/2.2512 'hp-48 cal for #1 in breezeway CASE=1 degf(r,n)=(ad_counts-3085.326)/2.268 'hp-48 cal for #2 in 2nd floor CASE=2 degf(r,n)=(ad_counts-3090.873)/2.3036 'hp-48 cal for #3 in 1st floor CASE=3 degf(r,n)=(ad_counts-3093.087)/2.2666 'hp-48 cal for #4 in basement CASE ELSE degf(r,n)=(ad_counts-3088.713)/2.2979 'use spare #5 if more channels END SELECT IF debug_flag=1 THEN PRINT #6, ad_channel, bitpattern2$, bitpattern$, ad_counts, degf(r,n) WRITE #7, TIME$,r,degf(r,1),degf(r,2),degf(r,3),degf(r,4) 'write to ad_degs.log END IF IF auto_test_flag=1 THEN GOSUB show_all_deg 'display house temperatures NEXT n INCR r 'the sample count IF debug_flag=1 THEN PRINT #6, "" WRITE #7, END IF IF r=4 THEN 'after 4 readings, average the data deg_F1=(degf(0,1)+degf(1,1)+degf(2,1)+degf(3,1))/4 deg_F2=(degf(0,2)+degf(1,2)+degf(2,2)+degf(3,2))/4 deg_F3=(degf(0,3)+degf(1,3)+degf(2,3)+degf(3,3))/4 deg_F4=(degf(0,4)+degf(1,4)+degf(2,4)+degf(3,4))/4 GOSUB save_temp 'record the average values r=0 END IF label_5: RETURN