Interrupt While Sleeping

Discussion in 'Embedded Systems and Microcontrollers' started by ELECTRONERD, Nov 14, 2010.

  1. ELECTRONERD

    Thread Starter Senior Member

    May 26, 2009
    1,146
    16
    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
     
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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
     
  3. ELECTRONERD

    Thread Starter Senior Member

    May 26, 2009
    1,146
    16
    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:

    Code ( (Unknown Language)):
    1.         if(!GPIO0)
    2.         {
    3.             Code;
    4.         }
    Code ( (Unknown Language)):
    1.         if(GPIE)
    2.         {
    3.             Code;
    4.         }
     
  4. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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:
     
  5. ELECTRONERD

    Thread Starter Senior Member

    May 26, 2009
    1,146
    16
    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?
     
  6. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
     
Loading...