wake up from sleep


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302

    Default wake up from sleep

    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

    Code:
        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
    Last edited by savnik; - 29th August 2007 at 20:25.

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


    Did you find this post helpful? Yes | No

    Default

    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.
    Regards,

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

  3. #3
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    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.

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


    Did you find this post helpful? Yes | No

    Default

    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.

    Code:
    @ 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.
    Regards,

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

  5. #5
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    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.

    Code:
    @ 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.

Similar Threads

  1. 16F181: can't wake up from sleep
    By Navaidstech in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 9th January 2010, 04:33
  2. 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
  3. 16F628A current high during sleep
    By Rubicon in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 9th October 2006, 10:21
  4. Wierd sleep issue
    By orca in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 14th March 2006, 22:06
  5. 18F2320 and sleep function
    By Brian in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th March 2005, 13:11

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