10 ! RE-SAVE "DIG_83480" 20 ! 30 ! Copyright: (c) 1994, Hewlett-Packard Co. All rights reserved. 40 ! Contributor: Colorado Springs Division 50 ! Product: Example Program 60 ! 70 ! $Revision: 3.0 80 ! $Date: 93/06/16 14:31:02 $ 6.9.93 90 ! $Author: hmgr $ Ed Mierzejewski 100 ! 110 ! Description: DIG_83480.ibw autoscales to get a waveform on screen and 120 ! digitizes the waveform. Then the operator can reposition 130 ! before transfering the data to the computer. Then the 140 ! computer will draw the waveform as repositioned on the 150 ! computer screen. It also saves the data to a record and 160 ! recalls that data before drawing it. 170 ! 180 ! Main Routine: Begin_main. 190 ! Sub routines: none. 200 ! Sub programs: Get_waveform, Graph, Initscope, Readme, Readme2, 210 ! Retrieve_wave, Save_waveform. 220 ! Functions: none. 230 ! Variable List: Preamble & Waveform, @Path, & @Scope 240 ! 250 ! Preamble = Real array for the first 15 parameters of the 260 ! preamble, they are numerics and the remaining 3 270 ! parameters are alphas and are not used. 280 ! Waveform = Integer array to store the wavefrom data. 290 ! @Path = the path for saving/recalling data to/from media. 300 ! @Scope = The scope's complete HPIB address. 310 ! 320 REAL Preamble(1:15) 330 INTEGER Waveform(1:32000) 340 Begin_main: ! 350 CALL Readme 360 CALL Initscope(@Scope) 370 CALL Get_waveform(@Scope,Waveform(*),Preamble(*)) 380 CALL Save_waveform(@Path,Waveform(*),Preamble(*)) 390 CALL Readme2 400 CALL Retrieve_wave(@Path,Waveform(*),Preamble(*)) 410 CALL Graph(Waveform(*),Preamble(*)) 420 PRINT TABXY(15,30);"Program has Ended." 430 LOCAL 707 440 End_main: ! 450 END 460 Begin_subs:! 470 ! 480 SUB Readme 490 ! Description: Readme prints program explaination to the computer 500 ! screen. 510 ! Parameters: none. 520 ! 530 CLEAR SCREEN 540 PRINT "DIG_83480.ibw does the following tasks:" 550 PRINT 560 PRINT " a. initialize interface and scope" 570 PRINT " b. digitize and acquire data" 580 PRINT " c. store data to disk" 590 PRINT " d. retrieve data from disk" 600 PRINT " e. draw signal on computer" 610 PRINT 620 PRINT "Assumed system configuration is:" 630 PRINT 640 PRINT " HP-IB address = 7" 650 PRINT " Scope address = 7" 660 PRINT " signal attached to channel 1" 670 PRINT 680 PRINT "If the addresses are not correct, change the ASSIGN " 690 PRINT "statements in sub program 'Initscope'." 700 PRINT 710 PRINT "Press Continue when ready to start" 720 PAUSE 730 CLEAR SCREEN 740 SUBEND 750 ! 760 SUB Readme2 770 ! 780 ! Description: Readme2 is user information and status. 790 ! 800 ! Parameters: none. 810 ! 820 CLEAR SCREEN 830 PRINT 840 PRINT "The waveform data and preamble information have now been" 850 PRINT "read from the scope and stored in the computer's disk." 860 PRINT 870 PRINT "When you press continue that information will be retrieved" 880 PRINT "from the disk, and plotted to the computer screen." 890 PRINT 900 PRINT "Press CONTINUE to continue." 910 PAUSE 920 CLEAR SCREEN 930 SUBEND 940 ! 950 SUB Initscope(@Scope) 960 ! 970 ! Description: Initscope assigns the path to the scope, initializes 980 ! the scope, autoscales, and sets up the acquisiton 990 ! parameters. 1000 ! Parameters: 1010 ! Passed: @Scope = the HPIB address of the scope. 1020 ! Internal: @Isc = interface select code of the HPIB interface. 1030 ! Modified Variables: @Scope and @Isc 1040 ! 1050 CLEAR SCREEN 1060 PRINT "INITIALIZE" 1070 Assign_paths: ! 1080 ASSIGN @Isc TO 7 ! Interface Select Code = 7 1090 ASSIGN @Scope TO 707 ! scope address 1100 Init_sys: !_ 1110 CLEAR @Isc ! clear HP-IB interface 1120 OUTPUT @Scope;"*RST;*CLS" ! set scope to default config 1130 OUTPUT @Scope;":AUToscale" 1140 OUTPUT @Scope;":SYStem:HEADer OFF" 1150 Acq_setup: ! 1160 OUTPUT @Scope;":ACQuire:COMPlete 100;POINts 500" 1170 OUTPUT @Scope;":WAVeform:FORMat BYTE;SOURce CHANnel1" 1180 ! 1190 ! Normally WORD data would be recommended because it allows better 1200 ! use of the full resolution of the scope, especially in ET MODE. 1210 ! Byte data is shown because HPBasic doesn't recognize signed bytes 1220 ! and requires a conversion. FNBcon will do the conversion. 1230 ! 1240 CLEAR SCREEN 1250 SUBEND 1260 ! 1270 SUB Get_waveform(@Scope,INTEGER Waveform(*),REAL Preamble(*)) 1280 ! 1290 ! Description: Get_waveform digitizes the autoscaled waveform, 1300 ! gets wavefrom data and preamble after the operator 1310 ! adjusts the display to show the data as desired. 1320 ! 1330 ! There are 2 forms of digitize: 1. 'with parameters' 1340 ! will digitize the specified channel/function, screen 1350 ! is blanked, then place the data in associated channel/ 1360 ! function memory. 2. 'without parameters' digitizes 1370 ! all 'on' channels/functions and places data in the 1380 ! associated channel/function memory, and leaves them on 1390 ! but stopped. 1400 ! 1410 ! Both digitizes are here and on adjacent lines. One of 1420 ! the lines must be commented out or only the last one 1430 ! will be used. 1440 ! 1450 ! Parameters: 1460 ! Passed: @Scope, Waveform, Preamble 1470 ! Internal: Digits = this is the length of the data header. 1480 ! Length = the number of bytes of data from the scope. 1490 ! End$ = enpties output buffer of linefeed. 1500 ! One_char$ = used to find the '#' character. 1510 ! 1520 ! Modified Variables: Waveform, Preamble, Digits, Length, End$, and 1530 ! One_char$. 1540 ! 1550 CLEAR SCREEN 1560 PRINT "Get_waveform" 1570 ! OUTPUT @Scope;":DIGitize CHAN1" 1580 OUTPUT @Scope;":DIGitize" 1590 User_sets_disp: ! 1600 LOCAL 707 1610 PRINT "Adjust Display as you want it. Press continue when ready." 1620 PAUSE 1630 Read_data: ! 1640 OUTPUT @Scope;":WAVeform:DATA?" 1650 ENTER @Scope USING "#,1A,";One_char$ 1660 IF One_char$="#" THEN 1670 ENTER @Scope USING "#,1D";Digits 1680 ENTER @Scope USING "#,"&VAL$(Digits)&"D";Length 1690 CLEAR SCREEN 1700 PRINT 1710 PRINT "Reading ";Length;" bytes from scope" 1720 ! 1730 !Redimension the array for the waveform data. After data is 1740 !read in, one extra byte read to clear the line feed (10) 1750 !attached to the end of the scope's output buffer. 1760 ! 1770 REDIM Waveform(1:Length) 1780 ENTER @Scope USING "#,B";Waveform(*) 1790 ENTER @Scope USING "-K,B";End$ 1800 OUTPUT @Scope;":WAVEFORM:PREAMBLE?" 1810 ENTER @Scope;Preamble(*) 1820 ELSE 1830 PRINT "BAD DATA" 1840 END IF 1850 SUBEND 1860 ! 1870 SUB Save_waveform(@Path,INTEGER Waveform(*),REAL Preamble(*)) 1880 ! 1890 ! Description: Save_waveform sends acquired data and preamble to the 1900 ! computer's disk. It is stored in 'WAVESAMPLE'. If 1910 ! 'WAVESAMPLE' already exist, it will be purged then a 1920 ! new one created. 1930 ! 1940 ! Parameters: 1950 ! Passed: @Path, Waveform, Preamble 1960 ! Internal: none 1970 ! 1980 ! Modified Variables: none 1990 ! Sub programs: Ertrap 2000 ! 2010 ON ERROR CALL Ertrap 2020 CREATE BDAT "WAVESAMPLE",1,4080 2030 ASSIGN @Path TO "WAVESAMPLE" 2040 OUTPUT @Path;Waveform(*),Preamble(*) 2050 SUBEND 2060 ! 2070 SUB Retrieve_wave(@Path,INTEGER Waveform(*),REAL Preamble(*)) 2080 ! 2090 ! Description: Retrieve_wave reads data and preamble stored in 2100 ! 'WAVESAMPLE'. 2110 ! Parameters: 2120 ! Passed: @Path, Waveform, Preamble 2130 ! Internal: Con = indexing variable 2140 ! Functions: FNBcon = converts from signed bytes. 2150 ! 2160 ASSIGN @Path TO "WAVESAMPLE" 2170 ENTER @Path;Waveform(*),Preamble(*) 2180 FOR Con=1 TO Preamble(3) 2190 Waveform(Con)=FNBcon(Waveform(Con)) 2200 NEXT Con 2210 SUBEND 2220 ! 2230 SUB Graph(INTEGER Waveform(*),REAL Preamble(*)) 2240 ! 2250 ! Description: Graph takes the converted data and plots it on screen. 2260 ! It uses the 'Y Display Range' to show the data as seen 2270 ! on screen vertically, and 'X Display Range' to show 2280 ! as seen horizontally (pre(14 and 12 respectively). 2290 ! 2300 ! Parameters: Waveform(*) = array of data values. Enters as q levels 2310 ! leaves as voltages. 2320 ! Preamble(*) = the preamble for the data. 2330 ! 2340 ! Internal: Vrange = preamble(14), y-axis duration of waveform displayed. 2350 ! Srange = preamble(12), x-axis duration of waveform displayed. 2360 ! Offset = preamble(15), center of screen vertically. 2370 ! vmin = lower limit vertically. 2380 ! vmax = upper limit vertically. 2390 ! hmin = lower limit horizontally (preamble(13)). 2400 ! hmax = upper limit horizontally. 2410 ! Hdata(*) = Horizontal values in proper units. 2420 ! Vdata(*) = Vertical values in proper units. 2430 ! I = indexing variable. 2440 ! 2450 ! Modified variables: Hdata(*), Vdata(*), and I 2460 ! 2470 ! Subprogram calls:V_convert and H_convert. 2480 ! 2490 ALLOCATE REAL Hdata(1:Preamble(3)) 2500 ALLOCATE REAL Vdata(1:Preamble(3)) 2510 CALL V_convert(Waveform(*),Preamble(*),Vdata(*)) 2520 CALL H_convert(Hdata(*),Preamble(*)) 2530 Vrange=Preamble(14) 2540 Srange=Preamble(12) 2550 Offset=Preamble(15) 2560 Vmin=Offset-Vrange/2 2570 Vmax=Vrange/2+Offset 2580 Hmin=Preamble(13) 2590 Hmax=Hmin+Srange 2600 GCLEAR !initialize graphics 2610 CLEAR SCREEN 2620 GINIT 2630 GRAPHICS ON 2640 VIEWPORT 0,130,35,100 2650 WINDOW Hmin,Hmax,Vmin,Vmax 2660 FRAME 2670 PEN 4 2680 MOVE Hdata(1),Vdata(1) 2690 FOR I=1 TO Preamble(3) !plot data points 2700 PLOT Hdata(I),Vdata(I),-2 2710 DRAW Hdata(I),Vdata(I)+ABS(Vmax-Vmin)*.002 2720 NEXT I 2730 PAUSE 2740 PRINT TABXY(0,18),"Vertical=";Vrange/8;" V/div";TAB(50),"Offset = ";Offset;"V" 2750 PRINT TABXY(0,19),"Time=";Srange/10;" s/div" 2760 DEALLOCATE Hdata(*) 2770 DEALLOCATE Vdata(*) 2780 SUBEND 2790 ! 2800 DEF FNBcon(INTEGER B) 2810 ! 2820 ! Description: FNBcon takes the signed byte value from the scope and 2830 ! converts it to a positive integer of the proper value. 2840 ! Parameters: 2850 ! Passed: B 2860 ! Internal: Orparam = value to OR with the passed value, B, when the 2870 ! MSB is set. 2880 ! Modified Variables: B 2890 ! 2900 Orparam=-256 2910 IF BIT(B,7) THEN B=BINIOR(Orparam,B) 2920 RETURN B 2930 FNEND 2940 ! 2950 SUB Ertrap 2960 ! 2970 ! Description: Ertrap is called by an error interupt. It checks for 2980 ! error #54 which will occur when there is a duplicate 2990 ! file name. The existing file will be purged. 3000 ! Parameters: none 3010 ! 3020 IF ERRN=54 THEN PURGE "WAVESAMPLE" 3030 OFF ERROR 3040 SUBEND 3050 ! 3060 SUB V_convert(INTEGER Wav(*),REAL Pre(*),Vdata(*)) 3070 ! 3080 ! Description: V_convert takes the data from the scope and converts it 3090 ! into voltage values using the equation from the manual. 3100 ! 3110 ! Parameters: Wav(*) = array of data values. Enters as q levels 3120 ! leaves as voltages. 3130 ! Pre(*) = the preamble for the data. 3140 ! Vdata (*) = array of vertical values, volts. 3150 ! 3160 ! Internal: yref = pre(10), level associated with y origin. 3170 ! yinc = pre(8), duration between y-axis levels. 3180 ! yorg = pre(9), y-axis value at level zero. 3190 ! C = indexing variable. 3200 ! 3210 ! Modified variables: Vdata(*) 3220 ! 3230 Yref=Pre(10) 3240 Yinc=Pre(8) 3250 Yorg=Pre(9) 3260 FOR C=1 TO Pre(3) 3270 Vdata(C)=(Wav(C)-Yref)*Yinc+Yorg 3280 NEXT C 3290 SUBEND 3300 ! 3310 SUB H_convert(Hdata(*),Pre(*)) 3320 ! 3330 ! Description: H_convert creates horizontal axis values using the 3340 ! equation from the manual. 3350 ! 3360 ! Parameters: Hdata(*) = Horizontal values. 3370 ! Pre(*) = the preamble for the data. 3380 ! 3390 ! Internal: xref = pre(7), data point associated with the x origin. 3400 ! xinc = pre(5), duration between x-axis data points. 3410 ! xorg = pre(6), x-axis value of first point in record. 3420 ! 3430 ! Modified variables: Hdata(*) 3440 ! 3450 Xref=Pre(7) 3460 Xinc=Pre(5) 3470 Xorg=Pre(6) 3480 FOR C=1 TO Pre(3) 3490 Hdata(C)=((C-1)-Xref)*Xinc+Xorg 3500 NEXT C 3510 SUBEND