Risultati da 1 a 2 di 2

Discussione: SX Oscilloscope

  1. #1

    Lightbulb SX Oscilloscope

    Source: http://www.piclist.com/techref/sceni...cope/index.htm

    by Alberto Geraci of BTX Sistemas Ė Argentina

    It is a simple oscilloscope project based in a SX28 microcontroller from UBICOM, it doesn't try to be an exact instrument measurement, only try to demostrate, with a very low cost and low quantity of materials, how much we could get from an SX28 plus the EPP parallel port in a PC.

    Let me to leave to the people who read this article to experiment with it, make some changes, or apply new ideas. If you like you could write to me at SPAMbtxsistemasTakeThisOuT at -Remove-ciudad.com.ar .

    I accompany in this article, the complete schematic diagram for the scope, a picture with the software in action and all source code, for both the SX (osc.src) and the PC (sxo-cpp.zip). [ed: a board layout was also submitted for the Olimex sponsored PCB contest]

    The project is in a basis of two parts, one is the SX code which implement all A/D conversion, the EPP communication, and the sampling of the wave to measure.

    The second part is the PC software that only reads the samples sent by the SX and show its in a window.

    This lets the PC software to be not responsible about the maximum wave frequency to be tested, and leave to the SX code all the quickly job, taking advantage of the 50 MIPS.

    I think that using a different A/D converter in this project, you could get more than 5 Mhz wide of band for the scope.

    About SX code:
    The original idea to take samples as quickly as possible with the SX28 in this project is the following:

    The samples taken by the A/D converter will be only 128 (total) each PC screen, to do all the things quickly, Iíve put all samples in the SX RAM memory, so after each sample taken by the AD converter, I save it in a different memory address, which will be incremented by the IND register for the next samples, once the input wave was sampled an the memory if obviously full, I send the entire SX memory content to the PC parallel port to show it in the PC screen. And then all begins again.

    You could see at the code that I am sending, to look for all this. Youíll see at the first part of code too, that I check for the SW1 switch, to know which will be the time-base to use. I try to get three different levels, one is the most quickly, where the samples are taken only one time each ,in the second I take ten times the same sample loosing time, and in the third 100 times to loose more time for lower frequencies. Why I used this method ?? because I lose a proportional time in a different time-base without caring the cycles in each part of the code.

    OK at this point we have a lot of different possibilities to change or to add, I think the first and most important to get more speed, for measure higher frequencies, is the change of the AD converter, in this project to demonstrate the work, I was using the ADC08831 which have a conversion time of 4 uSseg. Max, so think about a parallel FLASH AD converter would be tempting , per example clocked by an external clock unit, where all SX time needed to take a sample would be only read a entire RB port, and changing the EPP control handshaking lines to the RA free port pins.

    And what do you think about to use a SX48 or SX52 ?? we could take 256 samples each time using the same method. And running at 100 Mhz. Wow !!.

    It is better to think in a FIFO memory to save all samples, and get a bigger quantity of samples in each frame with a parallel FLASH AD converter like I said before, but, what will we do with the SX ?? perhaps we donít need it, so.. we could think a lot of different possibilities but that is your work ( If you have more time and money to try that ).

    Finally, if you havenít an ADC08831 to test the project, you can only replace the "conver" part of the SX code with just generated some numbers, simulating for example an square wave.

    About the PC software:

    The PC software was entire programmed in Visual C++ 6.0, all the code is available for you , the idea was to create an small window into a dialog based application, which shows you the wave measured with the hardware. Let me call this window as the "view" window pls.

    OK To obtain a good speed to redraw the view window, I created a DIB ( Device Independent Bitmap ) into this, and used the BitBlt function to draw the contents of it. Like I was not using "trigger" function for the Oíscope in this project, I did the redraw each 250 mSeg , but you could adjust it until 1 mSeg to obtain a good quantity of frames / Sec. OK I could write several pages of text about all the code but in this article it is not the purpose, any doubts or suggests, let me know please.

    I will comment now the principal parts of the code.

    First at all, the size of the "view" window is 256 by 256 pixels, and all the job is cook in the "RenderView" function, just enter in this, I configured the LPT1 port and the the control port value to work with a EPP mode, immediately I read the 128 samples sent by the SX code and put them into an array named "buffer" in which I left each sample with a empty byte between them ( Iíll explain, why this after). I did all the read part into a "for" loop, and then I correct the negatives values into another "for " loop, adding 256 if necessary.

    If you are thinking about, why 256x256 pixels in the view with only 128 samples, the answer is, because I make an average of all samples taken by the SX and put its in the holes left in the buffer array, so after this our resolution will increase in 256 pixels sampled.

    Like the maximum value sent by the SX for one sample is 255, here we have the 256 by 256 window view.

    We can see into the RenderView function too, a piece of code with three "for" loops that draw the background screen and the black lines in the view.

    Finally the type to pass, all buffer values into the DIB, needs to be looked with some care, because the DIB is drawn by one column each, instead rows.

    I put a language check button, so you can check the better choice for you , and a pause button to obtain a freeze of the picture, plus a "file services" frame with two buttons, to save or load any pictures if you want.

    OK Thatís all folks, and I hope, that you enjoy it

    Alberto Geraci
    BTX Sistemas.
    Codice:
    ; *****************************************************************************************
    ; 
    ; Filename: Osc.src
    ;
    ; Author: Alberto Geraci
    ;  BTX Sistemas 
    ;  Argentina.
    ;  
    ; Revision: 1.01
    ;
    ; Freq:  50MHz
    ;
    ; Compiled using: SX-Key.
    ;
    ; Date Written : Feb 20, 2002
    ;
    ; Last Revised : March 10, 2002
    ;
    ; Program Description:
    ;
    ;  Super Simple !! SX based oscilloscope:
    ;  Simple project to demostrate the SX power running at 50Mhz
    ;  working together with a PC parallel port.
    ;
    ; Interface Pins:
    ;  
    ;  CLK      equ     rb.6  ;A/D clock input
    ;  D0       equ     rb.7  ;A/D data out
    ;  CS  equ  rb.5  ;A/D chip select
    ;  RA.0 and RA.1   ;Inputs for selector (time base).    
    ;  RC port    ;Data to be send to PC. (D0 to D7 line).
    ;  RB.0    ;To pin 11 of DB25 (Wait line).  
    ;  RB.1    ;To pin 14 of DB25 (Data Strobe line).
    ;  
    ;*****************************************************************************************
    ;
      device sx28l,stackx_optionx
      device oscxt5,turbo
      freq 50000000
      reset reset_entry
      org 10h
    counter  ds   1
    data  ds  1
    CLK equ rb.6
    D0 equ rb.7
    CS equ rb.5
    ;****************************************************************************************************************
    ;****************************************************************************************************************
      org 20h
    reset_entry  
       mov  ra,#%11111111    ;init rc
      mov   !ra,#%00000000
       mov  rc,#%00000000    ;init rc
      mov   !rc,#%00000000
       mov  rb,#%00100000    ;init rb
      mov   !rb,#%10000010
      mov w,#$0E  ;
      mov M,w  ;
       mov !rb,#%011111111 ;
      mov w,#$0F  ;
      mov M,w  ;
    ;
      clr fsr     ;reset all ram banks
    :loop   
      setb   fsr.4
      clr   ind    ; zero all RAM
      ijnz  fsr,:loop
    ;
    ;****************************************************************************************************************
    ; MAIN
    ;****************************************************************************************************************
    ;
    main_loop
      ; port ra used to change time base X1 // X10 // X100.
      sb ra.0  ; ra.0=0 => one 
      jmp go_one
      sb ra.1  ; ra.1=0 => ten
      jmp go_ten
      jmp go_hundred ; ra.0=1 and ra.1=1 => hundred
    ;
    go_one  call one  ; 128 samples quickly. (max time between samples is the time of convertion).
      jmp continue
    go_ten  call ten  ; 128 samples but 10 times each. ( loosing time ).
      jmp continue
    go_hundred call hundred  ; 128 samples but 100 times each. ( loosing time ).
      jmp continue
    ;       ; completed all 128 bytes  
    ;
      ; it is time to send the samples to paralel port.
    continue clr fsr     ;reset all ram banks again
    dloop
      setb   fsr.4    ; same as before
      mov rc,ind    ; data to be send to PC port in RC
    out_port      ; send each byte of data to parallel port
      clrb rb.0
    npas  snb rb.1
      jmp npas
      nop
      setb rb.0
    ready  sb rb.1
      jmp ready
    ;
      ijnz  fsr,dloop   ;  
      jmp main_loop   ; 128 samples sended to paralel port. and all begins ahgain
    ;******************************************************************************************************************
    ;  org 400
    ;****************************************************************************************************************
    ;   SUB's
    ;****************************************************************************************************************
    get_data    ; Step to step get the data out from the ADC
      snb D0              ; is D0 high or low
      jmp chi
    clo  clrb $03.0
      rl data            ;
      ret
    chi  setb $03.0
      rl data            ;
      ret
    ;****************************************************************************************************************
    conver     ; this part of the code, do all the A/D convertion.
      clrb CLK
      clrb CS
      nop   ; Several nop's to decrease the clk for the ADC08831.
      nop
      nop
      setb CLK
      nop
      nop
      nop
      clrb CLK
      nop
      nop
      nop
      setb CLK
      nop
      nop
      nop
      clrb CLK
      call get_data
    ;
      setb CLK
      nop
      nop
      nop
      clrb CLK
      call get_data
    ;
      setb CLK
      nop
      nop
      nop
      clrb CLK
      call get_data
    ;
      setb CLK
      nop
      nop
      nop
      clrb CLK
      call get_data
    ;
      setb CLK
      nop
      nop
      nop
      clrb CLK
      call get_data
    ;
      setb CLK
      nop
      nop
      nop
      clrb CLK
      call get_data
    ;
      setb CLK
      nop
      nop
      nop
      clrb CLK
      call get_data
    ;
      setb CLK
      nop
      nop
      nop
      clrb CLK
      call get_data
      setb CS
      ret
    ;****************************************************************************************************************
    one
      clr fsr     ;reset all ram banks
    loopi   
      setb   fsr.4    ; inc memory
      mov counter,#1   ; used to simulate time base / 1
    anoth
      call  conver
      decsz  counter ; 
      jmp anoth 
    ;
      mov  ind,data   ; move one byte of data into RAM
      ijnz  fsr,loopi   ; inc bank
      ret
    ;****************************************************************************************************************
    ten
      clr fsr     ;reset all ram banks
    tloopi   
      setb   fsr.4    ; inc memory
      mov counter,#10   ; used to simulate time base / 10
    tanoth
      call  conver
      decsz  counter ; 
      jmp tanoth 
    ;
      mov  ind,data   ; move one byte of data into RAM
      ijnz  fsr,tloopi   ; inc bank
      ret
    ;****************************************************************************************************************
    hundred
      clr fsr     ;reset all ram banks
    hloopi   
      setb   fsr.4    ; inc memory
      mov counter,#100   ; used to simulate time base / 100
    hanoth
      call  conver
      decsz  counter ; 
      jmp hanoth 
    ;
      mov  ind,data   ; move one byte of data into RAM
      ijnz  fsr,hloopi   ; inc bank
      ret
    ;****************************************************************************************************************
    END
    Anteprime Allegate Anteprime Allegate    
    File Allegati File Allegati

  2. #2

    SX/B Code

    Please note that this code runs at 4 MHz and thus has a lower speed resolution.

    Also, as you can see from here, it has really nothing magic - it's just possible to see some data.

    In order to make it more precise, it would need also an external trigger source at regular intervals in order to sample the data, and interrupt handling or polling at these events.

    Also, as there are many free ports, it would be very easy to add additional base dividers and output 2 bytes with trigger and other useful information, such as the selected divider. Since the SX is fast, a 12 bit ADC could be used, too, and make the transmission to LPT 2-3 bytes wide.

    Codice:
    ' ==============================================================================
    ' Copyright     : (C) Y2K Software s.a.s. 2008 - All Rights Reserved
    ' ------------------------------------------------------------------------------
    ' Program Description
    ' SX Oscillator
    ' ==============================================================================
    ' Device Settings --------------------------------------------------------------
    DEVICE          SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
    FREQ            4_000_000
    ID              "OSC     "
    ' IO Pins ----------------------------------------------------------------------
    CS  VAR RB.5
    CLK  VAR RB.6
    DPin  VAR RB.7
    ' Constants --------------------------------------------------------------------
    ' Variables --------------------------------------------------------------------
    counter  VAR BYTE
    vdata  VAR BYTE
    ' Interrupt handler ------------------------------------------------------------
    'INTERRUPT 1000
    'ISR_Start:
    'ISR_Exit:
    ' RETURNINT ' {cycles}                                 
    ' ==============================================================================
    PROGRAM Start
    ' Subroutines / Jump Table -----------------------------------------------------
    GET_DATA SUB 0
    X1  SUB 0
    X10  SUB 0
    X100  SUB 0
    ' Program Code -----------------------------------------------------------------
    Start:
     OUTPUT RB.0
    Main:
     ' port ra used to change time base X1 // X10 // X100.
     IF RA.0 = 1 THEN
      X1
     ENDIF
     IF RA.1 = 1 THEN
      X10
     ENDIF
     X100
     ' it is time to send the samples to parallel port
     RC = vdata
     ' strobe
     LOW RB.0
     DO WHILE RB.1 = 0
     LOOP
     HIGH RB.0
     DO WHILE RB.1 = 1
     LOOP
     GOTO Main   ' error if page 0 overruns page 1
    ' 128 samples quickly. (max time between samples is the time of convertion) ----
    X1:
     FOR counter = 1 TO 1
      GET_DATA
     NEXT
     RETURN
    ' 128 samples but 10 times each ------------------------------------------------
    X10:
     FOR counter = 1 TO 10
      GET_DATA
     NEXT
     RETURN
    ' 128 samples but 100 times each -----------------------------------------------
    X100:
     FOR counter = 1 TO 100
      GET_DATA
     NEXT
     RETURN
    ' User data --------------------------------------------------------------------
    GET_DATA:
     LOW CS
     SHIFTIN DPin, CLK, MSBPOST, vdata
     HIGH CS
     RETURN

Tag per Questa Discussione

Segnalibri

Permessi di Scrittura

  • Tu non puoi inviare nuove discussioni
  • Tu non puoi inviare risposte
  • Tu non puoi inviare allegati
  • Tu non puoi modificare i tuoi messaggi
  •