Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Michael Karas
10/06/12 01:14
Read: 671 times
Beaverton Or

Msg Score: +1
 +1 Good Answer/Helpful
#188590 - Various Timer Functions
Responding to: Marshall Brown's previous message

You really are trying to tackle this in a way that have a number if big problems.

1) The amount of generated machine code to support your fancy table driven method will be horrendous.

2) Code of this type has a very nasty habit of breaking whenever certain types of local variables and calling arguments are optimized by the compiler or linker. Some compilers may be more susceptible to these problems than others. Keil is known to expose difficulties in how it attempts to optimize local memory usage via tool assigned overlaying.

3) Indirect calls through tables are generally not analyzable by the compiler or linker in the optimization phases of the build and almost always end up creating problems with register and local memory resource allocations.

You would be far far better off setting up your timer interrupt to have a state variable that counts 0 -> 9 -> 0 to 9. Then code a switch statement inside the timer ISR for each case of the state variable. Within the case blocks directly call the various types of subroutines unique to each case. You may also be advised to toss most if not all of the calling arguments to these subroutines such that they are all void func(void); type routines. Use global variables for critical states that are managed within these subroutines.

I have coded 8051 for maaaaaaaaaaaany years and can relate many examples of practical experience that has led to using techniques like I suggest above. There have also been a number of times that my work has veered off to other architectures that supported a nice standard stack environment that lent itself beautifully to C style coding. I would get into the habit of making "elegant" and more "complex" code similar in ilk to the kind of things that you are trying to use. Then I come back to an 8051 type project and let these habits dribble into my 8051 code. It is always a painful re-discovery that it is necessary to go back to writing much more simply architected code for the 8051.

Michael Karas

List of 13 messages in thread
Timers - Function Pointers      Marshall Brown      10/03/12 21:08      
   Too much for a '51?      Oliver Sedlacek      10/04/12 02:05      
      I Agree      Marshall Brown      10/04/12 03:27      
   Function Pointers...      Andy Neil      10/04/12 05:50      
   you are violating KISS      Erik Malund      10/04/12 08:41      
   Various Timer Functions        Michael Karas      10/06/12 01:14      
      Thanks Michael      Marshall Brown      10/06/12 23:34      
         regardless, you are violating KISS        Erik Malund      10/09/12 07:44      
            even on ARM      Stefan KAnev      10/09/12 13:40      
            The timer simply increments      Marshall Brown      10/11/12 15:58      
               bug      Marshall Brown      10/11/12 16:08      
                  more bugs      Maarten Brock      10/13/12 14:30      
                     thanks      Marshall Brown      10/14/12 13:31      

Back to Subject List