Harold Hallikainen wrote: > > Speaking of... A profiler for PIC code would be great! We could > then find out how much time is left and where all our time is being > spent. > Another problem... I tend to structure my code with the use of > subroutines. The main loop might have a half dozen calls, and those > routines might do another call. Same thing for interrupts. The ISR > consists of save context, btfsc, call something, btfsc, call something, > restore context. I've gotta be real careful to not run out of stack > space! I'[m using the 16c74a and to avoid running out of stack space, I > disabled interrupts before doing a subroutine call over a certain depth > in the main code. Now I'm getting overrun errors on the uart (receiving > at 250 kbps). I guess that I can keep the structure and get rid of stack > usage by going to macros instead of subroutines. > Any comments? > > Harold > Harold, this is a chalenge between programming_code_memory_availability versus stack+processor_idle_availability. For long time I fought trying to understand which one is the most important or would be more available. I installed a simple subroutine that first innitialize all the stack space with a pattern, lets say 33h, then at every while I check the stack from the end to the beginning, to find out where it is not 33h, so I get the information how far the machine used the stack already. After a while it will give you the maximum. Another routine running in a real batch partition, lowest priority just looping and counting a 128 bits counter. After a preset time, the value in that counter will tell me how much in "idle" the machine was. A simple instruction cycles per counter step will give you how many machine cycles per second you have available. For sure, using as much as possible the programming code memory, avoiding calls and returns, speed up the system. The use of macros is a must in this situations, if not you will have several copies of the same routine at the source code, leading to possible mistakes and turning it very difficult to change and do maintenance. I use a very small Serial-LCD (2pins) to show me all the time (once a second) the highest stack usage during software development. I sell those LCDs (3 x $10.00, check my webpage "offers"). Before that, or I was using much stack space (with less space for variables) or I was near the limit (without knowing it) and sometimes going in a big problem of stack pointer invading the variables area. -------------------------------------------------------- Wagner Lipnharski - UST Research Inc. - Orlando, Florida Forum and microcontroller web site: http:/www.ustr.net Microcontrollers Survey: http://www.ustr.net/tellme.htm