Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from...

30
1 © 2014 The MathWorks, Inc. Motor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

Transcript of Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from...

Page 1: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

1 © 2014 The MathWorks, Inc.

Motor Control:

Model-Based Design from Concept to

Implementation on heterogeneous SoC FPGAs

Alexander Schreiber, MathWorks

Page 2: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

2

ARM

Programmable Logic

Some components of a production application Production

System

Code

AXI Bus

IP1 AXI

Interface

Algorithm

HDL

Linux

Driver

Algorithm

C

IP2

IP3

System Motor

Page 3: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

3

ARM

Programmable Logic

From simulation to production Production Simulation

Simulink

Embedded Coder

HDL Coder

Algorithm

Model

Algorithm

Model

System

Code

AXI Bus

IP1 AXI

Interface

Algorithm

HDL

Linux

Driver

Algorithm

C

IP2

IP3

Motor

Model System Motor

Page 4: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

4

From simulation to prototype to production Production

Prog. Logic

Prototype

ARM

Simulation

Simulink

Embedded Coder

HDL Coder

AXI

Interface

Algorithm

Model

Algorithm

Model

Linux

Driver

AXI Bus

Motor

Model Motor System

ARM

System

Code

Vivado Algorithm

C

Programmable Logic

Vivado Algorithm

HDL

AXI Bus

IP1 AXI

Interface

Algorithm

HDL

Linux

Driver

Algorithm

C

IP2

IP3

Motor

Page 5: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

5

How can models help you

design a controller for Zynq?

Simulate on your desktop

– Model controller and plant system dynamics

– Design and debug components at control loop fidelity

– Assemble and verify components at implementation fidelity

Prototype on hardware

– Generate HDL code and build bitstream

– Generate C code and build ARM executable

– Collect hardware results and verify against simulation

Generate C/HDL code for production

Page 6: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

6

Example: Design a six-step trapezoidal controller

Page 7: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

7

Example: Design a six-step trapezoidal controller

Six-Step

Commutation

Processing System Programmable Logic

HDL code

Velocity Control

AX

I-li

te

Hall

Period

C code

Cortex™-A9

Open-source

LINUX

Ethernet

Inverter

Module

Hall

Interface

Motor FMC Card

PWM

Iso

lati

on

Velocity Estimate

Page 8: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

8

Split system into smaller design components

System Components

HDL code C code

Velocity Estimate

Components

Period

Velocity Estimate

Hall

PWM

Component

PWM

Control Loop Components

Velocity Control Six-Step

Commutation Hall

Six-Step

Commutation

Period

PWM

Velocity Estimate Hall

Velocity Control

Page 9: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

9

System Components

HDL code C code

Simulation let’s you choose where you want to start

Velocity Estimate

Components

Period

Velocity Estimate

Hall

PWM

Component

PWM Six-Step

Commutation

Period

PWM

Velocity Estimate Hall

Velocity Control

Control Loop Components

Velocity Control Six-Step

Commutation Hall

Page 10: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

10

Let’s use the tools!

Simulate control loop dynamics

Page 11: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

11

Design and simulate control loop components Specify tests and

simulate response

with continuous time

solver

Model motor and

load with fidelity to

capture dynamics of

interest

Model control loop

C/HDL components

– Specify velocity

control to runs at

1kHz rate

– Commutator rate will

be determined by

solver

“Auto” Rate 1kHz

Page 12: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

12 HDL code C code

Assemble components into system testbench

Control Loop Components

Velocity Control Six-Step

Commutation Hall

Page 13: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

13

Six-Step

Commutation

Period

PWM

Velocity Estimate Hall

Velocity Control

System Components

Assemble components into system testbench

Velocity Estimate

Component

Period

Velocity Estimate

Hall

PWM

Component

PWM

HDL code C code

Control Loop Components

Velocity Control Six-Step

Commutation Hall

Page 14: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

14

Assemble components into system testbench

Group components

which will be

implemented in

C/HDL

Algorithm HDL

Specification Model Algorithm C

Specification Model

Assemble and

simulate system to

assess impact of

peripherals on

control loop

Time to run system

simulation is

dictated by HDL

peripheral (PWM)

dynamics

10MHz

1kHz

Page 15: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

15

Compare component and system simulations Control loop

component simulation

runs faster but

ignores sensor effects

Page 16: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

16

Compare component and system simulations Control loop

component simulation

runs faster but

ignores sensor effects

Velocity resolution

due to hall effect

sensor is visible in

system level

simulation

System simulation

includes sensor

effects but runs

slower due to

peripheral dynamics

Page 17: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

17

How do I get from simulation to prototype?

Six-Step

Commutation

Processing System Programmable Logic

Velocity Control

AX

I-li

te

Hall

Period

Cortex™-A9

Ethernet

Inverter

Module

Hall

Interface

Motor FMC Card

PWM

Iso

lati

on

Velocity Estimate

Algorithm HDL

Specification Model Algorithm C

Specification Model

Open-source

LINUX

Page 18: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

18

Generate a bitstream for programmable logic

AX

I-li

te

Programmable Logic

AX

I-li

te

Zynq Support Package enables you to…

Generate bitstream consisting of algorithmic HDL code from models

and interfaces to FPGA pins and AXI-Bus

Algorithm HDL

Specification Model

Page 19: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

19

Generate an executable for ARM

Processing System

AX

I-li

te

Cortex™-A9

AX

I-li

te

Zynq Support Package enables

you to…

Generate ARM executable

consisting of algorithmic C code

from models and interfaces to

AXI-Bus

Algorithm C

Specification Model

Open-source

LINUX

Page 20: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

20

Generate an executable for ARM

Processing System

AX

I-li

te

Cortex™-A9

AX

I-li

te

Zynq Support Package enables

you to…

Generate ARM executable

consisting of algorithmic C code

from models and interfaces to

AXI-Bus

Provides data interface between

Simulink and ARM executable via

Ethernet

Ethernet

Algorithm C

Specification Model

Open-source

LINUX

Page 21: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

21

Algorithm

C

Algorithm C

Specification Model

Prototype on Zynq with interactive tests

Inverter

Module

Hall

Interface

Motor FMC Card

Iso

lati

on

Switches and scopes in Simulink model act as an

interface to generated executable running on ARM

Algorithm HDL

Specification Model

Page 22: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

22

Let’s use the tools to…

Prototype on Zynq

Page 23: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

23

Hardware results track simulation results

Page 24: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

24

Hardware results track simulation results

Prototyping

environment enables

verification of modeling

assumptions against

hardware

Correlation of results

provides confidence in

plant and controller

models

Confidence in models

enables engineers to

spend more time in

simulation and less

time on dynos

Page 25: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

25

Algorithm HDL

Specification Model

Generate algorithmic code for production

Generate C code for the algorithm

(i.e. function call) that you can integrate

into your production project

Generate HDL code for the algorithm

(i.e. entity) that you can integrate into your

production project

Algorithm C

Specification Model

Page 26: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

26

How did models help us design a controller for Zynq? Production

Prog. Logic

Prototype

ARM

Simulation

Simulink

Embedded Coder

HDL Coder

AXI

Interface

Algorithm

Model

Algorithm

Model

Linux

Driver

AXI Bus

Motor

Model Motor

Algorithm

C

Algorithm

HDL

Algorithm

HDL

Algorithm

C

Page 27: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

27

How do models become code?

27

Embedded Coder

Generates C code for the

algorithm (i.e. a C

function call)

Simulation

Simulink

Motor

Model

Embedded Coder Algorithm

C

HDL Coder Algorithm

HDL

HDL Coder

● Generates HDL code for the

algorithm (i.e. an HDL entity)

Algorithm

Model

Algorithm

Model

Page 28: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

28

How can models help you prototype on Zynq?

28

Zynq Support Package

Automates integrating

generated C code with an

ARM “parent project”

Automates wrapping

generated HDL code into

an IP Core and

integrating it with “parent

project” for

programmable logic

Provides a data interface

between Simulink and

ARM

Prog. Logic

Prototype

ARM

Simulation

Simulink

Embedded Coder

HDL Coder

AXI

Interface

Algorithm

Model

Algorithm

Model

Linux

Driver

AXI Bus

Motor

Model Motor

Algorithm

C

Algorithm

HDL

Page 29: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

29

How can models help you

design a controller for Zynq?

Simulate on your desktop

– Model controller and plant system dynamics

– Design and debug components at control loop fidelity

– Assemble and verify components at implementation fidelity

Prototype on hardware

– Generate HDL code and build bitstream

– Generate C code and build ARM executable

– Collect hardware results and verify against simulation

Generate C/HDL code for production

Page 30: Motor Control: Model-Based Design from Concept to ... fileMotor Control: Model-Based Design from Concept to Implementation on heterogeneous SoC FPGAs Alexander Schreiber, MathWorks

30

How can you accelerate your adoption of

simulation & code generation?

MathWorks Consultants can help you to:

Achieve the desired level of accuracy of motor and control models

Reduce dynamometer time

Integrate simulation and C/HDL code generation into your development process

Build in-house competency through knowledge transfer