Menu

Copy an array?

Help
mkstevo
2016-09-02
2016-09-03
  • mkstevo

    mkstevo - 2016-09-02

    Is there a simple (and preferably quick) way of copying the contents on an entire array into another (same sized) array?

    I'm trying to make a very basic oscilloscope. I have this working, but of course the LCD display can't display the signal quickly enough. This isn't a problem as I'm storing the display data in an array, then if the signal is removed for more than 10 cycles at the start of the buffer filling routine, the contents of the buffer are played out (slowly) onto my display. This is all working well. The problem is that to ensure the buffer is full, capture continues from the moment the signal is removed until it has been filled. As it is difficult to judge when to ground the probe to initiate the 'playback' the buffer may contain mostly null contents, depending on when during the fill routine, the signal was removed.

    My thought was that I could wait until the 'Capture_Array' was filled, then copy that into a second 'Playback_Array', if the playback was initiated part way through the 'Capture_Array' fill, it would be abandoned, with the filled contents from the 'Playback_Array' being used to update the display.

    Hope I've explained my self.

    I've tried something similar to this:

    #Define Signal              PortB.5
    Dir     Signal              In
    
    #Define StorLen       128 'Length of display storage buffer
    Dim StorageArray(StorLen)
    Dim PrintArray(StorLen)
    Dim StorIdx        As Word
    Dim BufferFull     As Byte
    Dim Stop_Print     As Byte
    
    ... Capture contents
       Let Capture_Array(StorIdx) = Signal
       Let StorIdx = StorIdx + 1
    
       If StorIdx > StorLen Then 'We've filled the Capture_Array
          Let StorIdx    = 1
          Let BufferFull = 1
          Let Stop_Print = 0
          Let Playback_Array = Capture_Array
       End If
    

    This leaves Playback array containing gibberish.

    I had thought of copying the contents byte by byte (Let Playback_Array(1) = Capture_Array(1) etc.) but thought that would be rather slow and hold up the capture.

     

    Last edit: mkstevo 2016-09-02
  • kent_twt4

    kent_twt4 - 2016-09-03

    I used a similar scheme to playback data captured during a data logging session. Adapted to the needs of a buffer fill, look for when the session ends, which seems to be done here, copy the address, and reset original address to start playback, like this:

    stopaddr = addr1
    addr1 = 0
    Repeat stopaddr
      addr1 += 1
      Buffer1(addr1) = Buffer2(addr1)
    end repeat
    
     
  • kent_twt4

    kent_twt4 - 2016-09-03

    Second thought is to load the shadow buffer during the inherent wait period during the adc conversion process. Take the first sample, during the next sample load the shadow buffer from the first result and so on, during the wait period. This is commonly known as the tad period for Pics. This would mean manual manipulation of the readAD() sub and storing locally in the gcb program.

     
  • mkstevo

    mkstevo - 2016-09-03

    Thanks for your kind suggestions.

    I came up with a solution similar to your second suggestion. I load the buffer at full speed. Pause the buffer loading. Then create an abreviated display from the buffer contents. Display the abreviated data. Pause the display to give time to view the data. Then capture an entire buffer again.

    As the playback can only be initiated during a wait period at the start of the buffer loading routine and the buffer loading is done at full speed (previously I wrote to the display in between each sample, moving the contents of the display each time), I'm now reasonably sure of getting a full buffer. The down side (sigh) is that the samples are taken so fast, that for slow signals the buffer is full of either highs or lows. To counter this I simply truncate long sequences as the playback display is generated. That allows me to display various frequencies within a frame of my sixteen pixels, though clearly, innacurately.

    The 'project' is to make a simple 'oscilloscope', using a standard 1602 HD4480 type 16x2 LCD display. As it isn't feasible to show sine waves on such a display, I'm simply displaying square waves indicating a 'High' or a 'Low'. Once I get my LCD display connected, I'll upload a picture.

     
  • mkstevo

    mkstevo - 2016-09-03

    I was inspired by this oscilloscope: LCDscope by Bruno Gavand.

     
  • mkstevo

    mkstevo - 2016-09-03

    Here is my attempt to do something similar:

    A data capture, and a partial 'playback' of the captured data.

     
  • mkstevo

    mkstevo - 2016-09-03

    A second (slower) capture of a signal. Due to the compression of the 'playback' there isn't a whole lot of difference in the played waveform. (Though the backlight makes the display look better?)

     

    Last edit: mkstevo 2016-09-03

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.