automatic code generation from matlab & simulink - · pdf fileautomatic code generation...

23
© 2009 The MathWorks, Inc. Automatic code generation from MATLAB & Simulink Stephan van Beek Senior Application Engineer The MathWorks

Upload: donhi

Post on 07-Feb-2018

334 views

Category:

Documents


10 download

TRANSCRIPT

Page 1: Automatic code generation from MATLAB & Simulink - · PDF fileAutomatic code generation from MATLAB & Simulink ... Targeting Embedded Microprocessors and DSPs ... generation MATLAB,

© 2

009 T

he M

ath

Work

s, In

c.

Automatic code generation from

MATLAB & Simulink

Stephan van Beek

Senior Application Engineer

The MathWorks

Page 2: Automatic code generation from MATLAB & Simulink - · PDF fileAutomatic code generation from MATLAB & Simulink ... Targeting Embedded Microprocessors and DSPs ... generation MATLAB,

2

who usesMATLAB?

Page 3: Automatic code generation from MATLAB & Simulink - · PDF fileAutomatic code generation from MATLAB & Simulink ... Targeting Embedded Microprocessors and DSPs ... generation MATLAB,

3

and what about

Simulink?

Page 4: Automatic code generation from MATLAB & Simulink - · PDF fileAutomatic code generation from MATLAB & Simulink ... Targeting Embedded Microprocessors and DSPs ... generation MATLAB,

4

The Digital System Design Challenge

How can we rule out bad algorithms faster?

How can implement our algorithms faster?

How can we ensure that our implementation matches our algorithm?

How can we collaborate with our hardware and software engineers? ASIC

C / C++

FPGA / ASIC MCU / DSP

HDL

MATLAB, Simulink, Stateflow

Algorithm and System Design

Page 5: Automatic code generation from MATLAB & Simulink - · PDF fileAutomatic code generation from MATLAB & Simulink ... Targeting Embedded Microprocessors and DSPs ... generation MATLAB,

© 2

009 T

he M

ath

Work

s, In

c.

Introduction to Model-Based

Design

Page 6: Automatic code generation from MATLAB & Simulink - · PDF fileAutomatic code generation from MATLAB & Simulink ... Targeting Embedded Microprocessors and DSPs ... generation MATLAB,

6

Problems with Traditional Development

Text-based

Prevents rapid

iteration

Prototypes

Incomplete and

expensive

Manual coding

Introduces human

error

Traditional testing

Errors found

too late in the

process

MS Word

LaTeX

Visio

MS PowerPoint

MATLAB Code

C/C++ Code

High-Level

Languages

VHDL

Verilog

C/C++

Simulation

Test Bench

Hardware Test

Environment

Requirements

and Specs

Design with

prototypes

Manual

Implementation

Test and

Verification

Page 7: Automatic code generation from MATLAB & Simulink - · PDF fileAutomatic code generation from MATLAB & Simulink ... Targeting Embedded Microprocessors and DSPs ... generation MATLAB,

7

Adopting Model-Based Design

Model Elaboration

Continuous Verification

Executable models

- Unambiguous

- Only “one truth”

Design with Simulation

- Reduces “real”

prototypes

- Systematic “what-if”

analysis

Automatic code

generation

- Minimizes coding

errors

Test with Design

- Detects errors

earlier

Requirements

and Specs

Design with

prototypes

Manual

Implementation

Test and

Verification

Rapid design iterations

Automatic code

generation

Design with

Simulation

Page 8: Automatic code generation from MATLAB & Simulink - · PDF fileAutomatic code generation from MATLAB & Simulink ... Targeting Embedded Microprocessors and DSPs ... generation MATLAB,

8

Model-Based Design Flow at its core

MATLAB, Simulink, Stateflow

Algorithm and System Design

C, C++

FPGA / ASIC MCU / DSP

VHDL, Verilog

System Design

and Simulation

Implement Digital Electronics

Embedded Software

Integration

Page 9: Automatic code generation from MATLAB & Simulink - · PDF fileAutomatic code generation from MATLAB & Simulink ... Targeting Embedded Microprocessors and DSPs ... generation MATLAB,

© 2

009 T

he M

ath

Work

s, In

c.

Introduction to

MATLAB & Simulink

Page 10: Automatic code generation from MATLAB & Simulink - · PDF fileAutomatic code generation from MATLAB & Simulink ... Targeting Embedded Microprocessors and DSPs ... generation MATLAB,

10

MATLAB at a glance

The leading environment

for technical computing

– Interactive development environment

– Technical computing language

– Data analysis and visualization

– Algorithm development

Page 11: Automatic code generation from MATLAB & Simulink - · PDF fileAutomatic code generation from MATLAB & Simulink ... Targeting Embedded Microprocessors and DSPs ... generation MATLAB,

11

Simulink at a glanceThe leading environment for system-level modeling and simulation

– Block-diagram environment

– Model, simulate and analyze dynamic systems

– Build verification test-benches

– Fully integrated with MATLAB

Discrete filter in Simulink Discrete filter in C

Page 12: Automatic code generation from MATLAB & Simulink - · PDF fileAutomatic code generation from MATLAB & Simulink ... Targeting Embedded Microprocessors and DSPs ... generation MATLAB,

12

Why Simulink? Model, simulate and analyze

Dynamic systems

o Multi-domain

o Multiple Rates

o Discrete and continuous

o Non-linear

Architecture exploration

o Rapidly model what-if scenarios

o Share a design idea

o Concept to implementation

Page 14: Automatic code generation from MATLAB & Simulink - · PDF fileAutomatic code generation from MATLAB & Simulink ... Targeting Embedded Microprocessors and DSPs ... generation MATLAB,

© 2

009 T

he M

ath

Work

s, In

c.

Edge Detection Demo

Page 15: Automatic code generation from MATLAB & Simulink - · PDF fileAutomatic code generation from MATLAB & Simulink ... Targeting Embedded Microprocessors and DSPs ... generation MATLAB,

15

Challenge:

=Stop sign

Bill: System Engineer

Page 16: Automatic code generation from MATLAB & Simulink - · PDF fileAutomatic code generation from MATLAB & Simulink ... Targeting Embedded Microprocessors and DSPs ... generation MATLAB,

16

Wikipedia:

Sobel Algorithm for Edge Detection

DEMO

Page 17: Automatic code generation from MATLAB & Simulink - · PDF fileAutomatic code generation from MATLAB & Simulink ... Targeting Embedded Microprocessors and DSPs ... generation MATLAB,

17

Challenge cont’d:

Bill: System Engineer

FPGA

John: FPGA Engineer

1%?

1 week?

DEMO

Page 18: Automatic code generation from MATLAB & Simulink - · PDF fileAutomatic code generation from MATLAB & Simulink ... Targeting Embedded Microprocessors and DSPs ... generation MATLAB,

18

Summary: Sobel Edge Detection Demo

Model Elaboration

Continuous Verification

Executable models- Unambiguous

- Only “one truth”

Design with Simulation- Reduces “real” prototypes

- Systematic “what-if”

analysis

Automatic code

generation- Minimizes coding

errors

Test with Design- Detects errors

earlier

Requirements

and Specs

Design with

prototypes

Manual

Implementation

Test and

Verification

Automatic code

generation

Design with

Simulation

Page 19: Automatic code generation from MATLAB & Simulink - · PDF fileAutomatic code generation from MATLAB & Simulink ... Targeting Embedded Microprocessors and DSPs ... generation MATLAB,

© 2

009 T

he M

ath

Work

s, In

c.

Automatic Code Generation Tools

from The MathWorks

Page 20: Automatic code generation from MATLAB & Simulink - · PDF fileAutomatic code generation from MATLAB & Simulink ... Targeting Embedded Microprocessors and DSPs ... generation MATLAB,

20

Top-Down Design Flow - Partitioning

MATLAB, Simulink, Stateflow

Algorithm and System Design

C, C++

FPGA / ASIC MCU / DSP

VHDL, Verilog

System Design

and Simulation

Implement Digital Electronics

Embedded Software

Integration

Concept Design

Implementation

Page 21: Automatic code generation from MATLAB & Simulink - · PDF fileAutomatic code generation from MATLAB & Simulink ... Targeting Embedded Microprocessors and DSPs ... generation MATLAB,

21

Hardware Implementation Flow

MATLAB, Simulink, Stateflow

Algorithm and System Design

FPGA / ASIC

Generic RTL

VHDL, Verilog

Mentor Graphics ModelSim

Cadence Incisive

Synopsys Discovery

EDA Simulator

Link

Legacy

/

External

CodeXilinx ISE

Altera

Quartus II

Synplify

Pro

PrecisionRTL

DesignCompiler

Leonardo

Filter Design HDL

Coder

Simulink HDL Coder

HDL Simulation

Synthesis

P & R

Page 22: Automatic code generation from MATLAB & Simulink - · PDF fileAutomatic code generation from MATLAB & Simulink ... Targeting Embedded Microprocessors and DSPs ... generation MATLAB,

22

Green Hills MULTI

TI Code Composer Studio

Analog Devices Visual

DSP++

Altium TASKING

Targeting Embedded Microprocessors and DSPs

MATLAB, Simulink, Stateflow

Algorithm and System Design

C, C++

Embedded IDE

Link

Real Time Workshop

Embedded Coder

Real Time Workshop

Integrated Design

Environment

TI C6000

Infeneon C166

Freescale

MPC5xx

STMicroelectronics

ST10

TI C2000

Target Support

Package

Specific

Peripheral

S/W

Drivers

Page 23: Automatic code generation from MATLAB & Simulink - · PDF fileAutomatic code generation from MATLAB & Simulink ... Targeting Embedded Microprocessors and DSPs ... generation MATLAB,

23

Automatic Code Generation Summary

ASIC

C / C++

FPGA / ASIC MCU / DSP

HDL

Ge

ne

rate

Ve

rify

Co-simulation

Converge on the best algorithm faster

Implement your algorithm faster

Ensure that your implementation matches your system model

Collaborate with your hardware / softwareengineers

Automatic code

generation

MATLAB, Simulink, Stateflow

Algorithm and System Design