| ??? 08/24/00 16:31 Read: times |
#4684 - RE: Making speedometer with 8051: |
Ben,
Its called a "binary search" in computer science. The binary effectively means dividing sets into twos. The trick is to precompute the data and structure it into strategically placed data. I use MS Excel for this and format the results into datablock statements that I capture and insert into my code. The subject of binary searches usually involves pointers for each cell and this is quite useful in dynamic data, but our example of the speedometer never chages the datablock. The pointers can be replaced with inferred addressing. A little intro to Binary tree depth in this application: Say I get an 8 bit counter result from a timer when the bicylce wheel completes one revolution (16 bits may be used at the cost of more overhead). This value is "X". Since a binary tree by definition splits the possibilities in two at every comparison, it would start like this: (0) there are 128 8-bit values in the table each representing the maximum value for its display equivalent: 00-99 (1) compare X to the midpoint of the table. If its greater than that value, move to high half else the low half. With this one comparison, 64 values have been ruled out. (2) compare X to the midpoint of the remaining set of valid choises (high 64 or low 64). The comparison decides if its in the remaining high 32 or low 32 set. (3) Each comparison splits the possibilities as follows: 128 classes: 1st comparison: 1 in 64 2nd comparison: 1 in 32 3rd comparison: 1 in 16 4th comparison: 1 in 8 5th comparison: 1 in 4 6th comparison: 1 in 2 7th comparison: 1 in 1 (found) (4) the trick is how the data is accessed to make it automatic. There is a special ordering that makes it very fast and easy, but a diminishing range into the list approach is good enough. When I do this type of code, its a very small djnz loop but the data has to be cleverly ordered. :) -Jay C. Box |



