Unexpected PIC reset (probably when byte variable overflows)


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2003
    Posts
    2,405

    Default Re: Unexpected PIC reset (probably when byte variable overflows)

    It sounds to me like PBP does not reset WDT for all instances. I.E. if you have only a simple loop, incrementing or decrementing a variable, with no PBP commands in the loop, you have a WDT reset.

    PBP will reset WDT in most command routines, but with something so simple, without any PBP library routines invoked, it may not be resetting WDT!

    And - why the heck did this reply end up as the 1st post magically? It was posted after post #6?
    Last edited by Bruce; - 2nd September 2011 at 21:36.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Unexpected PIC reset (probably when byte variable overflows)

    Hi,
    I've got a problem I can't seem to wrap my head around...
    The PIC I'm using is a 18F4520 and when I discovered the problem I was compiling with 2.6A but have now switched to 3.0.1.4

    Running the following code:
    Code:
    DEFINE OSC 8
     
    #CONFIG
        CONFIG OSC = HS
        CONFIG FCMEN = OFF
        CONFIG IESO = OFF
        CONFIG PWRT = ON
        CONFIG BOREN = OFF
        CONFIG WDT = ON
        CONFIG WDTPS = 512
        CONFIG CCP2MX = PORTC
        CONFIG PBADEN = OFF
        CONFIG LPT1OSC = OFF
        CONFIG STVREN = OFF   
        CONFIG MCLRE = ON
        CONFIG LVP = OFF
        CONFIG XINST = OFF
        CONFIG DEBUG = OFF
    #ENDCONFIG
     
    i VAR BYTE
     
    High PortD.0 : Pause 500 : Low PortD.0
    i = 0
     
    Main:
      i = i + 1
      PauseUs 20
    Goto Main
    Everything works as expected, and with everything I mean nothing happens really. PortD.0 pulses on startup and then it sits there doing "nothing" (I've waited for ~5 minutes, you'll understand why soon.)

    However, if I reduce the PauseUS to 10 or remove it completely the program restarts (PortD.0 pulses) roughly 22 times per second. (I know PauseUs 10 is border line on the specified miniumu of 9 for a 18F chip at 8Mhz) but why does it restart? And why does it restart if I remove it all together?

    This works:
    Code:
    Main:
    i = i + 1
    If I = 255 Then i = 0
    Goto Main
    While this restarts the PIC once every 3rd second:
    Code:
    Main:
    i = i + 1
    Goto Main
    The variable i is declared as a BYTE as can be seen above. It "feels" like it has something to do with i overflowing but why and why does it matter if I pause 20us?

    What am I doing wrong here? 18F4520, PBP 3.0.1.4, MPLAB 8.73a/MPASM 5.42, compiling for the correct chip from MCSP 5.0.0.0.

    Thanks!
    /Henrik.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: Unexpected PIC reset (probably when byte variable overflows)

    Damn edit "window" timed out allready....anyway...
    This too works, no restart:
    Code:
    Main:
    For i = 0 to 255
    NEXT
    Pause 1
    Goto Main
    While this doesn't
    Code:
    Main:
    For i = 0 to 255
    NEXT
    Goto Main
    However, this works:
    Code:
    Main:
    For i = 0 to 254
    NEXT
    Goto Main
    /Henrik.

  4. #4
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: Unexpected PIC reset (probably when byte variable overflows)

    MPASM 8.73 have some bug's, try 8.76...

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default Re: Unexpected PIC reset (probably when byte variable overflows)

    What happens if you change CONFIG WDT = ON to CONFIG WDT = OFF?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: Unexpected PIC reset (probably when byte variable overflows)

    Turning off the watchdog makes it work so that's what's resetting it for sure...

    The original code, where I notices it is like this:
    Code:
    Main:
      i = i + 1
      Gosub GetValue
      PortB = Out
    Goto Main
    Then the subroutine GetValue is a lookuptable with 255 entries returning the value in Out. It too restarts when the dog is unleashed. However, if I add IF i = 255 then i = 0 at the end it works. I then tried to boil that down to the minimum, which is what I posted above.

    So, is this an oversight on my behalf or an unwated side effect of a "tight" (it's not THAT tight) program?

    In any case, thanks Bruce!
    /Henrik.

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: Unexpected PIC reset (probably when byte variable overflows)

    How your lookup table looks like?

    I could be wrong but probably the generated asm for the IF/THEN have some CLRWDT while the lookup don't?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts