Strange problem with an 18F4580 based project


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Darrel, just checked the hardware file and these are the settings

    Code:
    ASM 
      __CONFIG    _CONFIG1H, _OSC_HSPLL_1H
      __CONFIG    _CONFIG2L, _PWRT_ON_2L  
      __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
      __CONFIG    _CONFIG3H, _PBADEN_OFF_3H
      __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    ENDASM
    If I read that then the WDT is running, and as I've not inserted DEFINE NO_CLRWDT 1 into the code then I assume that PBP has automatically inserted the resets through the code automatically. However on checking the corresponding asm file there are just the following references to CLRWDT in that file (towards the beginning)

    Code:
    ;---[Add an Interrupt Source to the user's list of INT Handlers]--------------
    INT_Handler  macro  IntFlagReg, IntFlagBit, Label, Type, Reset
      list
        local AfterSave, AfterUser, NoInt
    INT_Count += 1
    PrList#v(INT_Count)R = IntFlagReg
    PrList#v(INT_Count)B = IntFlagBit
    PrList#v(INT_Count)Priority = Priority
            GetIntInfo   IntFlagReg, IntFlagBit
            if (Found == YES)
                btfss    INT_Enable_Reg, INT_Enable_Bit, 0  ; if INT is enabled
                goto   NoInt
                btfss    INT_Flag_Reg, INT_Flag_Bit, 0      ; and the Flag set?
                goto     NoInt
                if (Priority == H)
                    bsf      _Serviced_H, 0
                else
                    bsf      _Serviced_L, 0
                endif
                ifdef NO_CLRWDT
                    if  (NO_CLRWDT != 1)
                        CLRWDT
                    endif
                else
                    CLRWDT
                endif
                    
                if (Type == PBP)                         ; If INT handler is PBP
                  if (Priority == H)
                    ifdef ReEnterHPused
                        GetAddress21  AfterSave, RetAddrH  
                        L?GOTO  _SavePBP_H        ; Save PBP system Vars in HP INT
                    else
        error "ReEnterPBP-18 must be INCLUDEd to use High Priority PBP interrupts"
                    endif
                  else ; Priority = L
                    ifdef ReEnterLPused
                        GetAddress21  AfterSave, RetAddrL  
                        L?GOTO  _SavePBP_L        ; Save PBP system Vars in LP INT
                    else
       error "ReEnterPBP-18LP must be INCLUDEd to use Low Priority PBP interrupts"
                    endif
                  endif
                endif

    I've searched for info on using the watchdog timer and came across Mel's post in 2003 ??? which helps explain how PBP uses the timer... but still a bit confused given the complexity of our code

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    To see where the CLRWDT instructions are inserted, you would have to look at the .LST file because they are part of the library, not the generated .ASM code.

    The one's you found are part of DT_INTS, and as you can see they also respond to the NO_CLRWDT define.

    The base period of the WDT on a 4580 is 4ms, and with a postscaler of 512 it will timeout after about 2 seconds.

    Your main loop will take less than 2 seconds each time so a single CLEARWDT statement at the end of the loop just before GOTO Main should suffice, although it may be advantageous to put it in the area where it updates the heater drives just to be sure that is getting accomplished. But then if you turn off power to all 4 channels, you'll have to clear it somewhere else or it will reset every 2 seconds. You may just have to play with it and see what works best.
    Code:
                IF ChannelPWR(pid_Channel) THEN
                    HeaterDrives(pid_Channel) = pid_Out
                    CLEARWDT
                ELSE
                    HeaterDrives(pid_Channel) = 0
                ENDIF
    HTH,
    DT

  3. #3
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post

    The base period of the WDT on a 4580 is 4ms, and with a postscaler of 512 it will timeout after about 2 seconds.

    Your main loop will take less than 2 seconds each time so a single CLEARWDT statement at the end of the loop just before GOTO Main should suffice,
    Darrel,

    I've added DEFINE NO_CLRWDT 1 at the start of the code along with other defines. Then added one CLEARWDT just before the GOTO MAIN -

    Just before the main loop the code jumps to a simple section that displays the current version
    Code:
    about:
        LCDOUT $FE,2,"   Multi - Therm    "
    lcdout $FE, $C0, "    Thermostat      "
    
    lcdout $FE, $D4, " Firmware Ver 4.60  "
    Pause 2000
    LCDOUT $FE,1
    goto main
    No with the CLEARWDT inserted as suggested the code is constantly displaying the about screen. IE its constantly resetting which looking at the pause 2000 line in the about the same as the WDT.

    So I commented out the GOTO About and the program ran fine, however if I jump to the main menu it quickly resets before you get chance to make any changes. So I guess I have to go through each section of the code to ensure that I insert enough CLEARWDT statements to allow the program to function, but not defeat the purpose of the WDT ?

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Yup, that's part of that "strategically" idea.

    And now you will appreciate the idea of "Event Driven" software, instead of GOSUB somewhere then return when it's finished, whenever that is.

    With event driven, everything keeps running, even if you're moving through menu's on an LCD.

    Keep in mind that if your light bulb spark is causing a false button press and it's going off into one of those routines ... the WDT won't help unless that routine times out eventually because now you've added CLEARWDT's to it.
    DT

  5. #5
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Yup, that's part of that "strategically" idea.

    And now you will appreciate the idea of "Event Driven" software, instead of GOSUB somewhere then return when it's finished, whenever that is.

    With event driven, everything keeps running, even if you're moving through menu's on an LCD.

    Keep in mind that if your light bulb spark is causing a false button press and it's going off into one of those routines ... the WDT won't help unless that routine times out eventually because now you've added CLEARWDT's to it.
    Yeah, having to work through the sub-routines to add the CLEARWDT so that it doesn't reset, but then to add some form of time out routine so that if nothing is pressed it returns to the main menu.

    I must admit my old brain finds it comfortable with the goto / gosub way of coding... the "if button pressed gosub xyz", and I wouldn't know how to re-work the code for event driven routines... still learning ! I'll keep plodding away through the code to insert the CLEARWDT hear and there, at least it will provide some form protection.

Members who have read this thread : 0

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