CarletonURocketry / avionics-software

CU InSpace's avionics software
https://cuinspace.wordpress.com
MIT License
10 stars 3 forks source link

Investigate Use of Fixed Point Math in MS5611 Driver #19

Closed samueldewan closed 3 years ago

samueldewan commented 5 years ago

Investigate Use of Fixed Point Math in MS5611 Driver

What Needs to be Done

Currently the MS5611 driver makes use of a fairly significant amount of floating point arithmetic in order to calculate the altitude from the pressure value returned by the sensor. The altitude is stored as a floating point value, which will necessitate more floating point math in order to perform comparisons in the main flight state machine code. In order to improve performance, it may be possible to use fixed point math instead of floating point. We need to investigate this possibility and determine if it is feasible to convert the existing code to fixed point without loosing any precision and whether it is worth the development time.

The first step would probably be to try and implement the existing algorithm using fixed point math in a test bench to see if it works. An appropriate number format will need to be found (how many whole/fractional bits are required to represent any possible altitude value as well as the intermediate values used in the calculations) and functions will need to be written (first in C, maybe in assembly later) to perform the required arithmetic operations on the chosen number format. The required calculations included a fractional power, which may be difficult to implement.

What has Been Done

The math required in the MS5611 has been implemented using floating point in ms5611.c.

Reference Material

Wikipedia article on Q format numbers

Document from ARM on fixed point math

This GitHub repository has some implementation of fixed point operations for cortex-m in assembly, but it can't be used directly as it is for larger M3 and M4 parts

Who is This For

The person who takes on this issue should know some C, possibly some ARM assembly and should be interested in experimenting with some math.

Timeline

This task should be completed by the end of February 2020.

samueldewan commented 3 years ago

We don't seem to be encountering any performance problems with the floating point path, and the SAME54 microcontroller we are moving to for the rocket has an FPU. I don't think this issue is worth spending any time on anymore.