Interrupt While Sleeping

Thread Starter

ELECTRONERD

Joined May 26, 2009
1,147
Hey Everyone,

I'm working on a project that requires my μC to wake up from sleep via an interrupt. I am using the PIC12F629 and HI-TECH compiler, but I'm don't quite understand how everything works.

The basic analogy of the program will run through some code if one of the IOC switches is activated. I'm told that I can't poll the GPIF bit while sleeping, so I assume I poll the GPIE bit?

Another notable factor that contravenes with my understanding is a peripheral interrupt. What are the differences and similarities that exist between a peripheral interrupt and a normal interrupt?

Really, the only misunderstanding I have is those two facets. In algorithm form, I believe I'll first determine the INTCON settings, then IOC settings, and figure out some way to 'know' when an interrupt occurred in the main function.

I would appreciate any help!

Thanks,

Austin
 

t06afre

Joined May 11, 2009
5,934
I think PORTB on that chip can generate interrupt on change. Even in sleep mode. But I am not on a machine with adobe pdf now. So I can not check but refer to the datasheet
 

Thread Starter

ELECTRONERD

Joined May 26, 2009
1,147
There isn't a 'PORTB' on this particular PIC. It uses the GPIO port, ranging from GP0 to GP5. I'm unsure of what to look for in my "if" statement; am I to look for GPIE or can I just examine GPIOX for whatever port I'm on? For instance:

Rich (BB code):
        if(!GPIO0)
        {
            Code;
        }
Rich (BB code):
        if(GPIE)
        {
            Code;
        }
 

Markd77

Joined Sep 7, 2009
2,806
You don't poll anything while sleeping. Code execution stops at the sleep instruction and it wakes back up either in the interrupt or by continuing. This bit is important:
When the SLEEP instruction is being executed, the
next instruction (PC + 1) is pre-fetched. For the device
to wake-up through an interrupt event, the corresponding
interrupt enable bit must be set (enabled). Wake-up
is regardless of the state of the GIE bit. If the GIE bit is
clear (disabled), the device continues execution at the
instruction after the SLEEP instruction. If the GIE bit is
set (enabled), the device executes the instruction after
the SLEEP instruction, then branches to the interrupt
address (0004h). In cases where the execution of the
instruction following SLEEP is not desirable, the user
should have an NOP after the SLEEP instruction.
 

Thread Starter

ELECTRONERD

Joined May 26, 2009
1,147
Then I must have to press the switch twice; once to initiate the interrupt and then a second time to examine the state of the pin after the μC has woke up? It seems to me that isn't necessary with the IOC register; I want code to commence after I have pressed a switch. I think it's just a matter of knowing what to examine with the interrupts.

I realize that the GIE bit is important, otherwise no interrupts at all would be possible. Although, what distinguishes a peripheral interrupt bit from a global interrupt bit?
 

Markd77

Joined Sep 7, 2009
2,806
You won't need to press the switch twice, a normal switch will still be bouncing by the time the PIC wakes from sleep.
There's no real difference between normal interrupts and peripheral interrupts apart from that the enable flags are in different registers.
If all the interrupt enable flags are cleared apart from GIE there still won't be any interrupts. GIE is special in that it is automatically turned off when an interrupt happens and re-enabled with RETFIE at the end of the interrupt.
The following interrupt flags are contained in the
INTCON register:
• INT pin interrupt
• GP port change interrupt
• TMR0 overflow interrupt
The peripheral interrupt flags are contained in the
special register PIR1. The corresponding interrupt
enable bit is contained in Special Register PIE1.
The following interrupt flags are contained in the PIR
register:
• EEPROM data write interrupt
• A/D interrupt
• Comparator interrupt
• Timer1 overflow interrupt
 
Top