PDA

View Full Version : 10F222 Wake on pin change



AvionicsMaster1
- 7th January 2014, 15:17
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.



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.

HenrikOlsson
- 7th January 2014, 18:42
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.



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.

gadelhas
- 8th January 2014, 01:34
Hi;

Here is a program that i wrote in the past.


'************************************************* ***************
'* 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

ruijc
- 8th January 2014, 10:13
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

AvionicsMaster1
- 8th January 2014, 21:24
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.

Charlie
- 9th January 2014, 01:27
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.

Demon
- 9th January 2014, 14:05
Would a low drop off 7805 help?

Robert

Charlie
- 9th January 2014, 15:32
How low is low? They usually need over a volt. Can you point to a spec sheet?

HenrikOlsson
- 9th January 2014, 17:09
Hi,
I don't really see the point of linear regulator. A 5V one, LDO or normal, will drop out of regulation pretty quick, then it behaves as if it wasn't there in first place - or worse. Using a lower voltage like 3.3V or 2.5V will only turn useful energy into heat in the regulator so that's no good either.

The "best" way would of course be a switching type boost/buck converter/regulator so that the PIC can be fed 2.5V (or whatever) from "any" supply voltage, the good thing about this is that the PIC Draws much less current at lower supply voltages so provided the converter/regulator is efficient you'd get more use out of the batteries. But, it adds complexity so.....perhaps use 3 cells in series instead of 4.

/Henrik.

Demon
- 9th January 2014, 17:56
How low is low? They usually need over a volt. Can you point to a spec sheet?


I haven't used one yet. I checked a few and can't find one that comes even close to what is needed here.

They should call them NAMDO; Not As Much Drop Off instead of LDO. :D

Robert

HenrikOlsson
- 9th January 2014, 18:42
Hi,
For reference, the LP2950 (http://www.ti.com/lit/ds/symlink/lp2951.pdf) has a maximum specified drop out voltage of 450mV @100mA load and 80mV @100uA. But like I said, for this application, I don't think using a linear regulator is a good idea.

The quiescent current of the regulator alone (the LP2950 that is) is 75uA which isn't much but it means that the regulator alone pulls like 50-100 times more current than the PIC does when it's sleeping.

/Henrik.

LinkMTech
- 9th January 2014, 20:14
This is part of a program I used to put a PIC16F685 to sleep running at 8MHz.
The unit runs on a CR2032 coin cell and managed to get it down to less than 50nA in Sleep mode.

I had to make sure the circuit was not going to be sourcing power to anything while on standby and it's important to shut things OFF before bedding down.

I read somewhere that the @ NOP after the @ SLEEP would be needed and found it would not stay asleep unless it was there. Hey, as long as it worked!



'================================================= ========================
' 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 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
MOSI = 0 ' Turn OFF SPI data line
_CSN = 0 ' Turn OFF module select line
TXEN = 1 ' Transmitter Vcc OFF
SEND = 0 ' Turn OFF MS encoder SEND input
Action = 0 ' Turn OFF all outputs
m = 0 ' Mode counter reset
IOCA = %00000110 ' Mode input pin RA4 configured for IOC.
IOCB = %10000000 ' ID_new input pin RB7 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