doppelhub / MuddersMIMA

Mudders Take on Manual IMA Control in the G1 Honda Insight
GNU General Public License v3.0
2 stars 4 forks source link

Enable correct RPM calculation #2

Closed Hurricos closed 3 months ago

Hurricos commented 9 months ago

The two commits in this PR enable correct RPM calculation, which was not working before.

Tested-by: Martin Kennedy hurricos@gmail.com

Addenda

I should probably write up a more complete testing procedure so I can document an A/B test.

Hurricos commented 7 months ago

Here is my complete A/B test of each of these commits:

Test procedure for e69d832ce08c7b72398149d7e28ec54ebe8b23c4 (RPM fixup pull request):

Hurricos commented 3 months ago

Can you optimize the "2/3" math, so the preprocessor only has to perform one division operation? Ideally '2' & '3' are both #define statements, too, so that they aren't magic numbers. Proposed implementation: "(ONE_MINUTE_IN_MICROSECONDS * ENGINE_REVOLUTIONS / NUM_TACHOMETER_PULSES) / periodBetweenTicks_us". The preprocessor will perform all constant-only math if it's all grouped together.

Done in commit a3f07010d2c54cef7d47a523ea9c4201bbf4217b. For other readers, godbolt.org with AVR GCC 13.2.0 and with flags -Os has this function going down from 0x92 bytes to 0x80 bytes: godbolt.org

Given that this is an ISR that runs once per engine pulse, these are important savings.