AN 669: Drive-On-Chip Reference Design
About the Drive-On-Chip Reference Design
AC and servo drive system designs comprise multiple distinct but interdependent functions to realize requirements to meet the performance and efficiency demands of modern motor control systems. The system's primary function is to efficiently control the torque and speed of the AC motor through appropriate control of power electronics. A typical drive system includes the following items:
- Flexible pulse-width modulation (PWM) circuitry to switch the power stage transistors appropriately
- Motor control loops for single- or multiaxis control
- Industrial networking interfaces
- Position encoder interfaces
- Current, voltage, and temperature measurement feedback elements.
- Monitoring functions, for example, for vibration suppression.
The system requires system software running on a processor for high-level system control, coordination, and management.
Intel Cyclone® and Intel® MAX® 10 devices offer high-performance fixed- and floating-point DSP functionality. Cyclone V SoC devices offer the integrated ARM-based hard processor subsystem (HPS); other Cyclone FPGA and Intel® MAX® 10 FPGA devices offer support for Nios II soft processors. Cyclone and Intel® MAX® 10 FPGA devices offer a uniquely scalable and flexible platform for integration of single- and multiaxis drives on a single FPGA. The Intel motor control development framework allows you to create these integrated systems easily. The framework provides a reference design that comprises IP cores, software libraries, and a hardware platform. The framework seamlessly integrates Intel system-level design tools such as DSP Builder and Qsys, and software and IP components that allow you to extend and customize the reference design to meet your own application needs. The framework also supports optimal partitioning decisions between software running on an integrated processor and IP performing portions of the motor control algorithm in the FPGA, to accelerate performance as required. For example, depending on the performance requirements of your system or the number of axes you need to support, you may implement all of the inner current control loop in hardware or entirely in software. The framework flexibly allows you to connect to the motor and power stages through off-chip ADCs, and feedback encoder devices and to connect to higher-level automation controllers through off-the-shelf digital encoder and industrial Ethernet IP cores, respectively.
The reference design offers vibration suppression, when you target the Cyclone V SoC devices. The design demonstrates how you can implement standard components (FFTs, FFT-post processing, IIR filter), to enable you to develop an automatic method for vibration suppression. You may use the FFTs and FFT postprocessing for condition monitoring, which detects vibrations that indicate degradation or wear and communicate the results to another system.
The reference design integrates Motor Control IP Suite components, a Nios® II soft processor subsystem, or ARM-based HPS, and software that uses an FOC algorithm. The reference design uses the Intel DSP Builder system-level design tool to implement the FOC algorithm.
DSP Builder provides a MATLAB and Simulink flow that allows you to create hardware optimized fixed latency representations of algorithms without requiring HDL/hardware skills. Intel provides DSP Builder fixed-point and floating point algorithms to demonstrate both options. The DSP Builder folding feature reduces the resource usage of the logic as an alternative to a fully parallel implementation. The reference design also includes an efficient Avalon® Memory-Mapped interface that you can integrate in Qsys.
Motor Control Boards
Board | Vendor | Website |
---|---|---|
Cyclone V SoC development board | Intel | https://www.intel.com/content/www/us/en/programmable/products/boards_and_kits/dev-kits/altera/kit-cyclone-v-soc.html https://www.intel.com/content/www/us/en/programmable/products/boards_and_kits/dev-kits/altera/kit-cyclone-v-soc.html |
MAX 10 FPGA development board | Intel | https://www.intel.com/content/www/us/en/programmable/products/boards_and_kits/dev-kits/altera/max-10-fpga-development-kit.html |
Terasic SoCKit | Terasic | http://www.terasic.com |
Board | Vendor | Website |
---|---|---|
Multiaxis Motor Control Board | Intel | https://www.altera.com/products/boards_and_kits/dev-kits/altera/kit-multi-axis-motor-control.html |
FalconEye 2 HSMC Motor Control Board | devboards | http://www.devboards.de |
An HSMC connector connects:
- The Cyclone V SoC development board to the Multiaxis Motor Control Board or the FalconEye 2 HSMC Motor Control Board
- The Cyclone V SoC and MAX 10 FPGA Development Boards and SoCKit to the FalconEye 2 HSMC Motor Control Board.
For availability of the Multiaxis Motor Control Board, contact your Intel sales representative.
Drive-On-Chip Reference Design Features
- Multiple field-oriented control (FOC) loop implementations:
- Fixed- or floating-point implementation targeting the ARM Cortex A9 processor on SoC devices
- Fixed- or floating-point implementation with Nios II processors targeting MAX 10 FPGA devices
- Fixed and floating-point accelerator implementations designed using Simulink model-based design flow with DSP Builder
- Integration in a single FPGA of single and multiaxis motor control IP including:
- PWM for two-level IGBT
- Sigma delta ADC interfaces for motor current feedback and DC link voltage measurement
- Position feedback with EnDat or BiSS
- Vibration suppression (SoC devices only):
- DSP Builder-designed FFT accelerator
- Peak detection
- Suppression filter
- System Console GUI for motor feedback information, vibration suppression demonstration, and control of motors
Getting Started
- Software Requirements
- Downloading and Installing the Reference Design
- Setting Up the Boards
- Compiling the Design
Either compile your design or use the Intel-provided pre-compiled .sof from the master_image directory of your reference design variant. - Compiling the µC/OS-II HPS Software
If you are targeting the Cyclone V SoC development board or SocKit, compile the µC/OS-II version of the HPS software. - Compiling the Nios II Software
- Programming the Hardware onto the Device
- Downloading the DS-5 HPS Software to the Device
- Downloading the Nios II Software to the Device
Prerequisites: import and compile the Nios II software in the Nios II Software Build Tools for Eclipse. - Creating and Booting an HPS SD Card Software Image
You create a bootable SD card that contains the software image, so you can boot the software automatically without using the DS-5 Debugger
Software Requirements
The reference design requires:
- The Altera Complete Design Suite version 15.0, which includes:
- The Quartus II software v15.0
- DSP Builder v15.0
- The Altera Nios II Embedded design Suite (EDS) v15.0
- The Altera SoC EDS v15.0 (for designs that target the Cyclone V SoC), which includes ARM Development Studio 5 (DS-5) Altera Edition.
- Terminal emulator such as Tera Term for SoC based designs
Downloading and Installing the Reference Design
-
Download the relevant reference design .par file for your development kit and power
board from the
Intel Design Store.
To obtain further support on the reference design, contact your local Intel sales representative.
-
Install the relevant reference design
.par file for your
development kit and power board.
Table 3. Design .par Files Variant Development Kit Power Board Processor DOC_4AXIS_CVSX Cyclone V SoC Intel 4 Axis HPS DOC_FE2H_CVSX Cyclone V SoC FalconEye 2 HSMC HPS DOC_FE2H_CVSX_XiP Cyclone V SoC FalconEye 2 HSMC HPS DOC_FE2H_MAX10 MAX 10 FPGA FalconEye 2 HSMC Nios II DOC_FE2H_SoCKit SoCKit FalconEye 2 HSMC HPS Note: The XiP variant does not use external DDR3 memory and executes all code directly from flash memory. - In the Quartus II software, click File > New Project Wizard.
- Click Next.
- Enter the path for your project working directory and enter variant name from the table for the project name.
- Click Next.
- Select Project Template.
- Click Next
- Click Install the design templates.
-
Browse to select the .par file for the reference design and browse to the destination directory where you want to install it.
Figure 1. Design Template Installation
- Click OK on the design template installation message.
-
Select the Drive on Chip Reference
design design example.
Figure 2. Design Template
- Click Next.
-
Click Finish. The Quartus II
software expands the archive and sets up the project, which may take some time.
Figure 3. Directory StructureThe reference design directory structure for the DOC_FE2H_CVSX variant
Setting Up the Boards
Setting Up the Motor Control Board with your Development Board
- Remove the SD card from the SoC board if it is fitted.
- Connect the power board to the development board using the HSMC connector.
- Connect a USB cable from the USB-Blaster connector on the development board to your computer. The Cyclone V SoC development board and SoCKit require an additional USB cable connected to the UART connector.
- Open the terminal emulator to connect to the virtual COM port (which has a large number, e.g. 12) at 115K baud.
- Apply power to the development board.
-
Compile the hardware and software and program the hardware and software to the development board:
The terminal must display the correct FPGA and power boards, otherwise you might damage either board.
- Apply power to the motor control power board.
- Before reprogramming the FPGA, or removing power from the development boards, always remove power from the motor control power board first.
Using BiSS with FalconEye 2 Board
- Remove the EnDat cable from the header on the HSMC adapter board.
- Connect a BiSS cable from the header on the HSMC adapter board to the BiSS encoder.
Compiling the Design
-
By default,
Intel configures
<variant>
.v for EnDat encoders for FalconEye 2
HSMC Motor Control Board projects; BiSS for all Multiaxis Motor Control Board
projects. In <variant>
.v, to use BiSS, add the following
line; to use EnDat, remove it (if present).
"define BISS"
-
Add the paths to the license files for the EnDat and BiSS IP components to the
Quartus II license path.
- Click Tools > License Setup.
- Copy any existing license paths into a text editor.
- Browse to the EnDat license file ip\endat_OCP\dsgn\vhdl_ava_ALT_enc_ocp\ocp _license.dat and click Open.
- Copy and paste this license path into your text editor. Add a semicolon to separate this text from the original text.
- Browse to the BiSS license file ip\biss_OCP\license.dat and click Open.
- Copy and paste this license path into your text editor. Add a semicolon to separate this text from the original text and teh EnDat license.
-
Copy and paste the text from the text editor to the Quartus II
License File dialog box.
The final license path is <Project directory>\ip\endat_OCP\dsgn\vhdl_ava_ALT_enc_ocp; <Project directory>\ip\biss_OCP\license.dat;<original license paths>. Alternatively, you can add this path to the Windows environment variable LM_LICENSE_FILE.
-
Click Processing > Start Compilation .
Note: You may edit the reference design project in Qsys.
Compiling the µC/OS-II HPS Software
-
To ensure that the environment is set up correctly, run SoC EDS command shell, then start DS-5 by typing eclipse& at the command prompt.
Note: Do not use the Windows start menu entry to start DS-5.
- Specify the \CVSX_DS5 directory as the workspace by browsing to the <path> \software\CVSX_DS5 directory.
-
Click OK to create the workspace.
Note: Close the welcome to DS-5 tab if it shows.
-
Import the makefile project CVSX_DS5:
- Select File > Import to open the Import window.
- Select General > Existing Projects into Workspace and click Next.
- Click Select Root Directory and browse to the project directory, DOC_CVSX in the workspace directory, CVSX_DS5.
- Click OK.
-
Click Finish.
Table 4. Software Project DirectoriesThe linked directories that appear in the Project Explorer view under DOC_CVSX Directory Description app Application main entry point. components Motor control component source and header files. hwlibs The build process copies selected files from the Altera Complete Design Suite hardware libraries to this directory. mc Motor control source and header files. objects The build process creates object files here. perf Performance monitor source and header files. platform Platform (development kit and RTOS) specific source and header files. source Source code. This directory contains other linked subdirectories. vibration Vibration suppression demo source and header files.
-
Single-axis power boards default to EnDat; multiaxis power boards default to BiSS. To override the default encoder, edit mc\mc.h to define the OVERRIDE_ENCODER macro:
#define OVERRIDE_ENCODER SYSID_ENCODER_ENDAT
#define OVERRIDE_ENCODER SYSID_ENCODER_BISS
- Rebuild the DOC_CVSX project: right-click DOC_CVSX project and click Build Project.
Compiling the Nios II Software
- Start Nios II EDS. Click Start > Altera > Nios II EDS > Nios II Software Build Tools
- Specify the \software folder as the workspace by browsing to the reference design \software directory.
- Click OK to create the workspace.
- Import application and board support package (BSP) projects:
-
Single-axis power boards default to EnDat; multiaxis power boards default to BiSS. To override the default encoder, edit mc.h to define the OVERRIDE_ENCODER macro:
#define OVERRIDE_ENCODER SYSID_ENCODER_ENDAT
#define OVERRIDE_ENCODER SYSID_ENCODER_BISS
- Rebuild the BSP project: right-click <variant>_bsp project, point to Nios II, and click Generate BSP.
-
Build the application project:
right-click <variant> project and click Build Project.
Note: On Windows, the first time you build the project might take up to one hour.Note: Repeat steps 6 and 7 if you make any changes to the Qsys project.
Programming the Hardware onto the Device
- In the Quartus II software, click Tools > Programmer.
- In the Programmer pane, select USB-Blaster II (or CV SoCKit for the Terasic SoCKit) under Hardware Setup and JTAG under Mode.
- Click Auto Detect to detect devices.
- If you are targeting a Cyclone V SoC, select any 5CSX device from the pop-up list. For MAX 10 devices, select any 10M50 device.
- Double-click on the File field for the 5CSX or 10M50 device from the pop-up list.
- Select the output_files/<project name>_time_limited.sof and click Open.
- Click OK on the time-limited .sof message.
- Turn on Program/Configure.
-
Click Start.
Note: Do not close the OpenCore Plus message that appears.
Downloading the DS-5 HPS Software to the Device
- Select Run > Debug Configurations.
-
Create new DS-5 debugger configuration:
- Right click on the DS-5 Debugger launch type
- Select New.
- On the Connection tab, select Debug Cortex-A9_0 under Cyclone V SoC (Dual Core)|Bare Metal Debug.
- In the Target Connection drop-down select USB-Blaster.
-
In the Bare Metal Debug Connection field, click
Browse… and
select the USB Blaster II
on localhost (or CV SoCKit on
localhost for the SoCKit).
Figure 4. Connection Tab
- Select the Debugger tab.
- In Run Control, select Connect Only.
- In Host working directory turn off Use default and change the path to ${workspace_loc:/DOC_CVSX} by clicking Workspace and selecting DOC_CVSX
- Click Apply to save the configuration, optionally specifying a name for the new configuration.
- Click Debug.
- Click Yes when the application asks you to switch to debug perspective.
- In the Command text field enter the command source debug.ds.
- Click Submit to load and run the preloader then load the application and run to main().
- Click Continue (green arrow) to run the application.
-
Check that the terminal console display shows the correct FPGA and power board
combination. For example:
0: [DECODE SYSID] Decoding hardware platform from QSYS SYSID data : 0x00D112FE 0: [DECODE SYSID] Design Version : 15.0 0: [DECODE SYSID] FPGA Board : Cyclone V SX SoC Dev Kit 0: [DECODE SYSID] Power Board : FalconEye v2.0 HSMC Single-axis 0: [DECODE SYSID] Encoder Type : EnDat 0: [DECODE SYSID] 1 axes available 0: [DECODE SYSID] Axis 0 : Enabled
- When the application is running, right-click on Cortex-A9_0 and click Disconnect from Target.
- Apply power to the power board. The motor starts to turn.
Downloading the Nios II Software to the Device
To program the Nios II software to the device:
-
In the Nios II EDS, on the Run menu, click Run configurations....
- Double click Nios II Hardware to generate a new run configuration.
- Click New_configuration.
- On the Project tab select the DOC_FE2H_MAX10 project in the Project name drop-down.
- Turn on Enable browse for file system ELF file. Browse to the software\DOC_DE2115 and select DOC_DE2115.elf.
- On the Target Connection tab, click Refresh Connections. The software finds the USB-Blaster cable.
- Click Apply to save changes, optionally specifying a name for the new configuration.
- Click Run to start the software.
-
Check that the terminal console display shows the correct FPGA and power board combination. For example:
0: [DECODE SYSID] Decoding hardware platform from QSYS SYSID data : 0x00D111FE 0: [DECODE SYSID] Design Version : 15.0 0: [DECODE SYSID] FPGA Board : Cyclone V E Dev Kit 0: [DECODE SYSID] Power Board : FalconEye v2.0 HSMC Single-axis 0: [DECODE SYSID] Encoder Type : EnDat 0: [DECODE SYSID] 1 axes available 0: [DECODE SYSID] Axis 0 : Enabled
- Apply power to the power board. The motor starts to turn.
Creating and Booting an HPS SD Card Software Image
-
Create a bootable SD card image using the prebuilt image that the SoC EDS includes.
- On Windows, download and install win32diskimager.
-
Find the bootable image for your development board.
For the Cyclone SoC development board find sd_card_linux_boot_image.img in the Intel SoC EDS default installation directory: C:\altera\15.0\embedded\embeddedsw\socfpga\prebuilt_images For the Terasic SoCKit, find sd_image_sockit_20140902.img (see related information).
- Use win32diskimager or Linux to write the bootable image onto your SD card.
- Copy DOC_CVSX_uImage to the FAT partition on the SD card.
-
Enter U-Boot:
- Insert the SD card in the board
- Apply power to the board.
- Open your Terminal Emulator software and connect to the board.Press the ‘Cold Reset’ (Intel SoC dev board) or ‘HPS_RST’ (SoCKit), while monitoring the terminal.
- Press HPS_RST (SoCKit) or Cold Reset (Intel development boards) and monitor the terminal.
- Press a key in the terminal window when prompted, before the countdown finishes and the operating system boots.
-
At the U-Boot prompt, edit the U-Boot environment by typing:
setenv mmcload "mmc rescan;fatload mmc 0:1 0x01000000 doc_cvsx_uImage 0 0x40; go 0x01000000"
-
Save the new environment setting by typing:
env save
- Configure the FPGA.
- Boot the software: press HPS_RST (SoCKit) or Cold Reset (Intel development boards) again.
Debugging and Monitoring Hardware with System Console
- In Qsys, click Tools > System Console or in the Quartus II software, click Tools . > System Debugging Tools > System Console The Quartus II software sets the working directory to the project directory.
-
In System Console, in the Tcl console type:
source DOC_debug_gui.tcl
General Tab
Connecting Demonstration
-
On the General tab, click Connect
JTAG to connect to hardware. The Messages
window displays:
INFO: Connecting to JTAG Master /devices/5CSEBA6(.|ES)|5CSEMA6|..@2#USB-1/(link)/JTAG/(110:132 v1 #0)/phy_0/master INFO: Checking for System ID at 0x1000_0000 : Value = 0x00f012fe INFO: Version = 15.0 Device Family = 2 Powerboard Id = 1 Design Id = 254 INFO: FPGA Board : Cyclone V SX SoC Dev Kit INFO: Power Board : FalconEye v2.0 HSMC Single-axis INFO: Design Version : 15.0
- Under Axis Select, select 0, 1, 2, or 3. for multiaxis power board only.
- Click Reset Motor to reset the motor control state machine and restart the motor in constant speed mode (100 rpm).
- To test the motor without any current or position sensor feedback, click Enable Open Loop Mode.
- To re-enable closed-loop control and continue to other demonstrations, press Disable Open Loop Test Mode.
Changing DSP Mode
- Software fixed-point
- Software floating-point
- DSP Builder fixed-point
- DSP Builder floating-point
Using Speed Control
- Under Speed Demo Setup enter Speed Value 1, Speed Value 2, and Speed Interval, to set the speed and time interval between speed value switches. You can select speeds from –3,000 to +3,000 rpm.
- Click Run Speed Demo to start a sequence where System Console switches the motor speed command alternately between the two speeds at the specified time interval.
- Alternatively, select a new Speed Request value in the drop-down list.
Using Position Control
- Type in two position values (from –36,000 to + 36,000 degree), a speed limit and a position interval.
- Click Run Position Demo.
System Console Dials
On the General tab, System Console displays the following dials:
- DSP Latency:
- Measures the runtime of the field-oriented control (FOC) algorithm with software timers in the interrupt service routine (ISR)
- Shows the time taken to execute the algorithm in the different DSP modes
- Speed. The instantaneous speed (rpm) of the motor
- Position. The position of the motor shaft in degrees. System Console sets the scale automatically based on the parameters you configure in the position demonstration.
Control and Diagnostics Tab
Monitoring Performance
- On the Control and Diagnostics tab, under Trigger Signal, select the signal you want to trigger the trace data capture. If you select Always, the trigger is always active.
-
Under Trigger Edge, select one of the following trigger types:
- Level (trigger signal must match this value)
- Rising Edge (trigger signal must transition from below to above this value)
- Falling Edge (trigger signal must transition from above to below this value)
- Either Edge (triggers on both falling and rising edge conditions).
-
Under Trigger Value, select the value that Trigger Edge uses to compare the signal value against.
Note: These values are raw integer values, not the scaled values that System Console displays in the graphs. Convert the raw integer values into scaled values.
- Click Update Trigger, if you update the Trigger Value.
- Under Trace Depth, select the number of samples to capture and display. System Console can store up to 4,096 samples on SoC or 2,048 samples on MAX 10 devices. Select a lower number of samples to make the System Console update rate faster, and zoom in on the graph as the graph scale autosizes to the number of samples.
- Specify a Trace Filename. System Console saves the trace data saved to a .csv file.
- Click Start Trace to start the trace; click Disable Trace again to stop the trace.
Signals and Raw Versus Physical Values
Signal Name | Description | Raw Integer Values | Equivalent Physical Value |
---|---|---|---|
Vu Vv Vw | Space vector modulation voltages applied to motor terminals u, v and w. | 0 to 3,125 | -200 to +200 V |
Iu Iv Iw | Measured feedback currents. Iv is derived from Iu and Iw. | -5,120 to +5,120 | -1 to 1 A |
Id IdCommand Iq IqCommand | FOC direct and quadrature currents and their commanded values. IdCommand=0 for a PMSM. | -5, 120 to +5,120 | -1 to 1 A |
Speed Speed Command | Speed derived from encoder readings and its commanded value. | -32,768 to +32,768 | -2048 to +2048 rpm |
Position PositionCommand | Position derived from encoder reading, and its commanded value. | 0 to 65,536 | 0 to 1rev |
Vd Vq | FOC direct and quadrature voltages. The Voltage Output Limit also uses this scaling, but only takes positive values. | -1,563 to +1,563 | -200 V to +200 V |
Vd_unfilt Vq_unfilt | Vd and Vq before the suppression filter (if your design includes vibration suppression) | -1,563 to +1,563 | -200 V to +200 V |
System Console Graphs
On the Control and Diagnostics tab, System Console displays the following graphs
- Space vector modulation (U,V,W) voltage.
- Feedback current (U,W,V). System console measures U and W, but derives V.
- Requested direct and quadrature currents versus actual currents.
- Requested versus actual speed.
- Position from encoder versus position command. Only available when you use position demonstration.
Tuning the PI Controller Gains
-
To tune PI controller gains, on the PI
Tuning tab, under Current Control Loop, enter values for:
- Kp (proportional gain).
- Ki (integral gain).
- Current Command Limit
- Output Voltage Limit
The design applies the current command limit in three places to limit the current:- The speed PI loop integrator.
- The speed PI loop output (current command).
- The current PI loop error. .
The design applies the output voltage limit in two places to limit the applied voltage:- Current PI loop integrator.
- Current PI loop output (Voltage command)
Note: For the Current Command Limit and Output Voltage Limit, the values you enter are based on raw values. The scaling is the same as for the trigger function values. - Click Update Parameters.
- Under Speed Control Loop:
- Enter values for Kp (proportional gain) and Ki (integral gain).
- Under Position Control Loop:
- Enter values for Position Kp and Position Ki. Click Update Parameters.
Vibration Suppression Tab
About the Demonstration
The demonstration shows how to improve speed control. Speed is never perfectly constant because motors include discrete parts such as magnets, electrical coils and steel cages to hold these components. As the motor rotates, the torque produced for a given current magnitude varies. These variations (cogging torques) produce accelerations leading to speed variations. The feedback controller adjusts the current to counteract the speed variations depending on the strength of the control gains. Stronger gains reduce speed variation, but may lead to control instability or amplify mechanical resonances.
The demonstration shows the level of speed variation with default speed control gains. It then shows the speed control step response. The step response should be fast and with little overshoot or oscillation, so the speed output should look similar to the square-wave input command. The speed control step response with standard gains is slow and may stop briefly at zero speed because of friction when the motor changes direction. Increasing the speed control loop proportional gain makes the response look much faster and without any visible stop at zero speed. However, the motor produces high-frequency noise that is audible and visible in the FFTs as a broad peak around 1kHz. In a real system with a mechanism connected to the motor, this noise can easily excite mechanical vibrations. To counteract this undesirable change, apply the suppression filter using a broad notch characteristic centred on 1kHz. The resulting waveform still has a fast, square shape, but the filter suppresses the noise. The speed variation with the combination of high gain and filter is much less than the original graph, showing the benefit of the faster control.
Starting the Demonstration
- Click Start demo.
- Click Advance demo to start the demonstration step 1. The demonstration highlights the text that describes this step.
- Click Advance Demo again to start each consecutive step.
- The demonstration finishes when you click Advance Demo and all text shows again with no highlighting.
- To repeat the demonstration, click Advance Demo again.
FFT0 and FFT1 Graphs
On the Vibration Suppression tab, System Console displays the following graphs:
- Input signal to FFT0 against time.
- The magnitude of FFT0 against frequency.
- Input signal to FFT1 against time.
- The magnitude of FFT1 against frequency.
The graphs update at the same time as the graphs on the Control and Diagnostics tab whenever the trigger function in that tab activates. Within the SoC, the 4,096pt FFT data recalculates after every 64 new data points. The data sample rate is 16 kHz, thus the FFTs recalculate at 250 Hz.
System Console saves both the time- and frequency-based data to the .csv file that you specify in the Control and Diagnostics tab. You can then verify offline the correctness of the FFT calculation.
The FFT magnitude data is in dB (i.e. 20*log10 absolute value in physical units) similar to a control system Bode plot.
A basic peak detection algorithm enables you to measure particular peaks and develop automated vibration suppression. For each of the two FFTs, the algorithm finds the maximum magnitude value between two specified frequency limits. Thus, you can search for peaks within a physically relevant range without seeing large FFT magnitudes that often occur at low frequencies. System Console shows the peaks with a cross-hair superimposed on the FFT magnitude graph. It shows the frequency and magnitude values below the graph.
You can zoom into an area of the graph by clicking and dragging the cursor over that area. To return to the original scaling, right-click on the graph and select Auto Range, Both Axes.'
Setting Up FFT
- On the Vibration Suppression tab, select the FFT signal.
- Select the frequency scale: linear or log.
- Select the peak detection low and high limit frequencies.
- Click Update Limits.
Setting Up Command Waveform
-
Enter values for the parameters.
Table 6. Command Waveform Parameters Parameter Value Description Waveform type Sine, Triangle, Square, Sawtooth The shape of the repeating waveform. Period (samples) 2 to 32768 Period of the waveform, in 16 kHz samples. For example, 2000 is equivalent to 8 Hz. Position amplitude -180 to +180 +/- amplitude of the waveform, if running in position control. Negative values create a 180 degree phase shift. Speed amplitude (rpm) -2048 to +2048 +/- amplitude of the waveform, if running in speed control. Negative values create a 180 degree phase shift. On/Off On or Off Switches the waveform on or off. The waveform is superimposed on the speed or position set points from the General tab. - Click Update waveform.
Setting Up Second Order IIR Filter
-
Enter values for the IIR filter.
Table 7. IIR Filter Parameters Parameter Values Description Fn (Hz) 2 to 8000 The ‘natural frequency’ of the filter numerator, Ωn/2π. Fd (Hz) 2 to 8000 The ‘natural frequency’ of the filter denominator, Ωd/2π. Zn (nondimensional) 0 to 1000 The damping factor of the filter numerator, ζn. Values less than 0.707 produce a trough around Fn before the numerator gain increases; larger values give a smoother (more damped) characteristic. Zd (nondimensional) 0 to 1000 The damping factor of the filter denominator, ζd. Values less than 0.707 produce a peak around Fd before the denominator gain decreases; larger values give a smoother (more damped) characteristic. On/Off On or off. Switches the filter on or off. Input gain 0 to 1 This gain is in series with the filter and multiplies the complete control loop. Normally leave at 1, but setting it to smaller values reduces the overall control loop gain if required to improve control loop stability. - Click Update Filter.
Functional Description for the Drive-On-Chip Reference Design
The Qsys system consists of:
- DC link monitor
- FOC subsystem
- FFTs (SoC only)
- Processor subsystem
- Four drive channels comprising the following motor control peripheral components:
- 6-channel PWM
- ADC interface
- Drive system monitor
- Encoder interface (BiSS or EnDat)
DC Link Monitor
The DC link monitor comprises:
- Parallel input and output (PIO) for PFC monitor
- DC link voltage monitor
- DC link current monitor
FOC Subsystem
FOC controls a motor's sinusoidal 3-phase currents in real time to create a smoothly rotating magnetic flux pattern, where the frequency of rotation corresponds to the frequency of the sine waves. FOC controls the current vector to keep:
- The torque-producing quadrature current, Iq, at 90 degrees to the rotor magnet flux axis
- The direct current component, Id, (commanded to be zero) inline with the rotor magnet flux.
The FOC algorithm:
- Converts the 3-phase feedback current inputs and the rotor position from the encoder into quadrature and direct current components using Clarke and Park transforms.
- Uses these current components as the inputs to two proportional and integral (PI) controllers running in parallel to limit the direct current to zero and the quadrature current to the desired torque.
- Converts the direct and quadrature voltage outputs from the PI controllers back to 3-phase voltages with inverse Clarke and Park transforms.
The FOC algorithm includes:
- Forward and reverse Clarke and Park transforms
- Direct and quadrature current
- Proportional integral (PI) control loops
- Sine and cosine
- Saturate functions
About DSP Builder for Intel FPGAs
After you develop the algorithm in Simulink*, DSP Builder can automatically generate pipelined HDL that it targets and optimizes to the chosen FPGA device. You can use this VHDL in a HDL simulator such as ModelSim* to verify the generated logic versus Simulink* and in the Quartus Prime software to compile the hardware. DSP Builder for Intel FPGAs gives instant feedback of the VHDL's logic utilization and algorithm latency in automatically generated Simulink* reports.
DSP Builder for Intel FPGAs Folding
The DSP Builder for Intel FPGAs folding feature reuses physical resources such as multipliers and adders for different calculations with the VHDL generation automatically handling the complexity of building the time division multiplexed (TDM) hardware for the particular sample to clock rate ratio.
DSP Builder Model Resource Usage
Intel compared floating- and fixed-point versions of the FOC algorithm with and without folding. In addition, Intel compared using a 26-bit (17-bit mantissa) instead of standard single-precision 32-bit (23-bit mantissa) floating point implementation. 26-bit is a standard type within DSP Builder that takes advantage of the FPGA architecture to save FPGA resources if this precision is sufficient.
Cyclone V devices use ALMs instead of LEs (one ALM is approximately two LEs plus two registers) and DSP blocks instead of multipliers (one DSP block can implement two 18-bit multipliers or other functions).
Algorithm | Precision (Bits) | Folding | Logic Usage (ALMs) | DSP Usage | Algorithm Latency (µs) |
---|---|---|---|---|---|
FOC, floating point including filter, DFf_float_alu_av.slx | 32 | No | 11.5k | 31 | 0.71 |
FOC, floating point including filter, DFf_float_alu_av.slx | 32 | Yes | 3.9k | 4 | 2.30 |
FOC, floating point including filter, DFf_float_alu_av.slx | 26 | No | 11k | 31 | 0.70 |
FOC, floating point including filter, DFf_float_alu_av.slx | 26 | Yes | 3.6k | 4 | 2.34 |
FOC, fixed point, including filter, DFf_fixp16_alu_av.slx | 16 | No | 1.6k | 36 | 0.22 |
FOC, fixed point, including filter, DFf_fixp16_alu_av.slx | 16 | Yes | 2.3k | 2 | 3.31 |
Algorithm | Precision (Bits) | Folding | Logic Usage (LEs) | Multiplier Usage | Algorithm Latency (µs) |
---|---|---|---|---|---|
FOC, floating point without filter, DF_float_alu_av.slx | 32 | No | 30k | 53 | 0.52 |
FOC, floating point without filter, DF_float_alu_av.slx | 32 | Yes | 6.5k | 10 | 1.75 |
FOC, floating point without filter, DF_float_alu_av.slx | 26 | No | 23k | 23 | 0.47 |
FOC, floating point without filter, DF_float_alu_av.slx | 26 | Yes | 5.4k | 6 | 1.61 |
FOC, fixed point, without filter, DF_fixp16_alu_av.slx | 16 | No | 2.2k | 12 | 0.14 |
FOC, fixed point, without filter, DF_fixp16_alu_av.slx | 16 | Yes | 2.7k | 2 | 2.08 |
The results show:
- The model with folding uses fewer processing resources but has an increase in latency.
- A floating-point model with folding also uses significantly fewer logic resources (LEs/ALMs) than a model without folding.
- The 26-bit floating-point format saves significant resources compared to 32-bit in MAX 10 devices but proportionally less in Cyclone V SoCs.
- The fixed-point algorithms without folding use the fewest logic resources and give the lowest latency.
The reference design implements these FOC configurations:
- Floating-point 26-bit model on MAX 10 devices ; 32-bit on Cyclone V, both with folding.
- Fixed-point 16-bit model without folding.
DSP Builder for Intel FPGAs Design Guidelines
In your design:
- For fixed-point designs use the variable precision support in DSP Builder for Intel FPGAs. Instead of using classical 32-bit datapath, investigate the algorithm and reduce the datapath to a dimension closer to the DSP block size.
- For fixed-point datapaths, disable bit growth for adders and subtracters. For example, use 27-bit data-paths on MAX 10 devices. The bit width should provide sufficient dynamic range for handling the values in the algorithm.
- Reduce the output of fixed-point multipliers to the same size as the inputs to better integrate in the datapath.
- Use smaller components when available. For example, pure sin and cos blocks require a range reduction stage. Use the smaller sin(pi*x) and cos(pi*x).
- Restructure a sin(pi*x) and a cos(pi*x) into a sin(pi*x) and sin(pi*(0.5-x)) to allow folding to reduce resource usage.
- Ensure that the select line of a multiplexer does not use more bits than necessary. For example, for a 2:1 multiplexer, the select line should be 1 bit.
DSP Builder for Intel FPGAs Model for the Drive-On-Chip Reference Designs
The FOC algorithm comprises the FOC algorithm block and a latch block for implementing the integrators necessary for the PI controllers in the FOC algorithm. DSP Builder for Intel FPGAs implements the latches outside because of limitations of the folding synthesis.
The reference design includes fixed-point and floating-point models that implement the FOC algorithm.
Each model calls a corresponding .m setup script during initialization to set up the arithmetic precision, folding factor, and target clock speed. The folding factor is set to a large value to minimize resource usage.
Model | Folding Factor | Clock Speed (MHz) | Input Precision | Output Precision |
---|---|---|---|---|
Fixed point | 500 | 100 | sfix16En10 | sfix32En10 |
Floating point | 500 | 100 | sfix32En10 | sfix32En10 |
The following models generate the FOC block including the Avalon-MM interface:
- DF_float_alu_av.slx for floating-point designs
- DF_fixp16_alu_av.slx for fixed-point designs
Verification models stimulate the FOC algorithm using dynamically changing inputs:
- verify_DF_float_alu.slx
- verify_DF_fixp16_alu.slx
Closed-loop simulation models validate that the FOC correctly controls a motor in simulation:
- sim_DF_float_alu.slx
- sim_DF_fixp16_alu.slx
A Simulink* library model contains the main FOC algorithm code, which the models reference:
- foc_blocks.slx
Generating VHDL for the DSP Builder Models for the Drive-On-Chip Reference Designs
- Start DSP Builder for Intel FPGAs.
- Change the directory to the ip\dspba.
- If you want a different numeric precision, edit the setup_ <Simulink Model> .m file corresponding to the model before opening it.
- Load the model. Check the status of the orange DSP Builder folding block. If the model includes it, folding is enabled. If it is removed or commented out, the model does not use folding.
-
On the Simulation menu, click Start.
DSP Builder for Intel FPGAs generates the VHDL files in ip\dspba\rtl (for Cyclone V devices) or ip\dspba\rtlmax10 (for MAX 10 devices).
Avalon-MM Interface
To allow direct connectivity in Qsys, the top-level DSP Builder for Intel FPGAs design adds blocks to terminate the parallel inputs and outputs and handshaking logic with an Avalon-MM register map.
DSP Builder for Intel FPGAs generates a .h file that contains address map information for interfacing with the DSP Builder for Intel FPGAs model.
To run the DSP Builder for Intel FPGAs model as part of the drive algorithm, a C function passes the data values between the processor and DSP Builder for Intel FPGAs. The handshaking logic ensures synchronization between the software and hardware. The software sets up any changes to hardware parameters such as PI gains, writes new feedback currents, position feedback and torque command input data before starting the DSP Builder for Intel FPGAs calculation. The software then waits for the DSP Builder for Intel FPGAs calculation to finish before reading out the new voltage command data.
The ISR that runs the FOC algorithm calls the C function with an option to switch between software and DSP Builder for Intel FPGAs implementations at runtime.
FFTs
Servo FFTs
Device | Logic | Memory | Other |
---|---|---|---|
Cyclone V | 550 ALMs | 29 M9K | 2 DSP blocks |
The processing time with a 100-MHz clock is around 0.6ms including the time to clock data out of the FFT block again. The processing time for two parallel FFTs is the same. You may choose other FFT implementations for the FPGA for faster processing times if required, at the expense of FPGA resources.
Running test_servofft.mdl
- When you run the test_servofft.mdl Simulink model in the project dspba directory, setup_test_servofft.m runs the set up configuration parameters for the FFT and imports sampled motor current data from the input data for the simulation file (test_servofft_sampledata.csv).
- DSP Builder generates the HDL code.
- Simulink runs the simulation, using the sampled current data from test_servofft_sampledata.csv as FFT input.
- analyze_test_servofft.m collects the simulation output and creates some MATLAB plots to verify correct calculation. It compares the simulated servo FFT output with that from the MATLAB FFT and with output data collected from servo FFT running in hardware.
Vibration Suppression
Methods of automatically tuning filter and control gains depend on:
- Knowledge of the mechanical and electrical properties of the mechanisms that the motor drives
- The effects of different filter settings on the overall control response
Command Waveform
You can choose the waveform shape, period (expressed as a number of 16 kHz samples), and amplitude.
IIR Filter
The IIR filter is a configurable second-order
digital filter, based on the second-order continuous time transfer function (in Laplace
notation):
The design converts the continuous time formulation to a discrete-time formulation using a combination of the Tustin (bilinear) transformation and frequency prewarping, which ensures that the discrete time and continuous time filter characteristics match at a specified frequency Ω:

The design applies prewarping to the denominator terms with Ω = Ωd and to the numerator terms with Ω = Ωn, which ensures that the filter preserves the corner frequencies of Ωd and Ωn after the transformation.
The design applies the IIR filter to the Vd and Vq voltage signals. These signals are the final outputs of the linear control system before the trigonometric transformation to stator-fixed voltages (Vα and Vβ) and the space vector modulation (SVM) conversion to transistor gate signals.
The IIR filter is integrated into the FOC algorithm. Different DSP modes use different implementations of the FOC algorithm. Each implementation of the FOC algorithm includes a matching implementation of the IIR filter.
IIR Filter Tuning Parameters
Parameter | Description |
---|---|
Ωd | Corner frequency (rad/s) above which the denominator response magnitude begins to decrease. |
ζd | Damping factor that determines the sharpness of the corner at Ωd; ζd < sqrt(0.5) results in a filter response peak (filter resonance) around Ωd, whereas ζd > sqrt(0.5) gives a more gradual (more strongly damped) transition with no peak. |
Ωn | Corner frequency (rad/s) above which the numerator response magnitude begins to increase. |
ζn | Damping factor that determines the sharpness of the corner at Ωn; ζn < sqrt(0.5) results in a filter response trough around Ωn, whereas ζn > sqrt(0.5) gives a more gradual transition with no trough. |
Use these four parameters to create different filter response shapes. For vibration suppression, use a notch characteristic to decrease the system gain only around the frequency of interest. Set Ωn = Ωd and ζn < ζd. The gain at Ωn = Ωd is then equal to ζn/ ζd
IIR Filter Examples
Description | Ωd (Hz) | Ωn (Hz) | ζd (nondimensional) | ζn (nondimensional) |
---|---|---|---|---|
Sharp notch with 10x gain reduction at 2 kHz | 2,000 | 2,000 | 0.3 | 0.03 |
Wide notch with 10x gain reduction at 1 kHz | 1,000 | 1,000 | 100 | 10 |


Vibration Detection
Nios II Subsystem for MAX 10 FPGA Development Kits
- Nios II fast processor
- Floating-point hardware custom instructions 2 (optional)
- Tightly coupled instruction and data memory
- JTAG master
- Performance counters
- Clocking and bridge
- SDRAM controller
- JTAG UART
- System console debugging RAM
- Debugging dump memory
The ISR uses the tightly coupled memory blocks for code and data to ensure fast predictable execution time for the motor control algorithm.
The Nios II subsystem uses the JTAG master and debug memories to allow real-time interactions between System Console and the processor. The reference design uses the System Console debugging RAM to send commands and receive status information. The debugging dump memory stores trace data that you can display as time graphs in System Console.
Motor Control Peripheral Components
- 6-channel pulse width modulator (PWM)
- ADC interface
- BiSS encoder interface
- EnDat encoder interface
- Drive system monitor
The reference design puts the motor control peripheral components in a separate Qsys subsystem (DOC_AXIS_Periphs.qsys), which allows you to disable, enable, or add, extra axes.
This section describes the motor control peripheral components and describes specific connectivity issues when instancing the motor control suite peripherals in Qsys.
6-Channel PWM
The PWM provides synchronization between multiple PWM instances. To implement this feature the reference design programs the PWMs identically: in Qsys one instance is the master PWM and connects the sync_out port to the other PWM sync_in port. For additional instances, continue chaining the sync_out port from the last instance to the next sync_in port. For example:
sync_out (PWM0) to sync_in (PWM1) and sync_out(PWM1) to sync_in(PWM2)
An internal counter defines the PWM period from 0 to PWMMAX and then back to 0. The design configures it for an 8-kHz rate, and the internal clock rate of the PWM is 50 MHz. To achieve an 8-kHz period with an internal clock rate of 50 MHz, set the carrier register value to 3,125. Therefore:
carrier = (50 MHz / 8 kHz) / 2 = 3,125
The carrier_latch output indicates to the position encoder to take a position reading. It is high for one clock cycle when the counter is at zero and at PWMMAX.
The start output indicates to the phase current ADC interfaces to start sampling. It is offset from the carrier_latch position, so it occurs at a fixed position before it. The pwm_trigger_up sets the trigger value when the PWM counter is counting up; pwm_trigger_down sets the trigger value when counting down (Table 14).
ADC Interface
To offset the effect of current ripple, the reference design centers the ADC reading at the PWM reversal point. The reference design configures the start pulse to be at:
(settling time)/2
The reference design configures the phase current ADC interfaces to a decimation rate of M = 128, which requires a settling time of 19.2 s. To centre the ADC sampling, apply an offset to the PWM trigger of 9.6 s (480 clock periods @ 50 MHz).
For an ADC clock rate of 20 MHz,
Decimation Rate | PWM Trigger Down | PWM Trigger Up | Offset (s) |
---|---|---|---|
64 | 240 | PWMMAX –240 | 4.8 |
128 | 480 | PWMMAX – 480 | 9.6 |
An additional ADC measures the combined current flowing from the DC link for power consumption measurements.
EnDat Encoder Interface
The EnDat IP core requires a strobe to capture a position reading at a time synchronized with the ADC interface. The reference design generates the EnDat strobe at the exact reversal point of the PWM without offset.
BiSS Encoder Interface
The ip\biss_OCP directory includes the datasheet for the BiSS Master IP core.
The BiSS IP core requires a strobe to capture a position reading at a time synchronized with the ADC interface. The reference design generates the BiSS strobe at the exact reversal point of the PWM without offset.
Motor Control Software
Doxygen generated HTML help files are in the software\CVSX_DS5\DOC_CVSX\source\doxygen or software\source\doxygen directory. Open the index.html file in a browser to view the help files.
Nios II Motor Control Software Project
Setting Up the Nios II BSP
If you make any changes to the default BSP:
- Map .exceptions to TCM_Instruction_Memory (configured in Nios II parameters in System Console)
- Map exceptions_stack_memory_region_name to TCM_Data_Memory - size = 1,024
- Map interrupt_stack_memory_region_name to TCM_Data_Memory - size = 1,024
- Add section .fast_math and map to TCM_Instruction_Memory
- Add section .table_data and map to TCM_Data_Memory
- Add section .drive_data and map to TCM_Data_Memory
SoC HPS Motor Control Software Project
Intel provides DS-5 debug script that first loads and runs the preloader, then loads and runs the application to a breakpoint at main(). Execution can continue from this point or you can set further breakpoints or configure memory watch windows.
Building the HPS Preloader
- Delete the existing \software\spl-bsp directory to remove the old preloader.
- Run the bsp-editor in the \software directory to ensure that the preloader generate in the correct directory, so the software Makefile can find it when building the HPS software. The watchdog timer must be disabled in the bsp-editor (turn off WATCHDOG_ENABLE).
SoC HPS Execute-in-Place (XiP) Variant
Building the Preloader for XiP
-
Configure the preloader for XiP in the bsp-editor:
- Turn off BOOT_FROM_SDMMC
- Turn on BOOT_FROM_QSPI
- Turn on SKIP_SDRAM
- Turn off WATCHDOG_ENABLE (unless the application is modified to pet the watchdog)
- Turn off SDRAM_SCRUBBING
- Turn off SDRAM_SCRUB_REMAIN_REGION
- Turn off HARDWARE_DIAGNOSTIC
- Generate the preloader.
- Compile the preloader (make all).
-
In include/configs/socfpga_common.h, search for the following macros and #define or #undef:
#define CONFIG_SPL_SPI_XIP
#define CONFIG_SPL_SPI_XIP_ADDR 0xFFA40040
#undef CONFIG_USE_IRQ
- Compile the preloader again (make).
Building the Application for XiP
Programming the QSPI FLASH With the XiP Preloader and Application
- Turn off then turn on the power to the board.
- Open the quartus_hps utility in a SoC EDS Command Shell.
-
Program the preloader:
quartus_hps -c 1 -o PV --boot=0 preloader-mkpimage.bin
-
Program the application:
quartus_hps -c 1 -o PV -a 0x40000 --boot=0 doc_xip-mkimage.bin
If the command fails the first time because the HPS boots from the existing QSPI contents, try again.
XiP Application Debugging Script
Document Revision History for AN 669: Drive-on-Chip Reference Design
Date | Version | Changes |
---|---|---|
2020.11.05 | 3.3 | Rebranded to Intel. |
2019.11.07 | 3.2 | No changes. |
2019.04.18 | 3.1 | Corrected link to iC Haus BISS interface website |
June 2015 | 3.0 |
|
June 2014 | 2.1 |
|
February 2014 | 2.0 |
|
May 2013 | 1.3 |
|
February 2013 | 1.2 |
|
November 2012 | 1.1 | Added FalconEye. |
August 2012 | 1.0 | Initial release. |