'-------------------------------------------------------------------------------- 'name : LogiAna_Dg_DE0nano_tst2_3.bas 'purpose : Logic Analyzer test 'revision : add pattern compare mode ' 'hardware : DE0-nano (Logic analizer & CGLCD control) ' = DE0nano_LogiAnaAndGLCD, in Qualtus v12 project ' : Color Graphic LCD (800x480) ' = Kyoritsu-Digit, Pachi-Slo Color Graphic LCD ' : Mega1284 board control the system ' with SD-Card to store data. ' 'function : set Trigger conditions to start storage of digital signal ' : display logic levels to Color Graphic LCD ' : input CH = 4 ' : trigger condition = level, edge for individual CHs (CH0-3) ' : condition = each CH ORed, 4CH All match, 2CH match (CH2,3) ' : storage RAM = 64k-bit x 4CH in FPGA ' : sampling CK = 100MHz, 10MHz, 1MHz, 0.1MHz selectable. ' Over 200MHz sampling may be possible depending on FPGA. ' ' ' FPGA command is sent from a micro controller Mega1284 to DE0-nano via SPI I/F. ' ' ' LCD Hardware : Color Graphic LCD ' : Pachi-Slot Color GLCD (sold by Digit) ' : Controlled by the same DE0nano. ' : 800x480 dots. RGB, 2^16 color. ' : The LCD is controlled by an FPGA = Cyclone-IV. ' : (Altera Cyclone-IV, EP4E22C6) ' : AVR (Mega1284) communicates with the FPGA via SPI interface. ' : Control commands are sent via SPI I/F from the AVR. ' ' char. ROM (embedded in the FPGA) is 7x9 dot / char. & 1 dot V space, ' which means 114 columns x 48 lines on the 800 x 480 pixel area. ' ' For control sequence, refer Digit_GLCD_cy2_control.txt ' ' AVR board Hardware : AVR = Mega1284 ' SD-Card slot (SPI IF) is added to the AVR board. (SPI I/F) ' FT232R external I/F board to communicate via USB with PC. ' 'NOTE: To program the AVR board, OFF the power, ' eject SD-card (not to conflict the SPI IF line, especially to MISO), ' power ON, and then program the AVR. ' '-------------------------------------------------------------------------------- ' Rem SW1~6 are push SW, and used as follows, with Rotary encoder. ' (all SW'es are not debounced.) ' ' SW1/SW2 Start/Stop ' SW3-4, and Rotary Encoder set the parameters. ' SW5 = Ope-Mode select ' SW6 = SDC-control ' ' operations '-------------------------------------------------------------------------------- ' Mode0 set sampling frequency & trigger conditions ' start/stop Logic analyzer ' GLCD display ' Mode1 Logic compare & Protocol display mode set. ' Mode2 SD-card storage ' Mode3 USB transfer ' ' ' In Mode-0, trigger conditions to start memorize logic pattern are set. ' Start/Stop Logic Analyzer. ' displays logic patterns into Color Graphic LCD. '-------------------------------------------------------------------------------- ' '-------------------------------------------------------------------------------- ' Mode-1: Logic compare & Protocol display mode set ' SD-Card = Logic data buffer (binary file: 64kB) ' ' filename = LwM.dat (M = filenumber) ' In Mode-1, user can store logic data into the SD-Card by binary. ' After this, user can compare logic data in Mode-0. ' Note: The file number is not incremented after the data storage. ' Use rotary encoder to change the file number. ' ' In Mode-1, user can set protocol analyzer setting. ' Current available setting is only I2C. ' Note: To properly display the I2C protocol, ' CH0 and CH1 must be SDA and SCL, respectively. ' '-------------------------------------------------------------------------------- ' '-------------------------------------------------------------------------------- ' Mode-2: SD-Card storage ' SD-Card = Windows file format. ' NOTE: cannot support SDHC type, only normal SDC is available. ' ' filename = LwN.txt (N = filenumber) ' In Mode-2, user can store logic data into the SD-Card. ' After this, user can draw and analyze the logic patterns under PC. ' The file number is auto-incremented after the data storage. ' '-------------------------------------------------------------------------------- ' '-------------------------------------------------------------------------------- ' Mode-3: Xfer data to PC via USB (Xfer from TXD0, & converted by FT232RL) ' data = text format. ' '-------------------------------------------------------------------------------- Rem Used ports ' ' PB5-7 : used for hardware SPI I/F ' PC2-7 : SW1-6 (0=Push) ' ' PC0, 1 : Rotary encoder /A, /B ' ' NOTE: to properly use the PC0-5, JTAG must be disabled by Fuse bit or Software. ' ' PB4 : SD-card /SS (SPI-I/F slave select) ' PA7 : SD-card /CD input ' ' PD0 (RXD0) : USB commnication with PC ' PD1 (TXD0) : USB commnication with PC via FT232RL ' PB0 : XCK0 for fast USART SPI I/F (SCK) ' PD2 : /SS for USART fast SPI I/F (common use with test LED) ' ' SPI I/F for GLCD controller (DE0-nano) ' /SS SPI lines for GLCD are named as /GSSn (n is a number) ' to distiguish from /SS signals for Logi-Ana. ' ' PD5 : /GRes (GLCD controller /Reset) ' PD4 : /GSS1 (for Data [16-bit]) ' PD7 : /GSS2 (for Parameter [24-bit] ' upper 8 = Parameter register #, lower 16 = value]) ' PD3 : /GSS3 (for Command or char. data, if MSB=0, char.) ' PA4 : WR_busy In (H=busy) ' SPI I/F for Logic-Analyzer (DE0-nano) control ' ' PB3 : /SS1 (for Command write [16-bit]) ' PA5 : /SS2 (for read of Trigger start RAM address [16-bit]) ' from this address - 3, data is valid. ' PA6 : /SS3 (for read address set) ' ' PB1 : /RD_counter CK (RAM RD address is incremented by /CK) (PA0 must be L) ' PA0-3 : read Data 0-3 ' ' PB2 : /Storage = start Logic Analyzer (L = active) ' PD6 : /End of logic analyzer (L = active) ' test LED ' ' PD2 : H = LED ON (common use with USART SPI /SS) ' '-------------------------------------------------------------------------------- ' ' Logic Analyzer (DE0-nano) control sequence ' ' initial setting: /Storage = H, /RD_CK = H, /SSNn = H. ' ' From Mega128, ' ' 1. Set command via SPI (/SSN1 assert) ' 2. assert L to Storage (DE0 start memorize data into internal SRAM in the FPGA) ' 3. If trigger condition was met, FPGA marks the memeory address. ' 4. After &HFFFF - 2 data was stored into SRAM, DE0 sets ENDN line (L). ' 5. Mege128 monitors ENDN -> L. When it was done, goto the next step. ' 6. Mega128 reads marking address, i.e. MAddr, of SRAM by asserting /SSN2. ' 7. Mega128 sets read address (MAddr. - 2) to FPGA by asserting /SSN3. ' 8. Mega128 reads a data (4-bit) via DT0-3 line. ' NOTE: To get data from FPGA, ' 2 pre-RD-CK must be asserted due to pipelined SRAM in the FPGA. ' 9. Mega128 assert RD counter CK (H -> L -> H) to advance the read address. ' 10. repeat step 8-9, until 64k data sets are read. ' 11. assert H to Storage to clear the FPGA operation. ' '-------------------------------------------------------------------------------- ' Command (16-bit) format to FPGA ' ' B15,14 = sampling CK select ' 00 = 0.1MHz, 01 = 1MHz, 10 = 10MHz, 11 = 100MHz ' ' B13: Start storage when all conditions are met. ' B12: Start storage when CH2 and CH3 conditions are met. ' ' B11: H = CH3 trigger Enable ' B10: H = CH3 edge trigger, L = CH3 level trigger ' B9: When edge, rise/fall as 1/0. When level, H/L level. ' ' B8: H = CH2 trigger Enable ' B7: H = CH2 edge trigger, L = CH2 level trigger ' B6: When edge, rise/fall as 1/0. When level, H/L level. ' ' B5: H = CH1 trigger Enable ' B4: H = CH1 edge trigger, L = CH1 level trigger ' B3: When edge, rise/fall as 1/0. When level, H/L level. ' ' B2: H = CH0 trigger Enable ' B1: H = CH0 edge trigger, L = CH0 level trigger ' B0: When edge, rise/fall as 1/0. When level, H/L level. ' ' ENDN = /End line is asserted to L after &HFFFD clocks from the trigger. ' ' NOTE: After the /Storage signal is asserted, ' SRAM in FPGA always stores data every sampling CK. ' Therefore, data 2-CK before the trigger-met condition, have been stored. ' User can read these data by setting (MAddr - 2) RAM address to FPGA. ' This can show data state befor the trigger. ' '-------------------------------------------------------------------------------- $regfile = "m1284pdef.dat" ' Mega1284 $crystal = 12000000 ' 12MHz clock $hwstack = 128 $swstack = 128 $framesize = 160 ' In the above, sufficient software stack ($swstack) greater than 32 is ' nescessary for normal operation of PRINT, INPUT, STR() etc. ' console I/O functions and statements, especially for Double variables. Rem Disable JTAG by software, if the Fuse bit has not been reset to disable the JTAG. ' So, if user want to use PC0-5 as normal I/O ports, ' he must disable JTAG setting by the following commands or reset the fuse bit. Mcucsr.jtd = 1 Mcucsr.jtd = 1 '----------------------------------------------------------------- ' ' Definition of constants ' '----------------------------------------------------------------- Rem delay ms definitions Const Dly1 = 300 ' for LED blink [ms] Const Dly2 = 200 ' for SW sense [ms] Const Dly3 = 700 ' for Rotary-Encorder sense wait [us] Const Dly4 = 10 ' for Rotary-Encoder post wait [ms] ' Color word def. for Graphic LCD (User can define other colors.) ' 16-bit pattern is composed of R, G, B data. ' = Red5~1 (Red0=always 0) ' = Green5~0 ' = Blue5~1 (Blue0=always 0) Const Black = &H0000 Const White = &HFFFF Const Red = &B11111_000000_00000 Const Light_blue = &B10000_000000_11000 Const Green = &B00000_111111_00000 Const Blue = &B00000_000000_11111 Const Gray = &B10000_100000_10000 Const Yellow = &B11111_111111_00000 Const Brown = &B11100_010000_00000 Const Sky = &B00000_111111_11111 Const Violet = &B11111_000000_11111 Const Light_green = &B00000_111000_10000 Const Orange = &B11111_111000_00000 Rem graphic area definition ' parameters for graph display Const Bvmag = 20 ' Pixel correspond to 1 Y range Const Bvskip = 40 ' wave Y separation Const Btmag = 4 ' time X Const Bvmag2 = 5 ' Pixel correspond to 1 Y range Const Bsepa = 30 ' Y offset for compare graph ' graph area Const Yrange = 210 Const Xrange = 650 Const Xrange2 = 200 ' Xrange advance Const X0posi = 80 Const Y0posi = 100 Const Ylabel = 14 ' Y label Row Const Ylskip = 4 Const Xlabel = 11 ' X label Col. Const Xlabel2 = 32 ' X label Row Const Ptcrow0 = 10 ' protocol char. row min Const Ptcrow1 = 12 ' protocol char. row max ' Column max Const Colmax = 57 ' @double size char. '----------------------------------------------------------------- ' ' Include subroutines for AVR-DOS & SD-card ' '----------------------------------------------------------------- Rem Define SD-card I/F (Hardware SPI) $include "Config_MMC2.bas" ' In this libraly, Hardware SPI is defined, ' and also /SS pin is defined as Portb.4. ' This libraly defines double rate SPI CK on ATMega1284. Set Portb.4 ' /SS -> H Rem Define AVR-DOS system $include "Config_AVR-DOS.bas" ' for FAT16 system Rem I/O port pin number definitions (PB4-7 (SPI) have been set in Config_MMC2.bas) Rem I/O port pin number definitions for SDCard Config Porta.7 = Input ' SDC /CD Sdc_ncd Alias Pina.7 ' NOTE: This version does not support WP signal of SD-Card. '----------------------------------------------------------------- ' ' I/O port definition ' '----------------------------------------------------------------- Config Portd.2 = Output ' Green LED (0=emit) Led Alias Portd.2 Usart_ssn Alias Portd.2 Rem push SW Config Portc.2 = Input ' /SW1 Config Portc.3 = Input ' /SW2 Config Portc.4 = Input ' /SW3 Config Portc.5 = Input ' /SW4 Config Portc.6 = Input ' /SW5 Config Portc.7 = Input ' /SW6 Sw1 Alias Pinc.2 Sw2 Alias Pinc.3 Sw3 Alias Pinc.4 Sw4 Alias Pinc.5 Sw5 Alias Pinc.6 Sw6 Alias Pinc.7 Rem rotary encoder Config Portc.0 = Input ' /A pin Config Portc.1 = Input ' /B pin Rem communication with DE0-nano (Logic Analyzer) ' SPI I/F for Logic-Analyzer (DE0-nano) control ' ' PA3 : /SS1 (for Command write [16-bit]) ' PA4 : /SS2 (for read of Trigger start RAM address [16-bit]) ' from this address - 3, data is valid. ' PA5 : /SS3 (for read address set) ' ' PA0 : /RD_counter CK (RAM RD address is incremented by /CK) (PA0 must be L) ' PB0-3 : read Data 0-3 ' ' PA1 : /Storage = start Logic Analyzer (L = active) ' PD6 : /End of logic analyzer (L = active) Config Portd.6 = Input Endn Alias Pind.6 ' /End status Config Porta.0 = Input Config Porta.1 = Input Config Porta.2 = Input Config Porta.3 = Input ' DT0-3 Config Portb.2 = Output Storagen Alias Portb.2 ' /Storage Config Portb.1 = Output Rdckn Alias Portb.1 ' Data RD /CK Rem NOTE: To get data from pipelined RAM ater the first address set via SPI, ' 2 pre-RD-CK must be asserted due to FPGA design. Config Portb.3 = Output Config Porta.5 = Output Config Porta.6 = Output Ssn1 Alias Portb.3 ' SPI /SS1 Ssn2 Alias Porta.5 ' SPI /SS2 Ssn3 Alias Porta.6 ' SPI /SS3 Set Ssn1 Set Ssn2 Set Ssn3 Rem Color Graphic LCD control (Communicate with FPGA (cyclone-II board) via SPI) ' SPI I/F for GLCD controller (DE0-nano) ' /SS SPI lines for GLCD are named as /GSSn (n is a number) ' to distiguish from /SS signals for Logi-Ana. ' ' PD4 : /GSS1 (for Data [16-bit]) ' PD7 : /GSS2 (for Parameter [24-bit] ' upper 8 = Parameter register #, lower 16 = value]) ' PD3 : /GSS3 (for Command or char. data, if MSB=0, char.) ' PA2 : WR_busy In (H=busy) ' ' PD5 : /GRes (GLCD controller /Reset) Config Porta.4 = Input Config Portd.4 = Output Config Portd.7 = Output Config Portd.3 = Output Wr_busy Alias Pina.4 ' WR_busy In Gssn1 Alias Portd.4 ' SPI /GSS1 (for pixel Data [16-bit]) Gssn2 Alias Portd.7 ' SPI /GSS2 (for Parameter [24-bit]) Gssn3 Alias Portd.3 ' SPI /GSS3 (for Command [8-bit]) Set Gssn1 Set Gssn2 Set Gssn3 Config Portd.5 = Output Gsys_resn Alias Portd.5 ' GLCD controller /Reset Reset Gsys_resn '----------------------------------------------------------------- ' ' Definitions of LCD control subroutines and functions ' '----------------------------------------------------------------- Rem Declare subroutines with local variables Declare Sub Lcdchar(byval Bs1 As Byte) ' usage = Lcdchar ASCII Declare Sub Lcdline(byval Xs1 As Integer , Byval Ys1 As Integer , Byval Xs2 As Integer , Ys2 As Integer) ' usage = Lcdline X1, Y1, X2, Y2 ' Gcolor = color word Declare Sub Lcdpset(byval Pxs3 As Integer , Byval Pys3 As Integer , Byval Pds3 As Word) ' usage = Lcdpset X, Y, data '----------------------------------------------------------------- ' ' Variables ' '----------------------------------------------------------------- Rem definition of variables Dim Cmode As Byte ' Mode number Dim Dflag As Bit ' display ' for file in SD-card Dim Fname As String * 32 ' text filename Dim Bfname As String * 32 ' binary filename Dim Fnum As Integer ' text file # ' filename is LwN.txt, ' where N is number. Dim Efnum As Eram Integer Dim Bfnum As Integer ' binary file # ' filename is LwM.dat, ' where M is number. Dim Ebfnum As Eram Integer Dim Temp1 As Byte Dim Tempstr As String * 32 Dim Dirset As Bit Dim Serr_flag As Bit ' for working Dim I As Integer , J As Integer Dim K As Integer , N As Integer , N1 As Integer , N2 As Integer Dim N4 As Integer , Nw As Word Dim Ns1 As Integer , Ns2 As Integer Dim K1 As Integer , K2 As Integer Dim I1 As Integer , J1 As Integer Dim I2 As Integer , J2 As Integer , I3 As Integer , J3 As Integer Dim D As Integer , D2 As Integer Dim Lng As Long , Lng2 As Long , Tlng As Long , Tlng2 As Long Dim L As Long , L2 As Long , L3 As Long Dim B As Byte , B2 As Byte , B3 As Byte , B4 As Byte , B5 As Byte Dim Ww1 As Word , Ww2 As Word Dim X As Single , Y As Single , Z As Single Dim S1 As String * 80 , S2 As String * 80 Dim S As String * 115 , Sspc As String * 120 Dim Stick As String * 16 Dim Saddr As Word Dim R_edge0 As Bit , F_edge0 As Bit ' CH0 rise/fall edge flag Dim R_edge1 As Bit , F_edge1 As Bit ' CH1 rise/fall edge flag Dim R_edge2 As Bit , F_edge2 As Bit ' CH2 rise/fall edge flag Dim R_edge3 As Bit , F_edge3 As Bit ' CH3 rise/fall edge flag ' Variables used for GLCD display Dim Sbank As Byte Dim Is0 As Integer Dim Ns As Integer Dim Wd As Word Dim Bhigh As Byte At Wd + 1 Overlay Dim Blow As Byte At Wd Overlay ' for SPI control Dim Sdao(3) As Byte ' NOTE: Parameter to Graphic controller FPGA is 24 bits. ' for character display to GLCD Dim Bs0 As Byte Dim Col As Byte , Row As Byte ' char. column (0 to 113), Row (0 to 47) Dim Csize As Byte Dim Icol As Integer , Jrow As Integer Dim X1 As Integer , Y1 As Integer ' these variables might be destroyed when call graphic subroutines Dim X2 As Integer , Y2 As Integer ' these variables might be destroyed when call graphic subroutines Dim Gcolor As Word ' pixel color ' for graph draw Dim Gx0 As Integer , Gy0 As Integer ' graph start (X, Y) Dim Gmag As Single ' graph Y magnify factor ' graph draw X index Dim Btick As Byte ' sample F information ' for STRING display Dim Cpos As Byte Dim Ccolor As Word ' character color Dim Bcolor As Word ' character background color Dim Comd As Byte ' CGLCD command ' for Logic Analyzer Dim Lpara As Word Dim Blpara_h As Byte At Lpara + 1 Overlay Dim Blpara_l As Byte At Lpara Overlay Dim Ramaddr As Word Dim Rama_h As Byte At Ramaddr + 1 Overlay Dim Rama_l As Byte At Ramaddr Overlay Dim Rdaddr As Word Dim Rda_h As Byte At Rdaddr + 1 Overlay Dim Rda_l As Byte At Rdaddr Overlay Dim Lng_addr As Long , Lng_addr2 As Long Dim Ofs_addr As Long ' offset address Dim Term As Integer ' trigger term Dim Wmag As Integer Dim Wdigit As Integer Dim Sflag As Bit ' start flag Dim Stop_flag As Bit ' stop flag Dim Dtflag As Bit ' data ready flag Dim Axflag As Bit ' axis draw Dim Wchgflag As Bit ' Wdigit was changed Dim Wvflag As Bit ' Wave parameter / not Dim Conti_flag As Bit ' Cotinuous/Single shot Dim Scount As Integer Dim Ptc_flag As Bit ' protocol Analyzer ON/OFF Dim Lcmp_flag As Bit ' logic compare ON/OFF Dim Bf_flag As Bit ' binary file has been load ' Protocol analyzer Dim I2c_sflag As Bit ' Started flag Dim I2c_dflag As Bit ' data part flag Dim I2c_count As Byte Dim I2c_row As Byte ' for protocol analyzer disp. Dim I2c_addr As Word Dim I2c_dcnt As Byte Dim I2c_dat As Word Dim Sda0 As Byte , Sda1 As Byte ' SDA state Dim Scl0 As Byte , Scl1 As Byte ' SCL state ' data buffer Dim Dbuf(xrange) As Byte Dim Dbuf2(xrange) As Byte Dim Pbuf(xrange) As Byte '----------------------------------------------------------------- ' ' Main program ' '----------------------------------------------------------------- Rem program start Rem initialize variables Lpara = 0 Reset Sflag Reset Stop_flag Reset Conti_flag Set Storagen ' stop Logi-Ana Reset Dtflag Reset Axflag Reset Wvflag Reset Bf_flag Wmag = 1 Wdigit = 0 Set Wchgflag Reset Dirset Reset Serr_flag Ramaddr = 0 Rdaddr = Ramaddr Lng_addr = Ramaddr Lng_addr2 = Lng_addr + &H10000 Ofs_addr = 0 Reset Ptc_flag ' protocol Analyzer ON/OFF Reset Lcmp_flag ' logic compare ON/OFF ' filenumber init. Fnum = Efnum If Fnum < 0 Or Fnum > 9999 Then Fnum = 0 Efnum = Fnum End If Bfnum = Ebfnum If Bfnum < 0 Or Bfnum > 9999 Then Bfnum = 0 Ebfnum = Bfnum End If Rem Port initialize ' FPGA I/F initialize Set Gssn1 ' reset SPI /SS of GLCD Set Gssn2 Set Gssn3 Set Ssn1 ' reset SPI /SS of Logi-Ana Set Ssn2 Set Ssn3 Set Rdckn ' reset Data RD /CK Reset Gsys_resn ' GLCD Reset Waitms 30 Set Gsys_resn ' release GLCD Reset ' Print "Board test start" ' program start indication. ' LED pico-pico. Reset Led For I = 1 To 3 Toggle Led ' change bit 1/0 Waitms Dly1 ' wait Dly1 ms Next I Reset Led ' wait GLCD power-up (wait release of Wr_busy signal from FPGA) Bitwait Wr_busy , Reset Rem initialize variables Reset Dflag Reset Dirset ' Directory has not yet read. Bcolor = Black ' back color = black Ccolor = White ' char. color Cmode = 0 Gx0 = 0 ' graph start X0 Sbank = &B0000_0000 ' video RAM bank = 0 Gosub Bank_set Gosub Glcd_cls ' GLCD clear screen Col = 1 Row = 1 S = "Logic Analyzer ver. 0.23 : Select Mode by SW6" Gosub Lcd_lprint ' large character print Term = 0 ' selected parameter term Gosub Disp_mode0 ' Mode0 display B = Pinc ' clear PortC previous input Rem Main loop Mloop: If Sflag = 1 Then ' Logi-Ana has started ' if SW2 is pushed, then stop If Sw2 = 0 Then Set Stop_flag ' stop flag Gosub Sw2wait End If ' if SW6 is pushed, then forced stop it If Sw6 = 0 Then Set Storagen ' Stop Logi-Ana Reset Sflag ' start flag Reset Dtflag Reset Axflag Col = 1 Row = 7 S = "Forced STOP by SW6" Gosub Add_space ' add space char. Gosub Lcd_lprint Gosub Wdisp Gosub Sw6wait Else If Endn = 0 Then ' signal has been detected Reset Ssn2 Spiin Sdao(1) , 2 ' get marked RAM address Set Ssn2 Rama_h = Sdao(1) Rama_l = Sdao(2) ' set to RAMaddr Ramaddr = Ramaddr - 3 Rdaddr = Ramaddr Lng_addr = Ramaddr Lng_addr2 = Lng_addr + &H10000 Lng_addr = Lng_addr + Ofs_addr Set Dtflag ' set Data flag If Conti_flag = 0 Then Set Stop_flag ' single If Stop_flag = 1 Then If Conti_flag = 1 Then Reset Sflag Col = 1 Row = 7 S = "STOP by SW2" Gosub Add_space ' add space char. Gosub Lcd_lprint Else Reset Sflag S = "Single shot Triggered" Gosub Add_space ' add space char. Col = 1 Row = 7 Gosub Lcd_lprint ' large character print End If Reset Stop_flag Else If Scount = 0 Then S = "Met the Trigger condition" Col = 1 Row = 5 Gosub Add_space ' add space char. Gosub Lcd_lprint ' large character print Incr Scount End If End If Set Wchgflag ' wave change flag Reset Axflag ' axis not yet drawn Gosub Wdisp ' wave display If Conti_flag = 1 And Sflag = 1 And Stop_flag = 0 Then ' continuous mode (re-trigger) Set Storagen Waitus 1 Reset Storagen End If End If End If ' end of SW6 sense If Sw3 = 0 Then Gosub Sw3op End If If Sw4 = 0 Then Gosub Sw4op End If If Sw5 = 0 Then Gosub Sw5op End If B = Encoder(pinc.0 , Pinc.1 , Rencl , Rencr , 0) ' rotary encoder sense Else ' has not started yet If Dirset = 1 Then If Sdc_ncd = 1 Then ' SD-Card ejected Reset Dirset End If End If If Sw1 = 0 Then Gosub Sw1op End If If Sw2 = 0 Then Gosub Sw2op End If If Sw3 = 0 Then Gosub Sw3op End If If Sw4 = 0 Then Gosub Sw4op End If If Sw5 = 0 Then Gosub Sw5op End If If Sw6 = 0 Then ' SW6 pushed -> mode select Incr Cmode If Sw5 = 0 Then ' SW5 & SW6 are pushed (advance to disk save & USB transfer) If Cmode > 3 Then Cmode = 0 Else ' SW5 is not pushed If Cmode > 1 Then Cmode = 0 End If Gosub Cdisp Gosub Sw6wait End If B = Encoder(pinc.0 , Pinc.1 , Rencl , Rencr , 0) ' rotary encoder sense End If Goto Mloop ' LOOP End Rem subroutines ' add spaces after string S Add_space: Ns1 = Len(s) Ns2 = Colmax Ns2 = Ns2 - Ns1 If Ns2 > 0 Then Sspc = Space(ns2) S = S + Sspc End If Return ' wait SW change Sw1wait: Waitms Dly2 Bitwait Sw1 , Set ' wait for SW1 release Return ' wait SW2 change Sw2wait: Waitms Dly2 Bitwait Sw2 , Set ' wait for SW2 release Return ' wait SW3 change Sw3wait: Waitms Dly2 Bitwait Sw3 , Set ' wait for SW3 release Return Sw4wait: Waitms Dly2 Bitwait Sw4 , Set ' wait for SW4 release Return Sw5wait: If Cmode >= 1 Then Return Waitms Dly2 Bitwait Sw5 , Set ' wait for SW5 release Return Sw6wait: Waitms Dly2 Bitwait Sw6 , Set ' wait for SW6 release Return ' mode display Cdisp: Select Case Cmode Case 0: Set Storagen ' Stop Logi-Ana Set Wchgflag ' wave change flag Gosub Disp_mode0 Case 1: Set Storagen ' Stop Logi-Ana Gosub Disp_mode1 Case 2: Set Storagen ' Stop Logi-Ana Gosub Disp_mode2 Case 3: Set Storagen ' Stop Logi-Ana Gosub Disp_mode3 End Select Return '----------------------------------------------------------------- ' ' Mode display ' '----------------------------------------------------------------- ' Disp_mode0 ' Logic analyzer mode Disp_mode0: Col = 1 Row = 44 S = Space(35) Gosub Lcd_lprint Col = 1 Row = 3 S = "Logic Analyzer: SW1/SW2=Start/Stop,SW5=Wave/LogiAna para" Gosub Add_space ' add space char. Gosub Lcd_lprint ' large character print Col = 1 Row = 5 If Wvflag = 0 Then S = "Set parameters: SW3/SW4 = select term, RotEnc = change" Else S = "Set Wave display: SW3/SW4 = Shrink -+, RotEnc = position" End If Gosub Add_space ' add space char. Gosub Lcd_lprint ' large character print Col = 1 Row = 7 S = Space(colmax) Gosub Lcd_lprint ' large character print Gosub Disp_mode02 Gosub Disp_mode04 Return Rem display LogiAna status Disp_mode02: ' sampling frequency I = Lpara Shift I , Right , 14 ' extract sampling f bits Select Case I Case 0: S = "0.1" Case 1: S = "1" Case 2: S = "10" Case 3: S = "100" End Select S = "Sample F = " + S S = S + "MHz " Row = 34 Col = 80 If Term = 0 And Wvflag = 0 Then Bcolor = Violet Else Bcolor = Black End If Ccolor = White Gosub Lcd_lprint2 Bcolor = Black ' CH0 trigger condition N = Lpara Gosub Trig_status S = "CH0 " + S2 If Term = 1 And Wvflag = 0 Then Bcolor = Green Else Bcolor = Black End If Ccolor = Red Row = 36 Col = 80 Gosub Lcd_lprint2 ' CH1 trigger condition N = Lpara Shift N , Right , 3 Gosub Trig_status S = "CH1 " + S2 If Term = 2 And Wvflag = 0 Then Bcolor = Blue Else Bcolor = Black End If Ccolor = Green Row = 38 Col = 80 Gosub Lcd_lprint2 ' CH2 trigger condition N = Lpara Shift N , Right , 6 Gosub Trig_status S = "CH2 " + S2 If Term = 3 And Wvflag = 0 Then Bcolor = Green Else Bcolor = Black End If Ccolor = Blue Row = 40 Col = 80 Gosub Lcd_lprint2 ' CH3 trigger condition N = Lpara Shift N , Right , 9 Gosub Trig_status S = "CH3 " + S2 If Term = 4 And Wvflag = 0 Then Bcolor = Blue Else Bcolor = Black End If Ccolor = Orange Row = 42 Col = 80 Gosub Lcd_lprint2 ' AND trigger condition N = Lpara And &H3000 If N = &H2000 Then S = "Trig : All CH AND" Elseif N = &H1000 Then S = "Trig : CH2 & CH3 " Else S = "Trig : CHs OR " End If If Term = 5 And Wvflag = 0 Then Bcolor = Orange Else Bcolor = Black End If Ccolor = Sky Row = 44 Col = 80 Gosub Lcd_lprint2 ' Single/Continuous If Conti_flag = 0 Then S = "Single " Else S = "Continuous" End If If Term = 6 And Wvflag = 0 Then Bcolor = Blue Else Bcolor = Black End If Ccolor = Yellow Row = 46 Col = 80 Gosub Lcd_lprint2 Return ' extract trigger status Trig_status: I = N And &B100 If I <> 0 Then J = N And &B10 K = N And 1 If J <> 0 Then If K <> 0 Then S2 = " Rise edge" Else S2 = " Fall edge" End If Else If K <> 0 Then S2 = " H level " Else S2 = " L level " End If End If Else S2 = "** " End If Return Rem disp sweep display range Disp_mode04: Ccolor = White If Wvflag = 1 Then Bcolor = Blue Else Bcolor = Black End If Col = 1 Row = 36 S = "Shrink(SW3-,SW4+) = 1/" S2 = Str(wmag) S = S + S2 Gosub Lcd_lprint2 ' large character print S = " t0 = " S2 = Str(ofs_addr) S = S + S2 N = Len(s2) N = 6 - N If N > 0 Then S1 = Space(n) S = S + S1 If Wvflag = 0 Then S = S + " " End If Gosub Lcd_lprint2 ' large character print If Wchgflag = 1 Then Reset Axflag Gosub Wdisp Reset Wchgflag End If Return ' Disp_mode1 ' Compare & protocol set Disp_mode1: Col = 1 Row = 3 S = "Logic compare & Protocol analyzer set" Gosub Add_space ' add space char. Gosub Lcd_lprint ' large character print Col = 1 Row = 5 S = "Rotary encoder = Binaly file # change: " Bfname = Str(bfnum) Bfname = "Lw" + Bfname Bfname = Bfname + ".dat" S = S + Bfname Gosub Add_space ' add space char. Gosub Lcd_lprint ' large character print Col = 1 Row = 7 S = "SW1 = File save, SW3, 4 = Compare, Protocol ON/OFF" Gosub Add_space ' add space char. Gosub Lcd_lprint ' large character print Col = 1 Row = 40 S = "Logic compare (SW3 in Mode1) = " If Lcmp_flag = 0 Then S2 = "OFF" Else S2 = "ON " End If S = S + S2 Gosub Lcd_lprint ' large character print Col = 1 Row = 42 S = "Protocol Analyzer (SW4 in Mode1) = " If Ptc_flag = 0 Then S2 = "OFF" Else S2 = "ON " End If S = S + S2 Gosub Lcd_lprint ' large character print Col = 1 Row = 44 S = "To enter mode2,3 push both SW5 & 6" Gosub Lcd_lprint Return ' Disp_mode2 ' SD-Card Disp_mode2: Col = 1 Row = 3 S = "Store data into SD-Card file: SW1 = Start" Gosub Add_space ' add space char. Gosub Lcd_lprint ' large character print Col = 1 Row = 5 S = "Rotary encoder = Text file # change: " Fname = Str(fnum) Fname = "Lw" + Fname Fname = Fname + ".txt" S = S + Fname Gosub Add_space ' add space char. Gosub Lcd_lprint ' large character print Col = 1 Row = 7 S = Space(colmax) Gosub Lcd_lprint ' large character print Return ' Disp_mode3 ' USB Disp_mode3: Col = 1 Row = 3 S = "Send data via USB: SW1 = Start, SW2 = Stop" Gosub Add_space ' add space char. Gosub Lcd_lprint ' large character print Col = 1 Row = 5 S = Space(colmax) Gosub Lcd_lprint ' large character print Return Rem Rotary encoder rotates to Left[counter-clockwise] (decrement value) Rencl: Waitus Dly3 B = Pinc B = B And &H03 ' Print B ' for debug If B <> &B01 Then If B = 0 Then Goto Rencr Return End If Select Case Cmode Case 0: If Wvflag = 0 Then ' Logi-Ana parameter set Select Case Term Case 0: ' sampling F I = Lpara Shift I , Right , 14 ' extract sampling f bits I = I And &B11 Decr I I = I And &B11 Shift I , Left , 14 J = Lpara J = J And &H3FFF I = I Or J Lpara = I Case 1: ' CH0 I = Lpara I = I And 7 Gosub Ch_set_minus K = Lpara K = K And &HFFF8 K = K Or J Lpara = K Case 2: ' CH1 I = Lpara Shift I , Right , 3 I = I And 7 Gosub Ch_set_minus K = Lpara K = K And &HFFC7 Shift J , Left , 3 K = K Or J Lpara = K Case 3: ' CH2 I = Lpara Shift I , Right , 6 I = I And 7 Gosub Ch_set_minus K = Lpara K = K And &HFE3F Shift J , Left , 6 K = K Or J Lpara = K Case 4: ' CH3 I = Lpara Shift I , Right , 9 I = I And 7 Gosub Ch_set_minus K = Lpara K = K And &HF1FF Shift J , Left , 9 K = K Or J Lpara = K Case 5: ' AND condition I = Lpara I = I And &H3000 If I = 0 Then I = &H2000 Elseif I = &H1000 Then I = 0 Else I = &H1000 End If K = Lpara K = K And &HCFFF K = K Or I Lpara = K Case 6: ' Trigger mode (Conti/Single) Toggle Conti_flag End Select Gosub Disp_mode02 If Sflag = 1 Then ' already started, change Logi-Ana setting Set Storagen ' reset Logi-Ana Sdao(1) = Blpara_h Sdao(2) = Blpara_l ' set Lpara Reset Ssn1 Spiout Sdao(1) , 2 ' Lpara set by SPI out to Logi-Ana FPGA Set Ssn1 Reset Storagen ' Start Logi-Ana Reset Dtflag End If Else ' change data display range If Wmag = 100 Then Return Lng = Ramaddr L2 = Xrange2 L2 = L2 * Wmag Lng_addr = Lng_addr - L2 If Lng_addr < Lng Then Lng_addr = Lng Ofs_addr = 0 Else Ofs_addr = Ofs_addr - L2 End If Set Wchgflag Reset Bf_flag Gosub Disp_mode04 End If Case 1: ' binary file# change N = Bfnum Decr Bfnum If Bfnum < 0 Then Bfnum = 0 If Bfnum <> N Then Ebfnum = Fnum Gosub Disp_mode1 Case 2: ' text file# change N = Fnum Decr Fnum If Fnum < 0 Then Fnum = 0 If Fnum <> N Then Efnum = Fnum Gosub Disp_mode2 End Select Waitms Dly4 Return Rem Rotary encoder to Right[clockwise] (increment value) Rencr: Waitus Dly3 B = Pinc B = B And &H03 ' Print B ' for debug If B <> &B00 Then If B = &B01 Then Goto Rencl Return End If Select Case Cmode Case 0: If Wvflag = 0 Then ' Logi-Ana parameter set Select Case Term Case 0: ' sampling F I = Lpara Shift I , Right , 14 ' extract sampling f bits Incr I I = I And &B11 Shift I , Left , 14 J = Lpara J = J And &H3FFF I = I Or J Lpara = I Case 1: ' CH0 I = Lpara I = I And 7 Gosub Ch_set K = Lpara K = K And &HFFF8 K = K Or J Lpara = K Case 2: ' CH1 I = Lpara Shift I , Right , 3 I = I And 7 Gosub Ch_set K = Lpara K = K And &HFFC7 Shift J , Left , 3 K = K Or J Lpara = K Case 3: ' CH2 I = Lpara Shift I , Right , 6 I = I And 7 Gosub Ch_set K = Lpara K = K And &HFE3F Shift J , Left , 6 K = K Or J Lpara = K Case 4: ' CH3 I = Lpara Shift I , Right , 9 I = I And 7 Gosub Ch_set K = Lpara K = K And &HF1FF Shift J , Left , 9 K = K Or J Lpara = K Case 5: ' AND condition I = Lpara I = I And &H3000 If I = 0 Then I = &H1000 Elseif I = &H1000 Then I = &H2000 Else I = 0 End If K = Lpara K = K And &HCFFF K = K Or I Lpara = K Case 6: ' Trigger mode (Conti/Single) Toggle Conti_flag End Select Gosub Disp_mode02 If Sflag = 1 Then ' already started, change Logi-Ana setting Set Storagen ' reset Logi-Ana Sdao(1) = Blpara_h Sdao(2) = Blpara_l ' set Lpara Reset Ssn1 Spiout Sdao(1) , 2 ' Lpara set by SPI out to Logi-Ana FPGA Set Ssn1 Reset Storagen ' Start Logi-Ana Reset Dtflag End If Else ' change data display range If Wmag = 100 Then Return Lng = Lng_addr L2 = Xrange2 L2 = L2 * Wmag L = Xrange L = L * Wmag Lng_addr = Lng_addr + L2 L = L + Lng_addr If L > Lng_addr2 Then Lng_addr = Lng Else Ofs_addr = Ofs_addr + L2 End If Set Wchgflag Reset Bf_flag Gosub Disp_mode04 End If Case 1: ' binary file# change Incr Bfnum If Bfnum > 9999 Then Bfnum = 0 Ebfnum = Bfnum Gosub Disp_mode1 Case 2: ' text file# change Incr Fnum If Fnum > 9999 Then Fnum = 0 Efnum = Fnum Gosub Disp_mode2 End Select Waitms Dly4 Return ' set CH trigger condition ' I = data, J = new value Ch_set: Select Case I Case 0: J = &B100 ' L level trig Case 4: J = &B101 ' H level trig Case 5: J = &B110 ' Fall edge trig Case 6: J = &B111 ' Rise edge trig Case 7: J = &B000 ' Disable Case Else: J = 0 End Select Return ' set CH trigger condition (minus direction) Ch_set_minus: Select Case I Case 0: J = &B111 ' Rise edge trig Case 4: J = &B000 ' Disable Case 5: J = &B100 ' L level trig Case 6: J = &B101 ' H level trig Case 7: J = &B110 ' Fall edge trig Case Else: J = 0 End Select Return Rem SW operations Rem SW1, SW2 (Start/Stop) Sw1op: Select Case Cmode Case 0: If Sflag = 0 Then ' not started Reset Stop_flag Scount = 0 Set Storagen ' reset Logi-Ana Set Sflag ' start flag Sdao(1) = Blpara_h Sdao(2) = Blpara_l ' set Lpara Reset Ssn1 Spiout Sdao(1) , 2 ' Lpara set by SPI out to Logi-Ana FPGA Set Ssn1 Reset Storagen ' Start Logi-Ana Reset Dtflag Reset Axflag Col = 1 Row = 5 S = Space(colmax) Gosub Lcd_lprint Col = 1 Row = 7 Ccolor = Yellow Bcolor = Blue S = "START (wait Trigger)" Gosub Add_space ' add space char. Gosub Lcd_lprint2 End If Case 1: ' save binary file Col = 1 Row = 5 S = "File-out START" Ccolor = Red Bcolor = Blue Gosub Add_space ' add space char. Gosub Lcd_lprint2 ' large character print Gosub Bfsave If Serr_flag = 0 Then Col = 1 Row = 5 S = "File-out END " Gosub Add_space ' add space char. Gosub Lcd_lprint ' large character print End If Case 2: Col = 1 Row = 5 S = "File-out START" Ccolor = Red Bcolor = Blue Gosub Add_space ' add space char. Gosub Lcd_lprint2 ' large character print Gosub Filesave If Serr_flag = 0 Then Col = 1 Row = 5 S = "File-out END " Gosub Add_space ' add space char. Gosub Lcd_lprint ' large character print End If Case 3: Col = 1 Row = 5 S = "USB Xfer START (SW3 = Abort)" Ccolor = Red Bcolor = Blue Gosub Add_space ' add space char. Gosub Lcd_lprint2 ' large character print Gosub Usbxfer Col = 1 Row = 5 S = "USB Xfer END" Gosub Add_space ' add space char. Gosub Lcd_lprint ' large character print End Select Gosub Sw1wait Return Rem SW2 operation Sw2op: Select Case Cmode Case 0: Set Stop_flag ' stop flag End Select Gosub Sw2wait Return Rem SW3,SW4 Operation ' various function under Mode# ' mode0: select parameter term ' wave display control Rem SW3 operation Sw3op: Select Case Cmode Case 0: If Wvflag = 0 Then Incr Term If Term > 6 Then Term = 0 Gosub Disp_mode02 Else Decr Wdigit If Wdigit < 0 Then Wdigit = 0 Set Wchgflag Reset Bf_flag Gosub Wmagset Gosub Disp_mode04 End If Case 1: Toggle Lcmp_flag Gosub Disp_mode1 End Select Gosub Sw3wait Return Rem SW4 operation Sw4op: Select Case Cmode Case 0: If Wvflag = 0 Then Decr Term If Term < 0 Then Term = 6 Gosub Disp_mode02 Else Incr Wdigit If Wdigit > 6 Then Wdigit = 6 Set Wchgflag Reset Bf_flag Gosub Wmagset Gosub Disp_mode04 End If Case 1: Toggle Ptc_flag Gosub Disp_mode1 End Select Gosub Sw4wait Return Rem SW5 operation ' Logi-Ana parameter set mode / Display parameter set mode Sw5op: Select Case Cmode Case 0: Toggle Wvflag Gosub Disp_mode02 Gosub Disp_mode04 End Select Gosub Sw5wait Return Rem Wmag set Wmagset: Select Case Wdigit Case 0: Wmag = 1 Case 1: Wmag = 2 Case 2: Wmag = 5 Case 3: Wmag = 10 Case 4: Wmag = 20 Case 5: Wmag = 50 Case 6: Wmag = 100 Lng_addr = Ramaddr End Select Return Rem wave graph display Wdisp: If Dtflag = 0 Then S = "No data" Col = 15 Row = 11 Gosub Lcd_lprint Return Else ' clear screen Gcolor = Black Gosub Gcset X1 = X0posi Y1 = Y0posi X2 = X1 + Xrange Y2 = Y1 + Yrange Gosub X1set Gosub Y1set Gosub X2set Gosub Y2set ' send clear-area command Comd = &H80 ' wait Area clear Gosub Comset End If If Axflag = 0 Then Gosub Axdraw Set Axflag End If If Wchgflag = 1 Then Reset Wchgflag Gosub Wgraph If Lcmp_flag = 1 Then If Bf_flag = 0 Then Gosub Bfload Set Bf_flag End If End If If Lcmp_flag = 1 Then Gosub Cwgraph ' compare data graph End If If Ptc_flag = 1 Then Gosub Ptc_disp ' protocol display End If End If Return Rem draw axis Axdraw: Gcolor = White I1 = X0posi J1 = Y0posi J2 = J1 + Yrange Lcdline I1 , J1 , I1 , J2 ' draw line I2 = I1 + Xrange Lcdline I1 , J2 , I2 , J2 ' draw line Row = Ylabel ' Y label Row For I = 0 To 3 S = Str(i) S = "CH" + S Col = 2 Gosub Lcd_lprint Row = Row + Ylskip Next I ' draw Time tick I = Lpara Shift I , Right , 14 I = I And 3 Btick = I Tlng = Lng_addr L2 = Ramaddr Tlng = Tlng - L2 Select Case Btick Case 0: Stick = "ms" Tlng2 = 10 Tlng = Tlng * Tlng2 Tlng2 = Tlng2 * Wmag ' us units Case 1: If Wmag < 10 Then Stick = "us" Else Stick = "ms" End If Tlng2 = Wmag ' us units Case 2: Stick = "us" Tlng2 = 100 Tlng = Tlng * Tlng2 Tlng2 = Tlng2 * Wmag ' ns units Case 3: Stick = "us" Tlng2 = 10 Tlng = Tlng * Tlng2 Tlng2 = Tlng2 * Wmag ' ns units End Select Gosub Ttick Return Rem draw time tick Ttick: Col = Xlabel Row = Xlabel2 J = Xrange J = J / 7 S = Space(j) Gosub Lcdprint Col = Xlabel Row = Xlabel2 X = Col Y = 50 ' 50 pixel for tick Y = Y / 7 ' 7x9 char. dots L2 = Tlng2 * 50 I1 = X0posi J1 = Y0posi J1 = J1 + Yrange J2 = J1 + 5 For I = 0 To 12 Lcdline I1 , J1 , I1 , J2 ' draw line I1 = I1 + 50 Select Case Btick Case 0: Z = Tlng Z = Z / 1000 S = Fusing(z , "####.#") Case 1: If Wmag < 10 Then S = Str(tlng) Else Z = Tlng Z = Z / 1000 S = Fusing(z , "####.#") End If Case 2 To 3: Z = Tlng Z = Z / 1000 S = Fusing(z , "####.#") End Select Tlng = Tlng + L2 Gosub Lcdprint X = X + Y K = X Col = K Next I Col = 50 Row = Xlabel2 Row = Row + 1 S = Stick Gosub Lcd_lprint Return Rem waveform graph Wgraph: L2 = Lng_addr L2 = L2 And &HFFFF Rdaddr = L2 Sdao(1) = Rda_h Sdao(2) = Rda_l ' set read address Reset Ssn3 Spiout Sdao(1) , 2 Set Ssn3 Rem NOTE: To get data from pipelined RAM ater the first address set via SPI, ' 2 pre-RD-CK must be asserted due to FPGA design. Reset Rdckn Waitus 1 Set Rdckn ' pre-CK Reset Rdckn Waitus 1 Set Rdckn ' pre-CK (2-CK) For I = 1 To Xrange If Wdigit = 0 Then ' non-shulink B = Pina B = B And &HF Reset Rdckn Waitus 1 Set Rdckn ' advance RD counter Dbuf(i) = B ' store into data buffer Else ' shulink data Reset R_edge0 Reset F_edge0 Reset R_edge1 Reset F_edge1 Reset R_edge2 Reset F_edge2 Reset R_edge3 Reset F_edge3 B2 = Pina B2 = B2 And &H0F B5 = B2 For J = 1 To Wmag B = Pina B = B And &H0F Reset Rdckn Waitus 1 Set Rdckn ' advance RD counter B3 = B2 And 1 B4 = B And 1 If B3 = 0 And B4 <> 0 Then ' exist CH0 rise edge Set R_edge0 End If If B3 <> 0 And B4 = 0 Then ' exist CH0 fall edge Set F_edge0 End If B3 = B2 And 2 B4 = B And 2 If B3 = 0 And B4 <> 0 Then ' exist CH1 rise edge Set R_edge1 End If If B3 <> 0 And B4 = 0 Then ' exist CH0 fall edge Set F_edge1 End If B3 = B2 And 4 B4 = B And 4 If B3 = 0 And B4 <> 0 Then ' exist CH0 rise edge Set R_edge2 End If If B3 <> 0 And B4 = 0 Then ' exist CH0 fall edge Set F_edge2 End If B3 = B2 And 8 B4 = B And 8 If B3 = 0 And B4 <> 0 Then ' exist CH0 rise edge Set R_edge3 End If If B3 <> 0 And B4 = 0 Then ' exist CH0 fall edge Set F_edge3 End If B2 = B Next J B4 = 0 If R_edge0 = 1 And F_edge0 = 1 Then B4 = B4 Or &H10 ' mark CH0 discrepancy End If If R_edge1 = 1 And F_edge1 = 1 Then B4 = B4 Or &H20 ' mark CH1 discrepancy End If If R_edge2 = 1 And F_edge2 = 1 Then B4 = B4 Or &H40 ' mark CH2 discrepancy End If If R_edge3 = 1 And F_edge3 = 1 Then B4 = B4 Or &H80 ' mark CH3 discrepancy End If B5 = B5 Or B4 ' mark cdiscrepancy bits Dbuf(i) = B5 End If Next I ' CH0 disp I3 = X0posi I3 = I3 + 1 J3 = Y0posi J3 = J3 + Bvskip ' H level Y J = J3 + Bvmag ' L level Y B = Dbuf(1) B = B And &H10 If B <> 0 Then Gcolor = Violet Lcdline I3 , J3 , I3 , J End If B2 = Dbuf(1) B2 = B2 And 1 I2 = I3 For I = 2 To Xrange Incr I3 B = Dbuf(i) Gcolor = Red B = B And 1 If B <> B2 Then If B2 <> 0 Then Lcdline I2 , J3 , I3 , J3 Lcdline I3 , J3 , I3 , J Else Lcdline I2 , J , I3 , J Lcdline I3 , J3 , I3 , J End If B2 = B I2 = I3 End If B3 = Dbuf(i) B3 = B3 And &H10 If B3 <> 0 Then Gcolor = Violet Lcdline I3 , J3 , I3 , J End If Next I Gcolor = Red If B = B2 And I2 <> I3 Then If B2 <> 0 Then Lcdline I2 , J3 , I3 , J3 Else Lcdline I2 , J , I3 , J End If End If ' CH1 disp I3 = X0posi I3 = I3 + 1 J3 = J3 + Bvskip ' H level Y J = J3 + Bvmag ' L level Y B = Dbuf(1) B = B And &H20 If B <> 0 Then Gcolor = Violet Lcdline I3 , J3 , I3 , J End If B2 = Dbuf(1) B2 = B2 And 2 I2 = I3 For I = 2 To Xrange Incr I3 B = Dbuf(i) Gcolor = Green B = B And 2 If B <> B2 Then If B2 <> 0 Then Lcdline I2 , J3 , I3 , J3 Lcdline I3 , J3 , I3 , J Else Lcdline I2 , J , I3 , J Lcdline I3 , J3 , I3 , J End If B2 = B I2 = I3 End If B3 = Dbuf(i) B3 = B3 And &H20 If B3 <> 0 Then Gcolor = Violet Lcdline I3 , J3 , I3 , J End If Next I Gcolor = Green If B = B2 And I2 <> I3 Then If B2 <> 0 Then Lcdline I2 , J3 , I3 , J3 Else Lcdline I2 , J , I3 , J End If End If ' CH2 disp I3 = X0posi I3 = I3 + 1 J3 = J3 + Bvskip ' H level Y J = J3 + Bvmag ' L level Y B = Dbuf(1) B = B And &H40 If B <> 0 Then Gcolor = Violet Lcdline I3 , J3 , I3 , J End If B2 = Dbuf(1) B2 = B2 And 4 I2 = I3 For I = 2 To Xrange Incr I3 B = Dbuf(i) Gcolor = Blue B = B And 4 If B <> B2 Then If B2 <> 0 Then Lcdline I2 , J3 , I3 , J3 Lcdline I3 , J3 , I3 , J Else Lcdline I2 , J , I3 , J Lcdline I3 , J3 , I3 , J End If B2 = B I2 = I3 End If B3 = Dbuf(i) B3 = B3 And &H40 If B3 <> 0 Then Gcolor = Violet Lcdline I3 , J3 , I3 , J End If Next I Gcolor = Blue If B = B2 And I2 <> I3 Then If B2 <> 0 Then Lcdline I2 , J3 , I3 , J3 Else Lcdline I2 , J , I3 , J End If End If ' CH3 disp I3 = X0posi I3 = I3 + 1 J3 = J3 + Bvskip ' H level Y J = J3 + Bvmag ' L level Y B = Dbuf(1) B = B And &H80 If B <> 0 Then Gcolor = Violet Lcdline I3 , J3 , I3 , J End If B2 = Dbuf(1) B2 = B2 And 8 I2 = I3 For I = 2 To Xrange Incr I3 B = Dbuf(i) Gcolor = Orange B = B And 8 If B <> B2 Then If B2 <> 0 Then Lcdline I2 , J3 , I3 , J3 Lcdline I3 , J3 , I3 , J Else Lcdline I2 , J , I3 , J Lcdline I3 , J3 , I3 , J End If B2 = B I2 = I3 End If B3 = Dbuf(i) B3 = B3 And &H80 If B3 <> 0 Then Gcolor = Violet Lcdline I3 , J3 , I3 , J End If Next I Gcolor = Orange If B = B2 And I2 <> I3 Then If B2 <> 0 Then Lcdline I2 , J3 , I3 , J3 Else Lcdline I2 , J , I3 , J End If End If Return Rem draw compare waveform graph Cwgraph: ' CH0 disp I3 = X0posi I3 = I3 + 1 J3 = Y0posi J3 = J3 + Bvskip ' H level Y J3 = J3 + Bsepa J = J3 + Bvmag2 ' L level Y B = Dbuf2(1) B = B And &H10 If B <> 0 Then Gcolor = Violet Lcdline I3 , J3 , I3 , J End If B2 = Dbuf2(1) B2 = B2 And 1 I2 = I3 For I = 2 To Xrange Incr I3 B = Dbuf2(i) Gcolor = Yellow B = B And 1 If B <> B2 Then If B2 <> 0 Then Lcdline I2 , J3 , I3 , J3 Lcdline I3 , J3 , I3 , J Else Lcdline I2 , J , I3 , J Lcdline I3 , J3 , I3 , J End If B2 = B I2 = I3 End If B3 = Dbuf2(i) B3 = B3 And &H10 If B3 <> 0 Then Gcolor = Violet Lcdline I3 , J3 , I3 , J End If Next I Gcolor = Yellow If B = B2 And I2 <> I3 Then If B2 <> 0 Then Lcdline I2 , J3 , I3 , J3 Else Lcdline I2 , J , I3 , J End If End If ' CH1 disp I3 = X0posi I3 = I3 + 1 J3 = J3 + Bvskip ' H level Y J = J3 + Bvmag2 ' L level Y B = Dbuf2(1) B = B And &H20 If B <> 0 Then Gcolor = Violet Lcdline I3 , J3 , I3 , J End If B2 = Dbuf2(1) B2 = B2 And 2 I2 = I3 For I = 2 To Xrange Incr I3 B = Dbuf2(i) Gcolor = Light_green B = B And 2 If B <> B2 Then If B2 <> 0 Then Lcdline I2 , J3 , I3 , J3 Lcdline I3 , J3 , I3 , J Else Lcdline I2 , J , I3 , J Lcdline I3 , J3 , I3 , J End If B2 = B I2 = I3 End If B3 = Dbuf2(i) B3 = B3 And &H20 If B3 <> 0 Then Gcolor = Violet Lcdline I3 , J3 , I3 , J End If Next I Gcolor = Light_green If B = B2 And I2 <> I3 Then If B2 <> 0 Then Lcdline I2 , J3 , I3 , J3 Else Lcdline I2 , J , I3 , J End If End If ' CH2 disp I3 = X0posi I3 = I3 + 1 J3 = J3 + Bvskip ' H level Y J = J3 + Bvmag2 ' L level Y B = Dbuf2(1) B = B And &H40 If B <> 0 Then Gcolor = Violet Lcdline I3 , J3 , I3 , J End If B2 = Dbuf2(1) B2 = B2 And 4 I2 = I3 For I = 2 To Xrange Incr I3 B = Dbuf2(i) Gcolor = Sky B = B And 4 If B <> B2 Then If B2 <> 0 Then Lcdline I2 , J3 , I3 , J3 Lcdline I3 , J3 , I3 , J Else Lcdline I2 , J , I3 , J Lcdline I3 , J3 , I3 , J End If B2 = B I2 = I3 End If B3 = Dbuf2(i) B3 = B3 And &H40 If B3 <> 0 Then Gcolor = Violet Lcdline I3 , J3 , I3 , J End If Next I Gcolor = Sky If B = B2 And I2 <> I3 Then If B2 <> 0 Then Lcdline I2 , J3 , I3 , J3 Else Lcdline I2 , J , I3 , J End If End If ' CH3 disp I3 = X0posi I3 = I3 + 1 J3 = J3 + Bvskip ' H level Y J = J3 + Bvmag2 ' L level Y B = Dbuf2(1) B = B And &H80 If B <> 0 Then Gcolor = Violet Lcdline I3 , J3 , I3 , J End If B2 = Dbuf2(1) B2 = B2 And 8 I2 = I3 For I = 2 To Xrange Incr I3 B = Dbuf2(i) Gcolor = Brown B = B And 8 If B <> B2 Then If B2 <> 0 Then Lcdline I2 , J3 , I3 , J3 Lcdline I3 , J3 , I3 , J Else Lcdline I2 , J , I3 , J Lcdline I3 , J3 , I3 , J End If B2 = B I2 = I3 End If B3 = Dbuf2(i) B3 = B3 And &H80 If B3 <> 0 Then Gcolor = Violet Lcdline I3 , J3 , I3 , J End If Next I Gcolor = Brown If B = B2 And I2 <> I3 Then If B2 <> 0 Then Lcdline I2 , J3 , I3 , J3 Else Lcdline I2 , J , I3 , J End If End If Return Rem protocol display ' I2C version ' SDA = CH0, SCL = CH1 Ptc_disp: ' clear excess display S = Space(13) For Row = Ptcrow0 To Ptcrow1 Col = 100 Gosub Lcdprint Next Row ' Store Data into Pbuf For I = 1 To Xrange B = Dbuf(i) B = B And &H33 ' extract , and , Pbuf(i) = B Next I ' check Ofs_addr If Wmag = 100 Then Goto Ptcdsp3 If Ofs_addr = 0 Then Goto Ptcdsp3 ' get protocol status at Ofs_addr Reset I2c_sflag I2c_count = 0 I2c_addr = 0 Reset I2c_dflag I2c_dcnt = 0 I2c_dat = 0 Lng = Ofs_addr Rdaddr = Ramaddr Sdao(1) = Rda_h Sdao(2) = Rda_l ' set read address Reset Ssn3 Spiout Sdao(1) , 2 Set Ssn3 Rem NOTE: To get data from pipelined RAM ater the first address set via SPI, ' 2 pre-RD-CK must be asserted due to FPGA design. Reset Rdckn Waitus 1 Set Rdckn ' pre-CK Reset Rdckn Waitus 1 Set Rdckn ' pre-CK (2-CK) B2 = Pina B2 = B2 And &H03 Scl0 = B2 And &B10 ' extract SCL Sda0 = B2 And &B01 ' extract SDA Do B = Pina B = B And &H03 Gosub Ptc_anal ' analize it Reset Rdckn Waitus 1 Set Rdckn Lng = Lng - 1 Loop Until Lng = 0 If I2c_sflag = 1 Then ' I2C started I3 = X0posi I3 = I3 + 4 I2c_row = Ptcrow0 Goto Ptcdsp5 End If ' I2C not started Ptcdsp3: ' protocol disp I2c_row = Ptcrow0 Reset I2c_sflag I2c_count = 0 I2c_addr = 0 Reset I2c_dflag I2c_dcnt = 0 I2c_dat = 0 I3 = X0posi I3 = I3 + 4 Ptcdsp5: B2 = Pbuf(1) B2 = B2 And &H03 Scl0 = B2 And &B10 ' extract SCL Sda0 = B2 And &B01 ' extract SDA For I = 2 To Xrange B = Pbuf(i) B3 = B B = B And &H03 Scl1 = B And &B10 ' extract SCL Sda1 = B And &B01 ' extract SDA If B <> B2 Then B3 = B3 And &H30 If B3 <> 0 Then S = "X" Gosub Ptc_print Goto Ptcdsp8 End If If I2c_sflag = 0 Then ' not started If B2 = &B11 Then If B = &B10 Then ' SCL = 1 & SDA = 0 S = "S" Gosub Ptc_print Set I2c_sflag I2c_count = 0 I2c_dcnt = 0 I2c_addr = 0 I2c_dat = 0 Else S = "I" 'illegal Gosub Ptc_print End If Goto Ptcdsp8 End If Else ' Started If B2 = &B11 And B = &B10 Then ' SCL = 1 & SDA = 0 ' Repeated Start S = "RS" Gosub Ptc_print Set I2c_sflag Set I2c_dflag I2c_dcnt = 0 I2c_dat = 0 Goto Ptcdsp8 End If If Sda0 = 0 And Sda1 <> 0 Then ' rise edge of SDA If Scl0 <> 0 And Scl1 <> 0 Then ' SCL = 1 ' Stop condition S = "P" Gosub Ptc_print Reset I2c_sflag Reset I2c_dflag Goto Ptcdsp8 End If End If If Scl0 <> 0 And Scl1 = 0 Then ' SCL fall edge If I2c_dflag = 0 Then ' SLA part Incr I2c_count If I2c_count < 9 Then B3 = B And 1 ' extract address bit Shift I2c_addr , Left K = B3 I2c_addr = I2c_addr Or K Elseif I2c_count = 9 Then B5 = I2c_addr S = "A=" S2 = Hex(b5) S = S + S2 B3 = B And 1 ' R/W bit If B3 = 0 Then S2 = "W" Else S2 = "R" End If S = S + S2 Gosub Ptc_print Else ' I2c_count = 10 B3 = B And 1 ' extract ACK If B3 = 1 Then S = "NAck" Else S = "Ack" End If Gosub Ptc_print Set I2c_dflag ' to the next Data get routine I2c_dcnt = 0 End If Else ' Data part Incr I2c_dcnt If I2c_dcnt < 8 Then B3 = B And 1 ' extract data Shift I2c_dat , Left K = B3 I2c_dat = I2c_dat Or K Elseif I2c_dcnt = 8 Then B3 = B And 1 ' extract data Shift I2c_dat , Left K = B3 I2c_dat = I2c_dat Or K B5 = I2c_dat S = "D=" S2 = Hex(b5) S = S + S2 Gosub Ptc_print Else ' I2c_dcnt = 9 B3 = B And 1 ' extract ACK If B3 = 1 Then S = "NAck" Else S = "Ack" End If Gosub Ptc_print I2c_dcnt = 0 End If End If ' end of IF SLA/Data ? End If ' end of IF SCL fall edge End If ' end of IF Start ? End If ' end of IF B<>B2 Ptcdsp8: B2 = B Scl0 = Scl1 ' memorize SCL Sda0 = Sda1 ' memorize SDA Incr I3 Next I Return ' subroutine for protocol print Ptc_print: I2 = I3 / 7 ' 7x9 char. Col = I2 Row = I2c_row Incr I2c_row If I2c_row > Ptcrow1 Then I2c_row = Ptcrow0 Gosub Lcdprint Return ' protocol analysis only Ptc_anal: Scl1 = B And &B10 ' extract SCL Sda1 = B And &B01 ' extract SDA If B <> B2 Then If I2c_sflag = 0 Then ' not started If B2 = &B11 Then If B = &B10 Then ' SCL = 1 & SDA = 0 Set I2c_sflag I2c_count = 0 I2c_dcnt = 0 I2c_addr = 0 I2c_dat = 0 Else 'illegal Reset I2c_sflag I2c_count = 0 I2c_dcnt = 0 I2c_addr = 0 I2c_dat = 0 End If Goto Ptcana8 End If Else ' Started If B2 = &B11 And B = &B10 Then ' SCL = 1 & SDA = 0 ' Repeated Start Set I2c_sflag Set I2c_dflag I2c_dcnt = 0 I2c_dat = 0 Goto Ptcana8 End If If Sda0 = 0 And Sda1 <> 0 Then ' rise edge of SDA If Scl0 <> 0 And Scl1 <> 0 Then ' SCL = 1 ' Stop condition Reset I2c_sflag Reset I2c_dflag Goto Ptcana8 End If End If If Scl0 <> 0 And Scl1 = 0 Then ' SCL fall edge If I2c_dflag = 0 Then ' SLA part Incr I2c_count If I2c_count < 9 Then B3 = B And 1 ' extract address bit Shift I2c_addr , Left K = B3 I2c_addr = I2c_addr Or K Elseif I2c_count = 9 Then B3 = B And 1 ' R/W bit Else ' I2c_count = 10 B3 = B And 1 ' extract ACK Set I2c_dflag ' to the next Data get routine I2c_dcnt = 0 End If Else ' Data part Incr I2c_dcnt If I2c_dcnt < 8 Then B3 = B And 1 ' extract data Shift I2c_dat , Left K = B3 I2c_dat = I2c_dat Or K Elseif I2c_dcnt = 8 Then B3 = B And 1 ' extract data Shift I2c_dat , Left K = B3 I2c_dat = I2c_dat Or K Else ' I2c_dcnt = 9 B3 = B And 1 ' extract ACK I2c_dcnt = 0 End If End If ' end of IF SLA/Data ? End If ' end of IF SCL fall edge End If ' end of IF Start ? End If ' end of IF B<>B2 Ptcana8: B2 = B Scl0 = Scl1 ' memorize SCL Sda0 = Sda1 ' memorize SDA Return '----------------------------------------------------------------- ' ' Color GLCD control subroutines ' communicate with FPGA ' '----------------------------------------------------------------- Rem GLCD control fundamental suroutines ' Clear GLCD screen ' (X1, Y1), (X2, Y2) must be preset. Glcd_cls: ' send clear area left-upper (X1, Y1) and right-lower (X2, Y2) to FPGA Gcolor = Black Gosub Gcset X1 = 0 Y1 = 0 X2 = 800 Y2 = 480 Gosub X1set Gosub Y1set Gosub X2set Gosub Y2set ' send clear-area command Comd = &H80 ' wait All RAM clear Gosub Comset Return ' set a dot ' usage = Lcdpset X, Y, data Sub Lcdpset(byval Pxs3 As Integer , Pys3 As Integer , Pds3 As Word) X1 = Pxs3 ' RAM Address Y1 = Pys3 Gosub X1set Gosub Y1set Gcolor = Pds3 Gosub Wrpixel End Sub ' Write a pixel dot ' 16-bit data is composed of R, G, B data. ' = Red5~1 ' = Green5~0 ' = Blue5~1. ' Supporse that parameter registers X1, Y1 have already been set. ' draw Gcolor Wrpixel: Wd = Gcolor Sdao(1) = Bhigh Sdao(2) = Blow Reset Gssn1 Spiout Sdao(1) , 2 Set Gssn1 Bitwait Wr_busy , Reset Return ' X1 set X1set: Sdao(1) = 0 Wd = X1 Paraset2: Sdao(2) = Bhigh Sdao(3) = Blow Paraset3: Reset Gssn2 Spiout Sdao(1) , 3 Set Gssn2 Bitwait Wr_busy , Reset Return ' Y1 set Y1set: Sdao(1) = 1 Wd = Y1 Goto Paraset2 ' X2 set X2set: Sdao(1) = 2 Wd = X2 Goto Paraset2 ' Y2 set Y2set: Sdao(1) = 3 Wd = Y2 Goto Paraset2 ' Gcolor set Gcset: Sdao(1) = 4 Wd = Gcolor Goto Paraset2 ' Col set Colset: Sdao(1) = 8 Sdao(3) = Col Goto Paraset3 ' Row set Rowset: Sdao(1) = 9 Sdao(3) = Row Goto Paraset3 ' Bcolor set Bcset: Sdao(1) = 10 Wd = Bcolor Goto Paraset2 ' Ccolor set Ccset: Sdao(1) = 11 Wd = Ccolor Goto Paraset2 ' Char. size set Csize_set: Sdao(1) = 12 Sdao(3) = Csize Goto Paraset3 ' video RAM R/W bank set ' =WR bank, = RD bank Bank_set: Sdao(1) = 13 Sdao(3) = Sbank Goto Paraset3 ' string print to GLCD from S ' usage = Gosub Lcdprint ' S must be set before call Lcdprint: Bcolor = Black Ccolor = White Lcdprint2: Gosub Bcset Gosub Ccset Csize = 0 Gosub Csize_set Gosub Colset Gosub Rowset Saddr = Varptr(s) Ns = Len(s) For Is0 = 1 To Ns Bs0 = Inp(saddr) ' get a memory byte Lcdchar Bs0 Incr Col Incr Saddr Next Is0 Return ' char. print to GLCD ' usage = Lcdchar ASCII ' Ccolor = character color (must be preset by the other command) ' Bcolor = background color (must be preset by the other command) Sub Lcdchar(byval Bs1 As Byte) Sdao(1) = Bs1 Reset Gssn3 Spiout Sdao(1) , 1 Set Gssn3 Waitus 1 Bitwait Wr_busy , Reset End Sub ' Large string print to GLCD from string varible S ' usage = Gosub Lcd_lprint ' S must be set before call Lcd_lprint: Bcolor = Black Ccolor = White Lcd_lprint2: Gosub Bcset Gosub Ccset Csize = 1 Gosub Csize_set Gosub Colset Gosub Rowset Saddr = Varptr(s) Ns = Len(s) For Is0 = 1 To Ns Bs0 = Inp(saddr) ' get a memory byte Lcdchar Bs0 Col = Col + 2 Incr Saddr Next Is0 Return Rem graphics ' draw line from (X1, Y1) to (X2, Y2) [pixel] ' Gcolor: Pixel color ' usage = Lcdline X1, Y1, X2, Y2 Sub Lcdline(byval Xs1 As Integer , Ys1 As Integer , Xs2 As Integer , Ys2 As Integer) Gosub Gcset X1 = Xs1 Y1 = Ys1 X2 = Xs2 Y2 = Ys2 Gosub X1set Gosub Y1set Gosub X2set Gosub Y2set Comd = &H82 Gosub Comset End Sub ' command set and wait execution end ' Comd = command byte Comset: Reset Gssn3 Spiout Comd , 1 Set Gssn3 Waitus 1 Bitwait Wr_busy , Reset Waitus 1 Return Rem SD-card directory read Sdc_dir: If Dirset = 1 Then Return ' directory has already been read Reset Serr_flag ' reset SDC error flag ' initialize SD-card driver If Sdc_ncd = 1 Then Goto Sderror Gbdriveerror = Driveinit() ' initiate SD-card drive If Gbdriveerror <> 0 Then Goto Driveerr 'Initialize error? ' Print #1 , "SDC Init. Ok" Goto Sdcl5 Sderror: Col = 1 Row = 10 S = "SDC not inserted" Gosub Lcd_lprint Set Serr_flag Return Driveerr: Col = 1 Row = 12 S = "Drive Error! (Turn snap-SW to RUN position)" Gosub Lcd_lprint Set Serr_flag Return Sdcl5: Temp1 = Initfilesystem(1) ' Initiate file system. Partition = 1 If Temp1 > 0 Then Goto Avrdoserr ' Check AVR-DOS error Lng2 = Disksize() Lng2 = Lng2 / 1000 Lng = Diskfree() Lng = Lng / 1000 ' Print #1 , "SDC free/capa="; ' Print #1 , Lng ; "/"; ' Print #1 , Lng2 ; " (MB)" Goto Sdcl6 Avrdoserr: Col = 1 Row = 14 S = "AVR-DOS Error!" Gosub Lcd_lprint Set Serr_flag Return Sdcl6: ' Directory display ' Print #1 , "Top directory display (. means root directory)" ' Print #1 , "Filename Date Time Size Attr." Tempstr = Dir( "*.*") While Len(tempstr) > 0 ' Print #1 , Tempstr ; " " ; ' Print #1 , Filedate() ; " " ; ' Print #1 , Filetime() ; " " ; ' Print #1 , Filelen() ; "byte " ; ' Print #1 , Hex(getattr()) Tempstr = Dir() Wend ' Print #1, Set Dirset Return Rem text file save Filesave: Gosub Sdc_dir If Serr_flag = 1 Then Col = 1 Row = 5 S = "SDC file ERROR" Gosub Lcd_lprint Return End If Gosub Openfile Col = 1 Row = 3 S = "Store text data into SD-Card file " Fname = Str(fnum) Fname = "Lw" + Fname Fname = Fname + ".txt" S = S + Fname Gosub Lcd_lprint ' large character print Gosub Disksave Gosub Closefile Return ' Open file Openfile: ' generate filename Open Fname For Output As #4 ' set initial message S2 = "Logic Analizer data" Print #4 , S2 S2 = "sampling frequency = " I = Lpara Shift I , Right , 14 I = I And 3 Select Case I Case 0: S = "0.1" S1 = "10 us" L2 = 10 Case 1: S = "1" S1 = "1 us" L2 = 1 Case 2: S = "10" S1 = "100 ns" L2 = 100 Case 3: S = "100" S1 = "10 ns" L2 = 10 End Select S = S + "MHz, " S2 = S2 + S S1 = "time tick = " + S1 S2 = S2 + S1 Print #4 , S2 ' CH0 trigger condition N = Lpara Gosub Trig_status S = "CH0 " + S2 Print #4 , S ' CH1 trigger condition N = Lpara Shift N , Right , 3 Gosub Trig_status S = "CH1 " + S2 Print #4 , S ' CH2 trigger condition N = Lpara Shift N , Right , 6 Gosub Trig_status S = "CH2 " + S2 Print #4 , S ' CH3 trigger condition N = Lpara Shift N , Right , 9 Gosub Trig_status S = "CH3 " + S2 Print #4 , S ' AND trigger condition N = Lpara And &H3000 If N = &H2000 Then S = "All CH AND" Elseif N = &H1000 Then S = "CH2 & CH3 " Else S = "CHs OR " End If Print #4 , S Print #4, Print #4 , "Tck Ch0 Ch1 Ch2 Ch3" Return ' Close file Closefile: Close #4 Incr Fnum ' auto increment file number Efnum = Fnum Return ' Data save to SD-card Disksave: Rdaddr = Ramaddr Sdao(1) = Rda_h Sdao(2) = Rda_l ' set read address Reset Ssn3 Spiout Sdao(1) , 2 Set Ssn3 Rem NOTE: To get data from pipelined RAM ater the first address set via SPI, ' 2 pre-RD-CK must be asserted due to FPGA design. Reset Rdckn Waitus 1 Set Rdckn ' pre-CK Reset Rdckn Waitus 1 Set Rdckn ' pre-CK (2-CK) Tlng = 0 For Lng = 1 To &H10000 S = Str(tlng) Tlng = Tlng + L2 B = Pina B = B And &HF Reset Rdckn $asm$ nop nop $end Asm$ Set Rdckn ' advance RD counter B2 = B And 1 If B2 <> 0 Then S = S + " 1 " Else S = S + " 0 " End If B2 = B And 2 If B2 <> 0 Then S = S + "1 " Else S = S + "0 " End If B2 = B And 4 If B2 <> 0 Then S = S + "1 " Else S = S + "0 " End If B2 = B And 8 If B2 <> 0 Then S = S + "1" Else S = S + "0" End If Print #4 , S ' store into SD-card Next Lng Return Rem binary file save Bfsave: Gosub Sdc_dir If Serr_flag = 1 Then Col = 1 Row = 5 S = "SDC file ERROR" Gosub Lcd_lprint Return End If Col = 1 Row = 5 S = "Store binary data into SD-Card file " Bfname = Str(bfnum) Bfname = "Lw" + Bfname Bfname = Bfname + ".dat" S = S + Bfname Gosub Lcd_lprint ' large character print Kill Bfname Open Bfname For Binary As #4 Rdaddr = Ramaddr Sdao(1) = Rda_h Sdao(2) = Rda_l ' set read address Reset Ssn3 Spiout Sdao(1) , 2 Set Ssn3 Rem NOTE: To get data from pipelined RAM ater the first address set via SPI, ' 2 pre-RD-CK must be asserted due to FPGA design. Reset Rdckn Waitus 1 Set Rdckn ' pre-CK Reset Rdckn Waitus 1 Set Rdckn ' pre-CK (2-CK) Tlng = 0 ' data read from FPGA & write to binary file For K = 1 To 64 For J = 1 To 8 For I = 1 To 128 B = Pina B = B And &H0F Reset Rdckn $asm$ nop nop $end Asm$ Set Rdckn ' advance RD counter Put #4 , B Next I Flush #4 Next J Next K Flush #4 Close #4 Return Rem binary file load & set display data into Dbuf2() Bfload: Gosub Sdc_dir If Serr_flag = 1 Then Col = 1 Row = 5 S = "SDC file ERROR" Gosub Lcd_lprint Return End If Bfname = Str(bfnum) Bfname = "Lw" + Bfname Bfname = Bfname + ".dat" Open Bfname For Binary As #4 Lng = Ofs_addr + 1 Seek #4 , Lng For I = 1 To Xrange If Wdigit = 0 Then ' non-shulink Get #4 , B Dbuf2(i) = B ' store into data buffer Else ' shulink data Reset R_edge0 Reset F_edge0 Reset R_edge1 Reset F_edge1 Reset R_edge2 Reset F_edge2 Reset R_edge3 Reset F_edge3 For J = 1 To Wmag Get #4 , B If J = 1 Then B2 = B B5 = B End If B3 = B2 And 1 B4 = B And 1 If B3 = 0 And B4 <> 0 Then ' exist CH0 rise edge Set R_edge0 End If If B3 <> 0 And B4 = 0 Then ' exist CH0 fall edge Set F_edge0 End If B3 = B2 And 2 B4 = B And 2 If B3 = 0 And B4 <> 0 Then ' exist CH1 rise edge Set R_edge1 End If If B3 <> 0 And B4 = 0 Then ' exist CH0 fall edge Set F_edge1 End If B3 = B2 And 4 B4 = B And 4 If B3 = 0 And B4 <> 0 Then ' exist CH0 rise edge Set R_edge2 End If If B3 <> 0 And B4 = 0 Then ' exist CH0 fall edge Set F_edge2 End If B3 = B2 And 8 B4 = B And 8 If B3 = 0 And B4 <> 0 Then ' exist CH0 rise edge Set R_edge3 End If If B3 <> 0 And B4 = 0 Then ' exist CH0 fall edge Set F_edge3 End If B2 = B Next J B4 = 0 If R_edge0 = 1 And F_edge0 = 1 Then B4 = B4 Or &H10 ' mark CH0 discrepancy End If If R_edge1 = 1 And F_edge1 = 1 Then B4 = B4 Or &H20 ' mark CH1 discrepancy End If If R_edge2 = 1 And F_edge2 = 1 Then B4 = B4 Or &H40 ' mark CH2 discrepancy End If If R_edge3 = 1 And F_edge3 = 1 Then B4 = B4 Or &H80 ' mark CH3 discrepancy End If B5 = B5 Or B4 ' mark cdiscrepancy bits Dbuf2(i) = B5 End If Next I Close #4 Return Rem USB communication Usbxfer: S2 = "Logic Analizer data" Print S2 S2 = "sampling frequency = " I = Lpara Shift I , Right , 14 I = I And 3 Select Case I Case 0: S = "0.1" S1 = "10 us" L2 = 10 Case 1: S = "1" S1 = "1 us" L2 = 1 Case 2: S = "10" S1 = "100 ns" L2 = 100 Case 3: S = "100" S1 = "10 ns" L2 = 10 End Select S = S + "MHz, " S2 = S2 + S S1 = "time tick = " + S1 S2 = S2 + S1 Print S2 ' CH0 trigger condition N = Lpara Gosub Trig_status S = "CH0 " + S2 Print S ' CH1 trigger condition N = Lpara Shift N , Right , 3 Gosub Trig_status S = "CH1 " + S2 Print S ' CH2 trigger condition N = Lpara Shift N , Right , 6 Gosub Trig_status S = "CH2 " + S2 Print S ' CH3 trigger condition N = Lpara Shift N , Right , 9 Gosub Trig_status S = "CH3 " + S2 Print S ' AND trigger condition N = Lpara And &H3000 If N = &H2000 Then S = "All CH AND" Elseif N = &H1000 Then S = "CH2 & CH3" Else S = "CHs OR" End If Print S Print Print "Tck Ch0 Ch1 Ch2 Ch3" Rdaddr = Ramaddr Sdao(1) = Rda_h Sdao(2) = Rda_l ' set read address Reset Ssn3 Spiout Sdao(1) , 2 Set Ssn3 Rem NOTE: To get data from pipelined RAM ater the first address set via SPI, ' 2 pre-RD-CK must be asserted due to FPGA design. Reset Rdckn Waitus 1 Set Rdckn ' pre-CK Reset Rdckn Waitus 1 Set Rdckn ' pre-CK (2-CK) Tlng = 0 ' time For Lng = 1 To &H10000 ' For Lng = 1 To 30 ' for debug S = Str(tlng) Tlng = Tlng + L2 B = Pina B = B And &HF Reset Rdckn Waitus 1 Set Rdckn ' advance RD counter B2 = B And 1 If B2 <> 0 Then S = S + " 1 " Else S = S + " 0 " End If B2 = B And 2 If B2 <> 0 Then S = S + "1 " Else S = S + "0 " End If B2 = B And 4 If B2 <> 0 Then S = S + "1 " Else S = S + "0 " End If B2 = B And 8 If B2 <> 0 Then S = S + "1" Else S = S + "0" End If Print S ' store into SD-card If Sw2 = 0 Then ' abort Print Print "Aborted by SW2" Gosub Sw2wait Return End If Next Lng Print Return Rem Interrupt subroutines ' NOTE: Do'nt use floating operations in the interrupt subroutines, ' especially for Double-float operations, ' because all AVR registers are not saved into the stack. ' Some float operations destroy un-saved register contents. ' NOTE2: Do'nt use multiple "Return" statements in one interrupt subroutine. ' (See BASCOM manual) ' In this program, no interrupt is used. ' program end