Changing 18F WDT postscaler on-the-fly


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

    Default Changing 18F WDT postscaler on-the-fly

    Someone asked about this recently on the Microchip forum. It's handy to
    know so I figured I would post the answer here also.
    Code:
        ; Changing WDT postscaler settings on-the-fly
    
        PROCESSOR 18F2620
        #include p18f2620.inc
        
        CONFIG OSC=HS,WDT=ON,WDTPS=128,LVP=OFF
       
        CBLOCK  0x000
          WDT_POST        ; value for new WDT postscaler
          LOOPS           ; loop var
        ENDC
    	
        org    0x0000
        bra    Main
    	
        org    0x0020
    	
    Main                    ; starts with WDT postscaler set to 1:128
        clrf    PORTB
        clrf    TRISB
    
        movlw   0x0A        ; toggle LED on/off 5 times
        movwf   LOOPS       ; at ~0.5 second intervals
    Next
        sleep               ; WDT postscaler = 1:128
        nop                 ; so we sleep here for 128 * ~4mS
        btg     LATB,0      ; toggle LED on RB0
        decfsz  LOOPS,F     ; decrement loop count
        bra     Next        ; repeat until loops = 0
    	
        ; point to CONFIG2H reg at 300003h
        movlw   0x30
        movwf   TBLPTRU
        movlw   0x00
        movwf   TBLPTRH
        movlw   0x03
        movwf   TBLPTRL
    
        movlw   B'00001011'     ; value for 1:32 WDT postscaler
        movwf   WDT_POST
    	
        movlw   B'11000100'     ; enable write to config area
        movwf   EECON1
    
        movff   WDT_POST,TABLAT ; Write new postscaler value
        tblwt   *               ; to table latch
        clrwdt                  ; kick the dog before the final write op
    
        movlw   0x55            ; Unlock
        movwf   EECON2
        movlw   0xAA
        movwf   EECON2
        bsf     EECON1, WR      ; Start the write
        nop
        bcf     EECON1, WREN    ; Lock up when we're done
    
        movlw   0x0A
        movwf   LOOPS
    	
    Finish                      ; toggles LED faster showing WDT change
        sleep                   ; at ~0.128 seconds
        nop                     ; WDT postscaler now = 1:32 so
        btg     LATB,0          ; LED toggles at ~32 * 4mS
        decfsz  LOOPS,F
        bra     Finish
    	
    Done
        clrwdt
        bsf     LATB,1          ; show we're done
        bra     Done
    	
        end
    Last edited by Bruce; - 1st August 2006 at 21:11.
    Regards,

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

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


    Did you find this post helpful? Yes | No

    Default

    Hi Bruce,

    I was looking at this code when it struck me that it looked very familiar.
    A quick slap on the forehead and "oh Yeah", now I remember.

    Run-Time Config
    http://www.picbasic.co.uk/forum/showthread.php?t=4093


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


    Did you find this post helpful? Yes | No

    Default

    Hey Darrel,

    Never saw that one before. Could have saved myself a little time...;o}

    Would be nice if Mchip could stuff this somewhere in a data sheet. It's really
    handy. I was fiddling with AN851 when I noticed the CFGS bit in EECON1.
    Regards,

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

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


    Did you find this post helpful? Yes | No

    Default

    Hey Bruce,

    AN851

    Never saw that one before. Could have saved myself a little time... writing the Run-Time Config.

    P.S. There's a nice autobaud routine in there too. Cool, needed that.<br>
    Last edited by Darrel Taylor; - 1st August 2006 at 20:42. Reason: autobaud
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Nice job on the macros too. Thanks for the link.
    Regards,

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

Similar Threads

  1. changing osc on the fly
    By viewgsm in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 6th February 2010, 15:13
  2. changing code from 16F to 18F microprocessor
    By SCC_699 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 14th May 2008, 13:27
  3. Changing declared variables names on the fly
    By jessey in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th December 2006, 06:34
  4. Mode changing on the fly
    By Angus Anderson in forum GSM
    Replies: 1
    Last Post: - 28th November 2006, 08:58

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