Question about waitcnt
Mazzini
Posts: 58
Good day,
sry for trivial question ,Can you explain me waitcnt ?
In the code below, it would copy CNT's Value and add 101, then wait for CNT+ t1 cycles and toggle OUTA,1 ?I'm not sure
sry for trivial question ,Can you explain me waitcnt ?
In the code below, it would copy CNT's Value and add 101, then wait for CNT+ t1 cycles and toggle OUTA,1 ?I'm not sure
waitcnt t1,#0 ' zero What does it for?
''*************** ''* PASD Test * ''*************** '' CON 'Use the following 2 lines if running on a Parallax PropDemo board _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 'Use the following 2 lines if running on a Hydra board '_clkmode = xtal1 + pll8x '_xinfreq = 10_000_000 VAR long Cog, TestVar OBJ dbg : "PASDebug" '<---- Add for Debugger PUB main Cog := cognew(@entry, @TestVar) + 1 dbg.start(31,30,@entry) '<---- Add for Debugger PUB stop if Cog cogstop(Cog~ - 1) DAT org 0 entry ' --------- Debugger Kernel add this at Entry (Addr 0) --------- long $34FC1202,$6CE81201,$83C120B,$8BC0E0A,$E87C0E03,$8BC0E0A long $EC7C0E05,$A0BC1207,$5C7C0003,$5C7C0003,$7FFC,$7FF8 ' -------------------------------------------------------------- mov DIRA,#$FF loop mov t1,CNT add t1,#101 waitcnt t1,#0 xor OUTA,#1 jmp #loop t1 res 1
Comments
It works thanks , but my goal is reach 1 second pause and $1FF is the upper limit
Do you know how achieve that ?may be I need an kind of nested loop..
My osc run at 80Mhz --> 20MIPS = 50ns *512 = about 25us, its right ?
Thank so much
delay*50ns = 4 second(?)
Thanks
the waitcnt command makes the cog stop completely until the systemcounter matches the value "t1 + delay"
As long as the cog is stopped as if you would stop the cpu-clock no commands are executed the cog is just frozen.
keep the questions coming
best regards
Stefan
from Propeller's datasheet
<<
Note that for a cog clock frequency of 80 MHz, the
***counter update period is a mere 12.5 ns***. This high speed,
combined with 32-bit precision, allows for very dynamic
signal generation and measurement...
>>
Thanks
waitcnt (1 + cnt) is 12.5ns
waitcnt (2 + cnt) is 25.0ns
waitcnt (1_000 + cnt) is 12.5us
...
if you use waitcnt in spin the minimum waittime is 385 clockticks.
This is because of the overhead caused by the SPIN-interpreter.
in PASM the minimum waittime is 9 clockticks. it needs minimum 8 clockticks to load actual value of cnt and then execute the waitcnt-command.
if you try to wait for a shorter timeperiod the systemcounter has already "overrun" the target-value and then it will take 2^32 / 80_000_000 = 53 seconds until
the free running systemcounter again matches the value used in the waitcnt command.
keep the questions coming
best regards
Stefan
I don't know SPIN , I just started with Pasm and I read this :
The first too will wait for a long time - by the time you've calculated cnt+1 or cnt+2 the cnt register will already be 8 greater and you'll be waiting for it to wrap round again...
But, true, the time to setup the waitcnt/spin takes up a lot more time ( >> ) than the clockperiod/cnt when you get way, way down there, and that's something to consider.