Cog registers?
heathclf
Posts: 43
In the past, I've had trouble opening new cogs, due to missing the fact that each have their own registers. I have fixed the previous problems by declaring my registers in methods that have been launched into new cogs, but I don't see how that's exactly the problem. I imagine it's something similar, as the function I want to run in a new cog doesn't work correctly, but works when I run it in the same cog; but this puts me in an infinite loop.
Thanks in advance guys.
Thanks in advance guys.
CON _xinfreq = 5_000_000 _clkmode = xtal1 + pll16x SERVO_Pin_Right = 29 SERVO_Pin_Left = 26 'Pinger PING_Pin = 28 'LCD LCD_Pin = 27 ' I/O Pin For LCD LCD_Baud = 19_200 ' LCD Baud Rate LCD_Lines = 4 'Compass Stuff Enable = 0 Clock = 1 Data = 2 TotTime = 20000*80 'Control Coefficients VAR byte i,j, stack1[noparse][[/noparse]100], stack2[noparse][[/noparse]100] long HTa, range[noparse][[/noparse]10], rangeAve, HT, LT, Hold, theta, K, thetaGoal OBJ LCD : "debug_lcd" ping : "ping" HM55B :"HM55B Compass Module Asm" PUB main | CntNow InitializeLCD 'FindAngle 'This will make it work, but I'm in an infinite Loop cognew(FindAngle, @stack1) ' This opens a new cog, so I'm not stuck in a loop, but my text doesn't show up PUB FindAngle 'The idea is to have a dedicated cog, just running this in an infinite loop, changing where the variable can be accessed by all HM55B.start(Enable,Clock,Data) repeat theta := HM55B.theta LCD.gotoxy(14, 2) 'Copied print lines LCD.decf(theta / 23, 3) ' waitcnt(clkfreq / 20 + cnt) PUB Print_Angle 'This function also does not work at all, when called, LCD.gotoxy(14, 2) 'I have to copy these two lines to the above method LCD.decf(theta / 23, 3) PUB InitializeLCD LCD.init(LCD_Pin, LCD_Baud, LCD_Lines) LCD.backlight(false) LCD.cursor(0) LCD.cls LCD.gotoxy(0, 0) LCD.str(string("HighTime : ")) LCD.gotoxy(0, 1) LCD.str(string("Range(in): ")) LCD.gotoxy(0, 2) LCD.str(string("Angle(theta): "))
Comments
-Phil
Here's all but the ASM code from the HM55B, which is called:
Any help would be appreciated. I'm at a loss.
Thanks, and keep 'em coming.
I don't think this would cause any problems, just the wrong or rather unexpected returned value... Remember that the angle returned in the theta value is in a 13-bit format which means that the returned value ranges from 0 to 8191 rather than the 0 to 359 that most people would expect.
0 Deg = 0
90 Deg = 2047
180 Deg = 4095
270 Deg = 6143
To convert the theta value to Deg, simply apply the formula...
Deg = theta * 45 / 1024
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 1/13/2009 3:52:54 AM GMT
Where 45 / 1024 ~ 22.7. So when I do get a number back, it's correct, I just don't get anything back when running it in it's own cog. The variable is defined in my VAR block, and so I'm fairly sure that each method and each cog sure have access to read from it. Is it possible that the new cog can't write to it for some reason? See what you think. I'll do some more work on it tomorrow afternoon. Thanks, again.
Also.... I am a little confused as to why you are using the HM55B.start every time that you call FindAngle. The HM55B.start should only be initialized once. Successive starts within FindAngle only starts up a new cog without closing the previous one. This could be your problem.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Can you use the ... "File-->Archive-->Project" and attach that file to your post so that I can look at it tomorrow when I'm at my desk? I think I know what is going on but I need the entire program to confirm my thoughts.
Never mind.. I think I have enough of your code. I will look at it closer and let you know.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 1/13/2009 4:45:41 AM GMT
Just for kicks, can you try this to see if anything prints to your LCD?
LCD.decf(4096 / 23, 3)
and then try....
LCD.decf(178, 3)
....and last but not least....
temp := 4096 / 23
LCD.decf(temp, 3)
... I have seen issues sometimes when you try to solve a formula inside of a CALL to another object. I just want to make sure that this is not happening here.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
But they still yield nothing when I try to run it through a new cog.
Post Edited (heathclf) : 1/13/2009 5:37:35 AM GMT
Um...yes. You're the man. Why did it? I'm confused. Will I have to run that script within each cog that I will want to write to the LCD?
"...Why did it?..." - for the same reason you have HM55B.start(Enable,Clock,Data) at the top of FindAngle... good job Pavel
When you start a new cog with the line that reads cognew(FindAngle,·@stack1)· you are in a sense encapsulating everything within FindAngle to operate in it's own cog.· Since the LCD initialization portion was not included, you lost connectivity to the LCD that was defined previously defined·in the other cog.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.