Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in...
Transcript of Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in...
![Page 1: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/1.jpg)
1© 2014 The MathWorks, Inc.
Modeling HDL components for
FPGAs in control applications
Mark Corless, Principal Application Engineer, Novi MI
![Page 2: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/2.jpg)
2
High resolution
voltage
modulation
Low latency
control loops
Critical
diagnostics
Position
sensing
System cost
reduction
Why would I use an
FPGA for a controls application?
FPGA = Field Programmable Gate Array
![Page 3: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/3.jpg)
3
How do I get an idea
out of my head
and into an
FPGA?
![Page 4: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/4.jpg)
4
How do I get an idea
out of my head
and into an
FPGA?
How do I get an idea
out of my head
and into a microprocessor?
![Page 5: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/5.jpg)
5
desktop simulation
rapid prototyping
production code generation
![Page 6: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/6.jpg)
6
That sounds nice, but…
Show me!
![Page 7: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/7.jpg)
7
Begin with existing C component models
Position
Velocity
Units
Open
Loop
Disabled
Encoder
CalibrationVoltage
Units
Current
Units
Mode
Scheduler
Field
Oriented
Control
Velocity
Control
![Page 8: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/8.jpg)
8
Create new HDL component models
Position
Velocity
Units
Open
Loop
Disabled
Encoder
CalibrationVoltage
Units
PWM
Peripheral
Current
Units
Encoder
Peripheral
Mode
Scheduler
Field
Oriented
Control
Velocity
Control
C HDL
HDL = Hardware Description Language
![Page 9: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/9.jpg)
9
Migrate some component models from C to HDL
Position
Velocity
Units
Open
Loop
Disabled
Encoder
CalibrationVoltage
Units
PWM
Peripheral
Current
Units
Encoder
Peripheral
Mode
Scheduler
Field
Oriented
Control
Velocity
Control
C HDL
![Page 10: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/10.jpg)
10
How did models help us design C
components?
![Page 11: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/11.jpg)
11
Baseline three-phase motor control hardware setup
FPGA
with vendor
provided
peripherals
Simulink Real-TimeTM
scheduler and peripheral interface
Controller model for C
implementationWe will use this for
HDL implementation
![Page 12: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/12.jpg)
12
Rapid prototyping model with Speedgoat bitstream
Controller model for C
implementation
Field-oriented controller
is the fastest loop and
runs at 25 kHz
![Page 13: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/13.jpg)
13
Rapid prototyping model with Speedgoat bitstream
Interface block to
encoder peripheral
on FPGA
Interface block to
PWM peripheral on
FPGA
Controller model for C
implementation
![Page 14: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/14.jpg)
14
Rapid prototyping model with Speedgoat bitstream
This is the end
result, but it’s
not where we
started…
![Page 15: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/15.jpg)
15
Simulate design on the desktop
Controller model for C
implementation
We started
designing the
controller at our
desktops…
Mathematical models
of motor, load, and
peripherals
![Page 16: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/16.jpg)
16
Simulate design on the desktop
“Lumped parameter”
model of encoder sensor
and peripheral
![Page 17: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/17.jpg)
17
Compare desktop simulation and hardware data
Correlation of simulation and
hardware results provided
confidence in the workflow
![Page 18: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/18.jpg)
18
How do I create a new HDL
component model?
![Page 19: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/19.jpg)
19
Begin with existing C component models
Position
Velocity
Units
Open
Loop
Disabled
Encoder
CalibrationVoltage
Units
Current
Units
Mode
Scheduler
Field
Oriented
Control
Velocity
Control
![Page 20: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/20.jpg)
20
Create new HDL component models
Position
Velocity
Units
Open
Loop
Disabled
Encoder
CalibrationVoltage
Units
PWM
Peripheral
Current
Units
Encoder
Peripheral
Mode
Scheduler
Field
Oriented
Control
Velocity
Control
C HDL
![Page 21: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/21.jpg)
21
Example workflow to design an HDL component
1. Design the component with a unit-level testbench
2. Integrate the component with the system-level testbench
3. Partition the design for code generation
4. Generate a bitstream for the FPGA
5. Prototype the design on real-time hardware
![Page 22: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/22.jpg)
22
1. Design the component with a unit-level testbench
Peripheral will
run at
33 MHz on the
FPGA
Lo-fidelity model to capture
25 kHz dynamics of combined
sensor and peripheral
![Page 23: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/23.jpg)
23
1. Design the component with a unit-level testbench
![Page 24: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/24.jpg)
24
1. Design the component with a unit-level testbench
![Page 25: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/25.jpg)
25
1. Design the component with a unit-level testbench
Simulation results provide
confidence in lo-fidelity and
implementation fidelity
peripheral models
![Page 26: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/26.jpg)
26
2. Integrate the component with the system-level testbench
Implementation fidelity peripheral models require a
1/33 MHz simulation step size so simulation time will be
longer than the testbench with lo-fidelity peripherals
![Page 27: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/27.jpg)
27
2. Integrate the component with the system-level testbench
Use lo-fidelity peripheral
models for interactive
control design
Use hi-fidelity peripheral implementation
models to confirm integrated behavior
![Page 28: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/28.jpg)
28
3. Partition the design for code generation
Group C components Group HDL components
Optionally generate
algorithmic
HDL code
![Page 29: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/29.jpg)
29
4. Generate a bitstream for the FPGA
Use HDL Workflow Advisor
to specify additional
information required to
create a bitstream
![Page 30: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/30.jpg)
30
4. Generate a bitstream for the FPGA
Specify card and FPGA
toolchain
![Page 31: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/31.jpg)
31
4. Generate a bitstream for the FPGA
Associate ports in model
with pins on FPGA or PCI
interface to processor
HDL Workflow Advisor will
automate interacting with the
Xilinx toolchain to create the
bitstream for the FPGA
![Page 32: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/32.jpg)
32
4. Generate a bitstream for the FPGA
HDL Workflow Advisor also
generates an interface block
which can be used with
Simulink Real-Time
![Page 33: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/33.jpg)
33
4. Generate a bitstream for the FPGA
We use a MATLAB® script
to only expose ports of
interest and make a prettier
mask
![Page 34: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/34.jpg)
34
5. Prototype the design on real-time hardware
Integrate bitstream interface
block into Simulink Real-
Time model
![Page 35: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/35.jpg)
35
5. Prototype the design on real-time hardware
Correlation of simulation and
hardware results provides
confidence in the workflow
![Page 36: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/36.jpg)
36
How do I migrate a component model
from C to HDL?
![Page 37: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/37.jpg)
37
Migrate some component models from C to HDL
Position
Velocity
Units
Open
Loop
Disabled
Encoder
CalibrationVoltage
Units
PWM
Peripheral
Current
Units
Encoder
Peripheral
Mode
Scheduler
Field
Oriented
Control
Velocity
Control
C HDL
![Page 38: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/38.jpg)
38
Migrate some component models from C to HDL
Position
Velocity
Units
Open
Loop
Disabled
Encoder
CalibrationVoltage
Units
PWM
Peripheral
Current
Units
Encoder
Peripheral
Mode
Scheduler
Field
Oriented
Control
Velocity
Control
C HDL
![Page 39: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/39.jpg)
39
Example workflow to migrate a component to HDL
1. Design the component with a unit-level testbench
2. Integrate the component with the system-level testbench
3. Partition the design for code generation
4. Generate a bitstream for the FPGA
5. Prototype the design on real-time hardware
Modify component to
account for differences
between C and HDL
Model to simplify timing
constraints for disparate rates
Add timing constraint file to
FPGA project
![Page 40: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/40.jpg)
40
Modify to account for differences between C and HDL
States can be reset through
enable or trigger portsStates are explicitly reset
using signals
![Page 41: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/41.jpg)
41
Modify to account for differences between C and HDL
“Tunable” parameters are
explicitly routed to ports
Parameters are “tunable”
directly from blocks or
data objects
![Page 42: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/42.jpg)
42
Modify to account for differences between C and HDL
Typically floating point for rapid
prototyping
Typically fixed-point for rapid
prototyping
![Page 43: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/43.jpg)
43
Model to simplify timing constraints for disparate rates
Integrate 25 kHz control loop
with 33 MHz peripheral
components
![Page 44: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/44.jpg)
44
Model to simplify timing constraints for disparate rates
Insert slow delay at fast to
slow rate transitions, this
makes it simple to author
timing constraint file
Example constraint file
![Page 45: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/45.jpg)
45
Compare simulation and hardware results
Correlation of simulation and
hardware results provides
confidence in the workflow
![Page 46: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/46.jpg)
46
What did we learn?
![Page 47: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/47.jpg)
47
High resolution
voltage
modulation
Low latency
control loops
Critical
diagnostics
Position
sensing
System cost
reduction
Models can help you design FPGA components for
control applications
![Page 48: Modeling HDL components for FPGAs in control applications · Modeling HDL components for FPGAs in control applications Mark Corless, Principal Application Engineer, Novi MI. 2 High](https://reader030.fdocuments.us/reader030/viewer/2022040401/5e784fc774d65d64bd58caad/html5/thumbnails/48.jpg)
48
Through this exercise we learned that…
C and HDL components often run at disparate rates
– Design components with similar rates of interest
– Confirm system level behavior by integrating components
– Consider low fidelity peripheral models for control design tasks
There are some differences when modeling for HDL than C
– Explicitly reset states and route tunable parameters for HDL
– Typically model HDL algorithms in fixed-point
– Consider adding delays to simplify timing constraint specification
Overall Model-Based Design is similar for C and HDL
– Simulate components to reduce dependency on hardware
– Rapid prototype to verify behavior on hardware
– Generate algorithm code for integration into production environment