Wait tick - Need help
I have the code for getting the prop to wait a second but is there a way to get it to wait a tick.
A tick is a 10, 000 of a millisecond.
The code for getting it to wait a millisecond is:
I thought:
would work but it waits for more like 10 seconds.
Can the prop handle waiting for such small amounts of time?
Thank you![smile.gif](http://forums.parallax.com/images/smilies/smile.gif)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
Post Edited (computer guy) : 10/13/2008 8:04:21 AM GMT
A tick is a 10, 000 of a millisecond.
The code for getting it to wait a millisecond is:
waitcnt(((clkfreq / 1_000 * Duration - 3932)) + cnt)
I thought:
waitcnt((((clkfreq / 1_000 * Duration - 3932)) + cnt) / 10_000)
would work but it waits for more like 10 seconds.
Can the prop handle waiting for such small amounts of time?
Thank you
![smile.gif](http://forums.parallax.com/images/smilies/smile.gif)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
Post Edited (computer guy) : 10/13/2008 8:04:21 AM GMT
Comments
waitcnt((((clkfreq / 1_000 * Duration - 3932)) + cnt) / 10_000)
is adding the 3932 ( which I'm assuming you're using as an offset that spin takes between getting the cnt value for the calculation ) and the current cnt value, before / 10_000 try doing / 10_000 first
waitcnt( ( ( (clkfreq / 1_000 * Duration) /10_000 ) - 3932 ) + cnt )
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://www.propgfx.co.uk/forum/·home of the PropGFX Lite
·
However it still takes 10 seconds if not longer.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
nop··· ' takes 4 clocks
nop··· ' takes 4 more
There's no way you'll get SPIN (interpreted) code to wait for such a short time, as there's a·significant overhead for the waitcnt SPIN instruction.· PASM runs ~50x faster than SPIN.
Note that this is ONLY if you want to wait for ONE tick, or very few.· If you want to wait for a few hundred ticks, you're getting within the realm of possibility.· It won't be cycle accurate like PASM, but it might be good enough - the overhead is more or less fixed, so waiting for (overhead + 10) is possible, but (overhead - 10) isn't.
In the example you've given, if 'Duration' isn't a constant, the code has to do an integer multiply of (1_000·*·Duration), then divide clkfrq by the result, both of which take some time.· The -3932 is probably compensating for the time passing while the calcs are done.· If Duration IS a constant, then the compiler could do all the math (except +cnt) at compile time, and that -3932 would probably cut down to -350 or so.
I hope that all makes sense.· [noparse]:)[/noparse]
Jason
Post Edited (JasonDorie) : 10/13/2008 8:32:02 AM GMT
DAT waitTick nop nop
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
Jason
Someone please correct me if I'm way off there.
If this is what you're trying to do, it's probably in your best interests to learn PASM.
Jason
I have a variable "output_time". This has a value like 59334592.
I need to increment a variable "temp" by 1 and then compare it to output_time.
If they match then continue else keep incrementing and compare.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
waitcnt( cnt + output_time )
...it'll take the current cycle count, add your 'output_time' value, and then wait until the cycle count reaches that new number. Assuming that your 'output_time' value is in clock ticks that'll work just fine. If you're running at 10MHz, that would be exactly right as 1 tick would equal 1 clock. At 80MHz, 1 tick = 8 clocks, so you'd need to use:
waitcnt( cnt + output_time*8 )
...and since *8 is just a shift left by 3, the compiler should optimize it for you and it will take very little time.
Does that help?
Jason
Post Edited (JasonDorie) : 10/13/2008 8:50:48 AM GMT
I will see how I go with the information you have provided.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://www.propgfx.co.uk/forum/·home of the PropGFX Lite
·
repeat while temp < new_time temp++ term.dec(temp) term.out(13)
Its not doing anything.
I have that code within another repeat statement.
If I change the code to
temp++ term.dec(temp) term.out(13)
It works fine.
Is there some rule about having a repeat statement within another?
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
Post Edited (computer guy) : 10/13/2008 9:55:35 AM GMT
if they're both 0 ( uninitialised )·it won't do anything as 0 (temp) is not < 0 (new_time)
or if·temp·is greater than or equal to·new_time
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://www.propgfx.co.uk/forum/·home of the PropGFX Lite
·
repeat temp++ term.dec(temp) term.out(13)
It doesn't work.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
can you post more of the code?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://www.propgfx.co.uk/forum/·home of the PropGFX Lite
·
I managed to get it working after setting the 2 variables properly.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.
Guitar Hero controller using the prop (WIP) --> HERE
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://www.propgfx.co.uk/forum/·home of the PropGFX Lite
·