production code generation using model-based design

50
1 © 2014 The MathWorks, Inc. Production Code Generation Using Model-Based Design: An AC Motor Control Case Study Chris Fillyaw, Application Engineering

Upload: others

Post on 02-Feb-2022

1 views

Category:

Documents


0 download

TRANSCRIPT

1© 2014 The MathWorks, Inc.

Production Code Generation Using

Model-Based Design: An AC Motor Control Case Study

Chris Fillyaw, Application Engineering

2

Embedded System

Motor

Hardware

Controller

C Code

System Model

Model your system, design your controller, and

generate code using Simulink

Controller

C Code

Controller

Model

Motor

Model

Motor

Hardware

3

Simulation vs. Hardware Measurements

4

What are we going to see in this case study?

Getting started with production code generation

Managing the data in your design

Solving a field issue in simulation and generating code

with the solution.

Verifying code execution time of the generated code

Scaling up the design and modeling more components

of your system

5

What are we going to see in this case study?

Getting started with production code generation

Managing the data in your design

Solving a field issue in simulation and generating code

with the solution.

Verifying code execution time of the generated code

Scaling up the design and modeling more components

of your system

6

Where do you start when adopting

Model-Based Design?

7

Start with a core controller component

8

Let’s explore this component…

9

Simulate to Understand Behavior

10

Prep Model for Code Generation with “Code

Generation Objectives”

11

Control Interface Elements

Function Prototype:

Calibration Parameters:

Measurement Signals:

12

Package up the generated code and distribute

Enable and specify filename:

Zip file created with all required source files:

13

What are we going to see in this case study?

Getting started with production code generation

Managing the data in your design

Solving a field issue in simulation and generating code

with the solution.

Verifying code execution time of the generated code

Scaling up the design and modeling more components

of your system

14

How do I manage data for my design?

15

Data Management with Simulink

Define

Edit

Share

101010 Simulink Data Objects

Model Explorer

Simulink Project

101010

16

Data Management with Simulink

Define

Edit

Share Store

101010 Simulink Data Objects

Model Explorer

Simulink Project

101010

Simulink Data Dictionary

17

Data Dictionaries link to your Simulink models

18

See differences, revert, and save changes to

the repository

19

Change tracking

20

Simulink Project integration

21

Enumerations scoped to data dictionary

22

What are we going to see in this case study?

Getting started with production code generation

Managing the data in your design

Solving a field issue in simulation and generating

code with the solution.

Verifying code execution time of the generated code

Scaling up the design and modeling more components

of your system

23

Are we done?

What if something breaks?

24

The email from the field…

25

Summary of the issues

26

Plan of attack

1. Duplicate the issue in Simulation

2. Add tuning parameter for current limit

3. Investigate issue and fix overshoot in the model

27

Duplicating the issue in Simulation

28

Adding a tuning parameter

Use data object for constant value:

Specify data object in model explorer:

29

Export data objects to data dictionary script

Run this script on model startup:

Right-click in model explorer:

30

Final solution

31

What are we going to see in this case study?

Getting started with production code generation

Managing the data in your design

Solving a field issue in simulation and generating code

with the solution.

Verifying code execution time of the generated code

Scaling up the design and modeling more components

of your system

32

How do I know if the generated code is

efficient enough?

33

Publications showing efficiency of generated

code

http://delphi.com/pdf/techpapers/2014-01-

0305.pdf

34

Publications showing efficiency of generated

code

http://delphi.com/pdf/techpapers/2014-01-

0305.pdf

35

What did our example look like?

Final implementation: 12µs out of 40µs budget

(30% CPU usage)

36

Why should I scale up the model to

include more components?

37

Catch design issues earlier in development

38

What are we going to see in this case study?

Getting started with production code generation

Managing the data in your design

Solving a field issue in simulation and generating code

with the solution.

Verifying code execution time of the generated code

Scaling up the design and modeling more

components of your system

39

How do I scale up the design?

40

Use function triggered subsystems for

ISR boundaries

41

Manage complex systems with multiple

model files

42

Use model referencing for multiple models

43

Can I manage algorithm variants

without dirtying the model?

44

Parameterize algorithm variants

45

Parameterize algorithm variants

46

Parameterize algorithm variants

47

What did we learn from this case study?

Getting started with production code generation– Code generation advisor

– Function prototype control

– Package up code and artifacts

Managing the data in your design– Store data in Data Dictionaries

– Difference/save/revert working data from the dictionary

– Simulink Project to manage all project files

Solving a field issue in simulation and generating code with the solution.– Solve issues in simulation

– Adding tuning parameters

Scaling up the design and modeling more components of your system– Catch design issues earlier in the development process

– Model referencing, subsystem variants, and reference configuration sets help architect your model and generated code.

48

Embedded System

Motor

Hardware

Controller

C Code

System Model

Model your system, design your controller, and

generate code using Simulink

Controller

C Code

Controller

Model

Motor

Model

Motor

Hardware

49

Where can I find more information?

Explore a demo on generating C code from a controller and verifying

its compiled behavior and execution time

>> docsearch "Field-Oriented Control of Permanent Magnet

Synchronous Machine"

http://mathworks.com/products/demos/shipping/rtw/rtwdemo_pmsmfoc_script.html

Watch recorded webinar: Embedded Code Generation for AC Motors

http://www.mathworks.com/company/events/webinars/wbnr61549.html

Watch 2012 MathWorks Automotive Conference recording of:

Parameterizing and Verifying a Permanent Magnet Synchronous

Motor Model

http://www.mathworks.com/company/events/conferences/automotive-conference-

michigan/2012/proceedings/registration.html?video=3

50© 2014 The MathWorks, Inc.