3-Phase BLDC Sensorless Motor Control on Kinetis User’s Guide Document Number: BLDCSLK60UG Rev. 0 04/2012 How to Reach Us: Home Page: www.freescale.com Web Support: http://www.freescale.com/support USA/Europe or Locations Not Listed: Freescale Semiconductor, Inc. Technical Information Center, EL516 2100 East Elliot Road Tempe, Arizona 85284 1-800-521-6274 or +1-480-768-2130 www.freescale.com/support Europe, Middle East, and Africa: Freescale Halbleiter Deutschland GmbH Technical Information Center Schatzbogen 7 81829 Muenchen, Germany +44 1296 380 456 (English) +46 8 52200080 (English) +49 89 92103 559 (German) +33 1 69 35 48 48 (French) www.freescale.com/support Japan: Freescale Semiconductor Japan Ltd. Headquarters ARCO Tower 15F 1-8-1, Shimo-Meguro, Meguro-ku, Tokyo 153-0064 Japan 0120 191014 or +81 3 5437 9125 [email protected] Asia/Pacific: Freescale Semiconductor China Ltd. Exchange Building 23F No. 118 Jianguo Road Chaoyang District Beijing 100022 China +86 10 5879 8000 [email protected] Freescale Semiconductor Literature Distribution Center 1-800-441-2447 or +1-303-675-2140 Fax: +1-303-675-2150 [email protected] Information in this document is provided solely to enable system and software implementers to use Freescale Semiconductor products. There are no express or implied copyright licenses granted hereunder to design or fabricate any integrated circuits or integrated circuits based on the information in this document. Freescale Semiconductor reserves the right to make changes without further notice to any products herein. Freescale Semiconductor makes no warranty, representation or guarantee regarding the suitability of its products for any particular purpose, nor does Freescale Semiconductor assume any liability arising out of the application or use of any product or circuit, and specifically disclaims any and all liability, including without limitation consequential or incidental damages. “Typical” parameters that may be provided in Freescale Semiconductor data sheets and/or specifications can and do vary in different applications and actual performance may vary over time. All operating parameters, including “Typicals”, must be validated for each customer application by customer’s technical experts. Freescale Semiconductor does not convey any license under its patent rights nor the rights of others. Freescale Semiconductor products are not designed, intended, or authorized for use as components in systems intended for surgical implant into the body, or other applications intended to support or sustain life, or for any other application in which the failure of the Freescale Semiconductor product could create a situation where personal injury or death may occur. Should Buyer purchase or use Freescale Semiconductor products for any such unintended or unauthorized application, Buyer shall indemnify and hold Freescale Semiconductor and its officers, employees, subsidiaries, affiliates, and distributors harmless against all claims, costs, damages, and expenses, and reasonable attorney fees arising out of, directly or indirectly, any claim of personal injury or death associated with such unintended or unauthorized use, even if such claim alleges that Freescale Semiconductor was negligent regarding the design or manufacture of the part. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2012. All rights reserved. BLDCSLK60UG Rev. 0 04/2012 1.1 Introduction This application demonstrates a low-power 3-phase brushless DC (BLDC) motor drive software. It is focused on a simple and easy to understand control approach to BLDC using MQX™ in a time-critical application. The control concept of the application is a speed closed-loop BLDC drive using back electromotive force (BEMF) sensing for position recognition. It serves as an example of a BLDC motor control system for low-voltage motor applications. The power stage is designed for an input voltage of +24V DC. The hardware is built on the Freescale Tower rapid prototyping system and contains the following modules: • TWR elevator • TWR K60N512 • TWR MC-LV-3PH • TWR serial There are two versions of the application software: • BLDC under the MQX RTOS and web server • BLDC on bare metal Both use the same source code for motor control. The MQX version contains a web server to demonstrate the benefits of the MQX-based solution. Both applications can also be controlled by the FreeMASTER software. This FreeMASTER PC application allows real-time monitoring or modification of all required variables through an easy and user-friendly graphical user interface. Selected variables can also be monitored in a time domain scope representation. The MQX version can be controlled from any web browser on a PC via the Ethernet communication interface, because in this version the web server is implemented. 1.2 About this manual Key items can be found in the following sections of this manual: • Introduction to the demo: Section 1.1, “Introduction” • Information about safety in using the demo: Section 1.3, “Warnings” • Setup instructions: Section 1.4, “Setup guide” • USB-to-serial installation: Section 1.5, “USB-to-serial cable driver installation” • FreeMASTER installation: Section 1.6, “FreeMASTER software installation” • Control via FreeMASTER: Section 1.7, “FreeMASTER control” • Ethernet controller setup: Section 1.8, “Ethernet setup” • Control of the application via Ethernet: Section 1.9, “Web control” • Control from another application: Section 1.10, “Integration of the motor control driver with other applications” Sensorless 3-Phase BLDC Motor Control on Kinetis, Rev. 0 Freescale Semiconductor 1 J-Link + RS232 + Ethernet CONTROLLER BOARD WORKSTATION 3-PH. POWER STAGE MOTOR a) K60N512 MICROCONTROLLER Figure 1. System configurations Figure 2. 3-phase BLDC motor control on Kinetis Sensorless 3-Phase BLDC Motor Control on Kinetis, Rev. 0 2 Freescale Semiconductor 1.3 Warnings The power stage includes power components that can reach temperatures hot enough to cause burns. To facilitate safe operation, 24V input power should come from a DC power supply that is current limited to no more than 4 amps. Keep the following points in mind while following the instructions in this guide: • Before moving scope probes, making connections, and so on, it is generally advisable to power down the 24-volt supply. • Wearing safety glasses, avoiding ties and jewelry, using shields, and operation by personnel trained in power electronics lab techniques are also advisable. • Do not plug any other cables into the demo system except for the power supply cable, Ethernet cable, and serial communication cable. The demo can be powered only via the Tower low-voltage power stage power jack. • Do not connect any USB cable to the demo while the power is applied to the power stage module. Connecting a USB cable to the Tower elevator module will cause damage to the Kinetis K60 MCU and other systems! • Only a J-Link can be used for firmware upload. 1.4 Setup guide The demo should be already configured, if not, configure it as is described below. 1. Jumper settings (board TWR-K60N512 REV C) (see Figure 3): — Jumper J6 to position 2-3—processor clock taken from the TWR-SER board (doesn’t work without the TWR-SER) 2. Jumper settings (board TWR-SER REV E) (see Figure 3): — J2—CLK_SEL 3-4 — J3—CLKIN-SEL 2-3 (processor clock is taken from the PHY) — J12—ETH-CONFIG 9-10 to select the RMII communication mode 3. Jumper settings (board TWR-MC-LV-3PH REV B) (see Figure 3): — J2, J3: 1-2—Internal analogue power supply — J10, J11, J12: 2-3—Phase A,B,C BEMF sense — J13: 2-3—DC bus current sense NOTE Both the processor and serial board (TWR-SER) have to be plugged into the Tower. The processor is using an external clock from the Ethernet PHY on these serial card. All jumpers and other hardware switches not specifically described are expected to be in factory-default positions. Please refer to the board user’s guide for the default settings. Sensorless 3-Phase BLDC Motor Control on Kinetis, Rev. 0 Freescale Semiconductor 3 Figure 3. Jumper configuration 4. If your demo is disassembled, you must connect all three boards to the Tower elevator. Be careful, it is very important to connect the side of the board marked with the white stripe to the white connector of the elevator. The recommended board order is: a) TRW-K60N512 b) TWR-SER c) Empty d) TWR-MC-LV-3PH 5. If you want to operate the demo via FreeMASTER, connect a serial cable between the serial board and the COM port of your computer. 6. Install FreeMASTER. (see Section 1.6, “FreeMASTER software installation”). 7. Extract the BLDC_KINETIS.exe archive into your computer. Sensorless 3-Phase BLDC Motor Control on Kinetis, Rev. 0 4 Freescale Semiconductor 8. Open the FreeMASTER project in ...\SW\FMSTR\TWR_BLDC_BM.pmp for bare metal, or ...\SW\FMSTR\TWR_BLDC_MQX.pmp for the MQX version, from the project directory. 9. Set up the COM port number in the FreeMASTER project options. The speed of the port should be 19200. (See Figure 4.) Figure 4. FreeMASTER configuration 10. You can also use the USB-to-serial cable (USB virtual serial port) that is part of the demo kit if your notebook or PC has only a USB port. If you use the USB-to-serial cable, follow Section 1.5, “USB-to-serial cable driver installation.” 11. Install the IAR Embedded Workbench. 12. The project directory contains its own BSP, PSP and library files, already configured as necessary. (you don’t need to install MQX on your computer). 13. Connect a J-Link to the TWR-K60N512 board. 14. Open the IAR project ..\SW\BM_KINETIS_BLDC_SENSORLESS\build_IAR\BLDC_example.eww for the bare metal version, or ...\SW\MQX_KINETIS_BLDC_SENSORLESS\BLDC_WEB_SERVER.eww for the MQX version, from the project directory. 15. Connect a 24V supply voltage to the power stage (the green LED [D7] near the power supply connector should be lit). DO NOT CONNECT ANY OTHER SUPPLY VOLTAGE OR USB CABLE. If any other voltage is applied, the hardware can be damaged. The power stage generates 3.3V and 5V for other modules in the tower system. The presence of 3.3V is indicated by LEDs D1 and D7, and the presence of 5V is indicated by D2 and D6 on the Tower elevator. 16. Load firmware via the J-Link and then run the application. 17. Start communication in FreeMASTER. 18. Connect the motor connector to the power stage. 19. Push the demonstration button or type a speed from 400 to 4000, or –400 to –4000 rpm, into the Speed Required field. The motor should run. Sensorless 3-Phase BLDC Motor Control on Kinetis, Rev. 0 Freescale Semiconductor 5 20. If the motor doesn’t run, check the status of the application in FreeMASTER. If the overcurrent fault has occurred, set up the overcurrent limit by turning trimmer R37 on the MC-LV-3PH power stage. NOTE Resetting of any fault status can be done only using the RESET button on the K60 board. 1.5 USB-to-serial cable driver installation 1. Don’t plug the USB-to-serial cable into your computer. 2. Insert the CD that is part of the demo kit into your CD-ROM drive. 3. For Windows XP Run the following file: [your CD ROM Drive]: \USB_to_RS232\Windows\Win_98_XP\Win98~XP_V2.0.21 Driver Installer.exe. For Windows 7 Run the following file: [your CD ROM Drive]: \USB_to_RS232\Windows\Win7_Vista\PL-2303 Vista Driver Installer.exe 4. Follow the onscreen instructions to complete the installation. 5. Plug the USB-to-serial adaptor into your computer’s USB port. 6. Open Device Manager under System Properties and check for the device you installed under Prolific USB-to-serial Comm Port (ComXX). Keep the number of the assigned COM port as it will be needed later during the FreeMASTER software configuration. The following is one possible way to open the System Properties window in Windows XP: at the Windows taskbar, click Start and then select \Settings\Control Panel\System. The System Properties window will appear. The Device Manager is located at the Hardware tab. 7. Now the USB-to-serial Cable is ready to use. Under Windows 7 the driver software sometimes causes FreeMASTER to stop working. This can be fixed by downgrading the driver to an older version. 1. Insert the CD that is part of the demo kit into your CD-ROM drive. 2. Plug the USB-to-serial adapter into your computer’s USB port. 3. By right-clicking on Computer, go to the Device Manager. Right-click to Prolific USB-to-Serial Comm Port (ComXX). 4. Choose Update Driver Software from the menu. 5. Click Browse my computer for driver software. 6. Click Let me pick from a list of device drivers on my computer. 7. Click Have Disk... 8. Navigate to ...\USB_to_RS232\Windows\Win7_Vista\ser2pl.sys. 9. Choose Prolific USB-to-Serial Comm Port. 10. Click Next. 11. Check the version of the driver. It should be: Sensorless 3-Phase BLDC Motor Control on Kinetis, Rev. 0 6 Freescale Semiconductor 12. Now the USB-to-serial cable is ready to use. 1.6 FreeMASTER software installation If there is no FreeMASTER software installed on the notebook or PC that you intend to use for the demo control, you can find the installation file on the enclosed CD in the folder \SW\FreeMASTER for PC\FMMASTERSW.exe, or check the most recent version on the Freescale FreeMASTER web page. In case of any problem with the installation process or with using the software, download the documentation from the Freescale web page. 1.7 FreeMASTER control After launching the application and performing all settings described above, click the scope: BLDC item in the project tree structure of the FreeMASTER application window, as shown in Figure 5. In this view, variables used for the application state, speed, PI controller, and ramp settings are visible. For the demonstration purposes, this is sufficient. Sensorless 3-Phase BLDC Motor Control on Kinetis, Rev. 0 Freescale Semiconductor 7 Figure 5. FreeMASTER user interface Description of variables: Speed required: This variable serves for entering the required speed of the motor and the direction of motion. If the number is negative, the motor runs in a counter-clockwise direction; if it is positive, the motor runs clockwise. You can modify this variable from –400 to –4000, and from 400 to 4000. Any other numbers will be ignored. Commutation threshold: For commutation tuning. Measured speed: Variable showing the measured speed. A speed under 200 rpm is not measured exactly. Standstill detection: Detection of a rotor standstill. If a rotor is locked, the software periodically tries to restart it. If the required speed is equal to 0, and motor is stopped for more than 2 seconds, the software turns off the PWM. Closed-loop: Enables or disables the speed regulator. If it is disabled, the Duty cycle parameter can be changed. [50%...100%] Integral gain, proportional gain: Speed PI controller setting. trMyRamp.s32RampDown: Motor acceleration. Can be set in rpm/s. trMyRamp.s32RampUp: Motor deceleration. Can be set in rpm/s. Sensorless 3-Phase BLDC Motor Control on Kinetis, Rev. 0 8 Freescale Semiconductor 1.8 Ethernet setup To configure the Ethernet communication interface on your PC, follow the steps below: 1. Disconnect all network cables and turn off your WIFI adapter. 2. Use the automatic IP configuration in your wired adapter local area connection setting window as shown in Figure 6. 3. Connect the Ethernet cable between the Tower serial module and your computer. 4. Click OK. 5. Wait for an established connection. 6. Open Internet Explorer. 7. Go to Tools\Internet options. 8. Click the LAN settings button. 9. Disable the proxy server, unchecking the box, as shown in Figure 7. 10. Click OK. Figure 6. Configuration of Ethernet connection Sensorless 3-Phase BLDC Motor Control on Kinetis, Rev. 0 Freescale Semiconductor 9 Figure 7. Configuration of MS Internet Explorer for demo control 1.9 Web control The MQX version of the application can be controlled via a web server, but you must set up your Ethernet interface as described in Section 1.8, “Ethernet setup.” Then follow the steps below. 1. Open Internet Explorer. 2. Write the IP address of the demo device into Internet Explorer. The default IP address is 169.254.3.3. Then press enter. 3. You should see a web page with the Freescale logo and the title Freescale MQX Web Server. 4. Click the BLDC Control on the left side of the web page. 5. You should see the web page as in Figure 8. 6. Click one of the buttons with the required speed. 7. The motor should be set in motion. NOTE The web server is optimized only for MS Internet Explorer 8. Sensorless 3-Phase BLDC Motor Control on Kinetis, Rev. 0 10 Freescale Semiconductor Figure 8. Web page for speed control 1.10 Integration of the motor control driver with other applications Both versions of the motor control driver can be part of other applications. The API is defined by the following six functions. A detailed description can be found in DRM135, 3-Phase BLDC Sensorless Control with MQX RTOS Using K60N512. 1. void Set_speed(int motor_number, signed short speed_input) The first parameter is the number of the motor that receives the command. This demo has only one motor, so enter 1. The second parameter is the input speed in signed short format. The input value is in RPM. Return: void 2. unsigned char Get_status(void) Return: Status of the application 0-IDLE, 1-STOP, 2-RUNNING, 3-ALIGNMENT, 6-EMERGENCY_STOP, 7-UNDER_VOLTAGE_FAULT, 8-OVER_VOLTAGE_FAULT, 9-OVER_CURRENT_FAULT 3. signed short Get_speed(int motor_number) Sensorless 3-Phase BLDC Motor Control on Kinetis, Rev. 0 Freescale Semiconductor 11 The first parameter is the number of the motor that receives the command. This demo has only one motor, so enter 1. Return: measured speed in signed short data format. The value is in RPM. 4. signed short Get_req_speed(int motor_number) The first parameter is the number of the motor that receives the command. Return: Required speed in signed short data format. The value is in RPM. 5. void Set_ramp_up(int motor_number, int ramp_up) The first parameter is the number of the motor that receives the command. Second parameter: Ramp up profile. The value is in RPM per second. Return: void 6. void Set_ramp_down(int motor_number, int ramp_down) The first parameter is the number of the motor that receives the command. Second parameter: Ramp down profile. The value is in RPM per second. Return: void NOTE Because the hardware connection between the K60 tower board and the low-voltage power stage doesn't allow performing a reset of the MOSFET driver by a software command, some faults can be cleared only by pressing the reset button on the K60 tower board. Only in this way can the MOSFET driver properly execute the reset procedure. Sensorless 3-Phase BLDC Motor Control on Kinetis, Rev. 0 12 Freescale Semiconductor