Shop OBEX P1 Docs P2 Docs Learn Events
optimizing memory reads — Parallax Forums

optimizing memory reads

Keith MKeith M Posts: 102
edited 2007-11-02 15:31 in General Discussion
I've written a routine to copy a byte of data from a serial memory chip (Ramtron FM25256) to a variable.

SCK = serial memory clock pin
SO = serial output pin from memory to SX

Note that the memory is already primed and already has the first bit of the byte on the SO pin prior to entering this routine.


MOV nsb, #8
CLR gotdata   'this is unnecessary

loopzz:

SETB SCK          ‘outputs are latched on falling edge, this just raises the clock
                         ‘note that the other instructions that follow serve to allow
                         ‘at least 28ns for a minimum clock high time.

MOVB C, SO       ‘read the bit into carry
RL gotdata          ‘bring the bit via carry into gotdata, leftshifting for MSB
DEC nsb             ‘decrement bit counter
CLRB SCK           ‘drop clock (clock low min is 28ns, data not valid until Todv, or 24ns)
                          ‘data comes valid 24ns after this clock drop.

JNZ loopzz          ‘delay here is long enough for Todv and Tcl(clock low time)




My serial memory can run pretty fast, up to 15mhz clock. MOVB is a multi-word 4-cycle instruction. As a result, it's expensive.

The code works fine, but is there a way to optimize it?

Thanks

Keith

Comments

  • BeanBean Posts: 8,129
    edited 2007-10-31 22:59
    Make SO either Bit 0 or Bit 7 of the port. Then you can use "MOV W,<<RB"(Bit 7) or "MOV W,>>RB"(Bit 0) to get the bit into the carry. These are 1 cycle instructions.

    Also, you could unroll the loop. Just repeat the instruction 8 times instead of doing "DEC nsb" and "JNZ loopzz".

    Bean.

    Post Edited By Moderator (Chris Savage (Parallax)) : 11/2/2007 3:54:59 PM GMT
  • Keith MKeith M Posts: 102
    edited 2007-11-02 15:31
    As usual, thanks Bean.

    Because a lot of my operations are bit-based routines, and I'm processing literally millions of bits, every little bit helps.

    Thank you.

    Keith
Sign In or Register to comment.