10F222 Wake on pin change


Closed Thread
Results 1 to 12 of 12

Hybrid View

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

    Default 10F222 Wake on pin change

    Ladies and Gents,
    For some reason I keep trying to use smaller PICs instead of larger. My query today is about the Wake-on-pin change feature of the 10F222 and how to implement it.

    I've got this program that while sleeping is pulling around 3uA at 6ish volts which is pretty good but I want, well, less. I'm not using a voltage regulator and am feeding 4 x AAA battery voltage to the circuit/PIC. My question is, is this the correct way to implement a wake on pin change? I think this is just a loop that naps alot and that's why it uses so little power not a wake on pin change.

    Code:
    clear
    
    define OSC 4 ' if changed make sure to change config statement
    adcon0 = 0         ' Turn off ADC
    option_reg = %01000000 ' 7 = !GPWU wake on pin change. 6 = !GPPU weak pull up 
    status = 0
    osccal = %00000000  ' oscillator calibration
    trisio = %1000      ' All but GP3 is output
    gpio = 0
    
    #CONFIG
           __config _IOFSCS_4MHZ & _WDT_ON & _MCLRE_OFF & _CP_OFF
    #ENDCONFIG
    
    
    GREEN var gpio.1             '-----------------------------variables and constants
    RED var gpio.0
    BLUE var gpio.2
    SWITCH VAR GPIO.3 
    state var byte
    
    start_here:                  ' ------------------------------finally the program
    state = gpio  ' read the gpio ports
    adcon0 = 0 ' I read somewhere that after a reset you need to set this register again
    nap 5
    if switch = 0 then gosub light_LED ' looking for the button
    goto start_here
    
    light_led:         '-----------------------------------------------------led sub
    
    red = 1            
    pause 1000
    red = 0
    green = 1
    pause 1000
    green = 0
    blue = 1
    pause 1000
    GREEN = 1
    red = 1
    pause 1000
    GPIO = 0
    
    return
    
    END
    I didn't add a schematic so I hope a word picture will do. The LED cathodes are connected to ground and the anode to a resistor, forget size, and the resistor to PIC port pins. The switch is between the PIC and ground. I know I could get lower current if I used a slower oscillator but that will take up two pins leaving me only 1 output pin. My ultimate goal is to have this battery powered device sit on the shelf for a very long time without having to change the batteries.

    I'd appreciate some learning if someone would be willing to part with it.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,610


    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.

  3. #3
    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

  4. #4


    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

  5. #5
    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.

  6. #6
    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.

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