Dwayne Dietrich

RTI problem

Discussion created by Dwayne Dietrich Employee on Jan 29, 2006
This message contains an entire topic ported from a separate forum. The original message and all replies are in this single message. We have seeded this new forum with selected information that we expect will be of value to you as you search for answers to your questions.
 
Date: Fri Jan 14, 2005 10:00pm
Subject: RTI problem
 
    hi
I am using real time interrupt to repeat a sequence of routines.
The sequence repeats for like 20 times and all of a sudden the entire
microcontroller stops. It kinda hangs. Only a reset gets it out of this
lock out and then the same thing repeats.
I am not able to figure out the reason.
Can somebody help me?

-----------------------------------------------------------------------
Date: Fri Jan 14, 2005 5:03pm
hi
I am using real time interrupt to repeat a sequence of routines.
The sequence repeats for like 20 times and all of a sudden the entire
microcontroller stops.

====================
Bet you are pushing more registers than you are pulling... maybe jumping out
of a subroutine or interrupt handler by mistake? Stack keeps growing till it
overwrites something. Make stack bigger, see if it runs longer....
-----------------------------------------------------------------------
Date: Fri Jan 14, 2005 10:06pm

    thanks for such a quick response
may I know how to make the stack bigger?
-----------------------------------------------------------------------
Date: Fri Jan 14, 2005 5:14pm

===========================
If writing in assembler, programmer must load stack pointer at a hi address.
When a subroutine is called, or a register is pushed on to the stack, , the
stack pointer decrements to point to the next lower address in memory. Maybe
you forgot to load the stack pointer in the beginning of the program? If
writing in c, compiler or linker or ide will have a way to specify size of stack.,
or use some standard default size. Do you use c or assembler?
-----------------------------------------------------------------------
Date: Fri Jan 14, 2005 10:19pm
 
 
    Iam using asembly
lds $0c00
shd do the job. Correct me if I am wrong.
-----------------------------------------------------------------------
Date: Fri Jan 14, 2005 5:24pm

    lds $0c00
 
====================
I assume $0c00 is a high ram address. Maybe you should use $0bff, and dont
forget the immediate sign! LDS #$0BFF... you told it to "load the contens of
location $0c00" which had who knows what in it.....
-----------------------------------------------------------------------
Date: Fri Jan 14, 2005 10:27pm
 
 
    thanks a ton
shall try this tommorrow
-----------------------------------------------------------------------
Date: Fri Jan 14, 2005 11:53pm

I tried initializing the STACK, it ran for a longer time.However, when I
simply commented the psh and pul mnemonics in the code ( just to test) it
did make much difference , it hanged as previously.
I do not know wat is going wroong?
help me!
-----------------------------------------------------------------------
Date: Sat Jan 15, 2005 1:34am

Might help if you post some code here, you haven't
given us much to go on.
-----------------------------------------------------------------------
Date: Sat Jan 15, 2005 1:53am

    Perhaps the "sequence of routines" you run from the Real Time
Interrupt cannot complete before the next RTI tries to hit. Also,
you should probably not call any of the routines used by the RTI from
the "foreground" code, especially if those routines modify global
variables or have internal static variables. If you toggle a port
pin at the start and end of the RTI routine, you can monitor how long
it's taking with an oscilloscope.
If you don't have something like NOICE, you can still detect "stack
creep" by adding some code that monitors the value of the stack
pointer, and if the stack gets outside a certain range takes some
action like toggling a port pin or sending an SCI character.
If you are using C make sure all the variables used by both the RTI
and for the foreground are of type "volatile". In CodeWarrior you
can set the stack size by editing the .prm file visible in
the "Files" tab at screen left. CW defaults to a very small stack
just past the end of the variable space. A stack creeping down into
variable space makes for really interesting debugging. Remember that
all the variables declared inside a function use up stack space while
the function is executing, so be careful of declaring arrays inside
functions...an array of ints 128 elements long declared inside a
function can use up the entire default CW stack space.
It is probably a good idea not to do too much processing inside the
RTI. Use the RTI to do just enough checking to detect conditions
that require attention. But rather than handling these conditions in
the RTI, just set flags and do the extended processing for these
conditions in the main event loop. Among other things this prevents
conflicts for system resources between the RTI and the foreground
routines. Since the RTI uses up a lot of system time, try inlining
all the code it needs to execute inside a single function instead of
spreading the code around in separate functions. This will reduce
the RTI overhead time and also keep the stack much shallower.
-----------------------------------------------------------------------
Date: Sat Jan 15, 2005 11:38am

If you are using assembly, make sure that the interrupt routine ends with RTI and not
RTS.
It cause stack overflow.
-----------------------------------------------------------------------
Date: Fri, 14 Jan 2005 20:19:13 -0800 (PST)

Iam using asembly
lds $0c00
shd do the job. Correct me if I am wrong.
-----------------------------------------------------------------------
Date: Sat Jan 15, 2005 11:53am
   
thanks to all
I fixed the problem. The problem was with SCI initialization which was
getting messed up in one of the routines.
thanks again

 
 

Message Edited by Dietrich on 01-29-2006 11:24 AM

Outcomes