Propeller First Step
jmspaggi
Posts: 629
Hi all,
I just received my prop and I'm trying to play with it.
I did a home made PASM version of Fibo. It can probably been improved, but I was able to do something at least.
Now, I have one question.
Here is the code
How can I wait for the cog to complete in order to read the result? Because if I run this code, it will create cog1 to 7 very quickly, then fail to create a new code. And I will never see the results, and they will all try to use the same array to store the stack, and so on. Also, I'm not 100% sure for the cogit and cogstop lines.
So do I have a way to check the cog status in a repeat loop in my Spin code?
Thanks,
JM
I just received my prop and I'm trying to play with it.
I did a home made PASM version of Fibo. It can probably been improved, but I was able to do something at least.
Now, I have one question.
Here is the code
{{ fibo.spin }} con _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 var long Table[noparse][[/noparse]64>>2] ' 64 bytes ... keep var data all the same type so addresses are contiguous obj sx : "FullDuplexSerial" PUB Main | n, t1, t2 sx.start(31,30,0,115200) waitcnt(clkfreq+cnt) sx.str(string($d,"Spin FIBO Test",$d)) repeat n from 0 to 24 sx.str(string($d,"FIBO ")) sx.dec(n) t1 := cnt/1000000 Table[noparse][[/noparse]0] := n cognew(@Fibo, @Table) t2 := cnt/1000000 sx.str(string(" = ")) sx.dec(result) sx.tx(" ") sx.dec((t2-t1)*1_000_000/(clkfreq/1000)) sx.str(string("ms")) DAT org 0 Fibo mov FibResult, #0 ' So far, result is 0 mov tptr, par mov TabAddr, tptr ' tabadr contains table pointer mov TopAddr, tptr ' topadr contains top of the table jmp #MLoop MLoop rdbyte Temp, TopAddr ' Read the value on the stack cmp Temp, #2 wc,wz ' Do we have 2 or less in the stack?6 IF_A jmp #Above add FibResult, #1 ' Yes. So add 1. cmp TopAddr, TabAddr wc, wz ' Is there still work on the stack? IF_E jmp #End sub TopAddr, #1 jmp #MLoop ' And continue Above sub Temp, #1 wrbyte Temp, TopAddr add TopAddr, #1 sub Temp, #1 jmp #MLoop2 End wrbyte FibResult, TabAddr cogid Temp cogstop Temp ret FibResult long 0 Temp long 0 TabAddr long 0 ' Storage for table address TopAddr long 0 ' Top of the storage address tptr long 0 ' use RES only at end of cog pasm code
How can I wait for the cog to complete in order to read the result? Because if I run this code, it will create cog1 to 7 very quickly, then fail to create a new code. And I will never see the results, and they will all try to use the same array to store the stack, and so on. Also, I'm not 100% sure for the cogit and cogstop lines.
So do I have a way to check the cog status in a repeat loop in my Spin code?
Thanks,
JM
Comments
I found a way to wait for the cog to complet, but it's not always working. There should be a better way to do that.
Also, this code is not working [noparse]:([/noparse]
It's working for 0 to 4, but not above that. I tried in pProppelerSim just the ASM code, and it's working fine [noparse]:([/noparse] So I don't really understand why it's not working there.
Any clue?
Thanks,
JM
Normally we want to start one COG one time and post messages to it about what needs to be done.
You could use two variables in this case: one called "doit", the other called "number".
So, in spin where your cognew is now, you set number := fibonumber, then set doit := non-zero.
In your PASM you "Spin" waiting for "doit" to be non-zero, read the number, calculate, store the result back to number, and set doit to zero. In Spin, you wait for doit to be zero before advancing to the next spin statement.
You can figure out the rest.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
May the road rise to meet you; may the sun shine on your back.
May you create something useful, even if it's just a hack.
My final goal is to use all the COGs on that. So I will have to define more than one doit...
Anyway, I will first make this one working before doing another one [noparse];)[/noparse]
Anyclue why FIBO 5 is giving me a so big number when fibo 1 to 4 are working fine?
JM
re: fn(14), even returning a long doesn't help. So there is one more worm who didn't make it back to the can ...
Post Edited (kuroneko) : 4/21/2010 2:56:34 AM GMT
Here is a version which return a long, but it's still not return the right value.
I have also try to modify the exit condition, but it's never exiting the loop now [noparse];)[/noparse]
Can you point me what's rong with this peace?
Also, I built the code this way becayse my final goal is to tun it on multi-cogs. So I want to have more than one cog ready/writing the stack.
Thanks,
JM
is backwards. Try this
The $ refers to the current instruction i.e. wrlong which is not equal null which is the important bit. Then it produces the same results as my version (SPIN or PASM).
What, you mean run fibonacci on multiple cogs? Or run stuff in general? You run out of bit space anyway (~50) so it seems a bit of a waste [noparse]:)[/noparse]
Also, why using
instead of
? Is it faster? Of it's the state of the art to do such update?
For the multi cog, it's more for me a way to try, learn, do mistakes, investigate and so on. Fibo is the only think I found to far for that [noparse];)[/noparse] Later, I will try to find some other usefull thinkg to do. But I'm missing ideas.
Thanks,
JM
I have so much to learn with PASM and SPIN...
Thanks again!
JM