The following document contains information on Cypress products. Colophon The products described in this document are designed, developed and manufactured as contemplated for general use, including without limitation, ordinary industrial use, general office use, personal use, and household use, but are not designed, developed and manufactured as contemplated (1) for any use that includes fatal risks or dangers that, unless extremely high safety is secured, could have a serious effect to the public, and could lead directly to death, personal injury, severe physical damage or other loss (i.e., nuclear reaction control in nuclear facility, aircraft flight control, air traffic control, mass transport control, medical life support system, missile launch control in weapon system), or (2) for any use where chance of failure is intolerable (i.e., submersible repeater and artificial satellite). Please note that Spansion will not be liable to you and/or any third party for any claims or damages arising in connection with above-mentioned uses of the products. Any semiconductor devices have an inherent chance of failure. You must protect against injury, damage or loss from such failures by incorporating safety design measures into your facility and equipment such as redundancy, fire protection, and prevention of over-current levels and other abnormal operating conditions. If any products described in this document represent goods or technologies subject to certain restrictions on export under the Foreign Exchange and Foreign Trade Law of Japan, the US Export Administration Regulations or the applicable laws of any other country, the prior authorization by the respective government entity will be required for export of those products. Trademarks and Notice The contents of this document are subject to change without notice. This document may contain information on a Spansion product under development by Spansion. Spansion reserves the right to change or discontinue work on any product without notice. The information in this document is provided as is without warranty or guarantee of any kind as to its accuracy, completeness, operability, fitness for particular purpose, merchantability, non-infringement of third-party rights, or any other warranty, express, implied, or statutory. Spansion assumes no liability for any damages of any kind arising out of the use of the information in this document. ® ® ® TM Copyright © 2013 Spansion Inc. All rights reserved. Spansion , the Spansion logo, MirrorBit , MirrorBit Eclipse , TM ORNAND and combinations thereof, are trademarks and registered trademarks of Spansion LLC in the United States and other countries. Other names used are for informational purposes only and may be trademarks of their respective owners. Fujitsu Semiconductor (Shanghai) Co., Ltd. Application Note MCU-AN-500067-E-14 F²MC-8FX FAMILY 8-BIT MICROCONTROLLER MB95330 SERIES 120° HALL SENSOR/SENSORLESS DC INVERTER CONTROL F2MC8L/8FX SOFTUNE C LIBRARY APPLICATION NOTE 120° DC Inverter Control SOFTUNE C LIB Application Note V1.4 Revision History Revision History Version Date Updated by Modifications 1.0. 2009-11-20 Kevin Wang First draft 1.1 2009-11-30 Kevin Wang Modify 1.2 2010-01-11 Kevin Wang Modify 1.2 2010-03-08 Kevin Wang Modify 4.1 1.3 2010-03-30 Kevin Wang Update motor drive waveform and back waveform 1.4 2010-12-07 Kevin Wang Add HW description Add DTTI.c file Add drive level choice function Add get motor speed function Add how to adjust parameter Add more motor fail indicate This manual contains 23 pages. 1. The products described in this manual and the specifications thereof may be changed without prior notice. To obtain up-to-date information and/or specifications, contact your Fujitsu sales representative or Fujitsu authorized dealer. 2. Fujitsu will not be liable for infringement of copyright, industrial property right, or other rights of a third party caused by the use of information or drawings described in this manual. 3. The contents of this manual may not be transferred or copied without the express permission of Fujitsu. 4. The products contained in this document are not intended for use with equipment which require extremely high reliability such as aerospace equipment, undersea repeaters, nuclear control systems or medical equipment for life support. 5. Some of the products described in this manual may be strategic materials (or special technology) as defined by the Foreign Exchange and Foreign Trade Control Law. In such cases, the products or portions theory must not be exported without permission as defined under the law. © 2009 Fujitsu Semiconductor (Shanghai) Co., Ltd. MCU-AN-500067-E-14 – Page 2 120° DC Inverter Control SOFTUNE C LIB Application Note V1.4 Contents CONTENTS REVISION HISTORY .............................................................................................................. 2 CONTENTS ............................................................................................................................ 3 REVISION HISTORY .............................................................................................................. 4 1 INTRODUCTION ................................................................................................................ 6 2 OPERATION PRINCIPLES AND THEORY ....................................................................... 7 2.1 Hall Sensor Drive ...................................................................................................... 7 2.2 Sensorless Drive ....................................................................................................... 9 2.2.1 Sensorless Startup ...................................................................................... 9 2.2.2 Normal Run ............................................................................................... 10 3 HW DESCRIPTION .......................................................................................................... 11 4 LIBRARY INSTALLATION ............................................................................................... 12 4.1 Components ............................................................................................................ 12 4.2 Procedure ............................................................................................................... 12 5 LIBRARY FUNCTIONS AND EXTERNAL VARIABLES ................................................. 13 5.1 Function Syntax ...................................................................................................... 14 5.2 External Variables ................................................................................................... 17 6 USAGE OF LIBRARY FUNCTIONS ................................................................................ 18 6.1 Operation Flow ........................................................................................................ 18 6.1.1 Start Motor ................................................................................................ 18 6.1.2 Change Motor Speed ................................................................................ 19 6.1.3 Set Motor Rotation Direction ..................................................................... 19 6.1.4 Stop Motor................................................................................................. 20 6.1.5 Get Motor Speed ....................................................................................... 20 6.1.6 Adjust Parameter ...................................................................................... 21 7 SAMPLE PROGRAM....................................................................................................... 22 8 ADDITIONAL INFORMATION ......................................................................................... 23 MCU-AN-500067-E-14 – Page 3 120° DC Inverter Control SOFTUNE C LIB Application Note V1.4 Revision History Revision History Date 2009-11-20 2009-11-30 2010-01-11 2010-03-08 2010-03-30 2010-12-07 Author Kevin Wang Kevin Wang Kevin Wang Kevin Wang Kevin Wang Kevin Wang Change of Records V1.0, First draft V1.1, Modify V1.2, Modify V1.2, Modify 4.1 V1.3, Update motor drive waveform and back waveform V1.4, Add HW description Add DTTI.c file Add drive level choice function Add get motor speed function Add how to adjust parameter Add more motor fail indicate This manual contains 22 pages. MCU-AN-500067-E-14 – Page 4 120° DC Inverter Control SOFTUNE C LIB Application Note V1.4 CONTENTS CONTENTS REVISION HISTORY .............................................................................................................. 2 CONTENTS ............................................................................................................................ 3 REVISION HISTORY .............................................................................................................. 4 1 INTRODUCTION ................................................................................................................ 6 2 OPERATION PRINCIPLES AND THEORY ....................................................................... 7 2.1 Hall Sensor Drive ...................................................................................................... 7 2.2 Sensorless Drive ....................................................................................................... 9 2.2.1 Sensorless Startup ...................................................................................... 9 2.2.2 Normal Run ............................................................................................... 10 3 HW DESCRIPTION .......................................................................................................... 11 4 LIBRARY INSTALLATION ............................................................................................... 12 4.1 Components ............................................................................................................ 12 4.2 Procedure ............................................................................................................... 12 5 LIBRARY FUNCTIONS AND EXTERNAL VARIABLES ................................................. 13 5.1 Function Syntax ...................................................................................................... 14 5.2 External Variables ................................................................................................... 17 6 USAGE OF LIBRARY FUNCTIONS ................................................................................ 18 6.1 Operation Flow ........................................................................................................ 18 6.1.1 Start Motor ................................................................................................ 18 6.1.2 Change Motor Speed ................................................................................ 19 6.1.3 Set Motor Rotation Direction ..................................................................... 19 6.1.4 Stop Motor................................................................................................. 20 6.1.5 Get Motor Speed ....................................................................................... 20 6.1.6 Adjust Parameter ...................................................................................... 21 7 SAMPLE PROGRAM....................................................................................................... 22 8 ADDITIONAL INFORMATION ......................................................................................... 23 MCU-AN-500067-E-14 – Page 5 120° DC Inverter Control SOFTUNE C LIB Application Note V1.4 Chapter 1 Introduction 1 Introduction This document describes the implementation of 120° conduction hall sensor/sensorless brushless DC motor control using the provided F2MC-8L/8FX SOFTUNE C library and the Fujitsu MB95F330 8-bit microcontroller. The operation principles, specification, library installation, library function description and operation of library functions are included. MB95F330 series 8-bit Micro-controller can be used to control the operation of a 3-phase brushless DC motor using the 120° conduction inverter control solution. MCU-AN-500067-E-14 – Page 6 120° DC Inverter Control SOFTUNE C LIB Application Note V1.4 Chapter 2 Operation Principles and Theory 2 Operation Principles and Theory 2.1 Hall Sensor Drive Below is the brief working principle for MCU to drive motor with hall sensor. A multi-pulse generator outputs six switch signals to drive IGBT inverter. Three channel hall sensor signals are detected by MCU input capture to achieve motor position. One channel over-current signal is output by IGBT inverter to MCU to protect the whole system. H1 MCU-AN-500067-E-14 – Page 7 120° DC Inverter Control SOFTUNE C LIB Application Note V1.4 Chapter 2 Operation Principles and Theory One electrical cycle is divided into 6 states. The relationship between three channel hall sensor signals (H1, H2, H3) and six channel inverter switch signals (Up, Un, Vp, Vn, Wp, Wn) is shown as below: MCU-AN-500067-E-14 – Page 8 120° DC Inverter Control SOFTUNE C LIB Application Note V1.4 Chapter 2 Operation Principles and Theory 2.2 2.2.1 Sensorless Drive Sensorless Startup The suggested startup method is forced startup. The following is the driving pattern. The marker A and A’ are the state change, while A – B is the position detect mask-off period used to mask off unwanted interrupt when the back EMF is very weak during startup. MCU-AN-500067-E-14 – Page 9 120° DC Inverter Control SOFTUNE C LIB Application Note V1.4 Chapter 2 Operation Principles and Theory 2.2.2 Normal Run The normal run consists of 12 different driving patterns and 6 different states. The following shows the relationship between the driving patterns and the expected interrupts from the position detection circuit. Marker explanation: A: position detection interrupt B: change state C: change chopping-arm D: position detection interrupt enable A’: next position detection interrupt A – B: commutation delay B – C: change arm delay C – D: change arm mask-off period MCU-AN-500067-E-14 – Page 10 120° DC Inverter Control SOFTUNE C LIB Application Note V1.4 Chapter 3 HW Description 3 HW Description The library is used for MB95F330 and MB95F390 series MCU. This library only uses the multi-pulse generator of MCU and it uses three interruptions: 16-bit reload timer ch.1, MPG (writing timer or compare match) and MPG (DTTI). The16-bit reload timer ch.1 and the MPG (writing timer or compare match) interruptions are closed in the library. The MPG (DTTI) interruption is open. In order to use this library more easily, the connection between MCU and motor drive circuit should be as below. MCU Up OPT0 OPT1 OPT2 OPT3 OPT4 OPT5 SNI0 SNI1 SNI2 DTTI Un Vp Vn Wp Wn W Back EMF V Back EMF U Back EMF Over Current Motor drive circuit Back EMF Drive OPT0 MCU Up Un Vp Vn Wp Motor drive circuit Wn H1 H2 H3 Over Current OPT1 OPT2 OPT3 OPT4 OPT5 SNI0 SNI1 SNI2 DTTI Hall Sensor Drive Note: OPT0, OPT1, OPT2, OPT3, OPT4, OPT5, SNI0, SNI1, SNI2, DTTI: MCU pin. Up: U phase upper arm inverter switch signal. Un: U phase lower arm inverter switch signal. Vp: V phase upper arm inverter switch signal. Vn: V phase lower arm inverter switch signal. Wp: W phase upper arm inverter switch signal. Wn: W phase lower arm inverter switch signal. H1, H2, H3: Hall sensor signal. Over current: Over current signal. W Back EMF: W phase back electromotive force. V Back EMF: V phase back electromotive force. U Back EMF: U phase back electromotive force. Over Current: Over current protection signal. MCU-AN-500067-E-14 – Page 11 120° DC Inverter Control SOFTUNE C LIB Application Note V1.4 Chapter 4 Library Installation 4 Library Installation 4.1 Components The library package contains 3 files: File name Usage MB95F330 Motor Drive Library file, contains all function modules V0.2.0.lib DTTI.c Deal DTTI interrupt Motor.h Header file, contains prototypes of the modules and global variables Header file, contains the interrupt vector table declaration myvect.h 4.2 Procedure There are 3 steps to begin using the Motor.lib C library. 9 In F2MC-8L/8FX SOFTUNE, after creation of a new project, use PROJECT –> ADD MEMBER to add MB95F330 Motor Drive V0.2.0.lib and DTTI.c as a member. 9 Include Motor.h header file into C main program for external references. 9 Include myvect.h header file into the module which uses directive #pragma to generate the interrupt vector table. Thus, a project including Lib file is ready for the caller program. MCU-AN-500067-E-14 – Page 12 120° DC Inverter Control SOFTUNE C LIB Application Note V1.4 Chapter 5 Library Functions and External Variables 5 Library Functions and External Variables There are 5 global variables in the library: 9 Rotation_Direction 9 Start_Motor 9 Driver_Mode 9 Motor_State 9 Drive_Level There are 9 functional modules for library control: 9 Motor_Init 9 Sensor_Less_Start 9 Motor_Parm 9 Motor_Set_Change_Speed 9 Motor_Stop 9 Sensor_Less_Normal_Work 9 Hall_Sensor_Start 9 Hall_Sensor_Normal_Work 9 Motor_Get_Speed MCU-AN-500067-E-14 – Page 13 120° DC Inverter Control SOFTUNE C LIB Application Note V1.4 Chapter 5 Library Functions and External Variables 5.1 Function Syntax Syntax extern void Motor_Init(void); Description Initialize MCU resources to be ready for start and stop commands. Initialize port configuration. Initialize multi-function timer resources. Initialize speed check timer. Initialize interrupt. Initialize motor state to MOTOR_READY. Input parameters Void Return Void Syntax extern void Sensor_Less_Start( unsigned short start_duty_on, unsigned short start_period, unsigned short normal_duty_on, unsigned short normal_period); Description Input parameters Return Example Start motor from reset with sensorless drive Motor_State will be MOTOR_NORMAL or MOTOR_FAILURE Startup and normal run parameters are initialized. start_duty_on : startup carrier frequency duty on duration in 125ns unit Start_period : startup carrier period in 125ns period unit Normal_duty_on : carrier duty on duration when startup changes to normal run, in 125ns unit normal_duty : carrier period in normal run mode Void Sensor_Less_Start(400, 1600, 200, 800); 60us on time during startup = 400 x 125ns => 60000 5kHz carrier frequency => 1600 x 125ns startup carrier period, 25us on time just after startup = 200 x 125ns => 25000 10kHz carrier frequency => 800 x 125ns normal run carrier period MCU-AN-500067-E-14 – Page 14 120° DC Inverter Control SOFTUNE C LIB Application Note V1.4 Chapter 5 Library Functions and External Variables Syntax Description Input parameters Return extern void Motor_Parm(unsigned long speed_con, unsigned short csd, unsigned short cad,unsigned short camaskt, unsigned short stmaskt); Define runtime parameters with sensorless drive. Define speed constant for speed checking Define commutation delay duration Define the duration between change-state and changearm Define the mask-off period just after change-arm Define the mask-off period during startup speed_con= 6000000 / (2us x number of pole pair) csd, in x100 electric angle cad, in x100 electric angle camaskt, in x100 electric angle stmaskt, in 1us unit Void Example Motor_Parm(15000000, 0, 200,200, 2000); 2 pole pair => 60 / (2us x 2) = 15000000 0 change state delay after back EMF zero crossing => 0 2 change-arm delay after back EMF zero crossing => 200 After change arm, mask time =>200 During startup, 2ms = 2000 x 1us => 2000 Syntax extern void Motor_Set_Change_Speed(unsigned short speed); Description Set or change target rotational speed in RPM whenever sensorless drive or hall sensor drive is used. Input parameters speed in RPM Return Void Example Motor_Set_Change_Speed(6000); Set target speed to 6000rpm. Syntax extern void Motor_Stop(void); Input parameters Stop motor without brake. All driving outputs are inactivated. Speed checking timer is stopped. Multi-function timer is reset. Input capture edge detection are disabled. Void Return Void Description MCU-AN-500067-E-14 – Page 15 120° DC Inverter Control SOFTUNE C LIB Application Note V1.4 Chapter 5 Library Functions and External Variables Syntax extern void Sensor_Less_Normal_Work(void); Description Input parameters Control motor running normally with sensorless drive. Count change arm time. Void Return Void Syntax extern void Hall_Sensor_Start(unsigned short duty_on, unsigned short period); Description Start motor from reset with hall sensor drive. Motor_State will be MOTOR_NORMAL MOTOR_FAILURE Parameters are initialized Input parameters Return duty_on :Carrier frequency duty on duration in 125ns unit period : Carrier period in 125ns period unit Void Example Hall_Sensor_Start (150, 800); 18.75us on time during startup = 150 x 125ns => 150 10kHz carrier frequency => 800 x 125ns startup carrier period, Syntax extern void Hall_Sensor_Normal_Work(void); Input parameters Control motor running normally with hall sensor drive. Count motor speed. Control motor speed. Check hall sensor signal and change arm. Void Return Void Syntax extern unsigned int Motor_Get_Speed(void); Description Get motor actual speed. Input parameters Void Return Motor actual speed in RPM. Description MCU-AN-500067-E-14 – Page 16 or 120° DC Inverter Control SOFTUNE C LIB Application Note V1.4 Chapter 5 Library Functions and External Variables 5.2 External Variables Variable extern unsigned char Motor_State Description Motor operation mode Value MOTOR_READY, 1 : motor ready for accepting start command MOTOR_START, 2 : motor in startup stage MOTOR_NORMAL, 3 : motor in normal run stage MOTOR_FAILURE, 4 : motor which cannot run MOTOR_START_FAILURE, 5 : motor start failed OVER_CURRENT, 6: motor over current Variable extern unsigned char Rotation_Direction Description Motor running direction Value ANTICLOCKWISE, 0: motor anticlockwise running CLOCKWISE, 1: motor clockwise running. Variable extern unsigned char Driver_Mode Description Motor drive method Value HALL_SENSOR, 0: hall sensor drive SENSOR_LESS, 1: sensorless drive. Variable extern unsigned char Start_Motor Description Start motor signal Value FALSE, 0: the motor cannot be started. TRUE, 1: the motor can be started. Variable extern unsigned char Drive_Level Description Drive motor level choice Value Drive_High, 0: high level drive. Drive_Low, 1: low level drive. MCU-AN-500067-E-14 – Page 17 120° DC Inverter Control SOFTUNE C LIB Application Note V1.4 Chapter 6 Usage of Library Functions 6 Usage of Library Functions In general, user should follow the following steps to control the motor: 9 9 9 9 Set global variables with suitable values. Initialize the MCU resource. Start the motor with suitable startup speed. Modify motor synchronous speed, accelerating speed and decelerating speed by changing values of the global variables. 9 Stop the motor. 6.1 6.1.1 Operation Flow Start Motor This can be done by calling the following successively using appropriate parameters. Choice drive level (high or low) Is Driver_Mode SENSOR_LESS? YES NO Is Start_Motor TRUE? Is Start_Motor TRUE? NO NO Is Motor_State == MOTOR_NORMAL? Is Motor_State == MOTOR_NORMAL? YES Motor_Init; Start_Motor=FALSE NO Motor_Set_Change_Speed NO Start_Motor=FALSE YES Motor_Parm Motor_Init; Sensor_Less_Normal_Work Motor_Set_Change_Speed Hall_Sensor_Start Sensor_Less_Start MCU-AN-500067-E-14 – Page 18 Hall_Sensor_Normal_Work 120° DC Inverter Control SOFTUNE C LIB Application Note V1.4 Chapter 6 Usage of Library Functions 6.1.2 Change Motor Speed To change motor speed, please ensure that the motor is running under normal status. The following flow chart shows how to change the motor speed: Start Is Motor_State == MOTOR_NORMAL? NO YES Motor_Set_Change_Speed END 6.1.3 Set Motor Rotation Direction To set motor rotation direction, please ensure that the motor is under ready status. The following flow chart shows how to set the motor rotation direction. Start Is Motor_State == MOTOR_READY? YES Rotation_Direction=ANTI_CLOCKWISE Or Rotation_Direction=CLOCKWISE END MCU-AN-500067-E-14 – Page 19 NO 120° DC Inverter Control SOFTUNE C LIB Application Note V1.4 Chapter 6 Usage of Library Functions 6.1.4 Stop Motor To stop a motor, please ensure that the motor is under normal or startup status. The following flow chart shows how to stop the motor. Start Is Motor_State == MOTOR_NORMAL? Or Is Motor_State == MOTOR_START? YES Motor_Stop END 6.1.5 Get Motor Speed The following flow chart shows how to get motor actual speed. Start Motor_Get_Speed(); END MCU-AN-500067-E-14 – Page 20 NO 120° DC Inverter Control SOFTUNE C LIB Application Note V1.4 Chapter 6 Usage of Library Functions 6.1.6 Adjust Parameter When we use this library to drive a new motor, there are some parameters need to adjust. Because of different motors need different parameters. Adjust carrier frequency We can use the two functions to adjust motor carrier frequency. Hall_Sensor_Start(unsigned short duty_on, unsigned short period); We can adjust period for motor carrier frequency when we choose hall sensor drive. Sensor_Less_Start( unsigned short start_duty_on,unsigned short start_period,unsigned short normal_duty_on,unsigned short normal_period); When we choose sensorless drive, we can change start_period for adjusting the motor start carrier frequency and we change normal_period for adjusting motor normal run carrier frequency. It should keep the start duty as same as normal duty, otherwise the motor can’t start normally. Adjust start When we choose sensorless drive, maybe we should adjust some parameters to keep motor start normally. There are two functions need to adjust. Sensor_Less_Start( unsigned short start_duty_on,unsigned short start_period,unsigned short normal_duty_on,unsigned short normal_period); Motor_Parm(unsigned long speed_con,unsigned short csd, unsigned short cad,unsigned short camaskt, unsigned short stmaskt); We know when we just start motor. There is no Back-EMF can checked. So we use a timer to help motor change arm and bring Back-EMF. But how long we set timer and how large duty need? If the time of the timer is large or small, the motor can’t run normally. If the duty is large, the motor will over current and can’t start. If the duty is small, the Back-EMF of motor is very weak and we can’t check. Usually, we fix one parameter, adjust another one. For example, we fixed start_duty_on(start duty) , then we change stmaskt(timer). We also can fix stamaskt(timer), then we change start_duty_on(start duty). In order to keep motor can change start state to normal state, When we changed start_duty_on, we should change normal_duty_on to keep the start duty as same as normal duty. Set speed Because of different motors have different numbers of pole pair. So we should change this function for counting motor speed. Motor_Parm(unsigned long speed_con,unsigned short csd, unsigned short cad,unsigned short camaskt, unsigned short stmaskt); We should change speed_con according to numbers of pole pair by the follow formula. speed_con= 6000000 / (2x number of pole pair) Improve efficiency Sometimes, we find the efficiency is very low. We can adjust three parameters of Motor_Parm function. Motor_Parm(unsigned long speed_con,unsigned short csd, short cad,unsigned short camaskt, unsigned short stmaskt); MCU-AN-500067-E-14 – Page 21 unsigned 120° DC Inverter Control SOFTUNE C LIB Application Note V1.4 Chapter 7 Sample Program 7 Sample Program Motor.zip is a sample project containing source code which can drive a sensorless brushless or hall sensor DC motor with motor EV Board (PN: MB2146-440-E V1.2). Please refer to Motor EV Board MB2146-440-E HW User Manual. Tested configuration: DC motor: Fulling FL28BL26-15V-8006AF Number of phases: 3 Number of poles: 4 Supply voltage: 15VDC Minimum tested speed: 1000rpm Maximum tested speed: 7000rpm MCU work load: 8%~30% (Motor speed from 1000 rpm to 7000 rpm with sensorless drive); 2%~10% (Motor speed from 1000 rpm to 7000 rpm with hall sensor drive); MCU-AN-500067-E-14 – Page 22 120° DC Inverter Control SOFTUNE C LIB Application Note V1.4 Chapter 8 Additional Information 8 Additional Information For more information on how to use MB9595330 EV Board, BGM adaptor and SOFTUNE, please refer to Motor EV Board MB2146-440-E HW User Manual or visit Websites: English version: http://www.fujitsu.com/cn/fsp/services/mcu/mb95/application_notes.html Simplified Chinese Version: http://www.fujitsu.com/cn/fss/services/mcu/mb95/application_notes.html MCU-AN-500067-E-14 – Page 23