Cognew Freezes code, help?
Jermcb
Posts: 8
Hi Everyone,
I have decided to re-create the old 'snake' game using the parallax propeller chip. I have written the logic for the motion of the snake and the the output display for a TV screen. This all works nicely until I try and automatically update the position of the snake in a separate cog. As soon as I declare a new cog the code freezes.
So I have stripped down the code to the following basic lines and it still freezes. I cannot figure out why?
Main code:
Tester File:
If I comment out the "Snake.start" line in the main function then I can see the TV visibly updating the screen. But if I don't the code freeze's at that line!
Can anyone tell me why??
Thank you,
I have decided to re-create the old 'snake' game using the parallax propeller chip. I have written the logic for the motion of the snake and the the output display for a TV screen. This all works nicely until I try and automatically update the position of the snake in a separate cog. As soon as I declare a new cog the code freezes.
So I have stripped down the code to the following basic lines and it still freezes. I cannot figure out why?
Main code:
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 '''''''' TV Dimensions ''''''''''' Frame_Width = 2 Frame_y_top = -Frame_Width Frame_y_bottom = -207 Frame_x_right = 254 Frame_x_left = Frame_Width-1 '''''''' TV Dimensions ''''''''''' Num_Values_In_Snake = 100 VAR long Snake_x_vals[Num_Values_In_Snake] 'X-Coords long Snake_y_vals[Num_Values_In_Snake] 'Y-Coords long counter 'Generic Counter OBJ TV : "tv_terminal_graphics" Snake : "TesterFile" PUB main TV.start(12) DrawFrame CreateInitialSnake Plot_Snake Snake.start repeat DrawFrame TV.color(2) Plot_Snake ''''''''''''''''''''''''''''''''''''''''''''''''''''''' PUB CreateInitialSnake counter := 0 repeat 10 Snake_x_vals[counter] := 100 + counter Snake_y_vals[counter] := -103 counter := counter + 1 PUB DrawFrame 'Drawing Frame TV.Set_Clear TV.color(1) TV.Make_box(Frame_x_left, Frame_y_top, Frame_x_right, Frame_y_bottom, Frame_Width) PUB Plot_Snake counter :=0 repeat Num_Values_In_Snake TV.plot(Snake_x_vals[counter], Snake_y_vals[counter]) counter := counter + 1
Tester File:
VAR long Cog 'Cog Number long Stack[48] 'StackMemory long Counter 'Random Counter PUB start Counter := 0 Cog := cognew((MoveSnake), @Stack) +1 PUB Stop if Cog cogstop(Cog~ - 1) PRI MoveSnake repeat Counter := Counter + 1
If I comment out the "Snake.start" line in the main function then I can see the TV visibly updating the screen. But if I don't the code freeze's at that line!
Can anyone tell me why??
Thank you,
Comments
How are you going to tell if it's running? You might put in another PUB method like this:
cognew((MoveSnake), @Stack)
I'm not sure if I remember that right ... but you could give it a try. And it would make sense! The propeller tries to execute the function and pass the return value to cognew. But MoveSnake is an endless loop - never comeing back.
I removed the brackets, and it works now!