FPGA Lab Tutorial
FPGA Lab Tutorial
August 5, 2011
TABLE OF CONTENTS
OVERVIEW .......................................................................................................................................... 3 MODULE 1: Getting Started................................................................................................................. 4 1.1 1.2 1.3 1.4 Acquire the BeInMotion Development Kit .............................................................. 4 Install the Altera Design Software ........................................................................... 4 Extract the BeInMotion Lab Files............................................................................. 7 Install the USB-Blaster Device Driver ...................................................................... 7
MODULE 2: Examine the System Design......................................................................................... 10 2.1 2.2 2.3 Examine the System Tool Flow .............................................................................. 10 Examine the BeInMotion Kit.................................................................................. 11 System Architecture .............................................................................................. 12
MODULE 3: Create a new Quartus II Project.................................................................................... 13 3.1 3.2 3.3 3.4 3.5 Create New Quartus II Project ............................................................................... 13 Add Files to the Project ......................................................................................... 14 Specify Family and Device Settings ....................................................................... 14 Select EDA Tool Settings ........................................................................................ 15 Execute Setup Script .............................................................................................. 15
MODULE 4: Build the Qsys System.................................................................................................. 17 4.1 4.2 4.3 4.4 4.5 4.6 Launch Qsys ........................................................................................................... 17 Create New Component ........................................................................................ 18 Add Component to System.................................................................................... 21 Connect Component to System............................................................................. 21 Generate Qsys System ........................................................................................... 23 Compile the Quartus II Project .............................................................................. 24
MODULE 5: Import and Compile the Software Design Using Nios II EDS .................................... 26 5.1 5.2 5.3 5.4 5.5 Create Eclipse Workspace ..................................................................................... 26 Create New Nios II Application and BSP ................................................................ 27 Edit and Generate BSP........................................................................................... 29 Import Software .................................................................................................... 30 Load Design into Toolstick Using the Nios II Flash Programmer ........................... 33
OVERVIEW
MODULE 6: DC Motor Synchronization ........................................................................................... 36 6.1 6.2 6.3 Connect the Proximity Sensor Board..................................................................... 36 Drive the BeInMotion ............................................................................................ 36 Change Motor Parameters .................................................................................... 37
MODULE 7: Stepper Motor ................................................................................................................ 40 7.1 7.2 7.3 7.4 Create New Nios II Application .............................................................................. 40 Stepper Mode Parameters .................................................................................... 42 Run the Stepper Controller on the BeInMotion kit ............................................... 42 Change Stepper Modes ......................................................................................... 44
APPENDIX A: Hardware PID and Software PID ............................................................................... 45 APPENDIX B: Battery Gas Gauge ..................................................................................................... 46 B.1 B.2 Create New Nios II Application .............................................................................. 46 Run the Battery Status Application on the BeInMotion Kit................................... 49
APPENDIX C: Taking the Next Step.................................................................................................. 50 APPENDIX D: Troubleshooting ......................................................................................................... 51 APPENDIX E: Restoring the Factory Image ..................................................................................... 52
OVERVIEW
OVERVIEW What Does It Take To Create Your Own Motor Control System?
This lab teaches you how to create motor control systems implemented in programmable logic. You will build a processor-based hardware system and run software on it. You will see how quick and easy it is to build motor control systems using Alteras Qsys and the Nios II EDS to configure and integrate pre-verified IP blocks. The reference demos include programming the system as an autonomous vehicle with wall and edge avoidance and synchronized movement. Simple PID control will be used to influence the DC motor's speed and position. The stepper motor will be controlled based on full step, half step and micro-stepping modes. A final demo has been included in the appendix to monitor the charge remaining in the battery system and display the value on the LCD.
Lab Notes:
Many of the names that the lab asks you to choose for files, components, and other objects in this exercise must be spelled exactly as directed. This nomenclature is necessary because the pre-written software application includes variables that use the names of the hardware peripherals. Naming the components differently can cause the software application to fail. There are also other similar dependencies within the project that require you to enter the correct names. No IP licenses are required to run these reference demos. For technical support or questions, please review Appendix D "Troubleshooting" NOTE: This lab guide requires an Arrow Electronics BeInMotion FPGA-based Motor Control Kit (www.arrow.com/beinmotion).
1.1
This development kit can be ordered from http://www.arrow.com/beinmotion. It consists of two pieces, the BeMicro SDK development kit and the BeInMotion motorized base.
1.2
You will need to install the following design software packages: 1. Quartus II 11.0 Web Edition design software FPGA synthesis and compilation tool that contains Qsys and the MegaCore IP library with the Nios II processor IP core
2. Nios II 11.0 Embedded Design Suite A complete, integrated environment for software development If you already have both Quartus II and the Nios II EDS installed on your machine, you may skip ahead to Section 1.3 to extract the lab files. INSTALLING FROM THE DVD-ROM: Please skip ahead to step 4 of the installation instructions. INSTALLING FROM THE WEB: Please follow steps 1 through 4 of the installation instructions. The Web Edition can be downloaded from the Altera web site. PLEASE CAREFULLY FOLLOW THE STEPS SHOWN BELOW. 1. Go to the Altera Download web page at https://www.altera.com/download/dnl-index.jsp
3. Log-in to myAltera using your login credentials OR select Get One-Time Access
4. Altera Installer Setup. Run the Altera Installer and Navigate to the Installer Setup page. Select the Download Installation Files from the Internet radio button
5. Select Components. Select Quartus II Web Edition and Nios II Embedded Design Suite components for download.
1.3
Download BeInMotion.zip from http://www.arrow.com/beinmotion Create a folder called altera_trn on your PC (eg. C:\altera_trn). Extract the contents of BeInMotion.zip to the altera_trn folder on your PC. Make sure there are NO SPACES in the path name. This will create a BeInMotion_lab folder, which will be the root folder for the labs.
1.4
Connect the BeMicro SDK to the 80-pin edge connector on the motor base. Plug the Type A USB port to your PC. It is recommended to use a USB extension cable to reach from the PC to kit. Once connected, your Windows PC will find the new hardware and a message will come up and request that the driver needs to be installed. NOTE: The Mini-B USB connector on the BeInMotion Motor Base is used to charge the battery. Use an AC adaptor with USB power output of 5V at 0.5A or greater. LED1, a green LED on the motor base, will illuminate when the battery is charging and turn off once charging is complete. The battery will charge with the power switch on or off. Power supplied through the USB Type A port will power the kit, but will not charge the battery.
Windows XP
Windows 7
Windows XP USB-Blaster Driver Installation Select Install from a list or specific location (Advanced) and continue through the wizard. In the next dialogue box point the wizard to the drivers which can be found in your Quartus II installation directory under <install directory>\11.0\quartus\drivers\usb-blaster. If Windows presents you with a message that the drivers have not passed Windows Logo testing, please click Continue Anyway.
Windows 7 USB-Blaster Driver Installation If Windows 7 does not detect the driver, it can be installed manually through the Device Manager.
Open the Device Manager and Right Click on USB-Blaster. Select Update Driver Software...
In the next dialogue box select Browse my computer for driver software. Point the wizard to the drivers which can be found in your Quartus II installation directory under <install directory>\11.0\quartus\drivers\usbblaster. Check the box to Include Subfolders. If Windows presents you with a message that the publisher can't be verified, please click Install this driver software anyway.
CONGRATULATIONS!! You have just completed all the setup and installation requirements and are now ready to examine the system-level design.
2.1
The above diagram depicts the typical flow for system design. System definition is performed using Qsys. The results are two-fold:
System description that the Nios II Embedded Design Suite, the software design tool, uses to create a new project for the software application. HDL files for the system that are used by the Quartus II FPGA design software to compile and generate the hardware system. The output of the Hardware Flow is an FPGA image that is used to configure the FPGA. The output of the Software Flow is an executable from which the Nios II processor executes instructions.
2.2
This shows the major components of the BeInMotion kit. Featured components include Arrow Electronics' BeMicro SDK development kit with Altera Cyclone IV-E FPGA and the BeInMotion Motor Base designed by System Level Solutions. Other featured components include: Proximity IR Detector Proximity A/D Converter Battery Gas Gauge Stepper Feedback Current Sensor Stepper Feedback A/D Converter
Avago APDS9800 Linear Technology LTC2485 Linear Technology LTC2942-1 Linear Technology LTC1999 Linear Technology LTC1865
2.3
SYSTEM ARCHITECTURE
The system above can be created in Qsys using a standard library of re-useable IP blocks. The System Interconnect Fabric is automatically generated by Qsys and binds the blocks together. The system interconnect manages dynamic bus-width matching, interrupt priorities, arbitration and address mapping. This system is a full-featured processor system capable of running operating systems such as uC-OSII or Linux. The following pages will guide you through the process of building the embedded system shown above.
3.1
Name the project BeInMotion. NOTE: Verilog is case sensitive. Match the case exactly to match the top-level Verilog file.
Click Next.
3.2
On page 2, you will add pre-made source files to the new project. Click the Add All button to include all design files located in the project folder.
Click Next
3.3
Click Next.
3.4
3.5
The I/O pin constraints have been included in a Tcl script in order to set up the Quartus II project properly.
Under the Tools menu, select Tcl Scripts. In the Tcl Scripts dialog box, scroll down if needed to choose the pin_assignments.tcl script. Click Run.
The Tcl Console window will open when this script is run, it may be closed.
Under the Quartus Assignments menu, select Pin Planner. Observe the new pin assignments that have been added to the project. For now, the direction says Unknown. These will update to the correct direction (Input, Output or Bidir) when the project is compiled later on.
CONGRATULATIONS!! Your Quartus II project is set up. You are ready to start building your Qsys system.
Altera Corporation Arrow Electronics, Inc 16 BeInMotion Motor Control Lab August 2011
4.1
LAUNCH QSYS
From the Tools menu, select Qsys, or click the Qsys button on the toolbar. There may be a slight delay while the Qsys application launches.
In the Open dialog, select the system name BeInMotion_qsys.qsys. Click Open. Examine the Qsys GUI. Each component listed in the System Contents window has a Description, Clock Source, Memory Address, and IRQ, if required. The Component Library contains all available components to add to the system. The components used in this system come from a variety of sources. Most are Altera components that ship with Qsys such as the Nios II/e processor, Parallel I/O controller, Interval Timer, SPI Controller and the EPCS Serial Flash Controller. SLS created the motor controllers and DC motor optical receiver. The I2C masters are from OpenCores.org. Qsys integrates these components together and generates all files required for synthesis This lab requires a stepper motor controller, which is not in the Component Library. A new component will be created and added to the library.
4.2
Create the stepper motor controller to add to the Qsys Component Library
Click File, New Component... Click Next to advance past the New Component Introduction. Click Add... to select the source HDL
The file is analyzed for syntax errors, click Close NOTE: The two errors listed in the Messages window are corrected in the following steps.
Click Next
The ports found in the HDL top level entity are listed in the Signals tab. Qsys automatically detects the signal types. However, signals that route to the system top level must be exported through a conduit as follows: Change the Interface for signal st_output. Click the Interface column, choose new Conduit... This will change to "conduit_end". Change the Signal Type for st_output. Click the Signal Type column, choose export NOTE: Make sure you click on the word export. The GUI will appear to automatically select export, but it must be clicked in the pulldown box. Click Next
BeInMotion Motor Control Lab 19 August 2011
The Interfaces tab lists parameters for each signal's interface used by the component. Scroll down to view the parameters for avalon_slave_0. In the Associated Reset pull-down box, select reset.
Click Next Accept the default HDL parameters, click Next Enter the following for Library Info: Name: st_motor_top Display name: Stepper Motor Controller Version: 1.0 Group: SLS Description: Stepper Motor Created by: System Level Solutions Icon: Browse to C:\altera_trn\BeInMotion_lab\ip\stepper_motor\hdl and select sls_logo.jpg
4.3
The new Stepper Motor component is now contained in the library, add it to the system Expand SLS in the Component Library
Select Stepper Motor Controller Click + Add... The Qsys symbol for the Stepper Motor is displayed. Click Finish
4.4
The component's interface ports must be connected to the rest of the system. Start by renaming the component to match the name used in the top-level Verilog file. Right-click on the new stepper motor component in the System Contents window and click Rename
Enter stpr_motor_cntrl Connect the external 50 MHz clock to the stepper controller. Click the Clock selection to change from "unconnected" to ext_clk.
Expand the cpu component to reveal the Connections panel. This will allow us to make the necessary connections between the Stepper Motor Controller and the Nios II Processor.
Hold the mouse pointer over the Connection panel to view the connection options for stpr_motor_cntrl Connect the reset port by clicking the connection to cpu.jtag_debug_module_reset
Connect the conduit_end port to the top level by clicking in the Export column "Click to export" Enter stpr_motor
The Base address will remain 0x00000000 and there is no IRQ for the stepper motor controller. The completed component connections will look like this:
4.5
The Qsys system is ready to generate. First take a look at some of the project settings. Each of the following are tabs at the top of the screen. Click on each one to examine the settings. Address Map: List of all components with memory address ranges for each one Clock Settings: List of clocks available to use in the system. This includes external clocks and PLL generated clocks Project Settings: Block diagram symbol of all interfaces to the Qsys system. Scroll down to see the project level settings, leave these at the default. System Inspector: Provides detailed information of all connections and interfaces used in the system. HDL Example: VHDL and Verilog HDL code examples that can be used to instantiate the Qsys system. Generation: Includes options to create simulation models and test benches during generation. On the Generation page, Accept the defaults, click Generate.
Click Save
Qsys will generate the system, allow several minutes for this to complete. Click Close Generate Complete message Close Qsys, click File, Exit
4.6
Quartus II will compile the Qsys generated code and other source files included in the design. Quartus II creates an SRAM Object File (*.SOF) which is the configuration file for the FPGA. The .SOF contains the Nios II processor, which must be in the FPGA prior to downloading software, so the Programmer is run right after compilation. Click the Start Compilation button to begin. Allow 7-12 minutes for this to complete. The initial compilation will take longer than subsequent compiles since the database and other support files are created for the first time.
Once compilation is complete, click the Programmer button to load the FPGA
Click Hardware Setup... to select the USB-Blaster if it is not already selected. Verify the programming mode is set to JTAG
Verify that BeInMotion.sof is listed and the Program/Configure box is checked. If BeInMotion.sof is not listed as the current File, Delete the current file, click Add File..., and browse to the project folder C:\altera_trn\BeInMotion_lab to select BeInMotion.sof Click Start Once Progress reaches 100%, close the Programmer Window
CONGRATULATIONS!! You have completed the Qsys system and compiled the Quartus II project. The Nios II processor has been loaded into the FPGA, so you are ready to start building your software application for motor control.
MODULE 5: Import and Compile the Software Design Using Nios II EDS
MODULE 5: IMPORT AND COMPILE THE SOFTWARE DESIGN USING NIOS II EDS
Module Objective The Nios II EDS compiles the software applications that run on the Nios II processor. The Nios II EDS also creates the Board Support Package (BSP), which is the software's interface to the hardware generated by Qsys. The application in this module will compute the PID for each motor and drive each motor with PWM while taking feedback from an optical encoder. The following steps will guide you through creating a new BSP and Nios II application, downloading software to the BeInMotion and viewing PID parameter changes directly on the BeInMotion kit.
5.1
The Nios II EDS requires a workspace to store project files. Open the Nios II EDS Start->Programs->Altera->Nios II EDS 11.0->Nios II Software Build Tools for Eclipse. NOTE: If using Windows 7, right-click on this shortcut and select Run as administrator. Select location for workspace, click Browse... Navigate to project folder C:\altera_trn\BeInMotion_lab
MODULE 5: Import and Compile the Software Design Using Nios II EDS
5.2
Nios II EDS opens with an empty Project Explorer. Run the wizard to create the BSP and Application folders. The BSP uses the SOPCINFO file generated by Qsys to configure the Hardware Abstraction Layer and device drivers. This lab starts with a single Application folder, more will be added later to simplify switching software applications while using a common Nios II hardware platform. Nios II EDS has Project Templates that serve as software reference designs. We will use the Blank-Project Template and import the source code for this design. Click File, New --> Nios II Application and BSP from Template
Select SOPC Information File name: Click Browse ... Navigate to the project folder C:\altera_trn\BeInMotion_lab and select BeInMotion_qsys.sopcinfo Enter Application Project name: DC_Motor_Synchronization Check Use default location
MODULE 5: Import and Compile the Software Design Using Nios II EDS
Select template Blank Project Click Next Select Create a new BSP project based on the application project template Delete the default BSP name and enter Project name BeInMotion_bsp. This BSP will be used by several applications during this workshop.
MODULE 5: Import and Compile the Software Design Using Nios II EDS
5.3
Nios II EDS has created two folders, one for the BSP, and one for the application. These are located in the project folder's software directory, C:\altera_trn\BeInMotion_lab\software. The BSP folder contains system.h, Hardware Abstraction Layer (HAL) and device drivers. The following steps will guide you through editing the BSP properties and generating the BSP files. Right-click on the BSP folder BeInMotion_bsp and choose Nios II --> BSP Editor...
Check the boxes for enable_reduced_device_drivers and enable_small_c_library. This will reduce the code size so it will fit in the FPGA's on-chip memory. Scroll down and check the boxes for enable_exception_stack and enable_interrupt_stack The default settings will be used for the remainder of the BSP. Click on the tabs at the top of the BSP Editor to review the settings on each tab. Here you will see settings for selecting Software Packages, Drivers, Linker Script, Enable File Generation and Target BSP Directory.
MODULE 5: Import and Compile the Software Design Using Nios II EDS
Click Generate Click Exit Right-click on the BSP folder, BeInMotion_bsp, and choose Build Project to complete the BSP.
5.4
IMPORT SOFTWARE
The application folder in the Nios II EDS contains the C source code. The software application will run on the target hardware previously defined in the BSP. The following steps will guide you through importing software source files and compilation.
MODULE 5: Import and Compile the Software Design Using Nios II EDS
Expand General and choose File System Click Next Click From directory: Browse... Navigate to C:\altera_trn\beinmotion_lab\ import_code\dc_motor_synchronization Click OK Click the check box next to the folder dc_motor_synchronization to select all files in the folder
MODULE 5: Import and Compile the Software Design Using Nios II EDS
The design includes LCD support files which are in library format, set the library path in Properties Right-click on the Application folder, DC_Motor_Synchronization, and choose Properties
MODULE 5: Import and Compile the Software Design Using Nios II EDS
Select the dc_motor_synchronization application directory located at C:\altera_trn\beinmotion_lab\software\dc_motor_synchronization and click OK Click Yes to convert the path to a relative path Click Add... next to Library name: Enter slsgui Click OK The application is ready to be compiled. Right-click on the Application folder, DC_Motor_Synchronization, and choose Build Project.
5.5
Now that the software application is compiled, it can be downloaded directly to the FPGA via JTAG, or stored in serial flash memory located on the BeMicro SDK tool stick. The Nios II Flash Programmer can program to memory Nios II software executable files, FPGA configuration code and other data files such as coefficient tables or sine lookup tables. The following steps will guide you through storing the Quartus II *.SOF and the Nios II executable *.ELF to flash using the Nios II Flash Programmer.
MODULE 5: Import and Compile the Software Design Using Nios II EDS
Click File, New to create a New Flash Programmer Settings File Click Get flash programmer system details from BSP Settings File Click Browse ... to locate the BSP Settings File name Navigate to the BSP location C:\altera_trn\BeInMotion_lab\software\BeInMotion_bsp and select settings.bsp
Click OK Click Add... to include the hardware image file Select Files of type: Quartus II SOF File Navigate to the project folder C:\altera_trn\BeInMotion_lab and select BeInMotion.sof
MODULE 5: Import and Compile the Software Design Using Nios II EDS
Click Add... again, this time to include the software ELF Select Files of type: Nios II ELF File Navigate to the project application folder C:\altera_trn\BeInMotion_lab\software\DC_Motor_Synchronization and select DC_Motor_Synchronization.elf Click Start The flash is programmed when the message "Leaving target processor paused" appears. Click Exit
CONGRATULATIONS!! You have created and compiled the software application to control the DC motors in the BeInMotion kit. The flash memory is programmed, it's time to drive the kit!
6.1
6.2
Press either SW7 or SW8 corresponding to the position of the proximity sensor board and watch it go! Turn off the BeInMotion kit to reset or change modes.
6.3
In this closed loop control system, the encoder count values are fed into the PID algorithm which detects any differences between the two motors. Based on the error detected, the PWM duty cycle is changed to each motor accordingly to keep the motors synchronous. The three PID terms are Proportional Term (Present error), Integral Term (Accumulation of Past Errors) and Derivative Term (Prediction of future errors). The initial values have been chosen to properly tune the motors and keep them synchronous. If the constant parameters of these terms are chosen incorrectly, the system can become unstable.
Turn off the BeInMotion kit and reconnect the kit to the PC USB cable Open dc_motor_sync.c located in the DC_Motor_Synchronization Application folder Make the following modifications to PID parameters for DC motor 1: #define dc_m1_Kp 12 #define dc_m1_Ki 4 #define dc_m1_Kd 4
Click Save
Right click on the Application folder, DC_Motor_Synchronization, and choose Build Project.
Right Click on the Application folder, DC_Motor_Synchronization, and choose Run As -> Nios II Hardware
NOTE: The Nios II Run Configurations window will appear the first time Nios II- Run As Hardware is launched. Subsequent runs will download directly without opening this window. Changes to the Run Configurations can be made in Run -> Run Configurations.
Click the Target Connection tab to view the detected Processors and Byte Stream Devices.
Click Run NOTE: If the Run button is grayed out, click the Refresh Connections button.
Nios II Run As Hardware will download the new software image directly to the FPGA without overwriting the flash contents. This is a quick way to test out new code. Cycling power to the FPGA will restore the original code in flash memory. The system is ready when the Console reports "Starting processor"
Push the power switch to the ON position. Disconnect the USB cable, the kit will switch to battery power and stay on. Press SW7 or SW8 corresponding to the position of the proximity sensor board.
Notice that DC motor 1 is no longer stable since the PID calculation is no longer tuned to the motor. Reconnect the kit and experiment with different PID values.
CONGRATULATIONS!! You have run the DC motor control applications on the BeInMotion kit and modified the PID parameters controlling the motor synchronization.
7.1
Enter Project Name: Stepper_Motor BSP location: click Browse ... Select the BSP, BeInMotion_bsp Accept the defaults for the remaining options, Click Finish
Nios II EDS has generated a new Application folder, Stepper_Motor. Import source code into the folder. Right click on Stepper_Motor, choose Import
Click From directory: Browse... Navigate to C:\altera_trn\beinmotion_lab\ import_code\stepper Click OK Click the check box next to the Stepper folder Accept the rest of the defaults and click Finish
7.2
#define WAVE_STEP_FWD #define WAVE_STEP_BWD #define HALF_STEP_FWD #define HALF_STEP_BWD #define FULL_STEP_FWD #define FULL_STEP_BWD #define MICRO_STEP_FWD #define MICRO_STEP_BWD
Open st_motor_I_measurement.c located in the Stepper_Motor Application folder. Observe the stepper mode is set to FULL_STEP_FWD.
7.3
Connect the BeInMotion kit to the PC USB cable Compile the application. Right-click on the Application folder, Stepper_Motor, click Build Project.
Right-click on the Application folder Stepper_Motor, click Run As -> Nios II Hardware If the Run Configurations window appears, click Run
Once the software has loaded, the stepper motor will complete a few rotations using the Full Step stepper mode.
The feedback from the current sensor is displayed in the Nios II Console
7.4
In the Wave Drive mode only a single phase is activated at a time. It has the same number of steps as the Full Step mode, but the motor will have significantly less torque. Full Step is the usual method for driving a stepper motor. Two phases are always on and the motor will have full rated torque. When Half stepping, the drive alternates between two phases on and a single phase on. Micro Stepping is smoother compared to Full and Half Step Mode. The controller has to apply input pulses such that current flowing through the winding follows a sine/cosine pattern. The controller uses PWM to generate the sine waves.
Rebuild the project. Right-click Stepper_Motor, select Build Project Reload the software on the BeInMotion kit. Right-click on Stepper_Motor, select Run As -> Nios II Hardware Notice the change in speed of the motor and the current sensor feedback reported in the Nios II console during operation. Full Step Mode will have the greatest current consumption, Micro Step Mode will have the least.
CONGRATULATIONS!! You have created the stepper motor controller application and run it on the BeInMotion kit! The current consumption is reported in the Nios II Console during stepper mode operation.
Control loops can be accelerated by implementing them in hardware rather than using the processor to calculate the algorithm. A good example is implementing the PID calculation in hardware rather than software. An example has been provided in this lab. There are two PID controllers supplied with this lab, a hardware PID written in Verilog and a software PID written in C.
Rebuild the DC_Motor_Synchronization application and Run As->Nios II Hardware. NOTE: This hardware PID implementation was not designed to use floating point multiplication or addition. Make sure only integers are used when selecting the PID parameters for hardware PID mode. Altera offers these resources if you would like to learn more about floating point capabilities: Taking Advantage of Advances in FPGA Floating-Point IP Cores http://www.altera.com/literature/wp/wp-01116-floating-point.pdf Floating Point Megafunctions User Guide http://www.altera.com/literature/ug/ug_altfp_mfug.pdf
Altera Corporation Arrow Electronics, Inc 45 BeInMotion Motor Control Lab August 2011
B.1
Enter Project Name: Battery_Status BSP location: click Browse ... Select the BSP BeInMotion_bsp Accept the defaults for the remaining options, Click Finish
Nios II EDS has generated a new Application folder, Battery_Status. Import source code into the folder. Right click on Battery_Status, choose Import
Click From directory: Browse... Navigate to C:\altera_trn\beinmotion_lab\import_code\ battery_status Click OK Click the check box next to the battery_status folder Accept the rest of the defaults and click Finish
The design includes LCD support files which are in library format, set the library path in Properties Right-click on the Application folder, Battery_Status, and choose Properties
Expand Nios II Application Properties and choose Nios II Application Paths Click Add... next to Application library directories: Select the battery_status application directory located at C:\altera_trn\beinmotion_lab\soft ware\battery_status Click Yes to convert the path to a relative path Click Add... next to Library name: Enter slsgui Click OK
The application is ready to be compiled. Right-click on the Application folder, Battery_Status, and choose Build Project.
B.2
Once the build is complete, Right click on the Application folder Battery Status. Click Run As -> Nios II Hardware
The reset options for the battery gas gauge are displayed upon startup. Resetting the battery gas gauge with the minimum or maximum coulomb count values will provide the most accurate status within 1%. The battery gas gauge will continue monitoring the battery status even when the kit is powered off, or a new software application is loaded. SW5 writes a coulomb count value to the battery gas gauge according to the current voltage level. This method is 90-95% accurate. Press and hold SW5 until the "Reset Complete!" message appears. NOTE: Disconnect the mini-USB and BeMicroSDK USB cables before pressing SW5 to ensure an accurate voltage reading. SW5 needs to be pressed only the first time the application is run, or if the battery has been disconnected. The charge status will report "FULL" until this is done. SW7 writes the minimum coulomb count value to the battery gas gauge. When the battery is fully discharged and the kit will not power on, connect the mini-USB charge cable and power on the kit. Press and hold SW7 until the "Reset Complete!" message appears. SW8 writes the maximum coulomb count value to the battery gas gauge. When the battery has completed charging (green LED is off), press and hold SW8 until the "Reset Complete!" message appears.
BeInMotion Motor Control Lab 49 August 2011
Altera has a number of resources available to assist you further in product development Some of the resources available are:
APPENDIX D: Troubleshooting
APPENDIX D: TROUBLESHOOTING
1. LCD and LEDs flicker when the kit is powered on. The battery does not have sufficient charge to power on the kit due to the amount of current required by the stepper motor. Fully charge the battery or connect either USB cable and power on the kit. 2. Files are not added to the Quartus project when the Add All button is clicked. Make sure the Quartus working directory matches the location of the source files. For example, if BeInMotion.zip is extracted to C:\altera_trn, the working directory will be C:\altera_trn\BeInMotion_lab 3. Quartus error "Error: Port "stpr_motor_export" does not exist in macrofunction "b2v_inst" When creating the stepper motor component in Qsys, the signal type for the conduit port must be set to Export. Edit the Stepper Motor Controller component, click on the pull-down selection for Signal Type and choose Export. Regenerate the Qsys system before recompiling the Quartus project. 4. No USB Blaster found in the Quartus Programmer Hardware Setup, accompanied by error "Attempted to access JTAG server --internal error code 82 occurred" The JTAG server service is not running due to a firewall or anti-virus program running. See http://www.altera.com/support/kdb/solutions/rd04042011_1000.html If the Altera JTAG Server is not listed in Services, disable the anti-virus program and install the Quartus II Stand-Alone Programmer https://www.altera.com/download/software/prog-software to install the JTAG server service. 5. Application folders do not appear when creating a new Nios II application. The Nios II Software Build Tools must be run "As Administrator" on PCs with Windows 7 6. The Run Configurations window does not show any target connections. Click Refresh Connections to refresh the JTAG connection and detect the Nios II processor 7. The Run Configurations window reports "System timestamp mismatch" The hardware image running on the BeInMotion does not match the BSP. Load the newest hardware image (BeInMotion.SOF) using the Quartus programmer, then re-run the application. 8. Problem "The system console model is invalid. Cannot launch" Click OK and re-run Run As->Nios II Hardware. This usually occurs when the Nios II Console is still running from a previous launch. To prevent, click the red box to "Terminate and Remove Launch" on the Nios II Console prior to launching Run As-> Nios II Hardware.
Altera Corporation Arrow Electronics, Inc 51 BeInMotion Motor Control Lab August 2011
The BeMicro SDK - BeInMotion kit has been flashed with an FPGA hardware image and a software image. During development new images can be flashed to the board. Follow these steps to restore the factory image.
Open a Nios II Command Shell Start->All Programs->Altera->Nios II EDS 11.0->Nios II 11.0 Command Shell
Connect the BeMicro SDK-BeInMotion kit to a USB port on the PC Run the Script and wait for it to complete To restore DC_Motor_Synchronization, type To restore Stepper_Motor, type To restore Battery_Status, type source restore_dc_motor.sh source restore_stepper_motor.sh source restore_battery_status.sh