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

Preview:

Citation preview

1 © 2014 The MathWorks, Inc.

Motor 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

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

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

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

6

Example: Design a six-step trapezoidal controller

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

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

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

10

Let’s use the tools!

Simulate control loop dynamics

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

12 HDL code C code

Assemble components into system testbench

Control Loop Components

Velocity Control Six-Step

Commutation Hall

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

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

15

Compare component and system simulations Control loop

component simulation

runs faster but

ignores sensor effects

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

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

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

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

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

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

22

Let’s use the tools to…

Prototype on Zynq

23

Hardware results track simulation results

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

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

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

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

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

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

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