Shop OBEX P1 Docs P2 Docs Learn Events
Unexplained Propeller Hang Up — Parallax Forums

Unexplained Propeller Hang Up

Juliet Oscar EchoJuliet Oscar Echo Posts: 31
edited 2015-03-04 12:33 in Propeller 1
Propeller Community,

I have an issue with my code that causes the propeller to hang up randomly. I have been searching for the bug in my code on and off for over a year now and still haven't been able to find it. It has a very unique signature:

It will sometimes run perfectly for over 24 hours before crashing. Sometimes, though, it only runs for a few hours before crashing.

From what I understand, it is very rare to have an issue in your code that takes so long to cause a hang up. The main routine executes about once / minute.

Has anyone ever experienced a similar issue with their code? If so, where was the gremlin hiding? For now I have a cog dedicated as a watchdog, but I would rather find the culprit than patch it with an extra watchdog cog.

Thanks,

JOE

Comments

  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2015-03-04 07:44
    Propeller Community,

    I have an issue with my code that causes the propeller to hang up randomly. I have been searching for the bug in my code on and off for over a year now and still haven't been able to find it. It has a very unique signature:

    It will sometimes run perfectly for over 24 hours before crashing. Sometimes, though, it only runs for a few hours before crashing.

    From what I understand, it is very rare to have an issue in your code that takes so long to cause a hang up. The main routine executes about once / minute.

    Has anyone ever experienced a similar issue with their code? If so, where was the gremlin hiding? For now I have a cog dedicated as a watchdog, but I would rather find the culprit than patch it with an extra watchdog cog.

    Thanks,

    JOE

    I'm gazing into my crystal ball.....I'm concentrating....trying hard to imagine what your code might look like.....nope, give up..........can't see what your code is so I can't comment.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2015-03-04 07:46
    "Houston, ummm.... we have a problem here. Houston! Are you there Houston?"
  • Juliet Oscar EchoJuliet Oscar Echo Posts: 31
    edited 2015-03-04 08:07
    You guys are cracking me up. I'll try and get the code posted soon.
  • Mike GreenMike Green Posts: 23,101
    edited 2015-03-04 08:33
    Let's see ... things that seem to run ok for possibly long periods of time, then don't ...
    1) stack overflow
    2) array access out of bounds
    3) timing dependencies
  • David BDavid B Posts: 592
    edited 2015-03-04 08:36
    Last weekend I had a couple of the soldered connector tabs on the usb connector on a quickstart board come loose.

    I was powering the board over usb, so the program would run reliably for minutes at a time, then it would reset for no apparent reason.

    So keep an open mind; problems aren't always caused by code.
  • Juliet Oscar EchoJuliet Oscar Echo Posts: 31
    edited 2015-03-04 09:21
    David,

    I appreciate your insight. One of my first Propeller projects had me trying to write an auto pilot for my model airplane. For over a week I tried to find a random bug that turned out to be brownouts caused by too much load on one of the servos. All it took was a more robust power supply and the problem was solved.
  • Juliet Oscar EchoJuliet Oscar Echo Posts: 31
    edited 2015-03-04 09:23
    Let's try this again with dashes instead of spaces

    APRS_Tracker.spin
    APRS_Packet_Generator_V35.spin
    Bell202_Modem_Mod.spin
    umath.spin
    GPS_Light_V1.spin
    GPS_Str_NMEA_Heavy_V1.spin
    FloatMath.spin
    FullDuplexSerial.spin
    MS5607.spin
  • PublisonPublison Posts: 12,366
    edited 2015-03-04 09:29
    It would be best if you used the FILE>ARCHIVE in the Propeller Tool to create one ZIP with all the files.

    (Don't include the Propeller Tool"
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-03-04 09:53
    Your "Main" method calls itself. Spin doesn't handle recursive methods well. You may be (probably are) running out of stack space for cog #0.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-03-04 09:57
    If you change the end of your "Start" method to:
      repeat
        Main
    

    And remove the call to "Main" from the end of "Main", your code should behave much better.

    Alternatively, you could make "Main" an endless loop with a repeat at the beginning of the method and no call to "Main" at the end.
    PUB Main''-----------------------------------------------------------------------------------
      repeat
      'Transmitts position, temperatre, and pressure once every minute.
       
        Get_GPS_Data                                      
       
      'Get Sensor Data
        MS5607.Read
        MS_degC := MS5607.Temperature/10                        
        MS_Pa   := MS5607.Pressure
       
      'Transmit
        Transmit_Data
        Sigma := Sigma + 1
       
        Display_Data                  'For debug only. Comment out otherwise.
       
        wait(60)
    
  • Juliet Oscar EchoJuliet Oscar Echo Posts: 31
    edited 2015-03-04 10:01
    Duane,

    I appreciate your advice. I never knew Spin had an issue with recursive methods.

    Unfortunately, I have also run versions of the code where I used a repeat loop in the main method and still had the random hang up anywhere from a couple of hours to over a day later.
  • Heater.Heater. Posts: 21,230
    edited 2015-03-04 10:08
    Pretty much all languages you meet will have problems with run away recursion if you do something like that.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-03-04 10:18
    Duane,

    I appreciate your advice. I never knew Spin had an issue with recursive methods.

    Unfortunately, I have also run versions of the code where I used a repeat loop in the main method and still had the random hang up anywhere from a couple of hours to over a day later.

    Again, we would need to see the code to identify the trouble. The recursive method was certainly a problem in the code you posted.

    If the code still hangs with the changes I suggested, let us know.

    If you have a version of the code which you think already has this change, then it would help if you posted the other version.
  • Juliet Oscar EchoJuliet Oscar Echo Posts: 31
    edited 2015-03-04 10:35
    Thanks for your help Duane.

    Attached is a version of my code without the recursive method issue.

    To reiterate what I said earlier, my code hangs when I integrate APRS_Packet_Generator_V35.spin with Bell202_Modem_Mod.spin into my project. I believe the issue is most likely in APRS_Packet_Generator_V35.spin (maybe in Bell202_Modem_Mod.spin).

    Thanks again to everyone who is helping me with this problem.
  • ksltdksltd Posts: 163
    edited 2015-03-04 10:51
    Duane & Heated,

    What do you mean when you say "Spin doesn't handle recursion well" and "all languages have problems with recursion"?

    I don't know of any stack oriented language problems associated with recursion. Recursion certainly works just fine with the Spin compliler.

    However, recursion requires stack space, but that's not a language problem ...
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-03-04 10:56
    ksltd wrote: »
    Duane & Heated,

    What do you mean when you say "Spin doesn't handle recursion well" and "all languages have problems with recursion"?

    I don't know of any stack oriented language problems associated with recursion. Recursion certainly works just fine with the Spin compliler.

    However, recursion requires stack space, but that's not a language problem ...

    Agreed.

    I think Heater said it better than I with the qualifier "run away".

    It's not a problem with Spin. It's a problem with the structure of the program.

    I spoke imprecisely. Thanks for the correction.
  • ksltdksltd Posts: 163
    edited 2015-03-04 11:20
    The code in both your NMEA parser and your Packet Generator are written in such a way that it's not possible to tell how they ever work, never mind whether they might ever fail.

    NMEA devices are notorious for not matching the NMEA specification, which is notoriously lax. The way you're parsing sentences relies on pretty compliant devices. There's no error check to be sure your assumptions are being met. Your parser does check checksums if they're present, but it's not clear that your NMEA device includes checksums, which are optional.

    Your packet generator has a hard coded limit of 150 bytes, but there's no checking to ensure you don't exceed that limit.

    Without understanding much about the application, its just not written in such a manner that staring at the code is likely to turn up anything. I'd strongly suggest you do the following:

    Fill all unallocated memory with a constant pattern and check all that memory in your main loop where you wait. Similarly put a guard after the Packet in your packet generator and check that on each return. Try to figure out a similar strategy for your parser.

    From a coding perspective, you should change "pub" to "pri" everywhere you can without getting compiler errors. As it stands, it's really impossible to understand what's calling what.
  • Juliet Oscar EchoJuliet Oscar Echo Posts: 31
    edited 2015-03-04 11:43
    Thanks for the great suggestions ksltd.

    I think I'll but the NMEA parser on the back burner for now and focus on the Packet Generator as I have implemented my current NMEA parser in may projects without any problems... so far.

    As for the 150 byte hard coded limit, it's significantly higher than any packet I've ever had to transmit. However, it may be possible that it doesn't start at 0 on each itteration. I haven't been able to prove this though.

    As for your two suggestions on filling up all unallocated memory and placing a guard after the Packet in the packet generator, they both sound like great ideas. Is there any chance you have some example code to get me started?

    Thanks
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-03-04 12:01
    As for your two suggestions on filling up all unallocated memory and placing a guard after the Packet in the packet generator, they both sound like great ideas. Is there any chance you have some example code to get me started?

    I posted some code here which does this with stack space. The program dumps the area being used as stack space to the terminal each loop. It also counts up the unchanged memory. If you don't get a better suggestion, you might want to modify the code to monitor your the "unallocated memory".

    I guess you'd find the address of the unallocated memory by using F8?

    If you're monitoring a large chunk of memory, you probably don't want to dump it all to the terminal. You could just keep track of how much memory remains unchanged.

    Some of the unallocated memory will be used as the stack for cog #0 but I'm not sure how this works.
  • ksltdksltd Posts: 163
    edited 2015-03-04 12:33
    All unallocated memory is stack space for the main program.

    My recommendation would be to simply declare a very large array of longs - big enough that memory is nearly full ... and use that array to fill "unused" memory.
Sign In or Register to comment.