View Single Post
Old 04-06-2014, 08:32 PM   #6410 (permalink)
Astro
Dreamer
 
Join Date: Nov 2013
Location: Australia
Posts: 350
Thanks: 95
Thanked 214 Times in 151 Posts
Quote:
Originally Posted by MPaulHolmes View Post
Here's the modified throttleAverage code, as a sample. Thanks for the suggestion, Astro! I'm making the same change to pwmAverage and temperatureAverage. Totally unreadable, but pretty fast. haha:
Code:
throttleAverageTimes1024   //    = (31*throttleAverageTimes1024)/1024 + 1*ADThrottle) / 32 * 1024;
                           //    = 32*(throttleAverageTimes1024/1024) - 1*(throttleAverageTimes1024/1024) + 1*ADThrottle) / 32 * 1024; 

= ((throttleAverageTimes1024 >> 5) - (throttleAverageTimes1024 >> 10) + (long)ADThrottle) << 5;
I had to look up a wiki to find out what >> did in C programming language.
(One day i will have to learn C.)
A bitwise shift. Very neat.
Sometimes readability needs to take a back seat to performance. After all that's what comments are for.
  Reply With Quote
The Following User Says Thank You to Astro For This Useful Post:
MPaulHolmes (04-06-2014)