My prochip never works?
olivertog
Posts: 3
why this will not work? I cant get any thing to follow th repeat command either?
con
_clkmode = Xtal1
_clkfreq = 5_000_000
var
long stack[noparse][[/noparse]9]
pub main
cognew(inverter, @stack)
PUB Inverter
dira ~
dira[noparse][[/noparse]6..7]~~
waitpeq(%10, %10, 0)
outa[noparse][[/noparse]6]~~
waitcnt(4_000_000 + cnt)
outa[noparse][[/noparse]6]~
waitcnt(4_000_000 + cnt)
outa[noparse][[/noparse]7]~~
waitcnt(4_000_000 + cnt)
outa[noparse][[/noparse]7]~
waitpeq(%00, %10, 0)
inverter
con
_clkmode = Xtal1
_clkfreq = 5_000_000
var
long stack[noparse][[/noparse]9]
pub main
cognew(inverter, @stack)
PUB Inverter
dira ~
dira[noparse][[/noparse]6..7]~~
waitpeq(%10, %10, 0)
outa[noparse][[/noparse]6]~~
waitcnt(4_000_000 + cnt)
outa[noparse][[/noparse]6]~
waitcnt(4_000_000 + cnt)
outa[noparse][[/noparse]7]~~
waitcnt(4_000_000 + cnt)
outa[noparse][[/noparse]7]~
waitpeq(%00, %10, 0)
inverter
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
PG
2) At the end of Inverter, you have a recursive call to Inverter. This will very quickly use up the limited stack space and eventually start to fill up memory with stack frames from these calls without returns. A good initial stack space for simple routines without calls to other routines is 20 levels.
3) You didn't explain what happened or what you expected to happen.
dira[noparse][[/noparse]6..7]~~
waitpeq(%10, %10, 0)
this is what my original code looks like, I want it to wait for me to make pin 1 high, then continue
Notice that the main cog will quit after the COGNEW, but leave the 2nd cog running. This is because the implicit return from the PUB main goes to a cogstop.
in your thread-headline you suspected the propeller-CHIP not to work
this could be easily checked by loading one of the example-codes
one more or less obvoius thing:
the numbers of the IO-Pin start at ZERO so Pin 1 is the SECOND Pin .
There are two errors inside the code that you posted
first error: stacksize
you defined
a stacksize of 9 is not enough in most cases
if the stack is too small your program can crash immediatly
take a size of 20 longs and sometimes it will be nescessary to take 200 longs
second:
if you call the method Inverter INSIDE itself this is RECURSIVE
This will eat up ALL THE 32kB of RAM after some time and then your program crashes down
if the code inside the method Inverter should be repeated you MUST use a repeat-loop
this code works properly
some more hints:
use a clock of 80 MHz
use ClkFreq instead of harcoded numbers in waitcnt
"ClkFreq + cnt" means a delay of 1 second
"ClkFreq / 10 + cnt" means a delay of 0,1 second
"ClkFreq * 5 + cnt" means a delay of 5 seconds
best regards
Stefan