PDA

View Full Version : @sleep



jheissjr
- 5th March 2006, 03:19
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 :)

jheissjr
- 5th March 2006, 03:21
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

sougata
- 5th March 2006, 07:28
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

Melanie
- 5th March 2006, 09:02
If you're using the Assembler @ SLEEP, the WDT needs to be Disabled (OFF).

jheissjr
- 5th March 2006, 21:18
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)

Melanie
- 5th March 2006, 21:43
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...

jheissjr
- 5th March 2006, 22:25
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.

Melanie
- 5th March 2006, 22:34
Have you checked that when you burn your PIC, the WDT is set to OFF in your programming software?

jheissjr
- 5th March 2006, 22:42
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!