+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2019
    Posts
    1

    Default Watchdog timer not working as expected

    Hello
    I've got a problem on a PIC18F65J11 using PICBasic PRO 3.1 with the watchdog timer.

    I am testing some software but after a few hours of running it hangs up. The watchdog timer is enabled and I would assume that a WDT reset restarts the system.
    In order to test the proper function of the watchdog I wrote a little software that lights up LED1 on startup and then in the main loop flashes LED2. With the watchdog in the configuration bits enabled, the 'define NO_CLRWDT 1' and a 'clearWDT' instruction in the main loop the program runs fine. Then I remove the 'clearWDT' instruction in the software and run the program again. At startup LED1 ligths up and LED2 flashes for some time until the WDT runs into a timeout. Now I would have expected that a reset restarts the software and LED1 lights up and then LED2 flashes and so on. But there seems to be no restart. Somewhere the system hangs. To make sure that the reset vector is correct I added the 'RESET_ORG 0h' define at the start.

    To check to proper hardware function of the WDT I've written the same software in C, compiled it with XC8 and it works as expected: after the WDT runs into the timeout a reset starts the program again.

    Here is the software:

    The configuration bytes are:
    0000- f4a1 f904 f0f8

    Code:
    DEFINE OSC 8
    define RESET_ORG 0h
    define NO_CLRWDT    1
    
    DEFINE DEBUG_REG PORTD
    DEFINE DEBUG_BIT 5
    DEFINE DEBUG_BAUD 2400
    DEFINE DEBUG_MODE 1
    
    
      Clear 'Alle Variabeln löschen
      OSCCON=110000   'Set to 8 MHz
    
      Low PortD.6        ' LED2
      low PortD.7        ' LED1
      low PortB.2
    
      'Init Interrupts
      PIR1  =000000 'clear all Interrupt flags
      PIE1  =000000 'turn on USART Receive '+ P1_AD Interrupt  'V174
      INTCON=000000 'turn on Global Interrupts and Periph Interrupts
      INTCON2=000000 'PORT B Pullup disabled
      SSPCON1.5=0 'Disable SSP
     
    PortD.7 = 1
    Pause 1000
    PortD.7 = 0
    
    MainLoop :
    
        PortD.6 = 1
        Pause 100
        PortD.6 = 0
        pause 100 
    
    GoTo Mainloop
    Rigth now I am at loss as to what could be wrong. Any help would be appreciated.

    Regards
    WaaxNOX

  2. #2

    Default Re: Watchdog timer not working as expected

    I think define should be UPPER CASE.

  3. #3
    Join Date
    Aug 2003
    Location
    Australia
    Posts
    1,056

    Default Re: Watchdog timer not working as expected

    If you haven’t tied your MCLR pin high or disabled it, you could get an MCLR reset any time.
    Same with a brownout reset. I haven’t checked this hex configuration values you gave (nobody is going to decode that to English).

    There’s an RCON register which should contain a value for the cause of the last reset. It would usually be a power on reset,
    but after being reset by watchdog, would contain a different value. Of course your program has to run to be able to read and pulse out a value to read through LEDs.
    It will have a normal value for an ordinary power up reset, so you really only have to check that it’s different and flash a red LED meaning it was a watchdog reset.

  4. #4

    Default Re: Watchdog timer not working as expected

    From the PB3 manual

    2.15 Case Sensitivity
    PBP is not case sensitive, but Assembly Language is. This means that there are
    situations where case matters

    2.15.1 DEFINEs
    Since many of the DEFINEs in PBP pass data directly to the assembler, they
    should be considered case-sensitive. All defined parameters should be written in
    upper-case:
    DEFINE OSC 20 ' Correct
    DEFINE osc 20 ' Incorrect, and will not
    generate an error message


    your code
    define RESET_ORG 0h
    define NO_CLRWDT 1

    should be

    DEFINE RESET_ORG 0h
    DEFINE NO_CLRWDT 1

    try it and see if that was the problem.
    Last edited by aerostar; - 19th July 2019 at 06:33.

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,258

    Default Re: Watchdog timer not working as expected

    your code
    define RESET_ORG 0h
    define NO_CLRWDT 1

    should be

    DEFINE RESET_ORG 0h
    DEFINE NO_CLRWDT 1
    This is not correct. The original code is fine.

    The keyword DEFINE is a PBP keyword so it's NOT case sensitive, can be define, DEFINE, DeFiNE, DEFine, however you want to write it. The thing that comes AFTER the DEFINE keyword is passed to the assembler and the assembler IS case sensitve so RESET_ORG is not the same thing as reset_org.

    /Henrik.

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,541

    Default Re: Watchdog timer not working as expected

    Hi, Henrik

    straight from the Holy Manual $2.1 ...

    ' DEFINEs: See section 2.2 for more information.
    DEFINE OSC 20 ' Tell PBP the expected system-clock frequency
    2.3.3 DEFINEs defined
    For the user familiar with Assembly Language, the major clue to understanding is that DEFINEs in PBP are converted literally to Assembly Language #DEFINE directives.
    For the practical PBP user, there are a couple of fundamental points to consider:
    1) DEFINEs are CASE SENSITIVE!
    2) Specific DEFINEs are generally associated with PBP commands. The command pages will describe how the relevant DEFINEs affect the operation of each command.
    Alain
    Last edited by Acetronics2; - 19th July 2019 at 14:12.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    1,714

    Default Re: Watchdog timer not working as expected

    fwit henrik is 100% correct ,keywords are not case sensitive
    myths and fables abound ,i'm sick of even trying to correct them

  8. #8
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,258

    Default Re: Watchdog timer not working as expected

    Yeah, it's been covered on the forum many times over the years but it keeps coming back.
    It is NOT the keyword DEFINE that's case sensitive but what you're actually DEFINEing, ie RESET_ORG, NO_CLRWDT, OSC etc.

    Code:
    define OSC 20
    DEFINE OSC 20
    DeFIne OSC 20
    DEFine OSC 20
    These will all work because OSC (all upper case) is the assembly constant getting assigned the value of 20. If you use osc (which is not the same as OSC as far as the assembler sees it) it won't get the inteneded effect.

    They could have called it osc (or OsC or whatever) in which case you would have to match THAT case so it's not automatically all upper case - it just happens to be what the PBP developers decided to use.

    Prove me wrong and I'll crawl back under my stone :-)

    /Henrik.

Similar Threads

  1. Replies: 61
    Last Post: - 28th March 2019, 04:41
  2. PORTB.3 Input not working as expected.
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th March 2013, 09:58
  3. watchdog timer
    By amindzo in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 27th May 2011, 13:55
  4. I2CRead & I2CWrite not working as expected
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 4
    Last Post: - 14th April 2007, 17:37
  5. Watchdog Timer
    By barkerben in forum General
    Replies: 3
    Last Post: - 25th January 2005, 00:06

Members who have read this thread : 17

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