new cogs will not launch
sciguy
Posts: 48
Hey there, I'm brand new to the propeller chip, and I have read through all of the documentation. I can't seem to get my chip to launch anything in a new cog.
Here is an except from my code:
When I do that, the act method does not run.
But if i simply use
, it works fine.
Any suggestions.
Here is an except from my code:
VAR long stack [noparse][[/noparse]30] PUB main DIRA[noparse][[/noparse]0..5]~ DIRA[noparse][[/noparse]16..21]~~ cognew( act(1,16), @stack) PUB act(distance, outputPIN) | delay delay := ((clkfreq / 1_000)*distance) repeat 'inifinte loop waitcnt(delay + cnt) !OUTA [noparse][[/noparse]outputPIN]
When I do that, the act method does not run.
But if i simply use
act(1,16)
, it works fine.
Any suggestions.
Comments
PUB Main set P16 to P21 as outputs for that Cog, but the Cog invoked ( PUB Act ) will have its DIRA still
as all inputs.
There is a section of the Propeller manual that shows how all the DIRA and OUTA registers are connected together to control the actual I/O circuitry.
I'm trying to light up 5 different LEDs blinking at once, by using multiple cogs (I know I can do this serially, but I'm trying to learn). Only the first (green) LED is blinking, and the other's stay off.
MAIN FILE
check
2) You cannot use the same stack for two cogs running at the same time. You have to have a stack space for each one.
3) Don't use "DIRA[noparse][[/noparse]greenOUT..orangeOUT]~~", use "DIRA[noparse][[/noparse]outputPIN]~~" as I suggested. In your case, the former will work, but it won't work as a general case. Only set the direction bits to output mode (1) for those I/O pins that you want to control from that specific cog.
Post Edited (Mike Green) : 5/13/2008 6:24:08 PM GMT
(Thanks, by the way, you've been very helpful)
MAIN FILE
check
2) It's not a good idea to use COGINIT to start a new cog. You never know whether some other object is also using the same cog, even by mistake (because of a COGNEW). It's better to use COGNEW except where you absolutely know the cog number that you want to use.
3) Try something like:
You've gone well beyond making just the changes suggested. You've jumped from a single Cog
invoked from the main program to multiple Cogs invoked in sub-objects.
If I recall right, it's not possible to launch a method in a new Cog that way, where the method
to run is in a sub-object.
You need to move the coginit into the object itself, so your coginits in the main program
would become something like ...
And you'd need to add the DoCogInit mrthod to the object, something like ...
You would be better off using cognew rather than coginit and you'd probably
also benefit from moving the stack array into the object.
So I am trying to get things working with a circular buffer. Basically, I want information about when the lights should flash to be stored in an array, and pulled up a little while later, and be used to light an LED (basically just a delay). The lights seem to flash at intervals, but not as a result of my inputs.
CON
{INPUT PINS}
greenIN =0 'Input PIN for Green PhotoDiode
redIN =1 'Input PIN for Red PhotoDiode
yellowIN =2 'Input PIN for Yellow PhotoDiode
blueIN =3 'Input PIN for Blue PhotoDiode
orangeIN =4 'Input PIN for Orange PhotoDiode
{Output PINS}
greenOUT =16 'Output PIN for Green Button
redOUT =17 'Output PIN for Red Button
yellowOUT =18 'Output PIN for Yellow Button
blueOUT =19 'Output PIN for Blue Button
orangeOUT =20 'Output PIN for Orange Button
strumOUT =21 'Output PIN for Strum Bar
VAR
{THESE LENGTHS MUST EQUAL THE VALUE OF BUFFERLENGTH BELOW}
long green ]
long red[noparse][[/noparse] 55]
long yellow[noparse][[/noparse] 55]
long blue[noparse][[/noparse] 55]
long orange[noparse][[/noparse] 55]
long default[noparse][[/noparse] 55]
PUB DoCogInit (cogNum, distance, inputPIN, outputPIN, stackPtr)
__coginit(cogNum, act(distance, inputPIN, outputPIN), stackPtr)
PUB act(distance, inputPIN, outputPIN) | delay, i, j, bufferLength, checkBack, color
{IMPORTANT}
bufferLength := (distance/10)+5
delay := (clkfreq / 100) 'sets the delay in clock cycles
checkBack:= distance/10 'sets checkBack location for color array
DIRA[noparse][[/noparse] inputPIN]~ 'Sets inputPIN to input mode
DIRA[noparse][[/noparse] outputPIN]~~ 'Sets outputPIN to output mode
color:=default
if inputPIN == greenIN
__color:=green
if inputPIN == redIN
__color:=red
if inputPIN == yellowIN
__color:=yellow
if inputPIN == blueIN
__color:=blue
if inputPIN == orangeIN
__color:=orange
i:=0 'Initializes i to 0 for repeat loop
j:=0 'Initializes j to 0 for repeat loop
repeat while i<bufferLength 'Repeat for the circular buffer
__if INA[noparse][[/noparse] inputPIN] == 1 'if the pin is active...
____color[noparse][[/noparse] i] := 1 'set value to 1 in array
__else
_____color[noparse][[/noparse] i ] := 0
__if (i - checkBack) < 0 'if distance back loops...
_____j:=(i - checkBack) + (bufferLength - 1) 'loop the value to find j
__else 'else...
_____j:=i-checkBack 'otherwise, set j normally
__if color[noparse][[/noparse] j] == 1 'if j was on...
_____OUTA[noparse][[/noparse] outputPIN]~~ 'press the button
__color[noparse][[/noparse] j] := 0
__i++ 'increment i
__if i==bufferLength 'if end of circular buffer is reached...
_____i:=0 'reset i to initial array value
__waitcnt(cnt+delay) 'waits necessary time
__OUTA[noparse][[/noparse] outputPIN]~ 'releases button
Post Edited (sciguy) : 5/15/2008 7:27:24 PM GMT
1) Simplify this to a single cog and a single pin as best you can so it still illustrates the problem
2) Document better what you're trying to do, preferably with comments in the source.
3) Attach the source file to your message or use the [noparse][[/noparse] code ] [noparse][[/noparse] /code ] tags to maintain formatting.
Keep in mind that some subscripts like some single letters and digits are gobbled by the forum software.
4) Your main method just initiates the second cog without doing anything further. In that case, you
don't really need to have a separate cog since the first cog terminates itself.