Skip to content

[Usage]: Using high level quantities in small embedded systems without floating point unit #790

@Jay20194

Description

@Jay20194

Organization Type

Individual Developer

Organization Name (Optional)

No response

Primary Domain/Industry

IoT/Embedded Systems

Other Domain (if selected above)

No response

Project Stage

Production/Deployed

Development Team Size

Just me (1)

Use Case Description

I am using mp_units to do have a proper abstraction layer for quantity handling in an embedded system.
The current project is a throttle position controller, where I implemented my own derived quantities for angular positions and speeds expressed in percent but degree.
Because the used microcontroller, STM32F1, has no floating point unit I am using custom representation types based in CNL.
This combination enables my to calculate with quantities without the hassle of conversions, without the runtime cost of floating point calculations.

This is a hobby project, that is not distributed anywhere, but in my car on a race track ;)

Features Used

  • Basic quantity arithmetic (addition, subtraction, multiplication, division)
  • Unit conversions (m to km, s to h, etc.)
  • Dimensional analysis and compile-time validation
  • Custom units and dimensions
  • Quantity points
  • Text formatting and I/O
  • C++ modules support
  • Interoperability with other libraries
  • SI unit system
  • Other unit systems (CGS, Imperial, etc.)
  • Natural units
  • Freestanding mode

Key Benefits Experienced

  • much more expressive code, because I removed all the magic numbers to "convert" numbers after each calculation
  • simpler to write correct calculations, because using the unit symbols is enough, to get the expected result
  • output of unit tests is simpler to understand with unit symbols in text output
  • my old implementation with raw numbers and fixedpoint with base 10 took 120us to execute my main control loop. The switch to mp_units + CNL lowered it to 85us. The main impact was the switch from fixedpoint base 10 to base 2 (divisions turned into bit shifts) but mp_units was the enabler to do this change. (Debug build on target hardware STM32F103)

Impact on Your Project

Very helpful - Significant improvements

Usage Permissions

  • You can use our testimonial in documentation and presentations
  • You can mention our organization name publicly

Metadata

Metadata

Assignees

Labels

usage experienceUsage experience story from our form

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions