Main Content

Getting Started with Texas Instruments C2000 Microcontroller Blockset

This example shows you how to use C2000™ Microcontroller Blockset to run a Simulink® model on Texas Instruments™ C2000 hardware.

Introduction

C2000™ Microcontroller Blockset enables you to generate a real-time executable and download it to your TI development board. The blockset includes a library of Simulink blocks for configuring and accessing Texas Instruments C2000 peripherals and communication interfaces. In this example you will learn how to configure a simple Simulink model to generate code for any TI C2000 hardware and to run the generated code on the board to periodically turn an LED on and off. This example shows you how to configure two different models to run in different CPU cores.

Prerequisites

If you are new to Simulink, we recommend completing the:

Required Hardware

To run this example, you can use any TI C2000 hardware. For your convenience, the following hardware models are preconfigured to execute the example:

  • c2838x_cpu1_blink - TI F2838x(C28x) ControlCard and 180 pin ControlCard Docking Station

Model

Task 1 - Create, Configure and Run the Model for TI Piccolo F28069M LaunchPad (Single Core)

In this task you will create and configure a simple model blinking an on-board LED to run on TI Piccolo F28069M LaunchPad (Single core).

1. Enter slLibraryBrowser at the MATLAB® prompt. This opens the Simulink Library Browser.

2. In the Simulink Library Browser, navigate to Libraries > C2000™ Microcontroller Blockset and select C2806x processor.

3. Double-click the GPIO block. Review the block mask, which contains a description of the block and parameters for configuring the associated user GPIO.

4. In MATLAB, select HOME > New > Simulink Model.

5. Drag the GPIO block from C2806x library to the model.

6. Drag the Constant block from Simulink library to the model.

7. Connect the output of the Constant block to either one of the corresponding input of each GPIO block. Configure the GPIO and Constant block as follows:

  • a. Configure GPIO block with pin 39 for blue LED or with pin 34 for red LED.

  • b. Ensure the Toggle GPIO option is enabled. Enabling this option will toggle the GPIO pin when input passed to this block is 1. The rate of toggle will be based on the sample time of the input.

  • c. For Constant block, specify the sample time (0.5). Since the toggle option is enabled in GPIO block, this ensures GPIO is 1 for period of 0.5 sec and 0 for 0.5 secs. So, the period of the waveform is 1 sec.

8. Save your model and connect the TI Piccolo F28069M LaunchPad to your computer with a USB cable.

9. Open the saved model to configure the model for F28069M Launchpad:

  • a. Open the Modeling tab and press Ctrl+E (Model settings) to open Configuration Parameters dialog box.

  • b. Go to Hardware Implementation > Hardware board and select TI Piccolo F2806M LaunchPad.

  • c. Ensure Boot from Flash is enabled if the application has to load to the flash. If you do not select this option, the application loads to the RAM.

  • d. Click OK.

10. Go to the Hardware tab and click Build, Deploy & Start to generate code for the model and deploy the executable.

11. The generated code is built and run on the F28069M Launchpad automatically. When the model starts running on the F28069M Launchpad, observe that the user LED on the board blinks with a period of 1 second.

12. Save your model. A c28069_blink preconfigured model is included for your convenience.

Task 2 - Create, Configure and Run the Model for TI Delfino F28379D LaunchPad (Dual Core)

In this task you will create and configure a simple model blinking an on-board LED to run on F28379D Launchpad (Dual core).

F2837xD is a Dual core. You can create 2 models. One each for c28379D_cpu1_blink and c28379D_cpu2_blink to generate 2 separate executables.

Create a Model for CPU1 of F28379D

1. Enter slLibraryBrowser at the MATLAB prompt. This opens the Simulink Library Browser.

2. In the Simulink Library Browser, navigate to Libraries > C2000™ Microcontroller Blockset and select F2837xD processor.

3. Double-click the GPIO block. Review the block mask, which contains a description of the block and parameters for configuring the associated user GPIO.

4. Perform steps 4 to 8 of Task 1 for TI Delfino F28379D LaunchPad. For this task, configure GPIO block with pin 34 for red LED.

5. Select the TI Delfino F28379D LaunchPad and verify the CPU used for your model. For this task, select CPU1. This selection creates and downloads the executable for CPU1.

6. Go to the Hardware tab and click Build, Deploy & Start to generate code for the model and deploy the executable.

7. The generated code is built and run on the F28379D Launchpad automatically. When the model starts running on the F28379D Launchpad, observe that the user LED on the board blinks with a period of 1 second.

8. Save your model. A c28379D_cpu1_blink preconfigured model is included for your convenience.

Create a Model for CPU2 of F28379D

Since TI Delfino F28379D LaunchPad is a dual core processor, you can create a similar model using CPU2 option and blink the LED.

1. Perform the steps 1 to 4 of Task 2 for TI Delfino F28379D LaunchPad.

2. Select the TI Delfino F28379D LaunchPad and verify the CPU used for your model. For this task, select CPU2 and configure GPIO block with pin 31 for blue LED. This selection creates and downloads the executable for CPU2.

3. The generated code is built and run on the F28379D Launchpad automatically. When the model starts running on the F28379D Launchpad, observe that the user LED on the board blinks with a period of 1 second.

4. Save your model. A c28379D_cpu2_blink preconfigured model is included for your convenience.

Note:

  • Do not use the GPIO pins is used in CPU1.

  • Ensure that peripherals used in CPU1 are not used in CPU2. If same peripherals are used in CPU1 and CPU2, the model may not work as expected.

By creating 2 models for TI Delfino F28379D LaunchPad, you can blink 2 LED's. One from CPU1 and another with CPU2.

Task 3 - Create, Configure and Run the Model for F2838x (Multi-Core) Processor

In this task you will create and configure a simple model blinking an on-board LED to run on F2838x (Multi-core).

F2838x is a Multi-core processor. You can create 3 models to generate 3 separate executables for:

For CPU1 and CPU2 of F2838x(C28x)

1. Enter slLibraryBrowser at the MATLAB prompt. This opens the Simulink Library Browser.

2. In the Simulink Library Browser, navigate to Libraries > C2000™ Microcontroller Blockset > F2838x > Select F2838x_C28x processor.

3. Double-click the GPIO block. Review the block mask, which contains a description of the block and parameters for configuring the associated user GPIO.

4. Create CPU1 and CPU2 model by performing the steps 4 to 8 of Task 2 for F2838x(C28x) processor.

5. A preconfigured model (c2838x_cpu1_blink CPU1 and c2838x_cpu2_blink CPU2) is included for your convenience.

Note: Do not use the same GPIO pins used in CPU1 and CPU2.

For ARM Cortex-M4 of F2838x_M4

1. Enter slLibraryBrowser at the MATLAB prompt. This opens the Simulink® Library Browser.

2. In the Simulink Library Browser, navigate to Libraries > C2000™ Microcontroller Blockset > F2838x > Select F2838x_M4 processor.

3. Double-click the GPIO block. Review the block mask, which contains a description of the block and parameters for configuring the associated user GPIO.

4. Perform the steps 4 to 7 of Task 1 for F2838x-M4 processor and save the model.

Note: While configuring the GPIO pin, select the appropriate pin applicable for ARM Cortex-M4 processor. Do not use same GPIO pins used in CPU1 or CPU2.

5. Open the saved model to configure the model for F2838x-M4:

  • a. Open the Modeling tab and press Ctrl+E (Model settings) to open Configuration Parameters dialog box.

  • b. Go to Hardware Implementation > Hardware board and select TI F2838x. In the Processing Unit, select *CortexM4.

  • c. Ensure Boot from Flash is enabled if the application has to load to the flash. If you do not select this option, the application loads to the RAM.

  • d. Click OK.

6. Go to the Hardware tab and click Build, Deploy & Start to generate code for the model and deploy the executable.

7. The generated code is built on the F2838x (ARM Cortex-M4) and run automatically. When the model starts running on the F2838x (ARM Cortex-M4), observe GPIO pin toggling with a period of 1 second.

8. Save your model. A c2838x_armm4_blink preconfigured model is included for your convenience.

Note: For Multicore processor like F2838x, try Interchanging the GPIO's between CPU2 and ARM Cortex-M4 or CPU1 and ARM Cortex-M4 and observe the LED blink.

Other Things to Try

Experiment with other blocks in the Texas Instruments C2000 Processors Block Library. For example:

  • Create and run a model that repeatedly blinks an LED using the Pulse Generator block.

  • Create and run a model that repeatedly blinks an LED using the external mode example.