Embedded Coder

Using the Control Law Accelerator (CLA)

This example shows how to take advantage of the Control Law Accelerator (CLA) available on some of the TI Piccolo processors.

TI C2000 Support from Embedded Coder

Required Hardware:

For the LED blinking example:

  • TI® Piccolo F28069 or F28035 board

For the motor control application example:

  • TI® DRV8312 Three-Phase Brushless Motor Control Kit (DRV8312-C2-KIT or DRV8312-69M-KIT) with F28035 or F28069 Piccolo processor
  • Three-phase PMSM with Hall sensors attached to connector J10 of the DRV8312EVM board

Available Versions of This Example:

  • F28035 Piccolo: c28035blink_cla.mdl
  • F28069 Piccolo: c28069blink_cla.mdl
  • DRV8312 + F28069 Piccolo: c28069pmsmfoc_cla.mdl
  • DRV8312 + F28035 Piccolo: c28035pmsmfoc_cla.mdl

Copyright 2013 The MathWorks.

Contents

Model

The following figure shows an example model configured to take advantage of the CLA available on the hardware.

Description

This example shows how to generate code for a Simulink® model where one part of the algorithm runs on the Control Law Accelerator (CLA) available on the device. The CLA is a coprocessor that allows parallel processing. Using the CLA for time-critical tasks frees up the main CPU to perform other system and communication functions concurrently.

Limitations

Interactions between the CLA and the C28x CPU, along with CLA C compiler limitations, force specific modeling practices. Below is a list of concepts that reflect modeling practices described in this example:

  • The CLA application code can only be triggered from a C28x interrupt.
  • All the interfaces between CLA and CPU need to be placed in specific memory locations. The CpuToCla1MsgRAM memory section is used to exchange data from the C28x to the CLA. The Cla1ToCpuMsgRAM memory section is used to exchange data from the CLA to the C28x.
  • The CLA application code does not have access to global variables.
  • The CLA C compiler supports only two levels of function calls. CLA interrupt service routines may call leaf functions only. Leaf functions may not call other functions.
  • Recursive function calls are not supported.
  • Integer division, modulus, and integer unsigned comparison are not supported with the CLA C compiler.

For more details and an exhaustive list of limitations visit the TI web site.

These limitations have to be considered when modeling in Simulink. The following example shows how to trigger a CLA task, exchange data from the C28x CPU to the CLA using memory sections like CpuToCla1MsgRAM and Cla1ToCpuMsgRAM, schedule C28x interrupts at the end of the CLA task, and replace the standard linker command file to include CLA specific linking attributes.

Using the CLA with an LED Blinking Example

CLA Task Block

In the model c28069blink_cla.mdl, a CLA Task block is provided from the c2000demolib.mdl to trigger a CLA task. This block runs the downstream function-call subsystem on the CLA. On the CLA Task's block mask, you can specify the CLA task number and the associated interrupt triggering source. The downstream function-call subsystem is executed using the selected CLA Task when the selected interrupt triggers. In this example, CLA Task1 is used and Software is selected as the trigger source, which means that the CLA task is triggered at the sample rate provided in the sample time edit box.

Changing the Standard Linker Command File

A specific linker command file has to be selected to assign CLA memory sections. In the Model Configuration Parameters, under Coder Target > TargetHardware Resources > Build options, Use custom linker command file is selected and the preconfigured c28069_cla.cmd is used as linker command file. This file adds CLA memory sections description and can be found in the src directory at the root of the support package installation.

Interrupt Generation After CLA Task Completion

To trigger a C28x interrupt after the CLA task completes, an option is provided on the block mask. A CLA interrupt is generated when the CLA Task completes. CLA Task1 interrupt (CPU > 11, PIE > 1) is used as the interrupt source on the C28x Hardware Interrupt block. The function-call subsystem System executes at completion of CLA Task1 executes when this interrupt occurs. GPIO pin 34 (connected to LED on control cards) will toggle on every occurrence of CLA Task1 interrupt.

Data Exchange Between the CLA and the C28x CPU

All the interfaces between CLA and CPU need to be placed in specific memory sections. To gain specific access to these sections, custom storage classes CpuToCla1MsgRAM and Cla1ToCpuMsgRAM are defined in the dataclass package tic2000demospkg.

Model Configuration Required While Using the CLA

In the Model Configuration Parameters, under Optimizations > Signals and Parameters, Inline parameters needs to be selected. This is to avoid the creation of model structure global variables, as CLA can not access global data.

Discrete State Variables

All discrete state variables used inside CLA function-call subsystems have to be stored in Cla1ToCpuMsgRAM. For example, delay blocks, integrators have to be set to use the Cla1ToCpuMsgRAM storage class for state variables. See the State Attributes of the Delay block inside cla_subsystem for an example.

Other Guidelines to Consider While Using the CLA

Avoid the creation of subfunctions provided on atomic subsystems inside CLA function-call subsystems, as this creates nested functions that are not supported on the CLA.

The specificity of the CLA may require more operations on the model or may prevent the use of Simulink features. Make sure to go through the list of limitations provided in the CLA C compiler documentation. Make sure to use the features of Embedded Coder® to restrict the generated code in the limited syntax supported by the CLA C compiler.

How to Run the Example with Code Composer Studio v4 and v5

  • Open the example model c28069blink_cla.mdl or c28035blink_cla.mdl
  • Open Model Configuration Parameters and select the required tool chain on the Code Generation pane
  • Press Ctrl+B to build a binary executable and to automatically load and run the executable on the selected target

Permanent Magnet Synchronous Motor Field-Oriented Control (FOC) Using CLA Example Model

The following figure shows a permanent magnet synchronous motor field-oriented control (FOC) example model, which runs the FOC algorithm on the CLA

Permanent Magnet Synchronous Motor FOC Example Description

This example implements the field-oriented control (FOC) of a permanent magnet synchronous motor using the CLA. The FOC algorithm is implemented with a CLA Task and PWM duty cycles are refreshed on completion of CLA Task using the corresponding interrupt. This example requires a DRV8312 kit with an F28069 or F28035 control card. This example extends the Permanent Magnet Synchronous Motor Field-Oriented Control Example with the usage of CLA. All the considerations listed in the blinking LED example have been applied in this example.

How to Run the Example with Code Composer Studio v4 and v5

  • Open the example model c28069pmsmfoc_cla.mdl or c28035pmsmfoc_cla.mdl
  • Open Model Configuration Parameters and select the required tool chain on the Code Generation pane
  • Press Ctrl+B to build a binary executable and to automatically load and run the executable on the selected target

Troubleshooting

  • Make sure the Code Generation Tools version used for the CCSv5 or CCSv4 supports the CLA C Compiler
  • Make sure the latest C/C++ Header Files with CLA support are installed on your system. Use CheckEnvSetup to verify the versions and folders accessible by MATLAB