CLS OPEN "COM1: 4800,N,8,1,CD0,CS0,DS0,OP0,RS,TB2048,RB2048" FOR INPUT AS #1 'open COM1 for input FOR i% = 1 TO 6: READ a(i%): NEXT i% 'read in scale factors for each range DIM ADC(6, 2) FOR i = 1 TO 6: FOR j = 1 TO 2: READ ADC(i, j): NEXT j: NEXT i 'read in lower & upper limits for acceptable ADC values for each range FOR i = 1 TO 6: READ s$(i): NEXT i 'read range labels loop1: WHILE NOT EOF(1) a$ = INPUT$(LOC(1), #1) 'get encoded output from pcaxe v = VAL(RIGHT$(a$, 4)) 'decode switch position i% = v AND 7 IF i% < 1 OR i% > 6 THEN GOTO loop1 'discard invalid switch values & start again ADC% = (v AND 8184) / 8 'decode ADC reading CLS LOCATE 5, 1 PRINT "Press 1 for noise reduced reading" PRINT "Press x to exit" REM check if ADC value is within acceptable limits IF ADC% < ADC(i%, 1) OR ADC% > ADC(i%, 2) THEN LOCATE 1, 10: PRINT "consider using a different scale " REM proceed with calculations Scale = a(i%) voltage = ADC% / 1023 * 5000 dB = voltage / Scale dBV = dB - 93 v = 10 ^ (dBV / 20) dBm = dB - 80 power = 10 ^ (dBm / 10) REM Display results IF v >= 1 THEN v$ = " V" ELSE IF 1000 * v >= 1 THEN v$ = " mV": v = 1000 * v ELSE v$ = " uV": v = 1000000 * v IF power >= 1000 THEN p$ = " W": power = power / 1000 ELSE IF power >= 1 THEN p$ = " mW" ELSE power = power * 1000: p$ = " uW" LOCATE 10, 1 PRINT "Switch" PRINT "Position", "Scale", "ADC value" PRINT i%, s$(i%), ADC% PRINT PRINT PRINT PRINT "Total Measured Signal Voltage" PRINT PRINT USING "###.#"; v; PRINT v$; TAB(20); PRINT USING "###.#"; dBV; PRINT " dBV" PRINT USING "##.##^^^^"; power; PRINT p$; TAB(20); PRINT USING "###.#"; dBm; PRINT " dBm" PRINT PRINT PRINT PRINT "Noise Reduced Signal Voltage" PRINT PRINT USING "###.#"; v - vmin; PRINT v$; TAB(20); PRINT USING "###.#"; dBV - dBVmin; PRINT " dBV" PRINT USING "##.##^^^^"; power - powermin; PRINT p$; TAB(20); PRINT USING "###.#"; dBm - dBmmin; PRINT " dBm" REM check keyboard for options b$ = INKEY$ IF b$ = "1" THEN vmin = v: dBVmin = dBV: powermin = power: dBmmin = dBm IF b$ = "x" THEN END REM start again & get new values GOTO loop1 WEND GOTO loop1 DATA 44.7,49.3,61.2,81.1,123.9,250.1 DATA 24,1015,24,1016,24,1017,24,1018,24,1019,24,1020 DATA "10 dB","0 dB","-20 dB","-40 dB","-60 dB","-80 dB"