Deploying Motor Control Algorithms on Microchip dsPIC, PIC32, and SAM Controllers - MATLAB & Simulink
Video Player is loading.
Current Time 0:00
Duration 28:39
Loaded: 0.58%
Stream Type LIVE
Remaining Time 28:39
 
1x
  • descriptions off, selected
  • en (Main), selected
    Video length is 28:39

    Deploying Motor Control Algorithms on Microchip dsPIC, PIC32, and SAM Controllers

    Patrick Heath, Microchip
    Hithesh CN, Microchip

    Overview

    This webinar shows how to use Simulink, the new Motor Control Blockset, and the Embedded Coder to generate C code from motor control algorithms and deploy them to Microchip’s dsPIC digital signal controllers (DSCs), PIC32 and SAM microcontrollers (MCUs).  Starting with a sensorless Field-Oriented Control (FoC) algorithm modeled in the Motor Control Blockset, we will use the Embedded Coder to generate optimized code for a Microchip motor control device.  The code generation workflow will feature the use of the MPLAB Device Blocks for Simulink, which provides an integrated development environment and toolchain for configuring and generating all the necessary software to execute complex applications on Microchip MCUs and DSCs.  In addition, MPLAB Device Blocks for Simulink includes a Simulink embedded target for Microchip devices with peripheral device blocks and drivers.

    Highlights

    • Simulating sensorless Field Oriented Control (FOC) algorithms in Simulink and using the Motor Control Blockset
    • Generating optimized, production ready code with the Embedded Coder
    • Deploying code to Microchip’s dsPIC DSCs, PIC32 and SAM MCUs using MPLAB Device Blocks for Simulink

    About the Presenters

    Patrick Heath: Microchip

    Patrick is the Motor Control Marketing Manager for Microchip’s MCU16 Division, which includes the dsPIC family. He has nearly 40 years of experience working in the semiconductor industry split between Motorola and Microchip with a focus on supporting digital power and motor control applications.

    Hithesh CN: Microchip

    Hithesh is a Motor Control Application Engineer in Microchip’s MCU16 Division.  He has a Master’s Degree in Power Electronics and is currently working on various Motor Control algorithms and simulations using Microchip's dsPIC family of DSC devices.

    Brian McKay: MathWorks

    Brian McKay is a Technical Marketing Manager specializing in MathWorks solutions for embedded systems customers. He has been building customer solutions that combine MathWorks software with embedded hardware for over 20 years.

    Recorded: 30 Jul 2021

    Hello. I'm Brian McKay from The MathWorks. I'm a Partner Manager at MathWorks, the leading developer of mathematical computing software. And I've been to The MathWorks for 16 years.

    My background is in control systems, and most of my experience is combining hardware and software together to make embedded systems run. And that is exactly what we will do in this webinar.

    Today I will be joined by Patrick Heath and Hitesh CN from Microchip. Together we will talk about deploying motor control algorithms on Microchip dsPIC, PIC32, and SAM controllers.

    Our agenda for today. I will start with a very brief overview of motor control and MathWorks Motor Control Blockset. Next, Patrick from Microchip will do a quick introduction of Microchip, and an overview of their controllers, which span from dsPIC 16-bit digital signal controllers, to 32-bit PIC32 and SAM microcontrollers.

    Following Patrick, Hitesh will show us a demo of how to get and use MPLAB device driver blocks for Simulink, and run a motor control on a dsPIC controller connected to a PMSM motor.

    So why are we talking about brushless motors? Well, because they are everywhere. We can find them in electric vehicles, trains, industrial drives, medical devices, and even electric longboards. So by using field oriented control, we can digitally control these electric motors.

    And so why would we use Simulink for motor control? Well, because Simulink and model-based design for developing embedded motor control algorithms can help and accelerate your workflow.

    With model-based design and Simulink, we can quickly put together a control system and start testing and verifying it in closed loop desktop simulation. This can be done even before motor hardware is available.

    We provide a way to quickly go from design to implementation by automatically generating code from the Simulink model, and also the ability to use this code to spin a motor.

    To minimize development time we have many reference examples to quickly get you started on your next motor control project. And most importantly, the reason why our customers choose to use Simulink is faster development time.

    Motor Control Blockset lets you design and implement motor control algorithms for permanent magnet synchronous motors.

    In release R2020B we made a major upgrade on Motor Control Blockset that will automate and simplify the development process for embedded motor control algorithms.

    The product provides pre-built algorithmic blocks optimized for generating efficient code. There are sensor decoders for Hall sensor, quadrature encoder, and resolver. Sliding mode and flux observer blocks are provided for implementing centralist control.

    There are also blocks for motor parameter estimation and automated loop tuning. And finally, the product provides fully assembled reference examples for censored and centralist field-oriented control algorithms.

    This webinar is focusing on the deployment to hardware. So please visit the Motor Control Blockset product page on mathworks.com.

    There you can find many detailed resources and examples on how to use the model-based design for motor control simulation, and testing using Simulink, and Motor Control Blockset.

    Here's a quick preview of where we will end up today. Here we see a motor control, which was developed in Simulink and integrated with MPLAB device drivers for Simulink.

    Embedded coder generated the highly optimized C-code, which is deployed to a dsPIC 16-bit controller, which sits on a low voltage motor control development board, connected to a Hurst PMSM motor.

    In the video clip you can see the motor-- which is the blue plot-- respond to changes in the speed reference-- the yellow plot-- which is all controlled by a rotary potentiometer on the board.

    And next up is Patrick from Microchip, who will give us a brief introduction to Microchip and their families of 16-bit dsPIC digital signal controllers, and 32-bit PIC32 and SAM microcontrollers.

    Hi. My name is Patrick Heath, and I'm the Senior Marketing Manager responsible for Motor Control at Microchip. Today we have prepared this webinar to help show you how to use MathWorks new Motor Control Blockset to model a sensorless FOC algorithm.

    And further, how to use our code generation libraries to create the firmware and run a three phase BLDC motor.

    Before we get to that, it's important to understand where it fits into our overall motor control ecosystem. Motor control covers a broad, diverse range of applications. We have worked with customers making solutions for home appliances, automotive, consumer, and industrial applications.

    Along the way, we have learned that each application has some unique challenges, such as for a startup, or for achieving the maximum torque, or the maximum speed from the motor, just as each motor is different and requires tuning for its unique electrical parameters.

    Whatever your application, I believe that Microchip has the expertise, knowledge, and tools to help you spin your motor.

    Microchip has been designing motor controllers for over 15 years now, and along the way we've learned a thing or two about what motor control applications require.

    Since no one single solution optimally fits every application, Microchip provides a broad range of 8-, 16-, and 32-bit MCUs, DSCs, and FPGAs targeted towards motor control.

    These solutions are highly integrated, with digital and analog features such as A/Ds, Op-Amps, and comparators, in order to provide a lower bill of materials cost.

    We design and qualify our chips to meet the highest automotive grade requirements. Even if you are not designing an automotive motor control application, the improved reliability is beneficial.

    Ideally, motors should be seen, and not heard. Our algorithmic support is focused on sinusoidal PWM outputs running above the 20 kilohertz audible threshold.

    We also understand that many consumer and automotive applications are space constrained, and to help them we offer many smaller sized packages, down to 4 by 4 millimeters.

    Finally, our overriding goal has been to help reduce time to market by providing an ecosystem of support that reduces the development time for an application.

    As we are focusing on using MathWorks motor control models today, we can narrow our focus to the solutions that are supported with models and code generation. These motor controllers include our 16-bit dsPIC digital signal controllers, 32-bit SAM family of ARM cortex-based CPUs, and our 32-bit PIC32 MIPS based MCUs.

    Each of these products are really families of devices that offer a wide range of flash memory and pin counts to choose from.

    The dsPIC33 C family has a hybrid DSP and MCU core designed to optimize real time control. It includes both single and dual core devices capable of running multiple motors, and there is also a five volt family to support robust usage.

    Similarly, the SAM C, D, and E MCU families, based on the ARM cortex M0, M4F, and M7 cores provide a broad range of performance, memory sizes, and features, including an FPU on the upper end devices, as well as on the PIC32 MK family.

    Over time, our motor control ecosystem has grown to provide several different choices on how to generate motor control firmware. In parallel, our selection of hardware development boards and reference designs has also expanded to cover more applications.

    Let's take a closer look at some of these tools, starting with the hardware. Microchip provides a wide range of hardware designed to provide a starter solution to spin your motor.

    As you can see, on the left side of the chart, these include application-specific reference designs, reference motors to use to get started and for demos, and both high and low voltage development boards.

    These boards can be further segmented by the motor type, as shown along the bottom of the chart, with BLDC/PMSM support on the left, ACIM support in the middle, and stepper motor support on the right.

    As you can see on the upper right, Microchip has several new reference designs in progress. We have seen that these are very effective in helping customers reduce their time to market.

    Here's a closer look at our most popular motor control development boards. On the top is a picture of one of our mini plugin modules, or PIMs.

    There's a PIM for each of our superset DSC or MC motor control devices, and these PIMs plug into the MCLV-2 low voltage and MCHV-3 high voltage development boards.

    This modularity provides the flexibility to easily switch between the different dsPIC, SAM, or PIC32MK motor control devices, without having to design a separate hardware board for each device.

    Now let's switch to code generation. Traditionally, Microchip would provide an application note and the accompanying code as a starting point for a new motor control project.

    There are now over 25 different application notes, and more than 70 different starter projects available, some with tuning guides. In addition to those shown here, other application notes cover stepper motors and dual motor control.

    The second way to generate motor control firmware is to use our FOC GUI tool, called motorBench. This free tool runs on your PC or Mac and uses one of our motor control development boards along with your motor.

    It extracts the motor's unique electrical parameters, and the mechanical load parameters from the application, to generate the FOC code. The entire process takes only five to 10 minutes, and the code could then be programmed into the dsPIC to run the motor.

    motorBench has a large and growing number of control and rotor position feedback options, making it a very powerful and versatile tool for FOC code generation.

    The third way to generate motor control code is from a model after simulation. Microchip has developed an FOC and a PMSM motor model to run in MathWorks MATLAB Simulink environment.

    Today's webinar will demonstrate instead how to create a sensorless FOC model using MathWorks new Motor Control Blockset.

    In either case, code generators for the dsPIC, SAM, and PIC32MK motor controllers transform the model output into the firmware that runs a PMSM motor, as you will see in the demo.

    In today's demo, we will use a dsPIC motor control DSC. The dsPIC is comprised of a large family of over 2,000 devices built around a hybrid DSP/MCU core.

    This includes single and dual core devices available in a wide range of speed, flash memory sizes, ping counts, temperature, and two supply voltage ranges.

    In particular, the demo today will direct the model's output to generate the code to run a Hurst PMSM motor, attached to our MCLV-2 board, populated with a dsPIC33 EP 256 MC 506 PIM.

    This 70 megahertz dsPIC33 EP device has more than enough CPU bandwidth, as well as the motor control peripherals required for FOC. These include high resolution PWM outputs, and A/Ds, Op-Amps, and comparators for motor current feedback.

    This family has different flash memory and package sizes available to meet a wide range of application requirements. Now here's Hitesh, who will show us how it all works

    Thanks, Patrick. Now in this part of the presentation, we will see the demonstration of the sensorless field oriented control of permanent magnet synchronous motor using Simulink and dsPIC digital signal controller.

    In this demo, we will see how MATLAB Simulink can be used to simulate a model for controlling a permanent magnet synchronous motor with sensorless field oriented control.

    Once the simulation is completed, we use the same model to generate the code and run the real permanent magnet synchronous motor using Microchip's Motor Control Development Board, and observe its performance.

    In this demo, the code generation and the control of motor is done with Microchip's dsPIC33 EP 256 MC 506 digital signal controller. This is a 16-bit digital signal controller, with fixed point architecture. So the generated code will be in the fixed point implementation.

    The same Simulink model can be used to run on Microchip's PIC32 or SAM microcontrollers, but these are the microcontrollers with 32-bit and floating point architecture. And standard code while using these devices will be in 14 point implementation.

    Now we will see the basic working of sensorless field oriented control. This block diagram illustrates the entire process of sensorless field oriented control of a permanent magnet synchronous motor.

    Here, a 3/5 permanent magnet synchronous motor is controlled using the three phase motor. These blocks show the block-on-block transformations. Here we will only measure two of the three phase currents, and the third one can be input from these two currents.

    The IQ and IA time variables then form the actual sequence for the separately controlled IQ and IDPA controllers. The ID reference is set to zero, because we want the ID component, which comprises the variance equal to zero, unless we need a field weakening.

    The IQ reference comes from the outer speed control load, so that we have speed control load controlling the torque of the motor, just like the normal motor control systems.

    The output of the two inner loops of b and q VA controllers feeding to inverse power transformation block. Essentially, we're reversing the transformation process to get back to the physical three phase co-entities, which can be controlled via inverter here.

    This space vector modulation and the inverse block transformation block are rolled into one block here. The space vector modulation allows us to introduce the 3/5 voltages by modulating the on and off periods of the power switches in the 3/5 inverter.

    Because of sensorless operation of the permanent and asynchronous motor, the position and speed of the rotor has to be estimator or its permutation. So if flux observer based estimator is used to reject the position and speed of the rotor here.

    Now we will see the software and hardware tools required to run this demonstration. First, come into the software requirements. The latest version of MATLAB Simulink has to be installed.

    Along with this, the support packages like Embedded Coder, Fixed Point Designer, and Motor Control Blockset has to be installed. The Embedded Coder is needed to generate the code from the Simulink model and program into the microcontroller.

    In this demonstration, as we're using the 16-bit dsPIC digital signal controller with fixed point architecture, the Fixed Point Designer is used to convert all the Motor Control Block output to the fixed point format.

    Along with this, the MPLAB Device Blocks for Simulink has to be installed. This package will be heavy on the microchip device peripherals blocks that can be used in the Simulink.

    In addition to this, the MPLAB X IDE has to be installed. This is a integrated development environment provided by Microchip, and it supports all the software development for Microchip's 8-bit, 16-bit, and 32-bit family of devices. Along with this, the MPLAB XC Compiler has to be installed for programming the devices.

    Now will see how to install the Microchip softwares here. First, we will see how to install the MPLAB Device support for Simulink. For this, open the MATLAB and go to the Add-ons here, and search for MPLAB.

    Then you will get the MPLAB Device Blocks for Simulink package here. Open this, then add this file to the MATLAB.

    After adding this package you will see this Open Folder option. Open this folder in the MATLAB. In this folder you will be having installation files to install the MPLAB Simulink Toolbox into the MATLAB.

    To install the MPLAB Simulink Blockset Toolbox I will click on this install.p file here, and run this file. After that, it will ask for the permission to install the Toolbox package here. Give Y, that is S2, to install the package.

    Once the installation is done, then you will get this web page links for the MPLAB X IDE and the MPLAB XC compilers. To install the MPLAB X IDE, click on this MPLAB X. This will open the MPLAB X IDE web page. You will find more information on the MPLAB X IDE.

    You can go through this page, and to download the software, go to this View Latest Downloads, and download the latest version of MPLAB X IDE for the operating system requirements here.

    To install the MPLAB XC Compilers, click on this xc16 or xc32 link here. This will open the MPLAB XC Compiler web page. Here, you can see that MPLAB XC Compilers that are required for various Microchip devices are given here.

    To download the XC Compiler, go to the View Downloads and Compiler Downloads, and you can see there are various Compilers available, like XC8, XC16, and XC32.

    For 16-bit devices, download the XC16 compiler. For 32-bit devices, download the MP XC32 or 32++ compilers, and install these tools on your operating system.

    Now moving on to the hardware tools required to run this demonstration. The first one is the MCLV-2 Development Board. This is the low voltage development board for the Motor Control applications using Microchip's devices.

    The board is targeted to control a brushless DC motor or a permanent magnet synchronous motor in sensor or sensorless operation.

    The next one is the dsPIC33 EP 256 MC 506 external Op-Amp motor control plug in module. This plugged in module comes with dsPIC33 EP 256 MC 506 digital signal controller. And this can be used with MCLV-2 board.

    This data signal controller features a 70 MIPS dsPIC digital signal controller core, with integrated DSP. It also has enhanced on-chip peripherals, which can be used to control brushless DC, permanent magnet, synchronous, A/C induction, or stepper motors.

    To run the demonstration, we are using a 24-volt 3-phase permanent magnet synchronous motor from Hurst NT Dynamo. These are the part numbers of these tools given here.

    For more information on each of these tools, you can visit this web page by replacing this PartNumber by the actual part number of the device given here.

    We also need a MPLAB PICkit 4 in-circuit debugger. This is a programmer come debugger, used to program and debug the Microchip devices. A 24-volt power supply is required to power the MCLV-2 Development Board.

    And these are the part number of these products. And for more information on these products you can visit this link given here, by replacing the PartNumber by the actual part number of the products.

    Along with this, a USB to UART serial converter module is required. It can support up to the communication rate of 3 mega baud. This board is used to establish the communication between MCLV-2 board and the Simulink model.

    Now we will see the demonstration of the sensorless field oriented control model with the Microchip hardware. This is a Simulink model for the sensorless field oriented control, using Microchip device and hardware.

    The Microchip related files will be present inside this Hardware Init folder. If you open this, all the Microchip device peripherals are available inside of this folder.

    They are digital signal controller used, the compiler version, and the UART module of the device, the Timer model. Everything will be initialized here.

    This DOC file provides the web link to the digital signal controller data set. All the digital signal controller pin directed information will be provided in this block here.

    If any additional digital signal peripheral is required for the addition of new feature into this model, you can go to the library folder and go to the MPLAB Device Blocks for Simulink lab area.

    The various peripherals are available here for different Microchip devices. You can select this, and add the new feature to the MATLAB model.

    First, we will see the simulation on this model. After verifying the simulation result, we'll use the same model run on he real PMSM model.

    To run the simulation, go to this Edit Motor & Inverter Parameters file. In this file, all the information on the motor parameters, as well as the hardware parameters, will be given here.

    In order to choose a different motor or different hardware, you can edit the parameters of the motor and the hardware, and run this model for that hardware and the motor.

    For the simulation, run this file here. This will load all the motor and inverter variables declared in the MATLAB Simulink model to the values of the corresponding motor and time motor. Then come to this simulation page, and run the simulation.

    Once the simulation is completed, the outputs can be seen from the Data Inspector view. These are phase-current waveforms from the simulation. Initially, the motor starts with the offset calibration, and then loop operation, then moves to the closed loop operation.

    This is a zoom impression of the phase-current of the motor read by the microcontroller. This is the speed profile of the motor. The blue line shows the reference speed, and the orange line shows the actual motor speed.

    Here initially, in the open loop it runs at 0.1 per unit speed. After that, when it enters the closed loop, the motor speed goes to the reference speed set by the user. After that, if the reference speed is varied. The motor speed also varies according to the reference speed.

    Now we will see how to run this model with the Microchip hardware. First, we will see the hardware connections that are needed to run this model.

    Connect the dsPIC33 EP 256 MC 506 plug in module to the U9 connector of the MCLV-2 board. And connect external op-amp matrix board to the JF14 connector of the MCLV-2 board.

    Connect the power supply to the J2 connector, and then connect the 3-phase permanent magnet synchronous motor to the JSON connector of the MCLV-2 board.

    To program the device, connect the PICkit4 programmer comm debugger to the J12 connector here. To establish the communication between MCLV-2 board and the Simulink model, connect the USB to UART serial converter to the MCLV-2 board.

    To connect this, in the USB to UART module, select the voltage level as 3.3-volts. And then connect the RX pin of the UART module to the TX pin of the MCLV-2 board.

    Also, TX pin of the USB to UART module has to be connected to the RX pin of the MCLV-2 board. Then connect the ground of the MCLV-2 board and the serial model. Then connect the USB to the computer.

    After setting up the hardware, now we will see how to run the real PMSM motor from the MATLAB model Simulink model here.

    First, go to this Microchip tab here and enable this Flash after Build. This will enable the programming of the device after building the model. Also select the programmer connected to the MCLV-2 board, and enable this IPE interface for programming.

    After this, go to the Apps tab and open the Embedded Coder. After this, in order to build, generate, and program the code, click on this Build here. This will start building the model. After building, it will render the code and program into the microcontroller.

    After successful programming of the microcontroller, the summary of the build process is shown in the Diagnostic Viewer here. Also, the generated code will be popped up in the window next to the model here.

    In the MATLAB the over traceability of the code is enabled. That is, the code can be tracked from the model. If I click on this part of the model here, it will open the code of that part.

    Similarly, you can click on the part of the code and it will go to that part of the model here. So in this way, that over tracking of the code is enabled in this.

    One more point to be noted here is, the successful generation of the code will generate the MPLAB project, and that project will be saved in the same folder on which the MATLAB model is present.

    This is the same project as the MATLAB Simulink model, which is converted into the MPLAB project here. This MPLAB project can be opened from the MPLAB X IDE and programmed into the microcontroller.

    Now we will see the motor variables on the MATLAB here. Open this Microchip DSP host model here, and in the serial setup, select the Comport on which the UART module is connected. Run this model to see the waveforms.

    In order to run the motor, press the S2 button on the MCLV-2 board. Once the S2 button is pressed, the motor starts spinning and you can see the motor speed waveforms here.

    The top one is the reference speed set using the potential potentiometer. And the bottom blue waveform is the speed of the motor estimated by the microcontroller.

    In order to increase the speed, increase the potential motor value. Corresponding motor speed increases. And if we decrease the potential motor value, the motor speed decreases. In order to stop the motor, press the S2 button again.

    These are the current waveforms of the motor read by the microcontroller. To see the proper current waveform, we can zoom this part to see the actual phase currents. This is the end of the demo, and thanks for your attention. Now over to you, Brian.

    Thanks for the demo, Hitesh. The models from the demo can be found on MathWorks File Exchange. Go to the File Exchange and search for MPLAB.

    Now for a quick wrap up. We used MathWorks Simulink and Motor Control Blockset for field oriented control of a PMSM motor. We learned about Microchip's MPLAB Device Block for Simulink.

    We saw that this free package is available on MathWorks Add-on Explorer, and provides Simulink library blocks to help program peripherals for Microchip controllers.

    We added these blocks to our FOC model, and then used MathWorks Embedded Coder to generate C-code, which we downloaded and ran directly on a Microchip 16-bit dsPIC digital signal controller. And then we viewed the controller speed command and response.

    It is important to remember that the same workflow you saw for the 16-bit fixed point dsPIC in the demo also works for the 32-bit floating point PIC32 and SAM microcontrollers.

    In conclusion, you can select the Microchip controller that fits your application, and this workflow will help you quickly and easily program it from Simulink. Thank you.

    View more related videos