Shop OBEX P1 Docs P2 Docs Learn Events
Test program (way off) — Parallax Forums

Test program (way off)

yarisboyyarisboy Posts: 245
edited 2010-11-08 15:34 in Propeller 1
I wrote a test program using a DAT section in spin. When I ran it the first time I had garbage in all three displays. I changed the way I'm trying to get a memory location to shiftout and extinguished my displays. My first guess at least had bad results instead of none.

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2010-11-07 17:15
    yarisboy wrote: »
    I wrote a test program using a DAT section in spin. When I ran it the first time I had garbage in all three displays. I changed the way I'm trying to get a memory location to shiftout and extinguished my displays. My first guess at least had bad results instead of none.

    It would actually help if you post code that compiles ;)
    1. compile error, use e.g. SHIFTOUT(@DFIG[0],8)
    2. your bit loop isn't sync'd to the clock so the bits are sent as fast as SPIN can manage
    3. BYTE[PNTR][NBYT] will always access the byte after your array (NBYT is constant)
    4. Are you intentionally destroying the array data while sending it (<< 1)?
  • yarisboyyarisboy Posts: 245
    edited 2010-11-07 18:25
    kuroneko wrote: »
    It would actually help if you post code that compiles ;)
    1. compile error, use e.g. SHIFTOUT(@DFIG[0],8)
    2. your bit loop isn't sync'd to the clock so the bits are sent as fast as SPIN can manage
    3. BYTE[PNTR][NBYT] will always access the byte after your array (NBYT is constant)
    4. Are you intentionally destroying the array data while sending it (<< 1)?
    Thanks,
    SC
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-11-08 15:34
    Forgive me, but the SHIFTOUT method seems terribly convoluted. Is there a reason to use an external clock (external of the method, that is)? If a pure Spin method isn't fast enough then it may be better to write a custom output driver in PASM.

    It looks like you want to output one or more bytes from an array, MSBPOST. If that's the case, this version of the method seems cleaner and easier to follow.
    pub shiftout(pntr, count) | work
    
    '' pntr  : address of byte(s) to shift out
    '' count : number of bytes to shift out
    ''
    '' assumes E_PIN, C_PIN, and D_PIN are set as outputs
    
      outa[E_PIN] := 0                                              ' enable 
      repeat count
        work := byte[pntr++]                                        ' get a byte
        repeat 8
          outa[C_PIN] := 1                                          ' create clock pulse
          outa[C_PIN] := 0
          outa[D_PIN] := work >> 7                                  ' MSB first
          work <<= 1                                                ' next bit
        ' outa[D_PIN] := work                                       ' LSB first
        ' work >>= 1
            
      outa[E_PIN] := 1                                              ' disable
    

    By the way, I did some testing a few months ago and found that"
    outa[PIN] := 1
    outa[PIN] := 0
    

    ... is faster than:
    outa[PIN]~~
    outa[PIN]~
    
Sign In or Register to comment.