Main Content

MAT-file Logging on SD Card for Texas Instruments C2000 Processors

This example shows you how to perform MAT-file logging using Simulink® model on a Micro SD card mounted on Texas Instruments™ C2000™ Microcontroller Blockset.

Introduction

C2000™ Microcontroller Blockset supports logging of signals from Simulink® model. These signals are logged as MAT-file(s) on a Micro SD card mounted on Texas Instruments™ C2000™ Processors.

Signal logging enables you to monitor the signal behavior and to perform any historical analysis of the data. The data can be saved in any of these formats: Structure, Structure with time, or Array. You can save the signals using the following blocks:

  • To Workspace

  • Scope

  • Output port

This example provides you with the workflow to enable MAT-file logging and obtain the MAT-file on a Micro SD card mounted on Texas Instruments™ C2000™ Processors.

Required Hardware

To run this example, you need the following hardware:

  • Texas Instruments™ C2000™ Processors

  • External SD card interface(optional)

  • Micro SD card

Hardware Connection(For External SD Card Interface)

  • For the external SD card interface, based on the SPI module selected, the SIMO, SOMI, CLK and STE pin has to connected to corresponding GPIO pins of C2000 processor.

  • Connect VCC and GND pins to appropriate supply and ground.

Step 1 - Prepare the Connection and Configure a Simulink Model for MAT-File Logging

The MAT-file logging needs to be configured on the Simulink® model so that the selected signals are logged on the Micro SD card on Texas Instruments™ C2000™ Processors.

1. Insert the Micro SD card in the slot provided on the board.

2. Open the c28x_matfile_logging.slx model. This Simulink model is pre-configured for the TI Delfino F2837xD with MAT-File logging enabled. In this example, signals from the Scope block are logged.

3. In your model window, open the Configuration Parameters dialog box, go to the Hardware Implementation pane, and select the name of the target hardware from the Hardware board list. If required, you can change the Hardware board selection other than pre-configured F2837xD.

4. To enable MAT-file logging, go to Target hardware resources > SD card logging. Select the Enable MAT-file logging on SD card checkbox. Also select the desired SPI module and SPI baud rate and ensure in the SPI_x pane that all configurations are as required.

5. Click Apply and then OK.

6. Double-click the Scope block in the Simulink model. In the Scope dialog box, click the gear icon (Configuration Properties).

7. In the Configuration Properties: Scope dialog box, open the Logging tab, and select Log data to Workspace. Also select Limit data points to last and set a value of 512.

8. Select the Save format as Array/Structure with Time/Structure and click Apply and then OK.

9. On the Modeling tab, enter a value for the stop time. This is the duration for which the signal is logged. However, the model continues to run on the hardware and it is not affected by the time specified.

For example, in this demo model c28x_matfile_logging.slx, the stop time is 10. The signal will be logged for 10 seconds. If the stop time is Inf, the signal will be logged till the Micro SD card is full or the board is disconnected.

Step 2 - Deploy the Model on Texas Instruments C2000 Processors and View the MAT-files

After the Simulink model is configured for MAT-file logging, you can deploy the model on the connected Texas Instruments C2000 Processors and view the MAT-file(s) created on the Micro SD card.

Tip: To learn more about logging data, see Configure Model to Log Signals on SD Card.

1. In the Simulink model, go to Hardware tab and click Build, Deploy & Start button. The build process for the model starts and it is deployed on the Texas Instruments C2000 Processors board. On successful deployment of the model, the LED on the board starts blinking.

Note: For processor other than F2837xD, you have to replace the Digital Output block and select the appropriate GPIO pin for LED blinking.

2. To view the logged MAT-files, remove the Micro SD card from the board after the simulation time, and insert the card on your computer.

If the deployment of the model was successful, the MAT-files are generated on the Micro SD card as shown below:

After importing the MAT-files to your computer, you can use it for further analysis in MATLAB®.

Because the model running on the hardware creates multiple MAT-files, the logged data points are distributed across the generated MAT-files. You can create a stitcher function to combine these MAT-files into a single MAT-file that contains all the logged data points. To view an example of a MAT-file stitcher and understand its usage, enter the following command in the MATLAB® command window.

edit('c28x_MAT_stitcher.m');

Other things to try with MAT-file Logging on SD Card

In this example, a Scope block is used to log signals. However, the signals in a Simulink® model can also be logged on the SD card using the To Workspace block or by logging the output(s) of the Simulink® model. Explore the MAT-file logging of a Simulink model using these two techniques.

Related Topics

Configure Model to Log Signals on SD Card