Shop OBEX P1 Docs P2 Docs Learn Events
Waiting for a Smartpin output/completion state in the P2 — Parallax Forums

Waiting for a Smartpin output/completion state in the P2

roglohrogloh Posts: 5,170
edited 2020-02-16 23:59 in Propeller 2
What's the fastest/simplest way to have the P2 wait for a Smartpin operation to complete on a given (dynamic) pin, when it raises its input high at the end of the operation, e.g. in transition output mode?

I found 3 ways but wonder if there was anything better. I couldn't see a direct wait instruction for a pin high condition, like a "WAITP #/D" for example. My code is complicated by the fact that the "pin" register value is dynamic and not going to be known in advance or hardcoded etc. I guess method 3 is the simplest though it could introduce some jitter. The other two involve more setup instruction overhead latency which is not good in a tight sequence to control a pin.
'Method 1:
        mov     temp, pin
        or      temp, %110_000000 'selectable event 1 is pin high 
        setse1  temp
        waitse1

'Method 2:
        decod   temp, pin
        testb   pin, #5 wc
        waitpat temp, temp
    
'Method 3:
        testp   pin wz
  if_z  jmp     #$-1

Comments

  • 'Method:
    
              altd      pin, #%110_000000 'selectable event 1 is pin high
              setse1  0-0
              waitse1
    
    

    This doesn't require a temp long, leaves the C & Z flags alone, and is almost as fast as Method 3 without the possibility of jitter.
  • Thanks AJL. I like no jitter and no flags use. I think it might need to be "setse1 #0-0".

    I just tried to compile my method 2 and found it was coded wrong and incomplete. I think you would actually need to do this which is even more overhead:
    'Method 2:
            decod   temp, pin
            testb   pin, #5 wc
            setpat  temp, temp
            waitpat
    

    Actually digging into this for the HyperRAM pin control I'm slightly surprised waiting on a Smartpin or IO pin state is actually somewhat tricky to setup/execute on a P2. Its easier if the pin is known in advance and hardcoded.
  • cgraceycgracey Posts: 14,133
    AJL wrote: »
    'Method:
    
              altd      pin, #%110_000000 'selectable event 1 is pin high
              setse1  0-0
              waitse1
    
    

    This doesn't require a temp long, leaves the C & Z flags alone, and is almost as fast as Method 3 without the possibility of jitter.

    Wow! It never occurred to me to use ALTD for such a thing.
  • roglohrogloh Posts: 5,170
    edited 2020-02-17 00:49
    cgracey wrote: »
    Wow! It never occurred to me to use ALTD for such a thing.

    Just tried it and it works well. I now have nice back to back clocks coming out after the address phase.
  • rogloh wrote: »
    cgracey wrote: »
    Wow! It never occurred to me to use ALTD for such a thing.

    Just tried it and it works well. I now have nice back to back clocks coming out after the address phase.

    It takes a village...
Sign In or Register to comment.