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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/06/07 07:20
Read: times


 
#142802 - don't think as a PC programmer....
Responding to: ???'s previous message
In PC, many times it does not matter whether the operation takes 1us or 1ms or 1s (many times it should matter but they simply don't care - ever succeeded to prepare and drink a coffee until a PC did it's job? :-( ). So, the natural choice is to spare the programmer's time and use a high level language, which should alleviate the programmer from thinking about the implementation details, including range checking (<flame of the week> I said, should, as life's different, and a strange PDP-originated-assembly language (a.k.a. C) is used widely, instead of a proper high level language; and people like to code today instead of program</flame of the week>).

But, the prudent embedded programmer should make the mcu's life as easy as possible; especially if this is a snippet which occurs within the interrupt. First, it's your responsibility to take care of the limits, so either you make sure it will never overflow the type of your choice, or precede this line by some range checking code (or, as is the sad but most common practice today, ignore it and wonder why it does not work) - preferrably the first. Second, you should precalculate as much constants as possible. I'd for example split your figure into the addition (which is constant), and multiplication, and think very very hard, whether the division is absolutely necessary. I'd also never attempt to make the routine absolutely flexible in regardas of crystal value; rather, prepare a set of constant for the common crystal frequencies (7.3728MHz, 11.0592MHz, 12MHz, 14.7456MHz, 16MHz, 18.432MHz, 20MHz, 22.1184MHz, 24MHz). At the end of the day, you'll find out that these are in fact only 2 sets of frequencies with a relatively big common denominator and that'll govern the chosen "simplification" pattern.

YMMV

JW


List of 31 messages in thread
TopicAuthorDate
Problem with using Timer 1 of AT89S52 in C            01/01/70 00:00      
   methodology and the raw reason            01/01/70 00:00      
      Range of Variables            01/01/70 00:00      
         What type is AxisAngle?            01/01/70 00:00      
            AxisAngle is char            01/01/70 00:00      
            Integer < 65536?            01/01/70 00:00      
               Working within the range of long integers            01/01/70 00:00      
                  so I should....?            01/01/70 00:00      
                     A float constant            01/01/70 00:00      
                        what's the different            01/01/70 00:00      
                           const float...            01/01/70 00:00      
                              which means the compiler            01/01/70 00:00      
                     floats            01/01/70 00:00      
         drop float            01/01/70 00:00      
            Since I have just started to learn C...            01/01/70 00:00      
               A real programming language            01/01/70 00:00      
            Fractional Equivalence            01/01/70 00:00      
         Why?            01/01/70 00:00      
            there is a reason for this...            01/01/70 00:00      
               don't think as a PC programmer....            01/01/70 00:00      
                  Application vs. Hardware Platform            01/01/70 00:00      
                     the prudent programmer...            01/01/70 00:00      
                  PDP?            01/01/70 00:00      
                     it's not similar to the REAL assembly, of course,            01/01/70 00:00      
            Division is not always first            01/01/70 00:00      
               You are right.            01/01/70 00:00      
                  Explicitness            01/01/70 00:00      
                     is this when the C-code...            01/01/70 00:00      
                     agree with the agreement            01/01/70 00:00      
   Try this, can be better            01/01/70 00:00      
      Superfluous casts            01/01/70 00:00      

Back to Subject List