| ??? 08/24/00 13:43 Read: times |
#4681 - RE: Making speedometer with 8051: |
Babar,
Its easier than all that. Think about the problem backwards. You want a display in kilometers per hour displayed in LED or LCD numerics of limited digit count. Now figure out how many classes of answers you want displayed and precompute the thresholds for each class. For example... If you wanted to do two digits with no decimal point... you have 00 to 99 classes of answers. Now precompute the revolution count for each class upper limit and map those values into a quick lookup. You can use a binary search technique to quickly find the address of the class that the sample fits and map that to a decimal readout. For 00-99km, you'd be able to map a binary tree as 128 classes. That would take only 7 comparisons to find where your sample belongs in the 00-99 range. Rather than have a table entry for each class containging the two digits for the display, I'd use the address of the class found and make a simple mapping on that address offset magnitude. Using this technique, which is scalable up, is very fast. 00-99 would take only 128 or 256 bytes of CODE space and could be looked up in just 7 or so comparisons. You don't need pointers either fr the binary search as the unchanging data addresses can be inferred. I have a technique that very very fast but it wouldn't be needed in your application. -Jay C. Box |



