View previous topic :: View next topic |
Author |
Message |
cbarberis
Joined: 01 Oct 2003 Posts: 172 Location: Punta Gorda, Florida USA
|
PIC10F206 Does NOT want to wakeup on pin change |
Posted: Tue Mar 09, 2010 2:48 pm |
|
|
Hi, I don't know if anyone encountered any issues with the CCS compiler with the PIC10F206 but I seem to have an issue that I can't seem to find and it is most likely something I am missing in my code. I have a simple application where I use a 10F206 to act as a one hour timer while in the sleep mode. Basically I am waking every 2.3 seconds and incrementing a counter. When the counter is equal to the value of 60 min I turn on GP2 for 22 seconds and go back to sleep. During sleep I also look for a pin-change on the I/O (GP0,GP1 and GP3) if that occurs I wake up turn on GP2 for 22 seconds and go back to sleep. Seems quite simple!
But for some reason, I cannot get this thing to wake up on pin change. The WDT and sleep counter works fine. I looked at the options register and all seems to be correct. I am testing for GPWUF which is the bit in the status reg that gets set on pin change.
Perhaps I'm doing something so stupid that I just can't see?
Code: |
#include <10F206.h>
#FUSES WDT //Watch Dog Timer
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOPROTECT //Code not protected from reading
#use fast_io(B)
#use delay(clock=4000000,RESTART_WDT)
#byte STATUS = 0x003
#bit DC = STATUS.1
#bit PD = STATUS.3
#bit TO = STATUS.4
#bit GPWUF = STATUS.7
#byte GPIO = 0x006
#bit GP0 = GPIO.0
#bit GP1 = GPIO.1
#bit GP2 = GPIO.2
#bit GP3 = GPIO.3
#define UPTIME 22000
#define SLEEPCOUNTS 26 // 60 sec @ 2304ms // 1563 = 1hour
unsigned int16 SleepCount;
void Init()
{
SET_TRIS_b(0x0B);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_wdt(WDT_2304MS | DISABLE_PULLUPS);
//setup_wdt(WDT_2304MS);
GP2 = 0;
}
void main()
{
Init();
while(1)
{
if(GPWUF) // test for I/O pin change
{GP2 = 1;
delay_ms(UPTIME);
SleepCount = 0;
GP2 = 0;
//GPWUF =0;
}
if(PD) // test for WatchDog time out
{ SleepCount++;
if(SleepCount > SLEEPCOUNTS)
{ GP2 = 1;
delay_ms(UPTIME);
SleepCount = 0;
GP2 = 0; }}
sleep();
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Mar 09, 2010 3:54 pm |
|
|
Quote: |
During sleep I also look for a pin-change on the I/O (GP0,GP1 and GP3) |
1. Post a detailed description of the external circuits on these pins,
including any switches, pullups, etc.
2. Describe how you are testing it. Are you pressing a push-button
switch on GP0 ? Etc.
3. Are you testing this on real hardware, or is it a Proteus project ?
4. What is your compiler version ? |
|
|
cbarberis
Joined: 01 Oct 2003 Posts: 172 Location: Punta Gorda, Florida USA
|
|
Posted: Tue Mar 09, 2010 4:02 pm |
|
|
1. The circuit is very basic; 5V for VDD GP0,GP1 and GP3 are pulled up via 47K resistors and I am using a PB switch to pull these inputs to gnd. GP2 is got a LED so I can see it cycling, that is all there is to it.
2. Testing is in actual hardware, it works fine on the Proteus Vsim.
3. I am using the CCS V 4.105 |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Tue Mar 09, 2010 5:27 pm |
|
|
Hola Carlos,
GP2 pin may be controlled by various registers, in order to be sure that it is not assigned
to other function (T0CKI/COUT/FOSC4) after power up, turn off the comparators module in your init.
setup_comparators(NC_NC);
Regards,
Humberto |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Mar 09, 2010 5:49 pm |
|
|
Are you aware that on the 10F206, a Wake-up from Sleep-on-Change
causes the PIC to reset ? It doesn't continue operation at the next line
of code after the Sleep instruction. It resets. This behavior is designed
into the 10F206. From the PIC data sheet:
Quote: |
9.9.2 WAKE-UP FROM SLEEP
The device can wake-up from Sleep through one of
the following events:
1. An external Reset input on GP3/MCLR/VPP pin,
when configured as MCLR.
2. A Watchdog Timer time-out Reset (if WDT was
enabled).
3. A change on input pin GP0, GP1 or GP3 when
wake-up on change is enabled.
4. A comparator output change has occurred when
wake-up on comparator change is enabled.
These events cause a device Reset.
|
|
|
|
cbarberis
Joined: 01 Oct 2003 Posts: 172 Location: Punta Gorda, Florida USA
|
|
Posted: Tue Mar 09, 2010 6:26 pm |
|
|
Hi Humberto and PCM programmer!
Thanks for your help!
Yes I am aware that this device goes through a reset on pin change a wdt time out , meaning it goes back to main() and starts excecution all over, however the GPWUF bit should not get reset??? and I think therein lies the problem because when I test for it it is zero and it should be one.
I have also tried using the following:
setup_comparator(NC_NC | COMP_DISABLE_WAKEUP);
and also
setup_wdt(WDT_2304MS | PIN_CHANGE_FROM_SLEEP);
this is getting very frustrating!!!! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Mar 09, 2010 6:33 pm |
|
|
I think you should be testing for a Wake-up-On-Change-from-Sleep at
the very beginning of your program, not after calling the init() routine.
Also, see this note in the 10F206 data sheet. I don't see that you
are doing this in your code:
Quote: |
9.9.2 WAKE-UP FROM SLEEP
Note:
Caution: Right before entering Sleep, read
the input pins. When in Sleep, wake-up
occurs when the values at the pins change
from the state they were in at the last reading.
If a wake-up on change occurs and the pins
are not read before re-entering Sleep, a
wake-up will occur immediately even if no
pins change while in Sleep mode. |
|
|
|
cbarberis
Joined: 01 Oct 2003 Posts: 172 Location: Punta Gorda, Florida USA
|
|
Posted: Tue Mar 09, 2010 7:34 pm |
|
|
PCM programmer Once again YOU ARE RIGHT!!
The initialization routine was blowing away my GPWUF bit.
creating a flag:
Code: | int1 PinChangeFlag; |
Then acquiring the value of the GPWUF bit before the init()
Code: |
void main()
{
PinChangeFlag = GPWUF;
Init();
|
Then testing for that event:
Code: |
if(PinChangeFlag) // test for I/O pin change
{GP2 = 1;
delay_ms(UPTIME);
SleepCount = 0;
GP2 = 0; }
|
That was all that was needed! Sometimes the simple things in life are very hard to see. |
|
|
|