Can anyone tell me why nap & sleep won't work with the 18F452?


Results 1 to 6 of 6

Threaded View

  1. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    SLEEP should work fine on the 18F452. The WDT on this one has a typical time-out period of 18mS without the postcaler.

    With the postscaler set to 128 you have 128 * 18mS for ~2.304S before wake-up from SLEEP.

    It will definitely lock-up if you use SLEEP or NAP, and WDT isn't enabled, or you're not setting WDTCON.SWDTEN.

    Using NAP with the 18F, the Period argument isn't used, so it just sleeps for whatever the typical WDT time-out period is * the postscaler.

    With the postscaler set to 128, SLEEP 4 should give you roughly 4.6S.

    Here are a few that I've tested on the 18F452.
    Code:
    ' Config fuse settings in PBP 18f452.INC 
    '  __CONFIG    _CONFIG1H, _OSCS_OFF_1H & _XT_OSC_1H
    '  __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_128_2H
    '  __CONFIG    _CONFIG4L, _LVP_OFF_4L
            
        DEFINE OSC 4
        X VAR BYTE
        
        PORTD = 1
        TRISD = 0
    
    Main:  ' Use one at a time to see the difference
        GOTO SL1
        'GOTO SL2
        'GOTO SL3
        'GOTO SL4
    
    SL1:   ' Gives roughly 4.6 seconds / compiles to 130 bytes
        PORTD = PORTD ^ 1   ' Toggle D0
        SLEEP 4             ' ~4.6 seconds sleep
        GOTO SL1
        
    SL2:   ' Gives roughly 4.6 seconds / compiles to 60 bytes
        PORTD = PORTD ^ 1   ' Toggle D0
        X = 2       ' 2 x ~2.3 seconds = ~4.6 seconds sleep
        WHILE X
         NAP 1
         X = X - 1
        WEND
        GOTO SL2
        
    SL3:    ' Gives roughly 4.6 seconds / compiles to 46 bytes
        PORTD = PORTD ^ 1   ' Toggle D0
        X = 2       ' 2 x ~2.3 seconds = ~4.6 seconds sleep
        WHILE X
         @ SLEEP
         X = X - 1
        WEND
        GOTO SL3
    
       ' Gives roughly 4.6 seconds / compiles to 38 bytes
    ASM
    SL4
        MOVLW 1
        XORWF LATD,F
        MOVLW 2       ; 2 x ~2.3 seconds = ~4.6 seconds sleep
        SLEEP
        DECFSZ WREG,F
        GOTO $-4
        GOTO SL4
    ENDASM
        
        End
    Last edited by Bruce; - 4th February 2006 at 20:50.
    Regards,

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

Similar Threads

  1. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 09:00
  2. Sleep & nap
    By keymuu in forum mel PIC BASIC Pro
    Replies: 24
    Last Post: - 4th December 2008, 18:45
  3. Char. LCD and 18F452 on 20 MHz not work
    By samettin in forum General
    Replies: 11
    Last Post: - 28th July 2008, 09:59
  4. How do I get DATA @ to work with a 18F452?
    By jessey in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 2nd February 2006, 10:35
  5. Why doesn't my code for 18f452 work on 18f252?
    By senojlr in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 23rd December 2005, 02:42

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