PDA

View Full Version : wake up from sleep



savnik
- 29th August 2007, 20:23
I use pic16f628a with the code below.This code works.
I want to change the code , so the pic after 10 seconds to wake up for .1 sec and after go again to sleep



TRISB = %11110000
TRISA = %00000000
CMCON = 7
OPTION_REG.7=0 ' 0 = Enable PORTB Pull Ups
@ Device wdt_off ' Disable the WatchDog Timer
INTCON.3=1 ' Interrupt Control Register
PORTB = 0
PORTA = 0

loop:

PORTA.0 = 1 ' Turn LED On for 1 second
pause 1000
PORTA.0 = 0
INTCON.0=0
@ SLEEP
INTCON.0=0

goto loop

Bruce
- 29th August 2007, 21:08
Hi Savnik,

The device can wake-up from SLEEP through one of the following events:
1. External RESET input on MCLR pin
2. Watchdog Timer wake-up (if WDT was enabled)
3. Interrupt from RB0/INT pin, RB Port change, or
any Peripheral Interrupt.

If you're not using option #1 or #3, then your left with the watchdog timer, but this has a
period of around 18mS without the prescaler, and 128 * 18mS with a prescaler set to 128.

OPTION_REG = %00001111 would assign the prescaler to the WDT, and give you roughly
2.304 seconds before each wake-up from @ SLEEP.

COUNTER=0 ' clear before entry
WHILE COUNTER < 4
@ SLEEP
COUNTER=COUNTER+1
WEND

Would give roughly 9.2 seconds before exiting the loop, but it's still going to wake-up every
2.304 seconds and increment COUNTER.

savnik
- 31st August 2007, 08:13
Hi Savnik,

The device can wake-up from SLEEP through one of the following events:
1. External RESET input on MCLR pin
2. Watchdog Timer wake-up (if WDT was enabled)
3. Interrupt from RB0/INT pin, RB Port change, or
any Peripheral Interrupt.

If you're not using option #1 or #3, then your left with the watchdog timer, but this has a
period of around 18mS without the prescaler, and 128 * 18mS with a prescaler set to 128.

OPTION_REG = %00001111 would assign the prescaler to the WDT, and give you roughly
2.304 seconds before each wake-up from @ SLEEP.

COUNTER=0 ' clear before entry
WHILE COUNTER < 4
@ SLEEP
COUNTER=COUNTER+1
WEND

Would give roughly 9.2 seconds before exiting the loop, but it's still going to wake-up every
2.304 seconds and increment COUNTER.
I use Interrupt on RB4-7 Port change.
I have 4 button on rb4-7 , and if i push any button the pic wake up from sleep
and if i release the butoon the pic go again to sleep.
Now i want the pic every 10 seconds to wake up for .1 sec (without to push any button) and after go again to sleep.

Bruce
- 31st August 2007, 16:04
Well, if you're not going to use the WDT, and you can spare RB6 and RB7, you could use a
32,768kHz crystal with Timer1.


@ DEVICE PIC16F628A,WDT_OFF,LVP_OFF,MCLR_OFF,INTRC_OSC,BOD_ OFF

DEFINE OSC 4
SYMBOL LED = PORTB.0

LED = 1 ' At POR, LED off after 1st toggle
TRISB.0 = 0 ' LED pin an output
TMR1H = $60 ' Pre-load TMR1 with $6001
TMR1L = $01
PIR1.0 = 0 ' Clear TMR1 overflow interrupt flag bit
PIE1.0 = 1 ' TMR1 overflow interrupt enabled
INTCON.6 = 1 ' Enable TMR1 peripheral interrupt
T1CON = %00111111 ' External 32,768kHz crystal w\caps used, 1:8 prescale, TMR1 on

Main:
TOGGLE LED ' Indicates wake-up timing
@ SLEEP ' Goto sleep (for ~9.999 seconds)
T1CON.0 = 0 ' Stop TMR1 on overflow wake-up
TMR1H = $60 ' Re-load TMR1 with $6001
TMR1L = $01
PIR1.0 = 0 ' Clear TMR1 over-flow int flag
T1CON.0 = 1 ' Re-start TMR1
GOTO Main

END
That would wake-up after sleep at roughly 10 second intervals without a button press. Do
whatever you need for the .1 sec, then go back to sleep.

savnik
- 31st August 2007, 17:09
Well, if you're not going to use the WDT, and you can spare RB6 and RB7, you could use a
32,768kHz crystal with Timer1.


@ DEVICE PIC16F628A,WDT_OFF,LVP_OFF,MCLR_OFF,INTRC_OSC,BOD_ OFF

DEFINE OSC 4
SYMBOL LED = PORTB.0

LED = 1 ' At POR, LED off after 1st toggle
TRISB.0 = 0 ' LED pin an output
TMR1H = $60 ' Pre-load TMR1 with $6001
TMR1L = $01
PIR1.0 = 0 ' Clear TMR1 overflow interrupt flag bit
PIE1.0 = 1 ' TMR1 overflow interrupt enabled
INTCON.6 = 1 ' Enable TMR1 peripheral interrupt
T1CON = %00111111 ' External 32,768kHz crystal w\caps used, 1:8 prescale, TMR1 on

Main:
TOGGLE LED ' Indicates wake-up timing
@ SLEEP ' Goto sleep (for ~9.999 seconds)
T1CON.0 = 0 ' Stop TMR1 on overflow wake-up
TMR1H = $60 ' Re-load TMR1 with $6001
TMR1L = $01
PIR1.0 = 0 ' Clear TMR1 over-flow int flag
T1CON.0 = 1 ' Re-start TMR1
GOTO Main

END
That would wake-up after sleep at roughly 10 second intervals without a button press. Do
whatever you need for the .1 sec, then go back to sleep.
Thank you . I will try.