MC9S08GT16: stop instruction in interrupt subroutine

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

MC9S08GT16: stop instruction in interrupt subroutine

3,620 次查看
marigold80
Contributor I

Hi!

I’m using IRQ interrupt to put MC9S08GT16 stop 3 mode. The RTI interrupt periodically (every second) wakes up the processor. In RTI interrupt processor checks the state of the IRQ  pin and either enters stop mode again (IRQ low) or continues normal work (IRQ high). This is my code of RTI interrupt subroutine:

__interrupt void isrVrti(void)

{            

SRTISC |= 0x40;

if (FLAGI.SLEEP){

            IRQSC_IRQPE=1;

            asm {  

                                   NOP              

                                   BIH IRQ_HIGH           

            IRQ_LOW:     BCLR 4,0x14   

                                   STOP            

            IRQ_HIGH:    NOP

            }                     

            /* exit STOP */

     IRQSC_IRQACK=1;

     IRQSC_IRQIE=1;

     IRQSC_IRQPE=1;

     FLAGI.SLEEP=0;

     ...

} 

The problem is when I try to exit RTI interrupt subroutine when IRQ is high – the processor repeats instructions from: IRQ HIGH several times. On the other hand when processor stays too long in stop mode (IRQ is low for couple of minutes) reset occurs, caused by ILAD (attempt to access an illegal address). I guess I should take care of a stackpointer, but I don’t know how?

Thanks for any help,

Marigold

标签 (1)
0 项奖励
回复
6 回复数

1,348 次查看
tonyp
Senior Contributor II
Check recursion.  STOP enables interrupts like a CLI.

Also, check that your IRQ is edge triggered to avoid multiple triggers for the same (long) request.
0 项奖励
回复

1,349 次查看
marigold80
Contributor I

I disable all peripherals before entering stop mode, only RTI and external oscillator stays enabled. The power consumption is about 9uA, but I noticed that if the processor stays too long in stop mode (IRQ low), the power consumption drops to 2uA and putting IRQ high does not  wake the processor or ILAD reset occurs.

IRQ is edge triggered.

 

Regards,

Marigold

0 项奖励
回复

1,349 次查看
tonyp
Senior Contributor II
It's probably easier to execute STOP from outside the RTI ISR.
0 项奖励
回复

1,349 次查看
J2MEJediMaster
Specialist I
I'd have to agree with tonyp on this one. Trying to reenter the sleep mode from within an interrupt is going to cause all sorts of stack problems. I think you'd rather use the ISR only to wake up the MCU. The application would be sitting in a spin loop that checks to see if anything needs to be done. If so, it does it. If not, the logic falls through to execute the STOP instruction. This design might execute a few more instructions, but it's going to be more reliable than halting the MCU in the middle of an interrupt.

---Tom
0 项奖励
回复

1,349 次查看
marigold80
Contributor I

In accordance with Your advices I gave up reentering STOP mode during interrupt and moved STOP instruction to the loop in the main function. Everything is working fine now (at least it seems to do :smileywink:).

 

Thank You for help,

Marigold

0 项奖励
回复

1,349 次查看
tonyp
Senior Contributor II
Again, check recursion.  From your description, the RTI interrupt is always left incomplete during a STOP (perhaps you could correct by removing extra interrupt stack frames before executing STOP).  A second, third, ... infinite RTI will always increase your stack and you end up with stack overflow, and all sorts of problems.  This also explains the repeated execution of code following the STOP instruction.  It either crashes (with longer IRQs), or exits multiple nested RTIs.



Message Edited by tonyp on 2007-07-09 05:17 PM
0 项奖励
回复