Need help with deterministic timing using CNT in PASM
Mike G
Posts: 2,702
I copied this right out of the Propeller manual.
Right below this code snippet, I have a small code block of PASM code. The whole thing (delay and all) loops X number of times. I know that the rest of the code executes well under ¼ sec. See attached.
Given that a code block execute in under a ¼ second, how do I wrap the code block so that the time it take to execute the code block + X wait time = ¼ second?
Im not sure how to handle when CNT + delay overflows.
rdlong delay, #0 'Get clock frequency shr delay, #$2 'Divide by 4 mov time, cnt 'Get current time add time, delay 'Adjust by 1/4 second waitcnt time, delay 'Wait for 1/4 second
Right below this code snippet, I have a small code block of PASM code. The whole thing (delay and all) loops X number of times. I know that the rest of the code executes well under ¼ sec. See attached.
Given that a code block execute in under a ¼ second, how do I wrap the code block so that the time it take to execute the code block + X wait time = ¼ second?
Im not sure how to handle when CNT + delay overflows.
Comments
One thing I noticed is most of the instructions are around 4 clocks but some you are using are longer so just account for the longest of each one and add them up.
I beleive your right... should have read the waitcnt instruction a little closer.
How does it make the loop stay at just 1/4 a second or less?
then one loop cycle takes 1/4 second + time taken by "some code" + few cycles occupied by jmp and timing setup. The correct way is this: