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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
09/08/08 14:15
Read: times


 
#158069 - Take a look at the ranges
Responding to: ???'s previous message
Taking a look at the number range you want to get to will give some insight to how to scale with ints. You want decminal numbers 0-255 to scale to decimal numbers 1192 to 2216. The range of your incoming data is 256 levels and the range of your out doing data is 1025 levels, sounds like an almost perfect match for times 4 + an offset.

HC_Gain_scaled = (pot_level * 4) + HC_GAIN_LOW;


Now this will make it so 255 only scales to 2122 instead of 2216. If you need these last 4 you can shift it up by 2 and leave off the bottom 2 and top 2 perhaps. In that case your range would be 1194 to 2214. Otherwise you might want to move up to using longs as suggested by Christoph.

List of 15 messages in thread
TopicAuthorDate
Scale offset using ints by byte position location            01/01/70 00:00      
   Does type casting make sense here?...            01/01/70 00:00      
      Show us more.........            01/01/70 00:00      
         Here are defs and original function            01/01/70 00:00      
      ints, at leastin Keil, at 16 bits wide.            01/01/70 00:00      
         Christoph,            01/01/70 00:00      
            That makes things clearer.            01/01/70 00:00      
               A detail            01/01/70 00:00      
            Take a look at the ranges            01/01/70 00:00      
               Brett, that is helpful, I should add....            01/01/70 00:00      
                  No floating-point math required.            01/01/70 00:00      
   Its working but I have a question on theory            01/01/70 00:00      
      Rounding instead of truncate            01/01/70 00:00      
         oh, that is interesting            01/01/70 00:00      
         Russ' comment is right, though.            01/01/70 00:00      

Back to Subject List