Menu

GCB oscilloscope idea

2017-07-22
2017-07-22
  • stan cartwright

    stan cartwright - 2017-07-22

    I tried sampling adc and storing then displaying but at 3KHz it was 6 samples per wave cycle. I put an increaseing delay before each sample after a sync trigger idea to capture different parts of the wave form and it displays 50KHz as is. ie a sine wave looks like one. https://youtu.be/Y3QTnrOUeHQ
    ps .97 bog standard version so should be ok

    ;display repeatative wave forms on ILI9341 display with vectors ...Higher than adc sample rate ;)
    #chip mega328p,16
    #option explicit
    #include <glcd.h>
    ;Display setup
        #define GLCD_TYPE GLCD_TYPE_ILI9341
        #define GLCD_DC   portb.2 ;    DIGITAL_10         'HW Data command line DC
        #define GLCD_CS   portd.7 ;    DIGITAL_7          ' Chip select line CS
        #define GLCD_RESET   portd.4 ;      DIGITAL_4         ' Reset line Tie high..not needed
        #define GLCD_DO   portb.3 ;   DIGITAL 11          'HW Data out | MOSI SDI
        #define GLCD_SCK   portb.5 ;   DIGITAL_13          'HW Clock Line SCK
    ;
        #define ILI9341_HardwareSPI    ' remove/comment out if you want to use software SPI.
        'GLCD selected extension font set. ASCII characters 31-254, the extended font uses 1358 bytes of program memory
        #define GLCD_EXTENDEDFONTSET1
        GLCDfntDefaultsize = 1
    #define AD_Delay 2 10us ;dunno why
    ;
    ;#define analogue_in portc.0 ;uno A0
    ;dir analogue_in in
    dir portc.0 in
    dim volt,ptr1,ptr2 as byte
    ;buffers to hold old and new samples for fast drawing waveform
    dim buffer1 (238),buffer2(238) as byte ;screen X is 238 pixels in boarder
    ;start/end--new/old lines between new/old samples variables
    dim xpos_new as byte 
    dim ypos_new as byte
    dim xpos_old as byte
    dim ypos_old as byte
    dim xpos1_new as byte
    dim ypos1_new as byte
    dim xpos1_old as byte
    dim ypos1_old as byte
    ;
    dim xdiv as byte ;x pixels between plots
    dim xsamples as byte
    dim tmp as byte
    xdiv=1 ;1 pixel X to next sample as default
    xsamples=238 ;238 pixels in box
    ;
    GLCDRotate ( portrait_Rev ) ; portrait gives a 0-255 display height
    GLCDfntDefaultsize = 3 ;if I want text output
    GLCDCLS ILI9341_BLUE
    filledbox  0,0,239,257,ILI9341_BLACK
    box  0,0,239,257,ILI9341_YELLOW
    ;
    for ptr1=1 to xsamples ;read samples ;get 1st samples so they can be erased ?yeah got to
      ;  wait until analogue_in off
      ;  wait until analogue_in on
      wait until portc.0 off
      wait until portc.0 on ;triger level to "sync" :)
      for tmp = 1 to ptr1
      next tmp ;delay to catch different point in wave
      ; volt = READAD (analogue_in)
      volt = READAD (an0)
      buffer1 (ptr1)=255-volt ;fit to screen 0,0
      buffer2 (ptr1)=buffer1 (ptr1)
    next ptr1
    ;
    do ; start of main loop
      ptr1=1
      ptr2=1
      do until ptr1=xsamples-2 ;erase old screen data and redraw new
        ypos_old=buffer2 (ptr1) ;old data
        ypos_new=buffer2 (ptr1+1)
        xpos_new=ptr2+xdiv
      ;
        ypos1_old=buffer1 (ptr1) ;new data
        ypos1_new=buffer1 (ptr1+1)
        xpos1_new=ptr2+xdiv
      ;this updates display sample to sample eraseing last sample...looks steadier,less flicker
        line ptr2,ypos_old+1,xpos_new,ypos_new+1,ILI9341_BLACK ;erase last data
        line ptr2,ypos1_old+1,xpos1_new,ypos1_new+1,ILI9341_WHITE ;draw new data
      ;
        ptr1=ptr1+1 ;data pointer
        ptr2=ptr2+xdiv ;x position for start and end line x positions
      loop
      ; ploting done now redraw cursor that got erased by drawing trace
      line 1,127,239,127,ILI9341_GREEN ;X axis
      line 119,1,119,254,ILI9341_GREEN ;Y axis
      ;--- get new samples
      for ptr1=1 to xsamples
      ;  wait until analogue_in off
      ;  wait until analogue_in on
        wait until portc.0 off
        wait until portc.0 on ;trigger next sample same as last ie "sync"
        for tmp = 1 to ptr1
        next tmp ;delay to catch different point in wave
        volt = READAD (an0)
        buffer2 (ptr1)=buffer1 (ptr1) ;new data to old data
        buffer1 (ptr1)=255-volt ;set 0,0 top left screen and update new data
      next ptr1
    ;
    loop ;end of main
    
     

    Last edit: stan cartwright 2017-07-22
  • stan cartwright

    stan cartwright - 2017-07-22

    I put a frquency counter on it. I could use it to change display x range maybe. https://youtu.be/hhTC8z1GIaI

     
  • stan cartwright

    stan cartwright - 2017-07-22

    If readad starts on a leading edge, where is the leading edge on a not a square wave,eg sine wave?
    When readad is used does it turn off the digital part of the pin or do I do through registers?
    Sorry 2 questions. I can't keep up with readad improvements and so waiting for next release and data sheets in the mean time.
    Having googled "diy oscillocope", I haven't found this display idea used. It's not really real..or is it, on a repeated, unchanging waveform?
    With a quad op amp front end for dc off set for ac and volt range maybe little handythingamy. Could measure voltage and GCB is fast enough to do capacitance ESR. PWM sine wave through low pass r/c. Less extra hard ware the better.
    Ideas for ranges on a post card please to here ie could it be a useful project or academic demo?
    I can't think off a reason to build anything cos it's so cheap on ebay.
    Again, google diy oscilloscope. Lets do a GCB Swiss navy knife thingamyjig.
    ...and my robot is behaving tidy to :)

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.