Shop OBEX P1 Docs P2 Docs Learn Events
Fastest way to start a program after a falling edge — Parallax Forums

Fastest way to start a program after a falling edge

edited 2006-04-12 13:20 in General Discussion
Is there a faster way to execute code after any falling edge in ASM ? confused.gif·

This is what I came up with.

[color=#000000]Step1:                                      ;Loop until Low[/color]
[color=#000000]            SNB    RA.0                ;1 cycle (2 if skip)[/color]
[color=#000000]            JMP     Step3               ;3 cycles[/color]
[color=#000000]            JMP     Step2               ;3 cycles[/color]
 
[color=#000000]Step2:                                      ;Loop until High[/color]
[color=#000000]            SB       RA.0                ;1 cycle (2 if skip)[/color]
[color=#000000]            JMP     Step2               ;3 cycles[/color]
[color=#000000]            JMP     Step3               ;3 cycles[/color]
 
[color=#000000]Step3:                                      ;Loop until Low[/color]
[color=#000000]            SNB    RA.0                ;1 cycle (2 if skip)[/color]
[color=#000000]            JMP     Step3               ;3 cycles[/color]
[color=#000000]            JMP     @Main            ;4 cycles (on another page)
[/color]

-TRC

Comments

  • BeanBean Posts: 8,129
    edited 2006-04-12 01:33
    JB RA.0,$
    JNB RA.0,$
    JB RA.0,$
    JMP @Main

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module"·available from Parallax for only $28.95 http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module"·available from Parallax for only·$49.95 http://www.parallax.com/detail.asp?product_id=30015
    Product web site: www.sxvm.com

    Available now! Cheap 4-digit LED display with driver IC·www.hc4led.com

    "I reject your reality, and substitute my own." Mythbusters
    ·
  • NateNate Posts: 154
    edited 2006-04-12 01:45
    2 Clock cycles after high-to-low trans:



    JB RA.0,· $
    JNB RA.0,· $
    JB RA.0,· $

    (Main code here, no jump)





    Nate
  • edited 2006-04-12 06:29
    Nice, forgot about the current address pointer!
    ·
    The code space is tight (very tight) so I had to spilt things up a bit. This is what I ended up with, which works fine·since there is 16 clock cycles·during the last high transition.

     jb ra.0,$
     jnb ra.0,$
     jmp @Start
    
      ORG $200
    
     
    Start:
      jb SH2,$
     
    Main:
    

    Thanks for your help!

    -Dan-
  • BeanBean Posts: 8,129
    edited 2006-04-12 11:13
    Nate said...

    2 Clock cycles after high-to-low trans:

    JB RA.0,· $
    JNB RA.0,· $
    JB RA.0,· $

    (Main code here, no jump)

    The fastest conditional loop on the SX is 4 cycles (as in JB RA.0, $), but if the transition occurs right after the bit test, it will be 5 cycles until the next instruction. 3 for the jump back, 1 for the bit test, and 1 for the skip.

    Two cycles would be best case, 5 cycles worst case.

    Bean.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module"·available from Parallax for only $28.95 http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module"·available from Parallax for only·$49.95 http://www.parallax.com/detail.asp?product_id=30015
    Product web site: www.sxvm.com

    Available now! Cheap 4-digit LED display with driver IC·www.hc4led.com

    "I reject your reality, and substitute my own." Mythbusters
    ·
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-04-12 13:20
    And if an interrupt occurs,
    worst case is 5 + intperiod cycles

    regards peter
    ·
Sign In or Register to comment.