MUR Blog - Efficiently Programming Data Acquisition Systems

From Formula 1 to Formula SAE (FSAE), being aware of exactly how your car is performing on track is imperative to allow for proper maintenance and constant improvements of the vehicle.  This is where data acquisition systems (DAQ) come into play. Unfortunately, programming these systems aren’t always easy.  Here’s our experience and how we’ve managed to do so with the help of the MathWorks Simulink1 Embedded Coder2 software package. Common problems with programming DAQs or any automotive system includes reliability, changing needs and programmers who are unfamiliar with the hardware or programming standards.

When programming any embedded system that will likely have a long life, the key is to code for maintainability. This includes both porting the code to new platforms, and easily extending or changing portions of the code. Problems like these are neatly avoided by using the Simulink Embedded Coder. All platform-specific functions are neatly segmented into their own blocks with data processing and storage separated individually. Another advantage of the platform over coding directly in C or a language similar to C is the ability to ensure that no undesired data is lost.  Data loss usually results from accidentally casting into a different data type. Using platforms ensure correct units are used (e.g. converting between metric and imperial units), increases the speed of coding times and the ability to guarantee valid inputs into functions with the use of menus.


An Example Piece of Code Reading a Steering Angle Sensor and Transmitting it over a CAN bus After Conversion and Verification

One final feature that is very relevant for programming a DAQ is the ability to individually set sampling times and have the Simulink compiler deal with scheduling. This is also useful for other real-time applications like audio processing and automation. As can be seen in the model above, the model is simple and easy to understand. Data is easy to route around and pass through processing stages into outputs. Each section of the model can be changed independently, so that the above steering angle module can be worked on independently from other sensors, such as a wheel speed sensor or accelerometer. This is perfect for team work like FSAE as work can be done in parallel and be easily edited. In particular, when temporary sensors are added or if the project scope is expanded.

Besides the Simulink Embedded Coder, other options for programming tools include C with platform-specific libraries, Python on a more fully-featured device, or even Haskell, which has been attempted by another FSAE team. Due to the perks mentioned earlier on in the article, MUR is using Simulink to program our custom DAQ, as well as our motor controller algorithms and battery management system. Thus far, our experience working with Simulink has been very simple and rewarding. Bug fixing has been minimal as once a block is perfected, it’s only possible to introduce algorithmic bugs into the code. Initially, the board we chose to use for our project didn’t have Simulink support; therefore, we had to add it in. We did this by using the legacy code tool3 in MATLAB4 to convert C code we had written and compiled it from the model into C for use by Texas Instruments5’ C compiler for our Tiva microprocessor. The process of adding support was initially slow as we had to both learn how to use the microprocessor’s libraries and the legacy code tool correctly, plus ensure we had written code in the best way to implement this. However, with only a little bit of practice, we can write one module to include all necessary peripheral interface blocks, in approximately 4 hours including testing. Although more complex modules can take a bit longer, most of this time is spent learning how that module on the microcontroller works.

2 Our Prototype Data Acquisition Board

Testing is also interesting using Simulink, as it’s easy to change platform. As such, it’s possible to take the code and test it in MATLAB by only making alterations in the input section of the code. This lets us test how well our code runs as well as check for bugs in the logic of the code. There are also a number of validation tools available in Simulink, which are used to seek out any potential problems in a quick and consistent way. These tools provide us with a detailed report and helps ensure that we don’t accidentally do anything that is a problem, like use floating point numbers in code where they shouldn’t exist…

If you’ve made it this far, you can clearly see that the Simulink Embedded Coder is a useful tool for any real-time application by significantly decreasing the time needed to spend developing code. We also expect it to be useful for data processing too, as we can quickly run through the data we’ve collected and model how the car would react to real stimuli. Thus, allowing us to do what we do best – making the car go fast!

Want to hear more from us? Sign up here (embed sign up link) and never miss a post! No spam, promise.

About the Author:


Nicholas Hunn
Senior Low Voltage Engineer, 2017


  1. Simulink: 
    A block diagram environment for multidomain simulation and Model-Based Design. It supports simulation, automatic code generation, and continuous test and verification of embedded systems. Simulink provides a graphical editor, customizable block libraries, and solvers for modeling and simulating dynamic systems. It is integrated with MATLAB®, enabling you to incorporate MATLAB algorithms into models and export simulation results to MATLAB for further analysis.
  2. Embedded Coder:
    A software which enables additional MATLAB Coder™ and Simulink Coder™ configuration options and advanced optimizations for fine-grain control of the generated code’s functions, files, and data. These optimizations improve code efficiency and facilitate integration with legacy code, data types, and calibration parameters used in production.
  3. Legacy code tool:
    A MATLAB tool that allows integration of existing C, C++ or Fortran code into Simulink models.
    A multi-paradigm numerical computing environment and programming language developed by Mathworks. Provides many tools for implementation of algorithms, data analysis, interfacing with other languages and mathematical operations
  5. Texas Instruments:
    A global semiconductor design & manufacturing company.