@sleep


Closed Thread
Results 1 to 9 of 9

Thread: @sleep

  1. #1
    jheissjr's Avatar
    jheissjr Guest

    Default @sleep

    Using the below example I found in the old forum, I am having trouble with the @SLEEP command. The trouble I am having is that the PIC is waking up from sleep without the RB0/INT interrupt being triggerd. If I just let the PIC sit with no interrupt trigger source, it still flashes the LED when it should just be sleeping. Nothing is connected to the PIC except an indicator led on PortA and a wire to ground RB0/INT which triggers the interrupt. Any suggestions

  2. #2
    jheissjr's Avatar
    jheissjr Guest


    Did you find this post helpful? Yes | No

    Default

    Forgot to mention, the code does wake up it from sleep as it is supposed to. It just doesn't stay asleep when it hits the @ SLEEP line.

    '16F628A

    DEFINE OSC 10

    TRISB = %000000001
    TRISA.2 = %0 'Ouput Pin for Turning On/Off LED

    CMCON = 7

    OPTION_REG.7=0 ' 0=Enable PORTB Pull Ups
    OPTION_REG.6=0 ' 1=RB0 Rising-Edge Trigger, 0=Falling-Edge Trigger

    @CONFIG.2 = 0 ' 0=Watch Dog Off
    @CONFIG.6 = 0 ' 0=Brown Out Off
    @CONFIG.4 = 0 ' Set for High Speed Crystal
    @CONFIG.1 = 1 ' Set for High Speed Crystal
    @CONFIG.0 = 0 ' Set for High Speed Crystal

    top:
    INTCON=%00011000 ' Interrupt Control Register
    ' 7=0 - GIE - Global Interrupt Enable
    ' 6=0 - PEIE - Peripheral Interrupt Enable
    ' 5=0 - TOIE - TMR0 Overflow Interrupt Enable
    ' 4=1 - INTE - RB0/INT Enable
    ' 3=1 - RBIE - PORTB change interrupt Enable
    ' 2=0 - TOIF - TMR0 Overflow Flag
    ' 1-0 - INTF - RB0/Ext Interrupt Flag
    ' 0=0 - RBIF - PORTB Interrupt Flag
    @ SLEEP

    Pause 100
    PORTA.2 = 1 'Turn LED On for 1 second
    pause 1000
    PORTA.2 = 0 'Turn LED off before going back to sleep

    goto top
    Last edited by jheissjr; - 5th March 2006 at 04:27.

  3. #3
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default It may be the watchdog timer

    Hi,

    PBP uses the watchdog timer for its own sleep function. Even if you are running your asm sleep instruction the wdt wakes the PIC. There is a define that prevents PBP compiler from automatically inserting the clearwdt instruction. Combine it with the config registers to turn off the watchdog timer. I have never used it. Please check.

    Regards

    Sougata

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    If you're using the Assembler @ SLEEP, the WDT needs to be Disabled (OFF).

  5. #5
    jheissjr's Avatar
    jheissjr Guest


    Did you find this post helpful? Yes | No

    Default

    Hi Melanie,

    I agree that the Watch Dog needs to be disabled. I used this line which I thought should do it:

    @CONFIG.2 = 0 ' 0=Watch Dog Off

    Also tried this too
    @ CONFIG.2 = 0 ' 0=Watch Dog Off

    Maybe the order or location which I have the line is not correct? Or if I try disabling the watch dog using either of these two lines instead of @CONFIG.2=0, I get an 'Illegal Opcode (WDT_OFF)' error from MPASM.

    @DEVICE WDT_OFF => Illegal Opcode (WDT_OFF)
    @ DEVICE WDT_OFF => Illegal Opcode (WDT_OFF)

  6. #6
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    WDT is usually controlled from the Config Fuse definitions...

    http://www.picbasic.co.uk/forum/showthread.php?t=543

    Although Microchip have recently started tinkering with the CONFIG statement, so look in MPLABS HELP file for the latest syntax. Whn I've time I'll update that thread... or perhaps someone else might want to tag the latest MPASM amendments onto it...

  7. #7
    jheissjr's Avatar
    jheissjr Guest


    Did you find this post helpful? Yes | No

    Default

    In the datasheet it says "If the device is in Sleep mode, a WDT time out causes the device to wake up and continue with normal operation."

    The next line says "The Watch Dog can be permanently disabled by programming the configuration bit WDTE as clear." That is just what I have in my code (CONFIG.2 = 0) yet the PIC is still resetting itself.

  8. #8
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Have you checked that when you burn your PIC, the WDT is set to OFF in your programming software?

  9. #9
    jheissjr's Avatar
    jheissjr Guest


    Did you find this post helpful? Yes | No

    Default

    This is why I love the forum. That was the problem! Just incase anyone is using ICPROG and encounters this same problem, you have to uncheck the WDT check box. Thank you Melanie!

Similar Threads

  1. 12c508 @sleep command?
    By rtsandiego in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 14th January 2004, 07:59

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