10F222 Wake on pin change


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: 10F222 Wake on pin change

    Hi,
    When using the NAP command the PIC goes to sleep, for a while, wakes up, goes to sleep, wakes up and so on, keeping track of how many "cycles" in order to give you roughly the amount the sleeptime you tell it to. It uses the WDT to do this.

    Using Wake-on-change will put the PIC to sleep and it'll stay there until a change occurs. I've never used the feature and I've never used the 10F parts but it looks like all you need to do is enable GPWU (like you are doing). Then when you're ready to go to sleep you do a read of the GPIO register to get the current state and then put the chip to sleep using the assembly instruction SLEEP (not the PBP command) ie, @ SLEEP

    At this point the PIC will go to sleep until a change occurs on one of the GPIO pins which are set to be inputs. I think that you'll have to disable the WDT otherwise IT will timeout and Wake the PIC up.

    Code:
    start_here:                  ' ------------------------------finally the program
       adcon0 = 0 ' I read somewhere that after a reset you need to set this register again
       state = gpio  ' read the gpio ports
       if switch = 0 then gosub light_LED ' looking for the button
    @ SLEEP
    goto start_here
    Again, I've never actually tried this, just read the datasheet so take it for what it is.

    With that said I really wouldn't want to run it at anything above 5.5V......

    /Henrik.

  2. #2
    Join Date
    Aug 2008
    Location
    Portugal
    Posts
    240


    Did you find this post helpful? Yes | No

    Default Re: 10F222 Wake on pin change

    Hi;

    Here is a program that i wrote in the past.
    Code:
    '****************************************************************
    '*  Name    : Temporizador 3m p/ Lavar Dentes.BAS               *
    '*  Author  : gadelhas                                          *
    '*  Notice  : Copyright (c) 2012 ProSystems                     *
    '*          : All Rights Reserved                               *
    '*  Date    : 01-03-2012                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : Proteus + Circuito com SOT-23 e CR2032            *
    '*          : 10F222 - Wake from sleep através de IOC no GP3    *
    '****************************************************************
    @ __config _IOFSCS_4MHZ & _WDT_OFF & _MCLRE_OFF & _CP_OFF & _MCPU_ON
    
     DEFINE OSC 4
    
     '===================SRF AND PINOUT CONFIGURATION - 1-In / 0-Out=================
                  '76543210
         TRISIO = %00001000
           GPIO = %00000000
     OPTION_REG = %00000000 'OPTION_REG.7 - Wake on change bit 0=Enable
         ADCON0 = %00000000 'Analog pins disable
    
    '==================================ALIAS========================================
     VAZIO1 VAR GPIO.0
     VAZIO2 VAR GPIO.1
     LED    VAR GPIO.2
     MCLR   vAR GPIO.3
     GPWUF  var STATUS.7
     
    '=================================VARIABLES=====================================
     I VAR BYTE
     C VAR BYTE: C = 0
     
    '================================MAIN LOOP======================================
    @ movlw 0x01A  ;OSCCAL Value
    @ movwf OSCCAL
    
     IF GPWUF = 0 THEN DESLIGA  'Test what caused the Reset
     
    Main:
    
     WHILE MCLR = 0    'If button pressed for 3 seconds, turn on led
        PAUSE 100
        C = C + 1
        IF C = 30 THEN LIGA
     WEND
     
     FOR I = 0 TO 119 '~120 Segundos a Piscar de 1 em 1 Segundo
        HIGH LED
        PAUSE 500
        GOSUB VERIFICA 
        LOW LED
        PAUSE 500
        GOSUB VERIFICA
     NEXT
    
     FOR I = 0 TO 59  '~30 Segundos a Piscar de 0,5 em 0,5 Segundo
        HIGH LED
        PAUSE 250 
        LOW LED
        PAUSE 250
        GOSUB VERIFICA
     NEXT
    
     HIGH LED
     FOR I = 0 TO 59  '~30 Segundos sempre ligado
         PAUSE 500     
         GOSUB VERIFICA
     NEXT
     LOW LED
      
     'Sequencia de finalização
     HIGH LED: PAUSE 100: LOW LED: PAUSE 100
     HIGH LED: PAUSE 100: LOW LED: PAUSE 100
     HIGH LED: PAUSE 100: LOW LED: PAUSE 100
    
    DESLIGA:
     C = 0
     I = GPIO     'Must read GPIO before entering sleep. Read the Datasheet
    @ SLEEP
    @ NOP
    GOTO Main
    
    '================================SUB-ROUTINES===================================
    LIGA:
        HIGH LED
        PAUSE 1000
        WHILE MCLR !=0
        WEND
        LOW LED
    GOTO DESLIGA
    
    VERIFICA:
     IF MCLR = 0 THEN
         C = C + 1
         IF C = 6 THEN
             'Sequencia de finalização
             HIGH LED: PAUSE 100: LOW LED: PAUSE 100
             HIGH LED: PAUSE 100: LOW LED: PAUSE 100
             HIGH LED: PAUSE 100: LOW LED: PAUSE 100
             PAUSE 1000
             GOTO DESLIGA
         ENDIF        
     ENDIF
    RETURN
    END
    Thanks and Regards;
    Gadelhas

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: 10F222 Wake on pin change

    With that said I really wouldn't want to run it at anything above 5.5V......
    I agree...But for that you can just add a diode in series to lower the voltage down a bit.

    Regards
    Rui

  4. #4
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: 10F222 Wake on pin change

    Good idea on the diode. Thanks.

    I know what RTFDS says but for what I'm doing I assume the four AAA batteries are putting out somewhat less than 1.5V and typically the four pack is close to 5.6V. After a short period they are below the 5.5V level and stay like that for a long time with only a 3uA draw. They'll last even longer if I can get it down in the nano Amp range.

    I've yet to try the ASM sleep but will try soon. Thanks for ideas.

  5. #5
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: 10F222 Wake on pin change

    Brand new batteries will actually put out more than 1.5V. I'd recommend the diode. Also helps for the day you accidentally put them in backwards. Or use NiCDs.

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,160


    Did you find this post helpful? Yes | No

    Default Re: 10F222 Wake on pin change

    Would a low drop off 7805 help?

    Robert

  7. #7
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: 10F222 Wake on pin change

    How low is low? They usually need over a volt. Can you point to a spec sheet?

Similar Threads

  1. 10F222 wake/sleep
    By AvionicsMaster1 in forum PBP3
    Replies: 3
    Last Post: - 23rd August 2013, 08:03
  2. Interrupt-on-Change-pin!
    By PICante in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 11th February 2009, 20:22
  3. HELP !!! How change the voltage of a pin ????
    By stormdacta in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 21st August 2007, 20:55
  4. ? about sleep/wake on pin change and WDT
    By kessral in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 25th January 2007, 23:25
  5. 16F676 Interupt on Change pin determination
    By BGreen in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 5th May 2006, 17:04

Members who have read this thread : 0

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