foc matlab model with pll estimator based on an1292...

29
¤ 2016 Microchip Technology Inc. FOC MATLAB ® Model with PLL Estimator Based on AN1292 User’s Guide

Upload: vuongnhu

Post on 06-Sep-2018

284 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

¤ 2016 Microchip Technology Inc.

FOC MATLAB® Model withPLL Estimator Based on AN1292

User’s Guide

Page 2: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

page 2 ¤ 2016 Microchip Technology Inc.

Information contained in this publication regarding deviceapplications and the like is provided only for your convenienceand may be superseded by updates. It is your responsibility toensure that your application meets with your specifications.MICROCHIP MAKES NO REPRESENTATIONS ORWARRANTIES OF ANY KIND WHETHER EXPRESS ORIMPLIED, WRITTEN OR ORAL, STATUTORY OROTHERWISE, RELATED TO THE INFORMATION,INCLUDING BUT NOT LIMITED TO ITS CONDITION,QUALITY, PERFORMANCE, MERCHANTABILITY ORFITNESS FOR PURPOSE. Microchip disclaims all liabilityarising from this information and its use. Use of Microchipdevices in life support and/or safety applications is entirely atthe buyer’s risk, and the buyer agrees to defend, indemnify andhold harmless Microchip from any and all damages, claims,suits, or expenses resulting from such use. No licenses areconveyed, implicitly or otherwise, under any Microchipintellectual property rights unless otherwise stated.

Note the following details of the code protection feature on Microchip devices:• Microchip products meet the specification contained in their particular Microchip Data Sheet.

• Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the intended manner and under normal conditions.

• There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data Sheets. Most likely, the person doing so is engaged in theft of intellectual property.

• Microchip is willing to work with the customer who is concerned about the integrity of their code.

• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not mean that we are guaranteeing the product as “unbreakable.”

Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of ourproducts. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such actsallow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.

Microchip received ISO/TS-16949:2009 certification for its worldwide headquarters, design and wafer fabrication facilities in Chandler and Tempe, Arizona; Gresham, Oregon and design centers in California and India. The Company’s quality system processes and procedures are for its PIC® MCUs and dsPIC® DSCs, KEELOQ® code hopping devices, Serial EEPROMs, microperipherals, nonvolatile memory and analog products. In addition, Microchip’s quality system for the design and manufacture of development systems is ISO 9001:2000 certified.

Trademarks

The Microchip name and logo, the Microchip logo, AnyRate, dsPIC, FlashFlex, flexPWR, Heldo, JukeBlox, KeeLoq, KeeLoq logo, Kleer, LANCheck, LINK MD, MediaLB, MOST, MOST logo, MPLAB, OptoLyzer, PIC, PICSTART, PIC32 logo, RightTouch, SpyNIC, SST, SST Logo, SuperFlash and UNI/O are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries.

ClockWorks, The Embedded Control Solutions Company, ETHERSYNCH, Hyper Speed Control, HyperLight Load, IntelliMOS, mTouch, Precision Edge, and QUIET-WIRE are registered trademarks of Microchip Technology Incorporated in the U.S.A.

Analog-for-the-Digital Age, Any Capacitor, AnyIn, AnyOut, BodyCom, chipKIT, chipKIT logo, CodeGuard, dsPICDEM, dsPICDEM.net, Dynamic Average Matching, DAM, ECAN, EtherGREEN, In-Circuit Serial Programming, ICSP, Inter-Chip Connectivity, JitterBlocker, KleerNet, KleerNet logo, MiWi, motorBench, MPASM, MPF, MPLAB Certified logo, MPLIB, MPLINK, MultiTRAK, NetDetach, Omniscient Code Generation, PICDEM, PICDEM.net, PICkit, PICtail, PureSilicon, RightTouch logo, REAL ICE, Ripple Blocker, Serial Quad I/O, SQI, SuperSwitcher, SuperSwitcher II, Total Endurance, TSHARC, USBCheck, VariSense, ViewSpan, WiperLock, Wireless DNA, and ZENA are trademarks of Microchip Technology Incorporated in the U.S.A. and other countries.

SQTP is a service mark of Microchip Technology Incorporated in the U.S.A.

Silicon Storage Technology is a registered trademark of Microchip Technology Inc. in other countries.

GestIC is a registered trademarks of Microchip Technology Germany II GmbH & Co. KG, a subsidiary of Microchip Technology Inc., in other countries.

All other trademarks mentioned herein are property of their respective companies.

© 2016, Microchip Technology Incorporated, Printed in the U.S.A., All Rights Reserved.

ISBN:

Page 3: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

AN1292 FOC MATLAB ModelUser’s Guide

¤ 2016 Microchip Technology Inc. page 3

Preface ........................................................................................................................... 5Chapter 1. Introduction

1.1 Purpose ........................................................................................................ 111.2 Scope ........................................................................................................... 111.3 Overview ...................................................................................................... 11

Chapter 2. Implementation Requirements2.1 Hardware Requirements .............................................................................. 132.2 Software Requirements ................................................................................ 14

Chapter 3. FOC Model Overview3.1 Files in FOC Folder ...................................................................................... 19

Chapter 4. Top Level Miscellaneous Blocks4.1 ADC Block .................................................................................................... 214.2 Button Press Block ....................................................................................... 224.3 Motor Model Block ........................................................................................ 234.4 UART Transmit Block ................................................................................... 234.5 Setup for picgui Interface ............................................................................. 24

Chapter 5. Main State BlockChapter 6. FOC Control Block

6.1 FOC Control State Machine ......................................................................... 276.2 FOC Control Block Diagram ......................................................................... 286.3 PLL Estimator (AN1292 based) .................................................................... 29

Chapter 7. Test Results7.1 Simulation Results ........................................................................................ 317.2 Hardware Results ......................................................................................... 33

Chapter 8. ConclusionWorldwide Sales and Service .................................................................................... 37

Table of Contents

Page 4: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

AN1292 FOC MATLAB ModelUser’s Guide

¤ 2016 Microchip Technology Inc. page 4

Preface

INTRODUCTIONThis preface contains general information that will be useful to know before using the AN1292 FOC MATLAB Model User’s Guide. Topics discussed in this preface include:• Document Layout• Conventions Used in this Guide• Warranty Registration• Recommended Reading• The Microchip Web Site• Development Systems Customer Change Notification Service• Customer Support• Document Revision History

DOCUMENT LAYOUTThis user’s guide describes how to use the AN1292 FOC MATLAB Model User’s Guide. The document is organized as follows:• Chapter 1. “Introduction” – This chapter gives purpose, scope and overview of

the document.• Chapter 2. “Implementation Requirements” – This chapter discusses the hard-

ware and software requirements for the implementation of the model.• Chapter 3. “FOC Model Overview” – This chapter provides an overview of the

FOC Model.• Chapter 4. “Top Level Miscellaneous Blocks” – This chapter discusses the

basic building blocks that can be used in any other models such as ADC, UART and so on.

• Chapter 5. “Main State Block” – This chapter emulates the main state machine.• Chapter 6. “FOC Control Block” – This chapter discusses the FOC control

block in detail.

NOTICE TO CUSTOMERS

All documentation becomes dated, and this manual is no exception. Microchip tools and documentation are constantly evolving to meet customer needs, so some actual dialogs and/or tool descriptions may differ from those in this document. Please refer to our web site (www.microchip.com) to obtain the latest documentation available.

Documents are identified with a “DS” number. This number is located on the bottom of each page, in front of the page number. The numbering convention for the DS number is “DSXXXXXA”, where “XXXXX” is the document number and “A” is the revision level of the document.

For the most up-to-date information on development tools, see the MPLAB® IDE on-line help. Select the Help menu, and then Topics to open a list of available on-line help files.

Page 5: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

AN1292 FOC MATLAB Model User’s Guide

page 5 ¤ 2016 Microchip Technology Inc.

• Chapter 7. “Test Results” – This Chapter illustrates the implementation results.• Chapter 8. “Conclusion” – This chapter provides a brief conclusion to the docu-

ment.

CONVENTIONS USED IN THIS GUIDEThis manual uses the following documentation conventions:

DOCUMENTATION CONVENTIONSDescription Represents Examples

Arial font:Italic characters Referenced books MPLAB® IDE User’s Guide

Emphasized text ...is the only compiler...Initial caps A window the Output window

A dialog the Settings dialogA menu selection select Enable Programmer

Quotes A field name in a window or dialog

“Save project before build”

Underlined, italic text with right angle bracket

A menu path File>Save

Bold characters A dialog button Click OKA tab Click the Power tab

N‘Rnnnn A number in verilog format, where N is the total number of digits, R is the radix and n is a digit.

4‘b0010, 2‘hF1

Text in angle brackets < > A key on the keyboard Press <Enter>, <F1>Courier New font:Plain Courier New Sample source code #define START

Filenames autoexec.batFile paths c:\mcc18\hKeywords _asm, _endasm, staticCommand-line options -Opa+, -Opa-Bit values 0, 1Constants 0xFF, ‘A’

Italic Courier New A variable argument file.o, where file can be any valid filename

Square brackets [ ] Optional arguments mcc18 [options] file [options]

Curly braces and pipe character: { | }

Choice of mutually exclusive arguments; an OR selection

errorlevel {0|1}

Ellipses... Replaces repeated text var_name [, var_name...]

Represents code supplied by user

void main (void){ ...}

Page 6: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

¤ 2016 Microchip Technology Inc. page 6

WARRANTY REGISTRATIONPlease complete the enclosed Warranty Registration Card and mail it promptly. Sending in the Warranty Registration Card entitles users to receive new product updates. Interim software releases are available at the Microchip web site.

RECOMMENDED READINGThis user’s guide describes the MATLAB® Simulink Model based implementation of FOC for a PMSM based on AN1292. The following application note is available and recom-mended as supplemental reference resource:• AN1292 “Sensorless Field Oriented Control (FOC) for a Permanent Magnet Syn-

chronous Motor (PMSM) Using a PLL Estimator and Field Weakening (FW)” which is available at:- http://ww1.microchip.com/downloads/en/AppNotes/01292A.pdf

Reference material for MATLAB peripheral blocksets and Motor Control blocksets are available at:• For MATLAB peripheral related information visit:

- http://www.microchip.com/Developmenttools/ProductDe-tails.aspx?PartNO=SW007023

• For Motor Control related information visit the following link, in the available cata-log of documents ensure to select the ones specific for dsPIC® devices:- http://www.microchip.com/design-centers/motor-control-and-drive/motor-con-

trol-simulation/motor-control-library-blockset

Page 7: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

AN1292 FOC MATLAB Model User’s Guide

page 7 ¤ 2016 Microchip Technology Inc.

THE MICROCHIP WEB SITEMicrochip provides online support via our web site at www.microchip.com. This web site is used as a means to make files and information easily available to customers. Accessible by using your favorite Internet browser, the web site contains the following information:• Product Support – Data sheets and errata, application notes and sample

programs, design resources, user’s guides and hardware support documents, latest software releases and archived software

• General Technical Support – Frequently Asked Questions (FAQs), technical support requests, online discussion groups, Microchip consultant program member listing

• Business of Microchip – Product selector and ordering guides, latest Microchip press releases, listing of seminars and events, listings of Microchip sales offices, distributors and factory representatives

DEVELOPMENT SYSTEMS CUSTOMER CHANGE NOTIFICATION SERVICEMicrochip’s customer notification service helps keep customers current on Microchip products. Subscribers will receive e-mail notification whenever there are changes, updates, revisions or errata related to a specified product family or development tool of interest.To register, access the Microchip web site at www.microchip.com, click on Customer Change Notification and follow the registration instructions.The Development Systems product group categories are:• Compilers – The latest information on Microchip C compilers and other language

tools. These include the MPLAB® C compiler; MPASM™ and MPLAB® 16-bit assemblers; MPLINK™ and MPLAB® 16-bit object linkers; and MPLIB™ and MPLAB® 16-bit object librarians.

• Emulators – The latest information on the Microchip MPLAB® REAL ICE™ in-circuit emulator.

• In-Circuit Debuggers – The latest information on the Microchip in-circuit debugger, MPLAB® ICD 3.

• MPLAB IDE – The latest information on Microchip MPLAB® IDE, the Windows® Integrated Development Environment for development systems tools. This list is focused on the MPLAB® IDE, MPLAB® SIM simulator, MPLAB® IDE Project Man-ager and general editing and debugging features.

• Programmers – The latest information on Microchip programmers. These include the MPLAB® PM3 device programmer and the PICkit™ 3 development programmers.

Page 8: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

¤ 2016 Microchip Technology Inc. page 8

CUSTOMER SUPPORTUsers of Microchip products can receive assistance through several channels:• Distributor or Representative• Local Sales Office• Field Application Engineer (FAE)• Technical SupportCustomers should contact their distributor, representative or FAE for support. Local sales offices are also available to help customers. A listing of sales offices and locations is included in the back of this document.Technical support is available through the web site at: http://support.microchip.com

DOCUMENT REVISION HISTORY

Revision A (October 2016)This is the initial released version of the document.

Page 9: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

AN1292 FOC MATLAB ModelUser’s Guide

¤ 2016 Microchip Technology Inc. page 9

Chapter 1. Introduction

1.1 PURPOSEThis document is intended to help the users to develop a MATLAB®/Simulink model, in reference to the algorithm discussed in AN1292(1) .

1.2 SCOPEThis document provides information about the FOC PLL model and lists the requirements to run the complete model in both hardware and simulation modes.

1.3 OVERVIEWThis document discusses the implementation of AN1292(1) in MATLAB®/Simulink with code generation capability for MCLV2 hardware, without the flux weakening scenario.

Note 1: In this document “AN1292” refers to the application note AN1292 “Sen-sorless Field Oriented Control (FOC) for a Permanent Magnet Synchro-nous Motor (PMSM) Using a PLL Estimator and Field Weakening (FW)” which is available at:

http://ww1.microchip.com/downloads/en/AppNotes/01292A.pdf

Page 10: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

AN1292 FOC MATLAB ModelUser’s Guide

¤ 2016 Microchip Technology Inc. page 10

Chapter 2. Implementation Requirements

2.1 HARDWARE REQUIREMENTSThe hardware setup requires the following:

1. dsPICDEM™ MCLV2 Development Board (Low Voltage) configured with an external Op-Amp Matrix Board http://www.microchip.com/DevelopmentTools/ProductDe-tails.aspx?PartNO=dm330021-2

2. dsPIC33EP256MC506 External Op-Amp Motor Control PIM http://www.microchip.com/DevelopmentTools/ProductDe-tails.aspx?PartNO=ma330031-2

3. Hurst DMB0224C10002 BLDC Motor http://ww1.microchip.com/downloads/en/DeviceDoc/Hurst%20Motor%20DataSheet.pdf

4. MPLAB REAL ICE In-Circuit Emulator http://www.microchip.com/Developmenttools/ProductDe-tails.aspx?PartNO=DV244005

or

MPLAB ICD 3 In-Circuit Debugger http://www.microchip.com/Developmenttools/ProductDe-tails.aspx?PartNO=DV164035

Page 11: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

AN1292 FOC MATLAB Model User’s Guide

page 11 ¤ 2016 Microchip Technology Inc.

2.2 SOFTWARE REQUIREMENTSThis section identifies various software that are to be installed and tested on a Windows PC which runs Windows7 OS (64bit). A quad core (or Core i7) computer with minimum 4GB RAM installed is recommended for smooth running of the MATLAB®/Simulink software. Execute the following instructions to be ready for the MATLAB/Simulink implementation:

5. Power Supply Unit (AC002013) http://www.microchipdirect.com/productsearch.aspx?Key-words=AC002013

6. UART to USB cable TrendNet TU-S9 https://www.trendnet.com/products/prodde-tail?prod=150_TU-S9

or

Saelig USB-COM-U13 http://www.saelig.com/product/USSP005.htm

1. Ensure that MATLAB R2015a 64bit or higher is installed, the recommend version is R2015aSP1 which is available at:

then,

http://www.mathworks.com/products/new_products/release2015a.html?refresh=true

2. Install MPLAB X IDE, the recommend is v3.20 which is available at:

http://www.microchip.com/mplab/mplab-x-ide

3. Install MPLAB XC16 Compiler, the recom-mended version is v1.24 which is available at:

http://www.microchip.com/mplab/compilers

4. Download PMSM Simulink® Motor Model which is available at:

http://www.microchip.com/design-centers/motor-control-and-drive/motor-control-simula-tion/pmsm-simulink-motor-model

5. Download Motor Control Library for dsPIC33F/dsPIC33E which is available at:Note: The folder downloaded should be added along with subfolders into the ‘path’ of MATLAB.

http://www.microchip.com/design-centers/motor-control-and-drive/motor-control-library

6. Download and install MPLAB 16-Bit Device Blocks for Simulink is available at:

http://www.microchip.com/SimulinkBlocks

and

http://www.microchip.com/forums/m878432.aspx#878432

Page 12: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

Implementation Requirements

¤ 2016 Microchip Technology Inc. page 12

After installing the specified versions of the software, when “ver” is entered in the MATLAB command window the following list is displayed:

Note: For information about adding a folder to the path, please refer to:- https://in.mathworks.com/help/matlab/matlab_env/add-remove-or-reorder-

folders-on-the-search-path.html

Page 13: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

AN1292 FOC MATLAB ModelUser’s Guide

¤ 2016 Microchip Technology Inc. page 13

Chapter 3. FOC Model Overview

The following FOC block diagram shows the principle Clarke, Park transformation and their inverse, along with the two PI Controllers for current and speed, and the speed and position estimator.

FIGURE 3-1: FOC CONTROL BLOCK DIAGRAM

Note: Speed and Position Estimator is the PLL estimator based on AN1292(1).

Page 14: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

AN1292 FOC MATLAB Model User’s Guide

page 14 ¤ 2016 Microchip Technology Inc.

The FOC model contains the blocks shown in the following diagrams.

FIGURE 3-2: BLOCK DIAGRAM WITH SIMULINK IMPLEMENTATION

FIGURE 3-3: MODEL CONTROL FLOW STRUCTURE

Note: Plant Model for simulation will be replaced by the actual motor and inverter, as shown in Figure 3-4.

Page 15: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

FOC Model Overview

¤ 2016 Microchip Technology Inc. page 15

FIGURE 3-4: CODE RUNNING IN HARDWARE

3.1 FILES IN FOC FOLDERThe files in the FOC folder are listed in the following table:

File Name Description

1. board_params.m Contains board parameters like shunt value, device voltage, etc2. ctrl_params.m Contains controller parameters - Transition speed, PI constants,

reference speed for simulation, etc3. estim_params.m Contains estimator parameters4. mc_plot18ch.m Decodes and plots UART data5. mtr_params.m Motor parameters6. pll_estim_params.m Estimator parameters that are unique to PLL Estimator7. PLL_Init_Param.m Master Initialization file that calls the other files in sequence8. PLL_Sim_Mtr.slx AN1292(1) based FOC Model

Page 16: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

AN1292 FOC MATLAB ModelUser’s Guide

¤ 2016 Microchip Technology Inc. page 16

Chapter 4. Top Level Miscellaneous Blocks

This section discusses the following blocks used, besides the FOC Control:• ADC Block• Button Press Block• Motor Model Block• UART Transmit Block

4.1 ADC BLOCKThe block converts the acquisition signal outputs of the dsPIC® ADC and converts them to Q15 format so that they can be used in the simulation and by the Simulink coder.

FIGURE 4-1: BLOCK DIAGRAM - ADC BLOCK

FIGURE 4-2: BLOCK DIAGRAM OF ADC BLOCK WITH SIMULINK IMPLEMENTATION

Note 1: Bipolar to unipolar refers to the changing range from [-1, 1] to [0, 1]2: Shunt gain converts shunt based convention to hall sensor based

convention

Page 17: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

AN1292 FOC MATLAB Model User’s Guide

page 17 ¤ 2016 Microchip Technology Inc.

4.2 BUTTON PRESS BLOCKThis block switches the motor from idle to a running state. It also incorporates the digital output of an LED to indicate that the motor is running.

FIGURE 4-3: BLOCK DIAGRAM - BUTTON PRESS BLOCK

FIGURE 4-4: BLOCK DIAGRAM - BUTTON BLOCK WITH SIMULINK IMPLEMENTATION

Note 1: “Main State” block receives the run command and it is not part of this block.

2: “MCLV2 Hardware” block is outside of this structure but it receives the output signal called Duty cycle.

Page 18: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

Top Level Miscellaneous Blocks

¤ 2016 Microchip Technology Inc. page 18

4.3 MOTOR MODEL BLOCKThis block contains Motor Simulation model, Load model and an ADC model that are used in the simulation.

FIGURE 4-5: BLOCK DIAGRAM - MOTOR MODEL BLOCK

4.4 UART TRANSMIT BLOCKThis block transmits variables from the dsPIC® to the UART communications port on the MCLV2 Board, and then to the PC for future analysis.

FIGURE 4-6: BLOCK DIAGRAM - UART TRANSMIT BLOCK

Note 1: Load considered is a fan type of load.2: ADC model converts the floating point current (A) to fixed point scaled

counts to be sampled by the control system.

Page 19: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

AN1292 FOC MATLAB Model User’s Guide

page 19 ¤ 2016 Microchip Technology Inc.

4.5 SETUP FOR PICGUI INTERFACEData is plotted on the PC using the picgui interface, by selecting the:1. Baud Rate 9216002. COM port accordingly 3. Connexion button

Note: Note: Once selected the Connexion button turns to Magenta, indicating that a connection is established between the PC and the device.

Enter “mc_plot18ch();” on the screen and then select Start, the following window gets displayed.

The window displays seven plots for: 1. Ia, Ib currents 2. Speed reference and estimated speed3. Id current 4. FFT on Ia current5. Iq current 6. Ed, Eq voltages7. Iq reference current “mc_plot18ch();” calls a function in “mc_plot18ch.m” file. This file is a script that decodes the raw data received over the UART and plots it in the user-readable graphs. This can be modified as per the user requirements for various data inputs.

Page 20: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

AN1292 FOC MATLAB ModelUser’s Guide

¤ 2016 Microchip Technology Inc. page 20

Chapter 5. Main State Block

This block emulates a “state machine” without an explicit state machine implementation from MATLAB®. The state machine controls running and stopping based on the run command it receives from the Button Press block (Figure 4-3). A “clear state” is imple-mented to clear all control history so that the motor can restart smoothly when needed.

FIGURE 5-1: BLOCK DIAGRAM - MAIN STATE BLOCK

FIGURE 5-2: BLOCK DIAGRAM - MAIN STATE BLOCK WITH SIMULINK IMPLEMENTATION

Note 1: - Activation conditions (when to transition)2: - Transition actions (what to do during transition)

Page 21: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

AN1292 FOC MATLAB ModelUser’s Guide

¤ 2016 Microchip Technology Inc. page 21

Chapter 6. FOC Control Block

6.1 FOC CONTROL STATE MACHINEThis block comprises of the FOC algorithm (which has the Open loop startup phase, Open loop to Closed loop transition, and Closed loop phase), and a PLL estimator for the motor.

FIGURE 6-1: BLOCK DIAGRAM – STATE MACHINE OF THE FOC CONTROL BLOCK

The inputs of the FOC Control state machine are FOC Enable command and the Ia, Ib, Potentiometer signal values. The output of the FOC Control state machine is the Duty cycle.

Note 1: - Transition enabled by Main State block2: - Transition conditions (what to do during transition)3: - Activation conditions (when to transition)

Page 22: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

AN1292 FOC MATLAB Model User’s Guide

page 22 ¤ 2016 Microchip Technology Inc.

The Timers, Integrators, PI Controllers within various blocks of the FOC Control are reset with a cleanup flag. Resetting: • ensures that the startup routine is repeatable. • is supported by the S2 button which allows toggling between starting and stopping

the motor. When toggling, the:• First press starts the motor, locks rotor position, then starts an Open loop and then

transitions to a Closed loop. • Next press stops the motor.

6.2 FOC CONTROL BLOCK DIAGRAM

FIGURE 6-2: FOC CONTROL BLOCKS IMPLEMENTATION WITH DETAILED SIMULINK SCHEMATIC

Blocks of the FOC Control are explained in the following table.

Note: The motor can be reset ‘n’ number of times using the S2 button.

Block Activation Description

Speed Control Activated only when the motor has transitioned or transitioning to a Closed loop.

Contains the PI Controller to control the speed.

Open Loop Start-Up Activated till the reference speed reaches a minimum safe value for transitioning to a Closed loop.

Initiates an Open loop speed ramp and generates a rotor angle till the motor transitions to a Closed loop.

Estimator Activated when the rotor locking is completed and the motor starts to spin.

Contains the PLL estimator from which the estimated rotor speed and angle is used for the Closed loop.

Current Control Activated whenever the FOC Control block is activated.

Contains Park, Clarke transformation and their inverse for the currents, and also the PI Controllers for the ‘d’ and ‘q’ axis currents.

OLtoCLTransition Activated during the transition from Open loop to Closed loop.

Ensures smooth switching from Open loop to Closed loop.Steps involved in switching are as follows:• Set offset_theta = OL_theta -

CL_theta• Theta = CL_theta + offset_theta• Slowly bring offset_theta to 0

Page 23: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

FOC Control Block

¤ 2016 Microchip Technology Inc. page 23

6.3 PLL ESTIMATOR (AN1292 BASED)

FIGURE 6-3: PLL ESTIMATOR BLOCK DIAGRAM

The PLL Estimator is based on the back EMF (BEMF) equations calculated in the stationary reference frame.

The stationary frame BEMFs are then transformed to rotating reference from ‘d’, ‘q’ co-ordinates using Park Transform. These coordinates are used to calculate the estimated speed by dividing the ‘q’ component of the BEMF with the voltage constant:

For more information please refer to AN1292(1).

LPF

LPF

Edf

Eqf

Ed

EqEE

ED D�E

d,q

+ +

1s

K)

ZRestimUestim

ED V D Rs ID Lsd lDdt--------x–x–=

EE V E Rs IE Lsd lEdt--------x–x–=

Sign

ED V D Rs ID Lsd lDdt--------x–x–=

EE V E Rs IE Lsd lEdt--------x–x–=

ZE1K)-------- Eqf Eqf� �sgn Edf�� �–> @=

Page 24: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

AN1292 FOC MATLAB ModelUser’s Guide

¤ 2016 Microchip Technology Inc. page 24

Chapter 7. Test Results

Following are the test results obtained when the model is simulated and programmed on hardware described in Chapter 2. “Implementation Requirements”:

7.1 SIMULATION RESULTSThe following figure shows three-phase currents under repeated motor start/stop oper-ations:

The following figure shows speed of the motor under repeated start/stop operations:

Page 25: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

AN1292 FOC MATLAB Model User’s Guide

page 25 ¤ 2016 Microchip Technology Inc.

The following figure shows the current during transitioning from an Open loop to a Closed loop:

The following figure shows the phase current under a steady state:

The following figure shows the variation of load torque under repeated start/stop con-ditions:

Page 26: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

Test Results

¤ 2016 Microchip Technology Inc. page 26

7.2 HARDWARE RESULTSThe following figure shows the current during transitioning from an Open loop to a Closed loop:

The following figure shows the phase current under a steady state:

Page 27: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

AN1292 FOC MATLAB Model User’s Guide

page 27 ¤ 2016 Microchip Technology Inc.

The following figure shows the data coming over UART:

Page 28: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

AN1292 FOC MATLAB ModelUser’s Guide

¤ 2016 Microchip Technology Inc. page 28

Chapter 8. Conclusion

The topics discussed and results observed in the document are as follows:• Hardware and software setup required for a MATLAB® Simulink based model• Implementation of various blocks used in the model• Simulations and hardware results and their similarities

Page 29: FOC MATLAB Model with PLL Estimator Based on AN1292 User…ww1.microchip.com/downloads/en/DeviceDoc/FOC MATLAB Model Us… · FOC MATLAB® Model with PLL Estimator Based on AN1292

page 29 ¤ 2016 Microchip Technology Inc.

AMERICASCorporate Office2355 West Chandler Blvd.Chandler, AZ 85224-6199Tel: 480-792-7200 Fax: 480-792-7277Technical Support: http://www.microchip.com/supportWeb Address: www.microchip.comAtlantaDuluth, GA Tel: 678-957-9614 Fax: 678-957-1455Austin, TXTel: 512-257-3370 BostonWestborough, MA Tel: 774-760-0087 Fax: 774-760-0088ChicagoItasca, IL Tel: 630-285-0071 Fax: 630-285-0075ClevelandIndependence, OH Tel: 216-447-0464 Fax: 216-447-0643DallasAddison, TX Tel: 972-818-7423 Fax: 972-818-2924DetroitNovi, MI Tel: 248-848-4000Houston, TX Tel: 281-894-5983IndianapolisNoblesville, IN Tel: 317-773-8323Fax: 317-773-5453Los AngelesMission Viejo, CA Tel: 949-462-9523 Fax: 949-462-9608New York, NY Tel: 631-435-6000San Jose, CA Tel: 408-735-9110Canada - TorontoTel: 905-695-1980 Fax: 905-695-2078

ASIA/PACIFICAsia Pacific OfficeSuites 3707-14, 37th FloorTower 6, The GatewayHarbour City, KowloonHong KongTel: 852-2943-5100Fax: 852-2401-3431Australia - SydneyTel: 61-2-9868-6733Fax: 61-2-9868-6755China - BeijingTel: 86-10-8569-7000 Fax: 86-10-8528-2104China - ChengduTel: 86-28-8665-5511Fax: 86-28-8665-7889China - ChongqingTel: 86-23-8980-9588Fax: 86-23-8980-9500China - DongguanTel: 86-769-8702-9880 China - GuangzhouTel: 86-20-8755-8029 China - HangzhouTel: 86-571-8792-8115 Fax: 86-571-8792-8116China - Hong Kong SARTel: 852-2943-5100 Fax: 852-2401-3431China - NanjingTel: 86-25-8473-2460Fax: 86-25-8473-2470China - QingdaoTel: 86-532-8502-7355Fax: 86-532-8502-7205China - ShanghaiTel: 86-21-5407-5533 Fax: 86-21-5407-5066China - ShenyangTel: 86-24-2334-2829Fax: 86-24-2334-2393China - ShenzhenTel: 86-755-8864-2200 Fax: 86-755-8203-1760China - WuhanTel: 86-27-5980-5300Fax: 86-27-5980-5118China - XianTel: 86-29-8833-7252Fax: 86-29-8833-7256

ASIA/PACIFICChina - XiamenTel: 86-592-2388138 Fax: 86-592-2388130China - ZhuhaiTel: 86-756-3210040 Fax: 86-756-3210049India - BangaloreTel: 91-80-3090-4444 Fax: 91-80-3090-4123India - New DelhiTel: 91-11-4160-8631Fax: 91-11-4160-8632India - PuneTel: 91-20-3019-1500Japan - OsakaTel: 81-6-6152-7160 Fax: 81-6-6152-9310Japan - TokyoTel: 81-3-6880- 3770 Fax: 81-3-6880-3771Korea - DaeguTel: 82-53-744-4301Fax: 82-53-744-4302Korea - SeoulTel: 82-2-554-7200Fax: 82-2-558-5932 or 82-2-558-5934Malaysia - Kuala LumpurTel: 60-3-6201-9857Fax: 60-3-6201-9859Malaysia - PenangTel: 60-4-227-8870Fax: 60-4-227-4068Philippines - ManilaTel: 63-2-634-9065Fax: 63-2-634-9069SingaporeTel: 65-6334-8870Fax: 65-6334-8850Taiwan - Hsin ChuTel: 886-3-5778-366Fax: 886-3-5770-955Taiwan - KaohsiungTel: 886-7-213-7828Taiwan - TaipeiTel: 886-2-2508-8600 Fax: 886-2-2508-0102Thailand - BangkokTel: 66-2-694-1351Fax: 66-2-694-1350

EUROPEAustria - WelsTel: 43-7242-2244-39Fax: 43-7242-2244-393Denmark - CopenhagenTel: 45-4450-2828 Fax: 45-4485-2829France - ParisTel: 33-1-69-53-63-20 Fax: 33-1-69-30-90-79Germany - DusseldorfTel: 49-2129-3766400Germany - KarlsruheTel: 49-721-625370Germany - MunichTel: 49-89-627-144-0 Fax: 49-89-627-144-44Italy - Milan Tel: 39-0331-742611 Fax: 39-0331-466781Italy - VeniceTel: 39-049-7625286 Netherlands - DrunenTel: 31-416-690399 Fax: 31-416-690340Poland - WarsawTel: 48-22-3325737 Spain - MadridTel: 34-91-708-08-90Fax: 34-91-708-08-91Sweden - StockholmTel: 46-8-5090-4654UK - WokinghamTel: 44-118-921-5800Fax: 44-118-921-5820

Worldwide Sales and Service

06/23/16