Waiting for a Smartpin output/completion state in the P2
rogloh
Posts: 5,787
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.
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
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.
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:
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.
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...