Top Banner
1 © 2013 The MathWorks, Inc. Introduction to Production Code Generation in Simulink: An AC motor control application Jeff Tackett, Application Engineering
18

Introduction to Production Code Generation in Simulink …ewh.ieee.org/.../20131019/MotorControl-Simulink-to-Code-Matrhworks.pdf · © 2013 The MathWorks, Inc.1 Introduction to Production

Apr 29, 2018

Download

Documents

vohanh
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to Production Code Generation in Simulink …ewh.ieee.org/.../20131019/MotorControl-Simulink-to-Code-Matrhworks.pdf · © 2013 The MathWorks, Inc.1 Introduction to Production

1 © 2013 The MathWorks, Inc.

Introduction to Production Code

Generation in Simulink: An AC motor control application

Jeff Tackett, Application Engineering

Page 2: Introduction to Production Code Generation in Simulink …ewh.ieee.org/.../20131019/MotorControl-Simulink-to-Code-Matrhworks.pdf · © 2013 The MathWorks, Inc.1 Introduction to Production

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

Page 3: Introduction to Production Code Generation in Simulink …ewh.ieee.org/.../20131019/MotorControl-Simulink-to-Code-Matrhworks.pdf · © 2013 The MathWorks, Inc.1 Introduction to Production

3

Let’s explore the AC Motor Control

application…

Page 4: Introduction to Production Code Generation in Simulink …ewh.ieee.org/.../20131019/MotorControl-Simulink-to-Code-Matrhworks.pdf · © 2013 The MathWorks, Inc.1 Introduction to Production

4

Simulation vs. Hardware Measurements

Page 5: Introduction to Production Code Generation in Simulink …ewh.ieee.org/.../20131019/MotorControl-Simulink-to-Code-Matrhworks.pdf · © 2013 The MathWorks, Inc.1 Introduction to Production

5

Introduction to Code Generation

Configuring model settings

Specifying the function prototype

Exporting parameters as global variables

Packaging the source and header files

Page 6: Introduction to Production Code Generation in Simulink …ewh.ieee.org/.../20131019/MotorControl-Simulink-to-Code-Matrhworks.pdf · © 2013 The MathWorks, Inc.1 Introduction to Production

6

Where do you start when adopting

Model-Based Design?

Page 7: Introduction to Production Code Generation in Simulink …ewh.ieee.org/.../20131019/MotorControl-Simulink-to-Code-Matrhworks.pdf · © 2013 The MathWorks, Inc.1 Introduction to Production

7

Start with a core controller component

Page 8: Introduction to Production Code Generation in Simulink …ewh.ieee.org/.../20131019/MotorControl-Simulink-to-Code-Matrhworks.pdf · © 2013 The MathWorks, Inc.1 Introduction to Production

8

Let’s explore this component…

Page 9: Introduction to Production Code Generation in Simulink …ewh.ieee.org/.../20131019/MotorControl-Simulink-to-Code-Matrhworks.pdf · © 2013 The MathWorks, Inc.1 Introduction to Production

9

Simulate to Understand Behavior

Page 10: Introduction to Production Code Generation in Simulink …ewh.ieee.org/.../20131019/MotorControl-Simulink-to-Code-Matrhworks.pdf · © 2013 The MathWorks, Inc.1 Introduction to Production

10

Prep Model for Code Generation with “Code

Generation Objectives”

Page 11: Introduction to Production Code Generation in Simulink …ewh.ieee.org/.../20131019/MotorControl-Simulink-to-Code-Matrhworks.pdf · © 2013 The MathWorks, Inc.1 Introduction to Production

11

Control Interface Elements

Desired Function Prototype:

Configuration:

Page 12: Introduction to Production Code Generation in Simulink …ewh.ieee.org/.../20131019/MotorControl-Simulink-to-Code-Matrhworks.pdf · © 2013 The MathWorks, Inc.1 Introduction to Production

12

Exporting global tuning parameters

Use data object for constant value:

Specify data object in model explorer:

Page 13: Introduction to Production Code Generation in Simulink …ewh.ieee.org/.../20131019/MotorControl-Simulink-to-Code-Matrhworks.pdf · © 2013 The MathWorks, Inc.1 Introduction to Production

13

Package up the generated code and distribute

Enable and specify filename:

Zip file created with all required source files:

Page 14: Introduction to Production Code Generation in Simulink …ewh.ieee.org/.../20131019/MotorControl-Simulink-to-Code-Matrhworks.pdf · © 2013 The MathWorks, Inc.1 Introduction to Production

14

Navigating between the model and generated

code

Page 15: Introduction to Production Code Generation in Simulink …ewh.ieee.org/.../20131019/MotorControl-Simulink-to-Code-Matrhworks.pdf · © 2013 The MathWorks, Inc.1 Introduction to Production

15

What did we learn from this example?

Initial steps for production code generation

– Code generation advisor

– Function prototype control

– Exporting global tuning parameters

– Navigating between the model and generated code

– Package up code and artifacts

Page 16: Introduction to Production Code Generation in Simulink …ewh.ieee.org/.../20131019/MotorControl-Simulink-to-Code-Matrhworks.pdf · © 2013 The MathWorks, Inc.1 Introduction to Production

16

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

Page 17: Introduction to Production Code Generation in Simulink …ewh.ieee.org/.../20131019/MotorControl-Simulink-to-Code-Matrhworks.pdf · © 2013 The MathWorks, Inc.1 Introduction to Production

17

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

Page 18: Introduction to Production Code Generation in Simulink …ewh.ieee.org/.../20131019/MotorControl-Simulink-to-Code-Matrhworks.pdf · © 2013 The MathWorks, Inc.1 Introduction to Production

18 © 2013 The MathWorks, Inc.