According to the Propeller Manual, CNT is not zeroed on start-up/reset and contains an arbitrary value. How arbitrary that value is I do not know, it may not be arbitrary enough to give a different random number seed every start-up. Also, in 'x := startpin +||CNT?//8', there's a one in 8 chance that the result will be the same as last start-up, and if you are unlucky, the time taken to go through the loop could be giving a result which always produces the same random number each time.
I do not know how the pseudo random number generation works on the Propeller, but it could be that the code doesn't give such a random result as desired. You could try something like ...
x := startpin + ( ( ||CNT/256 ) // 8 )
Or dedicate a variable to holding a random number, initialise it at start-up, then update the random number in the loop and use its latest value.
Set up a counter so it counts up to a certain number before looping, get the user to press a button at the start of the game and use the number in the counter as your random number seed.
the random number works that's fine at the moment with this code
x:=startpin + ||CNT?//8
but now i need to make the "simon" code i don't know i you know the game ..
dira[noparse][[/noparse]0..7] := %00000000
dira[noparse][[/noparse]8..15] := %11111111
delay := 80_000_000
delay2 := 10_000_000
delay3 := 5_000_000
w:=1
z:=1
repeat
if ina [noparse][[/noparse]0..7]
x:=startpin + ||CNT?//8
outputreg[noparse][[/noparse]z] := x
repeat w
simon[noparse][[/noparse]w] := outputreg[noparse][[/noparse]w]
dira[noparse][[/noparse]simon[noparse][[/noparse]w]] ~~
!outa[noparse][[/noparse]simon[noparse][[/noparse]w]] ' put the led on
waitcnt(delay + cnt )
' z must add by 1 so the next won't overwrite the array
outa[noparse][[/noparse]simon[noparse][[/noparse]w]] := 0
waitcnt(delay2 + cnt)
w:=w+1
z:=z+1
but he deasn't dop what i want ..
what it should do is ..
make an random number (ok)
put in an array (ok)
make a certain led on ( ok)
then if you klick again there must be 1 led more going on ( ok)
but it must first be the same led and than an other ( NOT OK )like an simon game ( if you don't know it go to this site : http://www.game.nl/game126.html )
and that is what is going wrong and i can't find the fault
x:=startpin + ||CNT?//8
about this .. i'm working with delay as you know and can the cnt in the random infect the cnt in the delaY?
btw i have found my fault in my last post
There are longer discussions from time to time referring to this subject. Search for "shadow register".
Writing to CNT will be the same as writing to INA.
The situation can be better understood in machine code, where you have "dest" and "source" positions
in an instruction wired differently to the "special registers".
The ? is not one machine instruction but leads to a little bit unknown code in the SPIN interpreter;
depending on that ?CNT will either produce the expected random results,
seeded with CNT := xxx, or a value directly related to the actual CNT value.
Note that there is a difference between using CNT directly ("linear ramp-up") and an
additional "spreading" instruction as ? which will distribute the bits through the word...
However it makes sense to use CNT as seed, as a (short) reset does not clear it, as has already been remarked.
ok i'm at my last game of the 5
but at this point i need a second cog to use ..
to generate a never ending repaet for a light that must light on/off hole the time ..
but i don't relly understand that command ...
can somoene give me a excplanation ?
i've been reading and trying but i don't get it ..
pub twister
dira[noparse][[/noparse]0..7] := %00000000
dira[noparse][[/noparse]8..15] := %11111111
delay := 80_000_000
delay2 := 10_000_000
dira[noparse][[/noparse] 8..15] ~~
!outa[noparse][[/noparse]8..15]
waitcnt(delay + cnt )
outa[noparse][[/noparse]8..15] := 0
waitcnt(delay2 + cnt )
repeat i from 0 to 8
outputreg[i]:=0
w:=8
z:=1
p:=0
speler:= 1
repeat w
x:=startpin + ||h?//8
outputreg[noparse][[/noparse]9] := x
repeat i from 0 to 8
if outputreg[noparse][[/noparse]9] == outputreg[i]
x:=startpin + ||h?//8
outputreg[noparse][[/noparse]9] := x
i:=0
p:=0
else
p:= 1
if p:=1
if speler== 1
outputreg[noparse][[/noparse]z] := outputreg[noparse][[/noparse]9]
dira[noparse][[/noparse]x] ~~
!outa[noparse][[/noparse]x]
elseif speler==2
outputreg[noparse][[/noparse]z] := outputreg[noparse][[/noparse]9]
cognew( flits,@sqstack)
if speler == 1
speler := 2
else
speler := 1
waitcnt(delay + cnt )
z:=z+1
outa[noparse][[/noparse]8..15] := 0
waitcnt(delay2 + cnt )
pub flits
repeat
dira[noparse][[/noparse]x] ~~
!outa[noparse][[/noparse]x]
waitcnt(80_000_000+ cnt )
outa[noparse][[/noparse]x] := 0
[/i][/i]
this is the full code of that part for what i have so far ...
but the cognew part .. can you excplain this to me .. i've been raidning in my manual pg 189 till 190
but i don't really get it ..
But get rid of that global X first, two differentz Xes are not allowed, or call the parameter Y
(and don't forget to change it in the body of flits to Y as well.)
And - BTW - don't forget to look inte the extremely good manual and the SPIN tutorial from time to time...
i don't get it ..
with the 2 different xes ... i mean .;
i need to use the x in my pub twister to be the same x as the purb flits ..
so ... i really don't get it .;
do i need to say that y:=x
and use y in the pub flits ? or what ?
Please read the sections about methods and parameters in the tutorial.
It starts on page 104 and it's called "Exercise 4"
I am sure it will help your understanding. I can't do it better...
i want to do a cognew .. but because i need a stack for that i always overwrite a piece of my program ..
rthis is probably because my stack is to small... ( i'm a right?)
but how do i know that i choose a stack big enouf ?
because know ... well my programm crashes all te time .. and that's not what i want
ok the stack problem is fixed ..
but now i have an other problem ..
everytime you say cognew he takes the next cog to proces the program under it... ( i hope i say it right)
but everytime i make a cog new the proces that was runing stops and will an other wil continue ...
ok ok .. maybe i said that badly i will try again ..
what i want to do is to put 4 led's on and of in an endless repaet
in 4 different cog's ..
but with me he stops the previouse led to light on/off and takes an other
this is the code i have
I doubt the program you posted did what you say, but there could be a misunderstanding of course...
(1) you did not indent the code for REPEAT 4; but I assume you did it in the IDE...
(2) You use pc.... in parallel routines; do you think this could work???
(3) You use the same stack for all routines. This certainly can not work. Think!
(4) Note that the first COG will stop after it has installed the other COGs; this it not an issue, just an information for you
ok i changed the cognew's in coginit
but now he doesn't do anaything ... this is the code i have ... i only put the code with the change the rest stays the same
if c ==1
coginit (1,flits(x),@stack)
c:=c+1
elseif c == 2
coginit(2,flits(x),@stack2)
c:=c+1
elseif c==3
coginit (3,flits(x),@stack3)
c:=c+1
elseif c==4
coginit(4,flits(x),@stack4)
c:=c+1
ok when i put just only 1 coginit it works like a cognew..
so now is my question .. how can i run this program flits on 4 different cog's with 4 differnt value's in the same variable?
or is this impossible?
ok i made a second pub named flits2 so i can run an other "pub" with the same code in it ..
i made an other stack ( stack2 ) as big as the other stack ...
and stil it doesn't work ..
i also first want to try this on 2 led's before i'm going to 4 .. maybe less difficult for trying
var
long stack[noparse][[/noparse]200]
long stack2[noparse][[/noparse]200]
long x
long h
long c
pub twister
c:=1
repeat 2
x:=||h?//8
if c==1
coginit (1,flits(x),@stack)
c:=c+1
elseif c==2
coginit (2,flits2(x),@stack2)
pub flits(ik)
pc.str(string(13,"ik="))
pc.dec(ik)
dira[noparse][[/noparse]ik]~~
repeat
!outa[noparse][[/noparse]ik]
waitcnt(5_000_000+ cnt )
pub flits2(jij)
pc.str(string(13,"jij="))
pc.dec(jij)
dira[noparse][[/noparse]jij]~~
repeat
!outa[noparse][[/noparse]jij]
waitcnt(5_000_000+ cnt )
i think that that is the problem .. the stack ....
because i debuged it with that program you gave me "propterminal"
and there i see that he goes into the flits pub but there is some fault i don't get ..
i will post a little piece of the debug text
what i get :
speler2 c
=ik=19
what it should be
speler2 c=1
ik=9
you see the difference?
and this is my problem .. how do i fix it ?
Comments
I do not know how the pseudo random number generation works on the Propeller, but it could be that the code doesn't give such a random result as desired. You could try something like ...
x := startpin + ( ( ||CNT/256 ) // 8 )
Or dedicate a variable to holding a random number, initialise it at start-up, then update the random number in the loop and use its latest value.
Graham
x:=startpin + ||CNT?//8
but now i need to make the "simon" code i don't know i you know the game ..
but he deasn't dop what i want ..
what it should do is ..
make an random number (ok)
put in an array (ok)
make a certain led on ( ok)
then if you klick again there must be 1 led more going on ( ok)
but it must first be the same led and than an other ( NOT OK )like an simon game ( if you don't know it go to this site : http://www.game.nl/game126.html )
and that is what is going wrong and i can't find the fault
about this .. i'm working with delay as you know and can the cnt in the random infect the cnt in the delaY?
btw i have found my fault in my last post
You can't write to CNT (but Desilva probably can[noparse]:)[/noparse]
If you want to have fun... do a little experiment... just read cnt into a variable and print that value to the screen.
Very Strange...and quite mysterious.
Rich
Writing to CNT will be the same as writing to INA.
The situation can be better understood in machine code, where you have "dest" and "source" positions
in an instruction wired differently to the "special registers".
The ? is not one machine instruction but leads to a little bit unknown code in the SPIN interpreter;
depending on that ?CNT will either produce the expected random results,
seeded with CNT := xxx, or a value directly related to the actual CNT value.
Note that there is a difference between using CNT directly ("linear ramp-up") and an
additional "spreading" instruction as ? which will distribute the bits through the word...
However it makes sense to use CNT as seed, as a (short) reset does not clear it, as has already been remarked.
Post Edited (deSilva) : 9/1/2007 8:40:32 AM GMT
but at this point i need a second cog to use ..
to generate a never ending repaet for a light that must light on/off hole the time ..
but i don't relly understand that command ...
can somoene give me a excplanation ?
i've been reading and trying but i don't get it ..
this is what i have .. but i need to be able to get the value x in that new cog
how do i do that ?
Could you post your entire code?
Rich
this is the full code of that part for what i have so far ...
but the cognew part .. can you excplain this to me .. i've been raidning in my manual pg 189 till 190
but i don't really get it ..
But this clearly decribed in the manual:
Or just:
something like
pub flits |x
or something .. because now he says that there must be a "," between the flits and (x) and he wants to leave the stack out of it ...
PUB flits(X)
what you need....
But get rid of that global X first, two differentz Xes are not allowed, or call the parameter Y
(and don't forget to change it in the body of flits to Y as well.)
And - BTW - don't forget to look inte the extremely good manual and the SPIN tutorial from time to time...
with the 2 different xes ... i mean .;
i need to use the x in my pub twister to be the same x as the purb flits ..
so ... i really don't get it .;
do i need to say that y:=x
and use y in the pub flits ? or what ?
It starts on page 104 and it's called "Exercise 4"
I am sure it will help your understanding. I can't do it better...
but i was reading at 189 and i didn't understood that ..
i'm really srry
maybe an other question ..
i need to make code to check if a button is pushed and that it stays pushed .. how can i do that best ?
rthis is probably because my stack is to small... ( i'm a right?)
but how do i know that i choose a stack big enouf ?
because know ... well my programm crashes all te time .. and that's not what i want
but now i have an other problem ..
everytime you say cognew he takes the next cog to proces the program under it... ( i hope i say it right)
but everytime i make a cog new the proces that was runing stops and will an other wil continue ...
ok ok .. maybe i said that badly i will try again ..
what i want to do is to put 4 led's on and of in an endless repaet
in 4 different cog's ..
but with me he stops the previouse led to light on/off and takes an other
this is the code i have
You show a repeat, but nothing is indented in your example after the 'repeat 4'.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko
it's just a typefault
it must be
(1) you did not indent the code for REPEAT 4; but I assume you did it in the IDE...
(2) You use pc.... in parallel routines; do you think this could work???
(3) You use the same stack for all routines. This certainly can not work. Think!
(4) Note that the first COG will stop after it has installed the other COGs; this it not an issue, just an information for you
but still i need to find some solution for the cognew .. but besieds that ....
the cognew problem .. can i fix it with the coginit? or stops the cog also if an other cog is started up ?
but now he doesn't do anaything ... this is the code i have ... i only put the code with the change the rest stays the same
so now is my question .. how can i run this program flits on 4 different cog's with 4 differnt value's in the same variable?
or is this impossible?
i made an other stack ( stack2 ) as big as the other stack ...
and stil it doesn't work ..
i also first want to try this on 2 led's before i'm going to 4 .. maybe less difficult for trying
what do i do wrong ? because i don't see it ??
The main problem is, that you still use PC, which is absolutely fine (though of limited use in real parallel situations).
Nevertheless: PC starts an assembly program in COG 1. You overwrite this COG and bingo!
So then start with COG #2 and everything will work fine (I hope )
You also should return to your first version, and improve it a little bit stylistically..
Suggestions:
- Use a count loop: REPEAT c FROM 2 TO 5
- Compute the start of the stacks dynamically: stack_address += 200*4
etc, etc
Post Edited (deSilva) : 9/6/2007 9:11:25 PM GMT
and now my program just runs over it.
so for 1 or an other reason it doesn't do that coginit ...
because i debuged it with that program you gave me "propterminal"
and there i see that he goes into the flits pub but there is some fault i don't get ..
i will post a little piece of the debug text
what i get :
speler2 c
=ik=19
what it should be
speler2 c=1
ik=9
you see the difference?
and this is my problem .. how do i fix it ?