time mesure
stef
Posts: 173
Hi everybody
Anyone has an idea on how to mesure simple the time between two prop input comming high?
I'm trying to do this in a project but I have no clue on how to start it.
I'm controling a machine that is triggering 5 inputs of the propeller. I need to menure the time as accurate as possible between different inputs comming high.
any ideas?
Stefan
Anyone has an idea on how to mesure simple the time between two prop input comming high?
I'm trying to do this in a project but I have no clue on how to start it.
I'm controling a machine that is triggering 5 inputs of the propeller. I need to menure the time as accurate as possible between different inputs comming high.
any ideas?
Stefan
Comments
waitpeq(state1, mask, 0)
t1 := cnt
waitpeq(state2, mask, 0)
t2 := cnt
time := t2 - t1
If Spin is not fast enough, there are equivalent PASM commands. Counters are also a possibility.
John Abshier
Sorry i did not gave a lot info. This is what i know. The 5 inputs can become high at any time . If one becomes high i need the time between that and the 4 others that become high after the first . if the second is slower than 0,5 sec after the first i can discard the time and start over. The second input becoms then the fist And I need to look at the time between the next input comming high. so times are between 0,01 and 0,5 sec to mesure.If all inputs becom high faster then 0,5 sec after the first i need the 4 times. Action is then taken depending the times.
Hope this is stil doable in spin.?
stef
(untested) This will put a start time and each of the inputs high time into an array. You can then subtract that time minus the start to get the difference. If any of the high inputs come more than half a second after the first one, it just restarts the loop. BEWARE: But if the second input never comes, it will just hang in the waitpne. You will have to add some code to watchdog it better if this may happen.
The code also assumes the high inputs will stay high long enough for the INA to be sampled a couple instructions after the waitpne.
I think this should be able to detect 10ms timing, but if you add too much more code it won't. You could do the same thing in PASM fairly easily and get much higher resolution (like 500 times more) and speed. I am bored today, you want a stab at that too?
Do you know also PASM? I never tried it. Untill now I did everything in spin.
Can you also provide me with an little example of PASM. I still need to learn but then I'm pointed in the right direction.
does it also influance the spin example if I run other code in other cog's?
stef
In Spin, you're talking about something like:
Note: This assumes that the pins will only go from low to high while this loop is going. That limits the number of entries in the arrays to 32 at most.
With this PASM code, worst case scenerio you end up with 687.5ns resolution, 500ns best case (depending on where the hub is). This could be streamlined (you could remove the wrlong until after all the times are received). Almost half the instructions in the lower loop is the watchdog. But about a third of the time could be wasted waiting for the hub to come around.
The PASM version assumes each pin will be held high for at least 590.5ns.
You may also want a line added to the PASM to allow you to know when the time array has been altered.