PDA

View Full Version : Help with waking a PIC10F222



brid0030
- 19th August 2009, 23:44
Once again I am at my wits end and need some help.

I'm trying to set up a PIC10F222 so that it will sleep and then wake up on a pin change at GPIO.3 or at GPIO.0. The datasheet says that wake-ups are possible using these two pins as well as GPIO.1. I have both GP3 and GP0 on pull-up resistors, and I bring the pins low to effect the wake-up. I can get the PIC to wake-up on with a change on GP3, but not on GP0. I have set these pins as input and I have the processor read them before going to sleep. I also have the WDT off and MCLR off (set in the INC file, not in the code). Here is the code I'm working with. Again, a low signal on GP3 (aliased as INT in the code below) wakes the PIC, but a low signal on GP0 (aliased as SDA) does nothing. Can anyone see what I have overlooked?


'Alias pins
INT VAR GPIO.3 'interupt (wake-up) pin (pin 6, input only)
SDA VAR GPIO.0 'I2C DATA PIN (pin 1),
SCL VAR GPIO.2 'I2C CLOCK PIN (pin 4)
LIGHT Var GPIO.1 'INPUT FROM LIGHT SENSOR (pin 3)

'SET UP VARIABLES
W0 VAR word 'GENERAL USE
B0 VAR BYTE 'GENERAL USE
B1 vAR BYTE 'GENERAL USE
CNT VAR BYTE 'USED FOR COUNTING minutes (4 bits plus one other bit)

'set initial CNT and W0
CNT = 0
w0 = 32768 '%1000000000000000 'SETS FLAG TO 1 AND REST ZERO
PAUSE 10000
logdata:
'Set up for sleep immediately
OPTION_REG = %10010000 'SET OPTION REGISTER FOR WAKE ON CHANGE
TRISIO = $00001001 'wake ups on GP3 and GP0
B0 = GPIO 'read pins to establish change state.
@SLEEP 'Zzzzzzzzzzzzzzzzz
'Pic will sleep until an interrupt from the clock or I2C bus
'Data interface signal from 2nd PIC will pull both SDA and SCL low
IF sDA = 0 tHEN 'if the data collector is plugged in then
iF SCL = 0 THEN
CNT = 0 'reset count
TRISIO = $00001111 'all inputs, relinquish I2C bus
REPEAT 'wait until data collection is done
PAUSE 100
uNTIL LIGHT = 1 'light signal restarts logging
cnT = 0 'reset count
GOTO logdata
eNDIF
eNDIF

brid0030
- 20th August 2009, 22:31
So I think it was that pesky ADC register. Gets me every time. I needed to have ADCON0 = 0 in there.

Now another problem. This pic seems to reset when it wakes from as opposed to carrying on where it left off. Does this mean I lose all my RAM variable values? Is it possible to save and restore the counter to continue a program after sleep? Surely someone has worked with these...

bogdan
- 20th August 2009, 23:07
...did you try

@ sleep
@ nop

?

Archangel
- 21st August 2009, 04:00
...did you try

@ sleep
@ nop

?

Hi brid0030,
your @SLEEP needs a space @ SLEEP, and as noted above an @ NOP or two sometimes helps too


Now another problem. This pic seems to reset when it wakes from as opposed to carrying on where it left off. Does this mean I lose all my RAM variable values? Is it possible to save and restore the counter to continue a program after sleep? Surely someone has worked with these...

How sure about the WDT timer being off are you? Did your programmer override your config due to check box being checked?


OPTION_REG = %10010000 'SET OPTION REGISTER FOR WAKE ON CHANGE

option reg set to enable on change interrupts and timer0 "1 = Increment on high-to-low transition on the T0CKI pin" seems to me this bit should be zero as you do not use the timer . . .

brid0030
- 22nd August 2009, 00:53
Thanks Joe. I'll try the spacing correction and the NOPs eventually, I hope. Now I am bogged down in some very mysterious compilation problems. I'll get a list of compilation errors about unrecognized symbols, but the symbols are "TRISIO" and "ADCON0" and "GPIO." And the really wierd part is that once these errors pop up they do not go away. I can delete the supposedly offending piece of code (whatever I last added to the program) and the errors remain. And they persist even when I erase more and more code. I have to cut and replace almost the entire program before the errors cease. I may start a new post about this with the code and everything if I do not find a solution in the next few days. Man...this project just keeps spiraling down...

By the way, I have tried the OPTION_REG line with the 4th bit high and low--seems to make no difference as the timer is off in both cases.

Archangel
- 22nd August 2009, 02:08
Thanks Joe. I'll try the spacing correction and the NOPs eventually, I hope. Now I am bogged down in some very mysterious compilation problems. I'll get a list of compilation errors about unrecognized symbols, but the symbols are "TRISIO" and "ADCON0" and "GPIO." And the really wierd part is that once these errors pop up they do not go away. I can delete the supposedly offending piece of code (whatever I last added to the program) and the errors remain. And they persist even when I erase more and more code. I have to cut and replace almost the entire program before the errors cease. I may start a new post about this with the code and everything if I do not find a solution in the next few days. Man...this project just keeps spiraling down...

By the way, I have tried the OPTION_REG line with the 4th bit high and low--seems to make no difference as the timer is off in both cases.I never delete until my program works as expected, I just comment out, make sure to use a semicolon when commenting ASM code. Try saving your project with a different name, sometimes that helps. Sometimes when trying to nail an error I comment out nearly everything, Look at the error, it should tell you which line in which file the offender is by line number, then open that file and look. When you compile PBP and whichever assembler you are using make several files, like any other real compiler does and the errors show up there, maybe PBP signs off on something but the assembler doesn't like it . . .