Shop OBEX P1 Docs P2 Docs Learn Events
Sample bytes at 5MHz without using the counters — Parallax Forums

Sample bytes at 5MHz without using the counters

BeanBean Posts: 8,129
edited 2013-09-21 16:31 in Propeller 1
I needed to sample bytes as fast as possible, but the counters are already used for something else.
After some experimenting I came up with this code that samples P0 to P7 at 5MHz.
I hope it helps others.
' Samples bytes at 5MHz (must use pins P0 thru P7)
      ' laBufAddr must be set to the hub address of the buffer to hold the samples (must be word aligned)
      ' sampleCnt must be set to the number of samples to take (must be an even value)
      '
      shr sampleCnt,#1          '             Divide sample count by two (using WRWORD)
      rdword value,laBufAddr    ' ??,+7       Dummy instruction to sync to hub
      mov value,ina             ' +7,+11      Read port put in value
      sub laBufAddr, #2         ' +11,+15     Adjust buffer address because it get inc'd before the first write
capture
        add laBufAddr,#2        ' +15,+19     Adjust buffer address to next word
        shl value,#1            ' +19,+23     Move byte in value so MSB is in bit 8
        movd value,ina          ' +23,+27     Put new data in bit 16 thru 9
        shr value,#1            ' +27,+23     Shift value so old data is now in bits 7-0 and new data in bits 15-8
        wrword value,laBufAddr  ' +31,+32,+7  Save the two data samples
        mov value,ina           ' +7,+11      Read the port
      djnz sampleCnt,#capture   ' +11,+15     Keep doing it until we are done


Bean

Comments

  • Mark_TMark_T Posts: 1,981
    edited 2013-09-18 18:51
    Mmmm, neat...
  • jmgjmg Posts: 15,173
    edited 2013-09-19 17:42
    Bean wrote: »
    After some experimenting I came up with this code that samples P0 to P7 at 5MHz.

    Nifty. Would it run any faster, reading 9 bits (sometimes users want 8 bits + strobe or flag)

    A variant on this I've wondered about, is one that stores edge-time-stamps. (so does not store anything when data is static)

    Because it stores more, the peak rate has to be a little lower, but the dynamic range is much larger, and I think WAITPNE can give finer sample resolution (with a caveat of some minimum change-spacing )

    One application would be a 'Baud Meter' - a frequency counter that can extract actual Baud rates.
  • Mark_TMark_T Posts: 1,981
    edited 2013-09-21 08:15
    Hmm, I wonder what
                    waitpne ina, HFFFFFFFF
    
    actually does?

    Or maybe:
                    mov     ina, ina
                    waitpne ina, HFFFFFFFF
    
    Assuming I understand the shadow registers right...
  • Don MDon M Posts: 1,652
    edited 2013-09-21 08:38
    jmg wrote: »
    One application would be a 'Baud Meter' - a frequency counter that can extract actual Baud rates.

    That would be cool if someone came up with that.
  • kuronekokuroneko Posts: 3,623
    edited 2013-09-21 16:31
    Mark_T wrote: »
    Hmm, I wonder what
                    waitpne ina, HFFFFFFFF
    
    actually does?

    Or maybe:
                    mov     ina, ina
                    waitpne ina, HFFFFFFFF
    
    Assuming I understand the shadow registers right...
    Waiting until shadow[ina] is not equal ina. In the first case it most likely just exits given the pullups & Co on most boards (and provided you haven't touched shadow[ina] yet). In the second case it waits until ina differs from its last sample.
Sign In or Register to comment.