Page 334 - Programming Microcontrollers in C
P. 334

Table Look-up    319

            Table Look-Up

                          Often in the implementation of a practical problem it is necessary to
                          implement a conversion of data in a completely heuristic manner.
                          Observations are made and a curve of sorts is fit to the data. It is then
                          desired to put a few samples of this curve into a data table and then
                          calculate values between these samples with an accuracy that usually
                          requires interpolation between the points contained in the data table.
                          Such tables are usually sparse in that the number of measured points
                          across the range covered by the table are few. The curve in Figure
                          6-1 shows an example of such a conversion table, and the table itself
                          is shown as Table 6-3.

                          250

                          200


                          150

                          100

                           50


                            0
                             20             40             80            120            180
                              Figure 6-1: Data Conversion Curve


                                                              X        Y

                                                              20        5
                                                              40       15
                                                              80       50
                                                             120      120
                                                             180      240
                              Table 6-3: Look-Up Table


                              The object of the program is to deliver to the program a number
                          like 67 and get the proper result back from the table look-up routine.
                          The x value of 67 lies between the 40 and the 80 entry in the table.
                          Therefore, the interpolation calculation needed in this case is
   329   330   331   332   333   334   335   336   337   338   339