33 Replies Latest reply on Aug 29, 2017 11:57 AM by ntewinkel

    If I Had a Hammer

    jack.chaney56

      I used this as a clever draw to get more readers.  The actual intent is to start a discussion and get input from people for software.  Most of the discussions I have seen on the site are about inventing hardware solutions to popular problems.  I guess I am getting overloaded with how many ways there are to turn on an LED.  A significant amount of computer work is actually in the realm of information technology,  Too often what is lacking are skilled individuals that bring an array of tools to the task. The expression "If the only tool you have is a hammer, all your problems look like nails" is a problem I deal with in my professional life. I am constantly faced with vendors who provide the one pony circus (a million ways to make a state machine).

       

      Embedded programming is a discipline that requires the developer to be expert at OS scheduling, database management, hardware interfacing, design architecture, and structured objects, as well as proper coding style, and best solution language. It is a constant process of sharpening the tool set to get the best solution. I have taken to putting some tools into retirement as well. Archiving example code and hint/help files is done periodically so I don't have to keep my COBOL skills current, but, by archiving properly, it is possible with a bit of effort, to blow the dust off a few brain cells, and get back in step with my Fortran lines starting in column 7. (...how old is this guy?)

       

      Getting back to where I started with this, I wanted to put a call out to all you embedded PROGRAMMERS for tips and techniques and tricks learned that can become the foundation for tool boxes.

       

      Tips like:

      • Thinking like a computer
      • Faster graphics and ray tracing
      • Integer only formulas
      • Weight loss (or wait loss) compression
      • T...I...M...I...N...G...

       

      Again, some of these are done with hardware these days, but not all solutions have bottomless bank accounts. Sometimes a one chip 8-bit piece of hardware needs to run an 8 cylinder diesel fueling operation.

        • Re: If I Had a Hammer
          DAB

          Hi Jack,

           

          I can sympathize.

          Using high level programming languages hide a lot of detail you need to learn when going into embedded programming.

          Luckily I learned assembly language programming on an old PDP-11 minicomputer.

          That experience put me in a great position to dive into all of the microprocessors that came out after.

           

          I think you will find most work today is done in C, which in my opinion was a slight step above assembly language, but is reasonable simple to learn and use.

          Depending upon the vender you choose, most have extensive support libraries to implement both simple and complex applications on their products.

          Embedded operating systems get interesting.  In my day, yes I am probably older than you, we made simple control systems when we could and used more exotic OS products when the situation warranted it.

          I have built some very complex systems without needing an OS, but at the time, I had a great understanding of how the processors worked and how to exploit interrupts.

           

          Timing analysis was my forte, and I did some amazing things just by understanding how to fit functions together using interrupt timers and sometimes hardware additions.

           

          Everyone likes inexpensive tools and there are a host of those available free today.

          Arduino, Texas Instruments, Raspberry Pi, MBED, Pickit, and others have excellent free support tools.

           

          Take a good look at Energia, the Russians are making excellent progress with that tool to keep embedded software simple.

          They provide very useful examples and have very useful debugging tools.  I wish this type of support had been around in my day.  I used to chase things with an Oscope and logic analyzer.  Both very expensive at the time.

           

          There are also a number of free Operating Systems that you can pick up and learn.  Just be aware, it takes a while to get really proficient with each one.  My biggest problem with them is that you need to learn is what each OS does TO you.  Each OS has interesting implementations to efficiently facilitate your application.  Each can do interesting thing to your embedded software design, especially timing.

           

           

          So feel free to set up a list of questions, pick a vendor to focus on, and get started.

          I like TI, because they have a copious amount of documentation, a good of small to complex devices, all of which you can program with or without an OS using Energia or Code Composer Studio (CCS).

          Luckily, there is plenty of support on the web for most of the processor lines, it just depends on what you want to do and how complex you want to get.

           

          DAB

          3 of 3 people found this helpful
          • Re: If I Had a Hammer
            niteowl12

            Jack,

             

            Unfortunately, good programmers are something that can't be developed. You can share the tools and examples but the ones that truly understand machine logic are the ones that will shine. There is something to be said for a hardware solution though. There are benefits, and limitations, to having a piece of hardware that has the same function as a set of software. I fully agree that there should be an array of tools and multiple options for completing the same task whether it be cleverly written code, an ASIC, FPGA, or a well designed feedback circuit etc.

            • Re: If I Had a Hammer
              jack.chaney56

              Hi,

              Thanks for all the feedback. I was hoping to spend most of my day today responding and entering discussions with a bunch of you, but sadly I still need to generate a paycheck, and some excrement has just contacted the rotary impeller, and I must attend to it.

               

              to quote... "talk amongst yourselves"

               

              Jack

              • Re: If I Had a Hammer
                shabaz

                Hi Jack,

                 

                Interesting discussion : ) I never studied Fortran (although friends did who were studying subjects like chemical engineering I think) but I still had to try to decipher it a while back, because some code I wanted to use was written in that language.

                I archive off bits of code that I write, to save effort or at least be able to inspect it and improve on it the next time around.

                 

                Also, another tip could be to be prepared to get a book on a topic of interest (or even do a course) - many computing books get old quickly, but the knowledge at the right time is valuable and can save days/weeks of effort so it pays for itself.

                 

                Sometimes it is really instructive to think like a computer as you say, and along with that goes becoming comfortable occasionally inspecting compiled output, examining library files, etc. Also another nice tool (occasionally!) is being semi-aware (but not spend too much time on it) of the instruction set and what the compiler is doing, so that when it comes to the (rare) low-level troubleshooting, you have a rough idea of how to follow the content in memory.

                  • Re: If I Had a Hammer
                    jack.chaney56

                    shabaz

                     

                    I have this condition that a good friend remarked about. I always code in assembly, but think in objects.  No matter what language I am coding in I tend to analyze the instructions as to how they compile. Carry over from my old 360 system days when the compile was a job that had to be accounted as well as the runtime. It has saved me countless times knowing what the computer is capable of doing from a bare metal level, before applying high level axioms to the problem.

                     

                    I have noticed that more and more, the candidates for positions we are getting in (new graduates), are less and less familiar with the concepts of compiler design. I guess optimization is something best left to the experts at Microsoft .  I feel myself slipping into old man dinosaur mode, thinking, "I remember when I was starting out..."

                    1 of 1 people found this helpful
                  • Re: If I Had a Hammer
                    Instructorman

                    Seems like you have touched a nerve among the more seasoned members.

                     

                    A couple of your bullet point tips come right out of my teaching philosophy developed over a 25 year career of trying to get novice technologists to develop good coding habits.

                    Specifically, "Thinking like a computer" and "Integer only formulas".  I have based many embedded systems programming lectures and labs on those concepts.

                     

                    I have spent many hours single stepping classes of young technologists through a block of code, getting them to process each instruction as if they were the CPU, predicting register values, asserting outputs, and following conditional branch instructions.

                    The "integer only formulas" approach was especially useful when using an 8-bit microcontroller and a non-floating point capable compiler to do things like Fahrenheit to Celsius temperature conversion.

                     

                    Overall, I think the pedantic tedium I inflicted on my classes produced a net beneficial understanding of how computational hardware works in concert with code to accomplish useful things.

                     

                    Ah, the good old days.

                      • Re: If I Had a Hammer
                        ntewinkel

                        >"Integer only formulas"

                         

                        I noticed even fairly recently (within the last year I think) the difference floating point math makes for firmware. I'm pretty sure it was an Arduino app for an ATTiny I was working on, and as soon as I introduced some floating point math the package size bloated to use up far too much space (we're talking magnitude difference). And the kicker was that it wasn't even something requiring floating point - with just minor tweaks I brought the app size down immensely.

                         

                        I wish I could remember the exact example, but I'm sure it would be easy to replicate.

                         

                        -Nico

                          • Re: If I Had a Hammer
                            jack.chaney56

                            ntewinkel,

                             

                            Precisely what I was referring to. Fixed point for calculations saves tons and tons of calculation overhead and saves boatloads of memory. Time for my first contribution to the tools.

                             

                            Fixed point elements, the 16 bit solution

                            All data elements have like conversions, and a single set of units. All conversions are done externally to the device, or at the UI level.

                            Values are all maintained as integers types are:

                            • Temperature -> absolute degrees K * 100 (0 degrees C stored as 27315)
                            • Angle in binary radians 360 degrees converts to 32768
                            • Ratios are all fixed point * 1024 or 100% == 1024
                            • Pressure is stored in kPa * 100 absolute (1 atm stored as 10129)

                             

                            Limits of accuracy for equations are imposed based on 16 bit values

                            • angles (error +/- 0.0109 degrees)
                            • ratios < 6399.90% for unsigned or 3199.90% for signed (error +/- 0.049%)
                            • temperature < 655.35 degrees K or 382.20 degrees C (error +/- 0.005 degree C)
                            • pressure < 655.35 kPa or 6.47 atm (error +/- 50Pa)

                             

                            Additional limitations based on sensor measurement could be greater

                            History: [JAC] Original creation when the earth was cooling, Copyright(c) 2016 Chaney Firmware...  Use it as much as you like, as long as I get credit

                             

                            Jack

                            2 of 2 people found this helpful
                              • Re: If I Had a Hammer
                                jack.chaney56

                                I did want to add a small note for the selection of the units for angle and ratio.

                                Both of these are working on my conceptual approach of "thinking like a computer".

                                 

                                People use degrees or radians for angular measurements, computers don't really know the difference, if the radian is conceptualized as pi * a value for units, then altering the number system slightly affords the ability to make 2*214 instead of 2*pi. Then because a 16 bit integer offers +/- for direction of rotation 215 is used to represent 2pi. The other advantage of this is independent of + or - of angles, location is determined by simply masking off the highest bit. Try it with a few operations. Another added benefit will be presented in a future installment.

                                 

                                For ratio, this is simple because if you multiply by a ratio, you need to round and divide out the remainder in order to get back to a whole number portion. Using a power of 2 to represent 100% means, the divide instruction compiles to a right shift logical. In this case 10 bits. Also, rounding can be easily implemented by adding 512 (b0000000100000000) before the shift.

                                 

                                Because pressure and temperature are on opposite sides of my favorite pV=nRT the fact that both are multiplied by 100 provides self canceling.

                                 

                                Just thought I would explain,

                                Jack

                          • Re: If I Had a Hammer
                            Andy Clark (Workshopshed)

                            Back when I was doing karate, the students who had got to the top of their game went off and looked at other martial arts such as judo and taekwando. When they returned to karate their karate technique was better.

                             

                            This also works with software and hence it can be useful to look at other languages and areas to improve your own area. I've seen this myself bringing better code segregation and testing to VBA after a period with C#. I'm now doing all my hobby projects in NodeJS to see what that can bring.

                            1 of 1 people found this helpful
                            • Re: If I Had a Hammer
                              jack.chaney56

                              Needed to say something about tables versus formulas. For real time systems, tables always win.

                              • Given a non-linear curve where Y=f(x) and x is a measured value, the value at any point can be calculated using the function f(x)
                              • For simple linear equations accuracy is high and calculation can be performed simply with a single multiply and add
                              • For complex equations, accuracy becomes an issue, and the calculation can become difficult and time consuming.

                              • For short ranges, a linear interpolation can be used for a close approximation, but this becomes highly inaccurate outside a specified range

                              • Using fundamental calculus, if the range of delta X is distributed evenly, the linear interpolation between any two points more closely approximates any curve
                              • If greater accuracy is required the number of sections can be increased

                               

                              • By producing a table of these values, the equation becomes simple for any value Xn where Xn is between Xa and Xb
                              • The equation becomes:


                                 ƒ (X)=Ya+(((YbYa)·(XbXn))(XbXa) )

                                • Re: If I Had a Hammer
                                  jack.chaney56

                                  ...lost one of the diagrams

                                  2 of 2 people found this helpful
                                    • Re: If I Had a Hammer
                                      Instructorman

                                      I once had to calculate humidex in an 8-bit PIC microcontroller using the following formula - without using floating point:

                                      Humidex formula

                                       

                                      Yup, that got turned into a look up table faster than you can say "Holy Excel spreadsheet, Batman!"

                                        • Re: If I Had a Hammer
                                          koudelad

                                          One simple, but effective advice could be "learn to use spreadsheets and make graphs from them".

                                          I used Excel in practically all sensor applications, before implementing the formula to a microcontroller, just to check that the raw output values make sense to what is measured.

                                           

                                          • Recently I created a simple altimeter (hobbyist project) using an absolute pressure sensor. The barometric formula looks pretty hard to be calculated by a microcontroller:

                                          {P}=P_{b}\cdot \left[{\frac  {T_{b}}{T_{b}+L_{b}\cdot (h-h_{b})}}\right]^{{\textstyle {\frac  {g_{0}\cdot M}{R^{*}\cdot L_{b}}}}}

                                          or

                                          P=P_{b}\cdot \exp \left[{\frac  {-g_{0}\cdot M\cdot (h-h_{b})}{R^{*}\cdot T_{b}}}\right]

                                           

                                          However, using Excel, I found out that for a +/- 1000 m of altitude deviation is the pressure change ca. 11 Pa per 1 meter.

                                          One integer subtraction and an integer division is much simpler, even after considering the computation error.

                                           

                                          • Excel is also powerful to draw various graphs, calculate missing values and provide functions' approximations. This is especially useful when working with sensors that need to be calibrated (or were factory calibrated).

                                          The following graph shows an example of a function providing relative humidity value from  HTS221HTS221 sensor's raw output(using two calibration values It also shows that the sensors I have on my table are linear but the slope is a bit different And last but not least that the higher is the sensors output value the lower is the relative humidity(Please excuse the missing labels it was just a quick graph to demonstrate the point X axis shows relative humidity in rH Y axis shows an 16-bit signed output from the sensor

                                          2 of 2 people found this helpful
                                            • Re: If I Had a Hammer
                                              kas.lewis

                                              More information on how you did this would be great. Sounds like a greatly useful skill to have but not something a lot of us do have.

                                               

                                              Kas

                                                • Re: If I Had a Hammer
                                                  jack.chaney56

                                                  Hi kas.lewis

                                                  The process is part of a table lookup routine that I have in my toolbox. The process treats all tables as an NxM array, where N is the width and M is the height. The linkage to the data is done using a getter function so the data store can be abstracted.

                                                  The function passes X as a parameter of f(x). Because N is the width of the table, there are N elements in the array of equal spacing the max value for X is defined during design. For most cases in my work, I use the ratio element (described earlier) 1024. The delta (spacing between elements) can now be determined as dX = 1024/N.

                                                  The operation now needs two components, Xi which is the index into the table, and Xo witch is the offset from the index. The two values are obtained with the two operators, integer divide, and integer mod (remainder after division).

                                                  Xi = x / dX;

                                                  Xo = x % dX

                                                   

                                                  The getter function is called Z0 = getCal(table, x, y) using parameters of a table accessor, and the x and y indexes the function returns the content of the element (data type is determined by design).

                                                  The operation requires the indexed value and the next value in sequence or x(n) and x(n+1). However, if the table is N units the indexes only go from 0 to N-1, but if the divide operation returns N-1, N, which is the next element, is beyond the end of the array. To account for this, a linear extension is performed:

                                                  Z0 = getCal(table, Xi, y),

                                                  Z1 = Z0 + Z0 - getCal(table, (Xi - 1), y)

                                                  but for most cases it is simply Xi and (Xi + 1)

                                                   

                                                  Last, the interpolation is done as described before, this time with the defined variables  Z0+(((Z1Z0)·Xo)dX )

                                                  1 of 1 people found this helpful
                                                  • Re: If I Had a Hammer
                                                    koudelad

                                                    EDIT: My reply was quite long, so I decided to create a separate blog post from it: Using spreadsheets (Excel) for simple computations and approximations

                                                    I think there will be a huge amount of information over time in this thread, so it will be more readable for newcomers.

                                                     

                                                    David

                                                • Re: If I Had a Hammer
                                                  jack.chaney56

                                                  Hi Instructorman

                                                  I like the discussion of the baro sensor being used for altitude. The equations are good, and show step one of the process of developing an application. My intent of this forum was to provide tools and techniques to share with others in problem solving. So if you could, because you mentioned running into some hitches while working with standard packages like Excel, it would be extremely helpful if you would discuss what you did to overcome the issue in developing the embedded solution.

                                                  I can understand how a complex operation with  ex  and complex powers can become involved, especially with smaller processors that don't have floating point hardware. I have to perform pH conversion in many of the functions for our system, so I understand the headaches of dealing with log and anti-log operations.

                                                  So if you would be so kind as to expound on the tricks that got you to a final solution, that would prove helpful to the group.

                                                   

                                                  Thank you,

                                                  Jack

                                                    • Re: If I Had a Hammer
                                                      Instructorman

                                                        

                                                      Thanks jack.chaney56 for the coaxing.

                                                       

                                                      The work mentioned in my post was done for a client that owns the IP, so any discussion will be devoid of details, but I can describe the process I went through in general terms

                                                       

                                                      Actually, after reading rsc's post on the importance of documentation, which I completely agree with, and your follow up, I realized I would be relying on the quality of my own documentation to remember how I solved the tricky bits of getting an ex equation into an 8 bit PIC.  I worked on this problem back in 2010, so I remember that I did it, and that spread sheets and lookup tables were involved, but the details are not readily accessible in my working memory.  This is a great case study to illustrate why good documentation is so important.

                                                       

                                                      I have found the project files and started to reacquaint myself with the details.  Looks like we will soon find out if my documentation from 7 years ago was of sufficient quality to allow me to resurrect the methods and share them here.

                                                      I hope to post again in a few days with an explanation of how I solved the problem.

                                                       

                                                      Mark A.

                                                      • Re: If I Had a Hammer
                                                        koudelad

                                                        No big science happened there, I basically put all the constants, variables and the equation itself to a speadsheet and let the Excel calculate 10 000 values of an air pressure from 0 m to 10 000 m with a step of 1 m.

                                                        Then I calculated the pressure difference between each of the 1 meter zone and estimated the error. The trend line could also be added (as described in my previous comment) with some approximation. For implementation into a microcontroller, sometimes a simplified equation works, sometimes a lookup table.

                                                         

                                                        I was only interested in destinations easily reachable by a tourist (ca. 0 - 2500 m) in that case

                                                         

                                                        I wanted to emphasize that counting thousands of values to see the function behavior is just a matter of seconds for today's computers. And visualizing the data is often priceless.

                                                  • Re: If I Had a Hammer
                                                    DAB

                                                    Hi Jack,

                                                     

                                                    I completely agree about tables.

                                                    They are very fast, good enough and you can do approximation between values if you need them

                                                     

                                                    Back when I was programming 8085 processors, I built a single table that enabled me to do sine and cosine very quickly from the same table.

                                                    The time savings was immense, providing answers in a dozen microseconds verses using a math coprocessor that took milliseconds.

                                                     

                                                    When I build an integrated avionics simulator, I used tables for most functions and the run time result was very nice as opposed to trying to replicate all of the functions dynamically.

                                                     

                                                    Tables rule!

                                                     

                                                    If you look inside any real time game, you will find tables everywhere.

                                                     

                                                    DAB

                                                      • Re: If I Had a Hammer
                                                        jack.chaney56

                                                        DAB , I probably built the exact same table.  I was going to provide it as another installment for tips and tricks.

                                                         

                                                        If you build a 1/4 wave table using the binary radians that I described earlier, where 2pi = 215, bits 14 and 15 get used for determining the quadrant, and bits 0 through 13 get used for the table lookup.

                                                        The other trick to use is cos(n) = sin(n+8192) so everything comes out of the same table lookup.

                                                        if bit 15 == 1, return the negative value

                                                        if bit 14 == 1, use 8192 - n so the table reads backward.

                                                    • Re: If I Had a Hammer
                                                      rsc

                                                      The most important tip I can think of is to document what you do, both hardware and software.

                                                      When you get to the point you're writing code in several languages on several compilers for different projects,

                                                      it's easy to forget what formula you used for s subroutine, or what version of the program is in the machine today.

                                                      Always have a header in every file noting the last edit date, a change log, input and output variables, and any

                                                      derived formulas or assumptions about initial conditions.  I'm working on a project that uses NFC chips to track

                                                      software and hardware versions/changes.

                                                      Scott

                                                      1 of 1 people found this helpful
                                                        • Re: If I Had a Hammer
                                                          jack.chaney56

                                                          Can I have a "yay" for rsc (Scott)!!!  If I had a nickel for every time I have had to review what I have done over the course of the project.., So often the thing that kills greatness is the paperwork, or lack of it. The old saying is "if you have an hour to cut down a tree, spend 45min sharpening the saw".  Preparation and design should happen before any hardware or software gets implemented.  All the decisions about having something done in hardware, or in software should be determined with both groups represented in the room as well. Also, make sure you have the expertise to work with the tools you want to implement. I was on a project that decided to use FPGA components for a bundle of the routing circuits, but ran into a bit of a block when it was discovered the one person that knew how to design the FPGA firmware had exited a month before integration testing.

                                                           

                                                          Big time thank you,

                                                          Jack

                                                          • Re: If I Had a Hammer
                                                            DAB

                                                            As we used to say, the job isn't finished until the paperwork is done!

                                                             

                                                            Planning and the lack of documentation has killed more projects than I can count.

                                                             

                                                            After all, what good is a great build if nobody can figure out how to use it. (yes this is in reference to my last road test report.)

                                                             

                                                            DAB

                                                          • Re: If I Had a Hammer
                                                            kas.lewis

                                                            This is one awesome discussion, especially since some of this info might be really helpful in one of my upcoming projects.

                                                             

                                                            Kas

                                                            • Re: If I Had a Hammer
                                                              jack.chaney56

                                                              For people doing this as a hobby, I remember a relatively innocent posting* that showed up about 26 years ago today. Happy Birthday Linux

                                                               

                                                              Jack

                                                              * From: torvalds@klaava.Helsinki.FI (Linus Benedict Torvalds)
                                                              Newsgroups: comp.os.minix
                                                              Subject: What would you like to see most in minix?
                                                              Summary: small poll for my new operating system
                                                              Message-ID: <1991Aug25.205708.9541@klaava.Helsinki.FI>
                                                              Date: 25 Aug 91 20:57:08 GMT
                                                              Organization: University of Helsinki

                                                              Hello everybody out there using minix –

                                                              I’m doing a (free) operating system (just a hobby, won’t be big and
                                                              professional like gnu) for 386(486) AT clones. This has been brewing
                                                              since april, and is starting to get ready. I’d like any feedback on
                                                              things people like/dislike in minix, as my OS resembles it somewhat
                                                              (same physical layout of the file-system (due to practical reasons)
                                                              among other things).

                                                              I’ve currently ported bash(1.08) and gcc(1.40), and things seem to work.
                                                              This implies that I’ll get something practical within a few months, and
                                                              I’d like to know what features most people would want. Any suggestions
                                                              are welcome, but I won’t promise I’ll implement them :-)

                                                              Linus (torvalds@kruuna.helsinki.fi)

                                                              PS. Yes – it’s free of any minix code, and it has a multi-threaded fs.
                                                              It is NOT protable (uses 386 task switching etc), and it probably never
                                                              will support anything other than AT-harddisks, as that’s all I have :-(.

                                                              1 of 1 people found this helpful
                                                              • Re: If I Had a Hammer
                                                                jack.chaney56

                                                                Because this is a software focused discussion... I am giving a call-out for database folks out there.

                                                                 

                                                                SQL has become relevant as a language, and has stabilized to a general standard, so, how about some solutions to odd queries.

                                                                 

                                                                Jack

                                                                  • Re: If I Had a Hammer
                                                                    ntewinkel

                                                                    >how about some solutions to odd queries

                                                                     

                                                                    Versata did this quite well, with their "logic server". Most of a db based web application could be built with simple drag and drop. It was also quite easy to define specialized query objects using human-readable type of logic. You could build some very complex database queries without touching SQL.

                                                                     

                                                                    They got bought out by Trilogy, but I think the software is still there under some new name.

                                                                    Versata BRMS | Built for Big Business

                                                                     

                                                                    The same person who created that idea went on to later help form Espresso Logic, which has since been bought out by CA. https://www.ca.com/us/products/ca-live-api-creator.html

                                                                     

                                                                    Not sure how deep they've gotten into the magical SQL queries with the new product.

                                                                     

                                                                    (I worked for Versata in the early 2000s, before the dot-com bubble burst)

                                                                     

                                                                    Cheers,

                                                                    -Nico

                                                                  • Re: If I Had a Hammer
                                                                    jack.chaney56

                                                                    More software for falling objects, or phun with physics.  This one comes from my video gaming days, and once again showing floating point is highly overrated.

                                                                     

                                                                    First, units need to be abstracted, so they can be optimized to relate to real time and a form the computer understands, so let's start with time. The units for time, I like to use, are tics (not the bug). A tic is usually an update frequency of some sort. In my gaming days, it was usually 1/30th second (screen update), but lately for my engine management stuff, I upped it to 1mS.  For this I will go with the old tried and true,1/30th second.

                                                                     

                                                                    For distance, the unit I use is generically "dist", the advantage is, equations now become scale-able, based on the size of the playing field. Speed is always in units of dist/tic, and acceleration is dist/tic2.  In a coordinate universe, up is usually considered a positive direction, and gravity always has a downward action.  For this discussion we won't go into relative viewpoint stuff, because when the physicist was asked "what's up!?", she responded "why, the opposite direction from the local gravitational center". Back to our relative universe, up is the positive vector on the z axis. I need to establish that, because in a "first person" game play, gravity is often constant.  Looking up the information in my handy CRC Handbook of Chemistry and Physics, it says, acceleration due to gravity is -9.8m/s2 at earth's surface, and defining our unit dist as 1/4 inch we can make our conversion.

                                                                     

                                                                    meter     1000mm        1in            4dist        1sec2

                                                                    ------- = ------------ * ------------ * ---------- * -----------

                                                                    sec2        meter         25.4mm        in          900tic2

                                                                     

                                                                    and -9.8m/s2 works out to -1.7148dist/tic2 for integer operations -1 817/1143 dist/tic2

                                                                     

                                                                    Switching over to vector operations (of sorts), if an object at (x,y,z) is moving at motion vector [X,Y,Z], then at each tic the new object position will be (x+X, y+Y, z+Z). Also, for each tic acceleration action is accounted, and motion vector [X,Y,Z] is updated by {A,B,C} and the new motion vector is [X+A, Y+B, Z+C]. The acceleration due to gravity is {0, 0, -1 817/1143}.

                                                                     

                                                                    Now, how to deal with that pesky fractional part. It is the imposed error and is managed rather simply by using an error/correction method. In each instance, the numerator is added to the error (error starts as 0). so the first instance the result is 817, the second is 1634. When the error value is greater than the denominator, the motion vector gets an additional increment. In our gravity case subtract one more from [Z], then subtract the denominator from the error value.  The operation progresses 1634 - 1143, and the error value is now 491. The third instance the error is updated to 1308 and the value is greater than the denominator, so Z gets an extra 1 subtracted, and the error is corrected to 165. The pattern continues and gravity behaves exactly as expected.

                                                                     

                                                                    One more thing to consider. Because object(s) means there is more than one, and the operation gets repeated many times, and gravity isn't the only acceleration involved, error value should have a common denominator, so all the error values can just get added, and tested as a last step.  I like to use 1024, because it is large enough to manage a good amount of error, and if necessary it can be corrected using a logical shift.  This explains why I used it in my standard units for fixed point ratio.