sleep on 12f629


Closed Thread
Results 1 to 8 of 8

Thread: sleep on 12f629

  1. #1
    Join Date
    Jan 2007
    Location
    Brazil
    Posts
    108

    Default sleep on 12f629

    hello.

    I've looked for posts discussing @sleep on 12f629 but I got nothing (I did get, but nothing helpful). I would like to make 12f629 sleep an wake on gp3/!MCLR/Vpp change (on falling edge).

    Is this possible ? How?

    Thanks!

    Sylvio

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sirvo View Post
    hello.

    I've looked for posts discussing @sleep on 12f629 but I got nothing (I did get, but nothing helpful). I would like to make 12f629 sleep an wake on gp3/!MCLR/Vpp change (on falling edge).

    Is this possible ? How?

    Thanks!

    Sylvio
    How wide is this falling edge pulse?

    Do you realize that a short low going pulse on the MCLR pin is the same as a reset and therefore can be used as a wake up signal?

    Maybe use a 10K pullup on MCLR to Vdd, put your pulse into the MCLR pin itself thru a capacitor. As the pulse goes low, so does the cap, for a short period of time (depending on the size of the cap and the value of the pullup), then shortly later, the pullup resistor charges the cap back to Vdd...BAM...instant pulse generator...also, instant wake up...
    Try it and see what happens. It's worked for me before.

  3. #3
    Join Date
    Jan 2007
    Location
    Brazil
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    but i set MCLR_OFF
    in my project gp3 is an input and it is connected trought the bc548 collector pin...
    and the pulse takes around 1 second...
    thanks...

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sirvo View Post
    but i set MCLR_OFF
    in my project gp3 is an input and it is connected trought the bc548 collector pin...
    and the pulse takes around 1 second...
    thanks...
    Well, MCLR is an input...of a sort...

  5. #5
    Join Date
    Oct 2004
    Location
    Fayetteville Arkansas
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    Did you use an interupt routine? can you post the code you used?

  6. #6
    Join Date
    Jan 2007
    Location
    Brazil
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    Hi, here is all the code..:

    @ DEVICE pic12F629, INTRC_OSC_NOCLKOUT ; System Clock Options
    @ DEVICE pic12F629, WDT_OFF ; Watchdog Timer
    @ DEVICE pic12F629, PWRT_ON ; Power-On Timer
    @ DEVICE pic12F629, MCLR_OFF ; Master Clear Options (Internal)
    @ DEVICE pic12F629, BOD_OFF ; Brown-Out Detect
    @ DEVICE pic12F629, CPD_OFF ; Data Memory Code Protect
    @ DEVICE pic12F629, PROTECT_OFF


    Include "modedefs.bas"

    IGNICAO VAR GPIO.0
    IMOB VAR GPIO.1
    PARTIDA VAR GPIO.2
    AUX VAR GPIO.3
    ALARME VAR GPIO.4

    TEMPO VAR WORD 'time..
    LOAD VAR WORD
    CONT VAR BYTE

    CMCON = 7
    TRISIO = %00001000 'GPIO.3 INPUT ONLY
    GPIO = 0
    cont = 0
    TEMPO = 0
    LOAD = 55543
    ALARME = 0

    INTCON = %11000000 'enable interrupt
    PIE1 = 1 'enable tmr1 overflow interrupt
    On Interrupt Goto TE
    TMR1L=load.lowbyte
    TMR1H=load.highbyte

    IN: PIR1.0 = 0 'tmr1 flag clear
    if aux = 1 then
    SELECT CASE cont
    ' CASE 0
    ' IF TEMPO = 3000 THEN
    ' SLEEP AND WAKE ON GPIO.3 FALLING EDGE
    ' GOTO IN
    ' ENDIF
    CASE 1, 2
    IF TEMPO = 1000 THEN
    GOSUB RE
    ENDIF
    CASE 3
    IF TEMPO = 6000 THEN
    GOSUB RE
    ENDIF
    END SELECT
    goto in
    endif
    BRANCH CONT, [E1, E2,E3,E4]

    E1: PAUSE 100 ' THERE ARE THINGS DELETED INSIDE E1 - E4 LABELS
    CONT = CONT + 1
    T1CON = 1
    GOTO IN

    E2: PAUSE 100
    CONT = CONT + 1
    tempo = 0
    T1CON = 1
    GOTO IN

    E3: PAUSE 100
    CONT = CONT + 1
    T1CON = 1
    GOTO IN

    E4: PAUSE 100
    CONT = 0
    T1CON = 0
    GOTO IN

    DISABLE
    TE: tempo = tempo + 1
    PIR1.0 = 0
    TMR1L=load.lowbyte
    TMR1H=load.highbyte
    resume
    ENABLE

    RE: IGNICAO = 0
    IMOB = 0
    PARTIDA = 0
    TEMPO = 0
    CONT = 0
    T1CON = 0
    alarme = 0
    RETURN

    END

    ---------------------

    so, take a look on label IN, CASE 0
    i would like that to happen..

    i think it's necessary to use a kind of an interrupt handler and check the flags.. but a i dont know what flags to check..

    i think i'll need to set IOC.3 = 1 'enable gpio3 interrupt on pin chage

    .....

    i hope you help me.. sorry if that is too much..

    thanks a lot..!

    Sylvio

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


    Did you find this post helpful? Yes | No

    Default

    If you just want to put the PIC to sleep, and wake up on keypress, you don't
    need to enable global interrupts.

    Here's something to start with.
    Code:
    @ DEVICE INTRC_OSC_NOCLKOUT,WDT_OFF,MCLR_OFF
    
    DEFINE OSCCAL_1K 1
    
    GIE     VAR INTCON.7  ' Global interrupt enable 1=ON, 0=OFF
    GPIE    VAR INTCON.3  ' Port change interrupt enable 1=ON, 0=OFF
    GPIF    VAR INTCON.0  ' Port Change Interrupt Flag bit
    LED     VAR GPIO.0    ' LED output GND---/\/\/\---|<|--GPIO.0
    Key     VAR GPIO.3    ' Key input (10K pull-up w/switch to ground)
    X       VAR BYTE      ' G.P.
    
    CMCON = 7             ' All digital
    GPIO = 0              ' Clear port on boot
    TRISIO = %00001000    ' GPIO.3 input, rest outputs
    
    GIE = 0            ' Disable global ints
    GPIE = 1           ' Enable port change int
    IOC.3 = 1          ' Int-on-change for GPIO.3 enabled
    X = GPIO           ' Take a snap shot of port on boot
    	
    Main:
        X = 10
        REPEAT
         TOGGLE LED        ' Toggle LED
         X = X - 1
         PAUSE 250
        UNTIL X = 0
    
        @ SLEEP            ' SLEEP until Key is pressed
    
        WHILE Key = 0      ' Wait for Key release
        WEND
    	
        GPIF = 0           ' Clear port change interrupt flag
        GOTO Main
        END
    You take it from here. Pretty much all you need is in the data sheet, and it's
    simple to understand if you take your time...;o}
    Regards,

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

  8. #8
    Join Date
    Jan 2007
    Location
    Brazil
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    hey Bruce, thanks!

    That is what i was trying to get..
    I'm going to update my code and then i'll post de results...

    thank very much!

    Sylvio

Similar Threads

  1. 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
  2. 12F629 Won't SLEEP
    By jderson in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th August 2008, 12:08
  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. Programming 12F629 low power (Sleep)
    By Warrier in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 29th November 2004, 14:45

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