PDA

View Full Version : 10F222 wake/sleep



AvionicsMaster1
- 22nd August 2013, 15:27
Ladies and Gents,

I've been playing around with the 10F222 and its sleep/wake on pin change. Not trying to show my ineptness here but what do they mean by reading the input pins? This code works:

CLEAR
DEFINE OSC 4
adcon0 = 0 ' Turn off ADC
option_reg = %00001000 ' enable wake on pin, weak pull ups, prescaler to wdt
osccal = %00000000 ' oscillator calibration
trisio = %1101 ' GP1 only is output
gpio = 0 ' turn everything off

LED VAR gpio.1
i VAR BYTE

start_here:

IF gpio.0 = 0 THEN GOSUB Light_LED
IF gpio.3 = 0 THEN GOSUB Light_LED
SLEEP 5

GOTO start_here

Light_LED:
i = 0
FOR i = 0 TO 3
TOGGLE LED
PAUSE 8000
NEXT i
RETURN

END



I'd like to know if I did it right or is there something more subtle, or bodacious, I should be doing.

I've, I think, attached the page and my code. Constructive help greatly appreciated.

gadelhas
- 22nd August 2013, 16:23
Hi AvionicsMaster

Here is a code using IOC and Sleep.



'************************************************* ***************
'* Name : Temporizador 3m p/ Lavar Dentes.BAS *
'* Author : Hugo Oliveira *
'* 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

'=================================VARIABLES======= ==============================
I VAR BYTE

'================================MAIN LOOP======================================
@ movlw 0x01A ;OSCCAL Value
@ movwf OSCCAL
Main:


WHILE MCLR = 0
WEND

FOR I = 0 TO 119 '~120 Segundos a Piscar de 1 em 1 Segundo
HIGH LED
PAUSE 500
LOW LED
PAUSE 500
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
NEXT

HIGH LED
PAUSE 30000 '~30 Segundos sempre ligado
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

I = GPIO 'Must read GPIO before entering sleep. Read the Datasheet
@ SLEEP
@ NOP
GOTO Main
END

HenrikOlsson
- 22nd August 2013, 17:36
Hi,
There's a slight difference between the PBP command SLEEP and the ASM instruction SLEEP.

The PBP command uses the ASM instruction sleep but relies on the watchdog timer to periodically wake the PIC up in order to keep track of time. If you don't want the PIC to periodcally wake up you need to disable the watchdog and use the ASM instruction SLEEP directly.

What they mean by "reading the pins" is that before entering sleep mode you should make a "dummy read" of the pins in order to clear any mismatch which might otherwise cause the PIC to wake right back up.

/Henrik.

Ioannis
- 23rd August 2013, 09:03
On some PIC chips there is an option in Config Word that allows the WDT to be enabled when PIC is running and automatically disabled when it enteres SLEEP (in ASM command, not PBP sleep).

For example 16F1826/27. See page 44 of the datasheet at http://ww1.microchip.com/downloads/en/DeviceDoc/41391D.pdf

Ioannis