@SLEEP and the 12f683


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2010
    Posts
    3

    Default @SLEEP and the 12f683

    I'm a total newbie when it comes to the @SLEEP function, but I would like to use it in some coming projects so I'm hoping someone can give me a hand at setting up the chip and getting it working. Optimal settings preferred as from what I gather in searches here turning things off and setting ports before sleep has some effect on overall current draw while sleeping. And yes I have read and searched the forums but I can't seem to figure it out.

    I have this very basic and useless program here as an example and I would like to know how to implement the @SLEEP function and then wake the chip back up on a port change (button press).

    Code:
    @ DEVICE PIC12F683, MCLR_OFF, INTRC_OSC_NOCLKOUT, WDT_OFF, BOD_OFF, PWRT_OFF, FCMEN_OFF, IESO_OFF, CPD_ON, PROTECT_ON
    
    INTCON = %10001000 'internal oscillator
    OSCCON = %01110000 ' 8mHz
    CMCON0 = 7 'Comparators off
    GPIO = %00000000 'outputs low
    TRISIO = %00010000 'GP3 as input
    
    x VAR WORD    'timeout counter
    x=0
                     
    Main
    
    HIGH GPIO.0 'turn on led so I know the chip is alive
    
    IF GPIO.3 = 1 THEN
    HIGH GPIO.1  'light up GPIO.1 so I know the button was pressed
    PAUSE 50
    LOW GPIO.1
    x=0   'reset the timeout counter if the button is pressed
    ENDIF
    
    pause 100
    x=x+1
    
    IF x>50 THEN
    
    'go to sleep here if GPIO.3 is not pressed for 5 seconds
    'should come out of sleep when GPIO.3 is again pressed
     
    PAUSE 100
    ENDIF
    
    GOTO Main
    Basically with the above as long as GPIO.3 is pressed every 5 seconds it will never enter the sleep IF/THEN but when it does I would like the chip to go to sleep and wait for GPIO.3 to be pressed again as the wake up interrupt and then resume.

    From my searches here it appears I need to set flags and further configure the chip but that is all just words to me as it's not clicking upstairs. Can someone toss this dog a bone?

  2. #2
    Join Date
    Sep 2009
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    WDT_OFF you need to change that to WDT_ON

    Sleep uses the watch dog timer

    SLEEP Period

    Place microcontroller into low power mode for Period seconds. Period is 16-bits, so delays can be up to 65,535 seconds (just over 18 hours). SLEEP uses the Watchdog Timer so it is independent of the actual oscillator frequency. The granularity is about 2.3 seconds and may vary based on device specifics and temperature. This variance is unlike the BASIC Stamp. The change was necessitated because when the PICmicro executes a Watchdog Timer reset, it resets many of the internal registers to predefined values. These values may differ greatly from what your program may expect. By running the SLEEP command uncalibrated, this issue is sidestepped.

    Example

    SLEEP 60 ' Sleep for about 1 minute

    See Also

  3. #3
    Join Date
    Sep 2010
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    The PBP SLEEP command is not the same as assembly SLEEP

    With the watchdog timer on the chip won't go into real sleep mode, it will just sleep for a set period of time. I want the chip to hibernate until there is a change on GPIO.3 not sleep for a specific amount of time, and for this from what I have read the watchdog has to be off.

  4. #4
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default Try this...

    Here's a sample snippet of what I use on a PIC16F677 so you can ignore some of the extra not pertaining to the PIC12F683.
    Code:
    '=========================================================================
    '                           SLEEP Mode
    ' This routine provides an Ultra Low power consumtion until a button is
    ' pressed. All I/O's are setup for the PORTA/B Interrupt On Change function
    ' prior to going into standby condition. Any state change detected to these
    ' PORTs starts main loop and directs to proper routine.        
    '=========================================================================
     Sleep_mode:
        OPTION_REG.7 = 0    ' Global weak pull-up enable bit enabled
        WPUA = %00011111    ' Weak pull-ups enable on PORTA inputs except RA5
        WPUB = %00000000    ' Weak pull-ups disabled on PORTB
        TXEN = 1            ' Transmitter Vcc OFF
        SEND = 0            ' Turn OFF MS encoder SEND input
        Action = 0          ' Turn OFF all outputs
        m = 0               ' Mode counter reset to zero
        IOCA = %00010000    ' Mode input pin configured for IOC
        IOCB = %10000000    ' ID_new input pin configured for IOC
        Store_A = PORTA     ' Reads PORTA
        Store_B = PORTB     ' Reads PORTB
        INTCON = %00001000  ' RABIE (RA and RB Interupt Enabled)
        @ SLEEP             ; Goes mimi until a change of state is detected
        @ NOP               ; 1 instruction cycle
    
    '=========================================================================    
    woke_up: ' goes on from here then will go back to sleep with no activity
    I basically set everything OFF first then set the IOC, in your case it would be IOC=%000010000.
    Take a snapshot of the port to detect a difference.
    Set the INTCON and go to Sleep.
    Code:
    all_my_outputs = 0  ' you want to make sure there's no parasitic currents 
                        ' in your circuit of course
    all_my_vars = 0     ' zero out your counters if needed               
    IOC=%00001000       ' Sets GPIO.3 only for Interupt On Change
    Store_GPIO = GPIO   ' Snapshot of current port state
    INTCON.7=1          ' From data sheet: Global Interrupt Enable (GIE) must 
                        ' be enabled for individual interrupts to be recognized.
    @ SLEEP             ; Goes to sleep until a change of state is detected
    @ NOP               ; 1 instruction cycle - Bruce and others have explained 
                        ' why this was needed but I forget why at the moment.
    Hope this gets you going.
    Louie

  5. #5
    Join Date
    Sep 2009
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by crueheads View Post
    The PBP SLEEP command is not the same as assembly SLEEP

    With the watchdog timer on the chip won't go into real sleep mode, it will just sleep for a set period of time. I want the chip to hibernate until there is a change on GPIO.3 not sleep for a specific amount of time, and for this from what I have read the watchdog has to be off.
    You didn't say any thing about asm in your first post you said
    @sleep function
    PBP has a sleep function The wdt has to be on for it to work

    Glad you have it all worked out hope you have a good day

    I was going to post how to do it in asm but I'd go with LinkMTech code

  6. #6
    Join Date
    Sep 2010
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    You didn't say any thing about asm in your first post you said
    "@sleep function "
    Actually yes I did, the @ is PBP's insert one line of assembly notation. So asking about @SLEEP is asking about assembly sleep and not PBP native.

    LinkMTech thanks I'll give it a test tonight and see how it goes.

    Also after more searching last night I came across this thread http://www.picbasic.co.uk/forum/arch...hp/t-5676.html and the example Bruce posted appears to work.

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