Shop OBEX P1 Docs P2 Docs Learn Events
Need help with Cogs — Parallax Forums

Need help with Cogs

SmadhdkSmadhdk Posts: 4
edited 2010-12-13 19:03 in Propeller 1
Guys I need some help here..

When a command comes accross cog1 , and fires the runspeaker and the speaker does do what it is suppose to then the boxes quits operating correctly. I cant figure out whats happening. If I do not run the speaker command then everything continues to operate fine. What seems to be happening is the box quits responding. Can anyone see something that I am not?
pri XbeeReader
  repeat
   XB.API_Rx
      case XB.RxIdent
        $81:
            IF(strcomp(XB.RxData,string("1")))
               'This Fires makes sound then System seems to go ofline.
               RunSpeaker      
            IF(strcomp(XB.RxData,string("2")))
               Identify
               BeamOffLine
            IF(strcomp(XB.RxData,string("3")))
               RespondImHere
            IF(strcomp(XB.RxData,string("9")))
               Hot := true
               RespondOnline
            IF(strcomp(XB.RxData,string("0")))
               Hot:= false
               RespondOffLine

Comments

  • LeonLeon Posts: 7,620
    edited 2010-12-13 06:14
    Using Code and /Code would make your post more readable.
  • SmadhdkSmadhdk Posts: 4
    edited 2010-12-13 06:42
    thanks for the reply.
    I How about that.. :D
  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-12-13 06:47
    Never mind, I see you just fixed it.
  • kwinnkwinn Posts: 8,697
    edited 2010-12-13 06:54
    Smadhdk, took a quick look and could not see any obvious errors in the code. I do have a question about the "Parallax Serial Terminal" object though. As far as I know that is a terminal program that runs on the PC and is used for communications with the prop. Is this something you wrote or renamed?

    I would suggest using PST for debugging and insert a line at the beginning of the “XbeeReader” routine to display the value of “XB.RxData”. Keep in mind that XB.RxData must also be a string (an ascii 1 followed by a binary 0).
  • SmadhdkSmadhdk Posts: 4
    edited 2010-12-13 07:26
    Parallax Serial Terminal is coded out. I was using it for debug.

    The issue that i am seeing is that the case runs correctly , and the Runspeaker runs and completes. After that it seems that the box will not transmit again until I reset the box.

    If I understand it correctly:

    now the Main Sub runs in Cog0
    then the XbeeReader runs in Cog1

    is there some state that is happening to the Cogs that i need to reset after the runspeaker completes?
     case XB.RxIdent
            $81:
                IF(strcomp(XB.RxData,string("1")))
                   'This Fires makes sound then System seems to go ofline.
                   RunSpeaker      
                IF(strcomp(XB.RxData,string("2")))
                   Identify
                   BeamOffLine
                IF(strcomp(XB.RxData,string("3")))
                   RespondImHere
                IF(strcomp(XB.RxData,string("9")))
                   Hot := true
                   RespondOnline
                IF(strcomp(XB.RxData,string("0")))
                   Hot:= false
                   RespondOffLine
     
    


    In the above statement, String 2, 3, and 9, work correctly. string 1 and 0 do not. Could that be because im using 1 and 0 there and it is getting confused somehow? I might need to check that.
  • kwinnkwinn Posts: 8,697
    edited 2010-12-13 07:47
    It is possible that you are comparing the binary values "0" and "1" (hex 00 and 01) to the ascii characters "0" and "1" (hex 30 and 31). An easy mistake to make. Use PST to send the hex values of the character received and the terminating 0 that should follow it. Also try putting a "RunSpeaker" statement at the beginning of the routine to verify it is running.
  • kwinnkwinn Posts: 8,697
    edited 2010-12-13 08:08
    PS, it is a good idea to post your code as an archive so all the objects you are using are included. I can not find "XBee_Object_1" in the obex, and it may be the problem is there.
  • SmadhdkSmadhdk Posts: 4
    edited 2010-12-13 08:25
    Sorry. There you go.
    pri XbeeReader
    repeat
     
        XB.API_Rx
        'logstr(XB.RxData)    
         case XB.RxIdent
          $81:
            IF(strcomp(XB.RxData,string("4")))
                RunSpeaker
                Hot := true    'Added this
                RespondOnline    'added this
            IF(strcomp(XB.RxData,string("2")))
                 Identify
                 BeamOffLine
            IF(strcomp(XB.RxData,string("3")))
                 RespondImHere
            IF(strcomp(XB.RxData,string("9")))
                 Hot := true
                 RespondOnline
            IF(strcomp(XB.RxData,string("5")))
                 Hot:= false
                 RespondOffLine 
     
    


    I added the 2 above lines and that function started working. Im currious. Is there something to do with the VAR being shared between 2 cogs?? Cog0 is My spin and Cog1 which runs the XbeeReader is another spin. Xbee_Object_1. Just a guess, but is there something special that I should do there to make that Var more available between the 2 cogs? it honestly is acting like its hit and miss on reading and writing it, kind of like they are not insync between the 2 cogs?
  • kwinnkwinn Posts: 8,697
    edited 2010-12-13 08:52
    Xbee_Object_1 only starts another cog to run a second copy of FullDuplexSerial. The rest of it is spin code that runs in the first cog. I would suggest commenting out the 2 lines you added and doing what I suggested in post 7 as a start. Once you have determined if it is a problem with the RunSpeaker or the case statement you can proceed from there.
  • kuronekokuroneko Posts: 3,623
    edited 2010-12-13 19:03
    VAR
      long  XbeeReaderStack[6]
    
    This stack size is way too small (it just about covers an empty method). Start with something bigger like 32 and go down from there. You could also check your stack usage with the Stack Length object (propeller tool library). With a fake XBee object and hard-wired methods I needed 18 longs already to get to the RunSpeaker method.

    As the SPIN stack grows towards higher addresses and this stack array being the last long entry you basically clobber your word/byte variables.
Sign In or Register to comment.