con
_clkmode = xtal1 + pll16x 'external low-speed crystal
_Xinfreq = 5_000_000 '16*5Mhz = 10Mhz crystal is set on 80MHZ
obj
pc : "PC_Interface"
PUB Main | mPos
'start the PC interface
pc.start(31,30)
repeat
setpos(0,0)
pc.str(string("Addresses for a,b, and c"))
setpos(2,1)
pc.str(string("@a"))
pc.hex(@a,4)
setpos(2,2)
pc.str(string("@b"))
pc.hex(@b,4)
setpos(2,3)
pc.str(string("@c"))
pc.hex(@c,4)
waitcnt(clkfreq+cnt)
DAT
a long 0
b byte "A"
c long 0
PRI setpos(px, py)
pc.out(10)
pc.out(px)
pc.out(11)
pc.out(py)
and i see taht it runs a little .. because it give in the terminal that there is a a, b and c that gets a adress or something ..
See three postings above: THOU SHALT NOT USE MY CODE BUT UNDERSTAND IT
You have to totally get rid it, and just include the things into your code you need, as I pointed out!
where did you looked for that package .. because i want to learn more about the "debugger "
and i want to see if there is a value in the inputreg and the output reg .. what is the code for that ?
In all the display drivers (and the PC interface driver), there is an "out()" routine, just like there is a "str()" routine. The "out()" routine takes a single character and displays it (or transmits it to the PC).
Most routines use clkfreq to compute the number of system clocks to produce a particular time delay. If you set _xinfreq and _clkmode or _clkfreq, the compiler uses these constants to figure out the value to use for clkfreq. For example, clkfreq / 1000 will be the number of system clocks for 1/1000 of a second (1 millisecond). If, for some reason, you didn't use clkfreq in your program to calculate these delays, then, whenever you change the system clock, you'd have to change all the delay values rather than just one or two constants when you recompile.
Post Edited (Mike Green) : 8/25/2007 1:43:02 PM GMT
(1) pc.out() : try it out!
(2) 80MHz: This is mysterious... Did you change your delay constants as well? When they stayed the same, than you are no longer waiting 1 and 0.2 seconds but only 125 ms and 25 ms respectivly, From your reports I had always the impression, that the program was not in the state you expected it in, but was waiting in just another loop...
o ok ..
but i'm working with the bin .. and it works fine for me . .so i'm not going to change that .. i think it's almost finsched
i just need to put a loop in the program so that when you hold a button pushed .. the prop.chip doesn't go on .. but stops for a whil till the button is pushe d..
the repeat with the whil ..
should do that as long there is button pressed the repeat runs .. because that is not what it does .. and i don't get what dthe problem
is ...
there is something else strange 2 .. he does everything correct .. till w=4
then he always starts over even when you pushed al the right buttons ....
and i have no idee what it can be .. is it tha 15;16;17 thing you talked me about ?
If you have such suspicion then do something Perhaps dimension both vectors to 20 rather than 16.
Just a little bit "headroom" can improve things. It SHOULD not be needed, but will cover minor "flaws" you will generally have in your program, e.g. you are clearing the vectors upto 17 in the first loop, but you planned to use it upto 16 only... This happens to the most experienced programmer.
ok everything is running like i want except ...
the first repeat ( i will add the code ) has a certain number and i want to make that variable ..
because i want to play20 rounds .. but now when you are wrong it just get counting up .. so if you ar at lvl 10 and you make a mistake you only can do an other 10 instead of 17 i've tried to change the code .. but it stays stuck after the first round and i can't figger out what the proble is .. can you please see for a moment ?
here is the code ( so it doesn't want to work with the m but it does work with a certain number ..
var
long i
long X 'random number
long Z 'number for the outputarray
long v
long w
long j 'number for the inputarray
long frequency
long h
long m
byte outputreg[noparse][[/noparse]99]
byte inputreg[noparse][[/noparse]99]
con
_clkmode = xtal1 + pll16x 'external low-speed crystal
_Xinfreq = 5_000_000 '16*5Mhz = 10Mhz crystal is set on 80MHZ
startpin = 8
delay = 80_000_000 ' how long the light stays on
delay2 = 10_000_000
delay3 = 5_000_000
pin = 18
obj
pc : "PC_Interface"
PUB Main | mPos
'start the PC interface
pc.start(31,30)
memory
pub memory
dira[noparse][[/noparse]0..7] := %00000000
dira[noparse][[/noparse]8..15] := %11111111
w := 1
m := 1
repeat m
x := 0
z := 0
j := 0
'if m==20
'abort
'else
repeat X from 0 to 17
outputreg [noparse][[/noparse]x] := 0
inputreg [noparse][[/noparse]x] := 0
dira[noparse][[/noparse] 8..15] ~~
!outa[noparse][[/noparse]8..15] ' put the led on
waitcnt(delay + cnt )
outa[noparse][[/noparse]8..15] := 0
waitcnt(delay2 + cnt )
repeat w
pc.str(string(13," Loop W="))
pc.dec(w)
X := startpin + ||i?//8 ' set X to a random number from 0 to 8 , starpin for the output. if the random number =0 it will start at a defined pinnumber
dira[noparse][[/noparse]X] ~~
!outa[noparse][[/noparse]X] ' put the led on
waitcnt(delay + cnt )
' waiting time to hold the led lighted
outputreg [noparse][[/noparse]z] := x
if outa[noparse][[/noparse]x] ' put pin X on 1 ( light op a led)
outputreg [noparse][[/noparse]z] := x
pc.str(string(13,"value in outputreg ="))
pc.bin(outputreg[noparse][[/noparse]z],8) ' to save what outpin has gone to 1
z := z + 1 ' z must add by 1 so the next won't overwrite the array
outa[noparse][[/noparse]x] := 0
waitcnt(delay2 + cnt )
repeat w
pc.str(string(13," Loop W="))
pc.dec(w) ' to see what switch is pressed
repeat
if ina [noparse][[/noparse]0..7]
outa[noparse][[/noparse]8..15] := ina[noparse][[/noparse]0..7]
pc.str(string(13,"some key pressed, INA="))
pc.hex(INA[noparse][[/noparse]0..7],2)
if ina[noparse][[/noparse]0]
outa[noparse][[/noparse]8] := ina[noparse][[/noparse]0]
inputreg [noparse][[/noparse]j] := 8
pc.str(string(13,"value in inputreg ="))
pc.bin(inputreg[noparse][[/noparse]j],8)
j := j + 1
'
elseif ina
outa[noparse][[/noparse]9] := ina
inputreg[noparse][[/noparse]j]:= 9
pc.str(string(13,"value in inputreg ="))
pc.bin(inputreg[noparse][[/noparse]j],8)
j := j + 1
'
elseif ina
outa[noparse][[/noparse]10] := ina
inputreg[noparse][[/noparse]j] := 10
pc.str(string(13,"value in inputreg ="))
pc.bin(inputreg[noparse][[/noparse]j],8)
j := j + 1
'
elseif ina
outa[noparse][[/noparse]11] := ina
inputreg[noparse][[/noparse]j] := 11
pc.str(string(13,"value in inputreg ="))
pc.bin(inputreg[noparse][[/noparse]j],8 )
j := j + 1
'
elseif ina
outa[noparse][[/noparse]12] := ina
inputreg[noparse][[/noparse]j] := 12
pc.str(string(13,"value in inputreg ="))
pc.bin(inputreg[noparse][[/noparse]j],8 )
j := j + 1
'
elseif ina
outa[noparse][[/noparse]13] := ina
inputreg[noparse][[/noparse]j] := 13
pc.str(string(13,"value in inputreg ="))
pc.bin(inputreg[noparse][[/noparse]j],8)
j := j + 1
'
elseif ina[noparse][[/noparse]6]
outa[noparse][[/noparse]14] := ina[noparse][[/noparse]6]
inputreg[noparse][[/noparse]j] := 14
pc.str(string(13,"value in inputreg ="))
pc.bin(inputreg[noparse][[/noparse]j],8)
j := j + 1
'
elseif ina[noparse][[/noparse]7]
outa[noparse][[/noparse]15] := ina[noparse][[/noparse]7]
inputreg[noparse][[/noparse]j] :=15
pc.str(string(13,"value in inputreg ="))
pc.bin(inputreg[noparse][[/noparse]j],8)
j := j + 1
'
repeat
pc.str(string(13,"--line 123: INA = "))
pc.hex (INA[noparse][[/noparse]0..7],2)
while ina[noparse][[/noparse]0..7]
waitcnt(delay2 + cnt )
outa[noparse][[/noparse]8..15] := 0
quit
v := 0
repeat w
if outputreg[noparse][[/noparse]v] == inputreg[noparse][[/noparse]v] ' compare the values in the 2 arrays
pc.str(string(13,"value in inputreg ="))
pc.bin(inputreg[noparse][[/noparse]v],8)
pc.str(string(13,"value in outputreg ="))
pc.bin(outputreg[noparse][[/noparse]v],8)
v := v + 1 ' next array
else
pc.str(string(13,"value in inputreg ="))
pc.bin(inputreg[noparse][[/noparse]v],8)
pc.str(string(13,"value in outputreg ="))
pc.bin(outputreg[noparse][[/noparse]v],8)
dira[noparse][[/noparse]8..15] ~~
!outa[noparse][[/noparse]8..15] ' put the led on
waitcnt(delay + cnt )
w := 0
m:=1
w := w + 1
m := m + 1
Have you enabled the "Block Group Indicators" in your Propeller Tool? If not you shoudld do that immerdiately.
Just press Cntr-I or set the Checkbox in the Options Menue
It looks as if there is wrong indention in your program, and you see it best with this option set.
v := 0
repeat w
if outputreg[noparse][[/noparse] v] == inputreg[noparse][[/noparse] v] ' compare the values in the 2 arrays
To better see these things you should always indent at least 5 blanks, not just 2 or 3 as most people do.
var
long x
long i
byte outputreg [noparse][[/noparse]99]
long w
pub simon
w:= 0
X := startpin + ||i?//8
outputreg[noparse][[/noparse]w] := x
repeat
pc.str(string(13," Loop W="))
pc.dec(w)
dira[noparse][[/noparse]outputreg[noparse][[/noparse]w]] ~~
!outa[noparse][[/noparse]outputreg[noparse][[/noparse]w]]
waitcnt(delay + cnt )
outa[noparse][[/noparse]outputreg[noparse][[/noparse]w]] := 0
waitcnt(delay2 + cnt)
hey
this is the part of code that i want to use i'm working on this already a 2 days ( not full days just 4 hour a day ) but i can't get it right
what must it do ..
well i want to make a loop that light 1 led up then in the next loop the same and an other ( so 2 led's) .. and os on and so on .. so you can start building op a serie of leds that comes back but where 1 is added..
( i hope i excplain it right it's , some kind of simon game )
can you give me some help ?
something else .. i have a random function in my program but everytime a start the program it makes the same numbers .. how is this possible? and how do i fix this ?
@ elecnoob : I would guess you are getting the same random number every time because it uses the same seed value to generate the first number. That same seed will be loaded from external I2C Eeprom on Propeller Chip Reset, so one mechanism would be to alter the seed value in the external I2C Eeprom after every reset.
Alternatively, update the seed value in some loop waiting for some indeterminate external event to happen; button push, data received etc.
I always wondered what would happen if I just indented a section of code... with out a repeat statement. Either it doesn't work at all or your code is brilliant[noparse]:)[/noparse]
I only looked at your last 2 notes so I could be wrong about this.
In your code section ... it looks like you need a repeat statement.
Another way to get a random seed is just to use CNT.
So,
x:=startpin + ||CNT?//8
looks like you also could use another variable... LEDSON
I would set your outputreg array to a size one more than the number of lights... so you don't have an indexing problem.
You should also fill your array with meaningless values...
you should also put your random number function in its own method...
so it would look something like this in psuedocode
ledson:=0
w:=1
repeat 8 'main loop
--get your random number
--'see if your array already has that number in it
--repeat with i from 1 to w
----'if array has the same random number... ignore that random number and adjust the value of w to w-1
--repeat with i from 1 to ledson
---turn pins off
---turn them on
--ledson++
--w++
hey tnx for the random code ..
i got the value's that i wanted in the right place so .. but when he continues he resets the value for 1 or an other reason and i can't find out why .. because i don't use the array after i loaded the value in it ..
so i don't understand waht the problem is ....
i shall add the full code here
dira[noparse][[/noparse]0..7] := %00000000
dira[noparse][[/noparse]8..15] := %11111111
w := 1
m := 2
x := 0
j := 0
delay := 80_000_000
delay2 := 10_000_000
delay3 := 5_000_000
repeat m from 1 to 20
pc.str(string(13," loop m ="))
pc.dec(m)
dira[noparse][[/noparse] 8..15] ~~
!outa[noparse][[/noparse]8..15] ' put the led on
waitcnt(delay + cnt )
outa[noparse][[/noparse]8..15] := 0
waitcnt(delay2 + cnt )
x:=startpin + ||CNT?//8
outputreg[noparse][[/noparse]w] := x
repeat w
pc.str(string(13,"outputreg[noparse][[/noparse]w]="))
pc.dec(outputreg[noparse][[/noparse]w])
' set X to a random number from 0 to 8 , starpin for the output. if the random number =0 it will start at a defined pinnumber
dira[noparse][[/noparse]outputreg[noparse][[/noparse]w]] ~~
!outa[noparse][[/noparse]outputreg[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]outputreg[noparse][[/noparse]w]] := 0
waitcnt(delay2 + cnt)
' z must add by 1 so the next won't overwrite the array
repeat w
pc.str(string(13,"outputreg[noparse][[/noparse]w]="))
pc.hex(outputreg[noparse][[/noparse]w],2) [color=#990000] ' here the value is correct [/color]
repeat time from 0 to 30_000
if ina [noparse][[/noparse]0..7]
outa[noparse][[/noparse]8..15] := ina[noparse][[/noparse]0..7]
pc.str(string(13,"some key pressed, INA="))
pc.hex(INA[noparse][[/noparse]0..7],2)
time := 0
if ina[noparse][[/noparse]0]
outa[noparse][[/noparse]8] := ina[noparse][[/noparse]0]
inputreg [noparse][[/noparse]j] := 8
pc.str(string(13,"value in inputreg ="))
pc.bin(inputreg[noparse][[/noparse]j],8)
j := j + 1
time := 0
'
elseif ina
outa[noparse][[/noparse]9] := ina
inputreg[noparse][[/noparse]j]:= 9
pc.str(string(13,"value in inputreg ="))
pc.bin(inputreg[noparse][[/noparse]j],8)
j := j + 1
time := 0
'
elseif ina
outa[noparse][[/noparse]10] := ina
inputreg[noparse][[/noparse]j] := 10
pc.str(string(13,"value in inputreg ="))
pc.bin(inputreg[noparse][[/noparse]j],8)
j := j + 1
time := 0
'
elseif ina
outa[noparse][[/noparse]11] := ina
inputreg[noparse][[/noparse]j] := 11
pc.str(string(13,"value in inputreg ="))
pc.bin(inputreg[noparse][[/noparse]j],8 )
j := j + 1
time := 0
'
elseif ina
outa[noparse][[/noparse]12] := ina
inputreg[noparse][[/noparse]j] := 12
pc.str(string(13,"value in inputreg ="))
pc.bin(inputreg[noparse][[/noparse]j],8 )
j := j + 1
time := 0
'
elseif ina
outa[noparse][[/noparse]13] := ina
inputreg[noparse][[/noparse]j] := 13
pc.str(string(13,"value in inputreg ="))
pc.bin(inputreg[noparse][[/noparse]j],8)
j := j + 1
time := 0
'
elseif ina[noparse][[/noparse]6]
outa[noparse][[/noparse]14] := ina[noparse][[/noparse]6]
inputreg[noparse][[/noparse]j] := 14
pc.str(string(13,"value in inputreg ="))
pc.bin(inputreg[noparse][[/noparse]j],8)
j := j + 1
time := 0
'
elseif ina[noparse][[/noparse]7]
outa[noparse][[/noparse]15] := ina[noparse][[/noparse]7]
inputreg[noparse][[/noparse]j] :=15
pc.str(string(13,"value in inputreg ="))
pc.bin(inputreg[noparse][[/noparse]j],8)
j := j + 1
time := 0
'
repeat
pc.str(string(13,"--line 123: INA = "))
pc.hex (INA[noparse][[/noparse]0..7],2)
while ina[noparse][[/noparse]0..7]
waitcnt(delay2 + cnt )
outa[noparse][[/noparse]8..15] := 0
quit
pc.str(string(13," outputreg="))
pc.dec(outputreg [noparse][[/noparse]w]) [color=#990000] ' here the value is incorrect, the value is 0 again [/color]
v := 1
repeat w
if outputreg[noparse][[/noparse]v] == inputreg[noparse][[/noparse]v] ' compare the values in the 2 arrays
pc.str(string(13,"value in inputreg ="))
pc.bin(inputreg[noparse][[/noparse]v],8)
pc.str(string(13,"value in outputreg ="))
pc.bin(outputreg[noparse][[/noparse]v],8)
v := v + 1 ' next array
p := 1
else
pc.str(string(13,"value in inputreg ="))
pc.bin(inputreg[noparse][[/noparse]v],8)
pc.str(string(13,"value in outputreg ="))
pc.bin(outputreg[noparse][[/noparse]v],8)
dira[noparse][[/noparse]8..15] ~~
!outa[noparse][[/noparse]8..15] ' put the led on
waitcnt(delay + cnt )
w := 0
m := 0
p := 2
w := w + 1
if p == 1
repeat f from 0 to 1000
vertraag := 10_000
dira[noparse][[/noparse]17] ~~
!outa[noparse][[/noparse]17]
waitcnt(vertraag + cnt )
elseif p==2
repeat f from 0 to 1000
vertraag := 60_000
dira[noparse][[/noparse]17] ~~
!outa[noparse][[/noparse]17]
waitcnt(vertraag + cnt )
can you tell me why he does this ? because i don't know it anymore
Comments
and i see taht it runs a little .. because it give in the terminal that there is a a, b and c that gets a adress or something ..
Now you have to think: What would I like to see from my program?
The simplest idea is: Where am I?
So you can include a "tracing"; add the following lines at the appropriate places:
pc.str(string(13," Loop W="))
pc.dec(w)
and
pc.str(string(13,"some key pressed, INA="))
pc.hex(INA[noparse][[/noparse]0..7],2)
You get the idea?
Note "13" is a newline on the terminal; there is a more advanced control by setting an absolute position..
Post Edited (deSilva) : 8/25/2007 12:18:32 PM GMT
but this is a neverending loop .. so it's impossible that it gets in my program ...
You have to totally get rid it, and just include the things into your code you need, as I pointed out!
Post Edited (deSilva) : 8/25/2007 12:53:10 PM GMT
i've done that .. but he makes the ina == uncorrect ..
he says they are 20, 10 and other numbers .. i that isn't possible i think
$10 means Bit 4
$20 means Bit 5
and so on..
I just had a look: There is also a bin-routine in the package, so you can do
pc.bin(INA[noparse][[/noparse]0..7], 8)
and i want to see if there is a value in the inputreg and the output reg .. what is the code for that ?
pc.bin(inputreg[noparse][[/noparse]j],8)
can this work ?
pc.dec(inputreg[noparse][[/noparse] j ] )
You can also try to output the complete vector:
"zz" has to be defined as a new variable, or take one you have already and do not need.
Edit: Heh, congrat!
what does this do ?
In all the display drivers (and the PC interface driver), there is an "out()" routine, just like there is a "str()" routine. The "out()" routine takes a single character and displays it (or transmits it to the PC).
Most routines use clkfreq to compute the number of system clocks to produce a particular time delay. If you set _xinfreq and _clkmode or _clkfreq, the compiler uses these constants to figure out the value to use for clkfreq. For example, clkfreq / 1000 will be the number of system clocks for 1/1000 of a second (1 millisecond). If, for some reason, you didn't use clkfreq in your program to calculate these delays, then, whenever you change the system clock, you'd have to change all the delay values rather than just one or two constants when you recompile.
Post Edited (Mike Green) : 8/25/2007 1:43:02 PM GMT
(2) 80MHz: This is mysterious... Did you change your delay constants as well? When they stayed the same, than you are no longer waiting 1 and 0.2 seconds but only 125 ms and 25 ms respectivly, From your reports I had always the impression, that the program was not in the state you expected it in, but was waiting in just another loop...
but i'm working with the bin .. and it works fine for me . .so i'm not going to change that .. i think it's almost finsched
i just need to put a loop in the program so that when you hold a button pushed .. the prop.chip doesn't go on .. but stops for a whil till the button is pushe d..
the best way to do this is to do it like this
or i'm a wrong ?
only the button thing i need to add .. and then i think it's finische..
But note: There is still some unfinished business about how many elements of the vectors you use: 15? 16? 17? Look again through your program!
normally it must work !!
should do that as long there is button pressed the repeat runs .. because that is not what it does .. and i don't get what dthe problem
is ...
then he always starts over even when you pushed al the right buttons ....
and i have no idee what it can be .. is it tha 15;16;17 thing you talked me about ?
Just a little bit "headroom" can improve things. It SHOULD not be needed, but will cover minor "flaws" you will generally have in your program, e.g. you are clearing the vectors upto 17 in the first loop, but you planned to use it upto 16 only... This happens to the most experienced programmer.
Post Edited (deSilva) : 8/26/2007 12:46:16 PM GMT
the first repeat ( i will add the code ) has a certain number and i want to make that variable ..
because i want to play20 rounds .. but now when you are wrong it just get counting up .. so if you ar at lvl 10 and you make a mistake you only can do an other 10 instead of 17 i've tried to change the code .. but it stays stuck after the first round and i can't figger out what the proble is .. can you please see for a moment ?
here is the code ( so it doesn't want to work with the m but it does work with a certain number ..
Just press Cntr-I or set the Checkbox in the Options Menue
It looks as if there is wrong indention in your program, and you see it best with this option set.
To better see these things you should always indent at least 5 blanks, not just 2 or 3 as most people do.
i was wothering if there was an option like that !!
thnx allot at last !!!
hey
this is the part of code that i want to use i'm working on this already a 2 days ( not full days just 4 hour a day ) but i can't get it right
what must it do ..
well i want to make a loop that light 1 led up then in the next loop the same and an other ( so 2 led's) .. and os on and so on .. so you can start building op a serie of leds that comes back but where 1 is added..
( i hope i excplain it right it's , some kind of simon game )
can you give me some help ?
Alternatively, update the seed value in some loop waiting for some indeterminate external event to happen; button push, data received etc.
I always wondered what would happen if I just indented a section of code... with out a repeat statement. Either it doesn't work at all or your code is brilliant[noparse]:)[/noparse]
I only looked at your last 2 notes so I could be wrong about this.
In your code section ... it looks like you need a repeat statement.
Another way to get a random seed is just to use CNT.
So,
x:=startpin + ||CNT?//8
looks like you also could use another variable... LEDSON
I would set your outputreg array to a size one more than the number of lights... so you don't have an indexing problem.
You should also fill your array with meaningless values...
you should also put your random number function in its own method...
so it would look something like this in psuedocode
ledson:=0
w:=1
repeat 8 'main loop
--get your random number
--'see if your array already has that number in it
--repeat with i from 1 to w
----'if array has the same random number... ignore that random number and adjust the value of w to w-1
--repeat with i from 1 to ledson
---turn pins off
---turn them on
--ledson++
--w++
Rich
i got the value's that i wanted in the right place so .. but when he continues he resets the value for 1 or an other reason and i can't find out why .. because i don't use the array after i loaded the value in it ..
so i don't understand waht the problem is ....
i shall add the full code here
can you tell me why he does this ? because i don't know it anymore