Regenerative Braking Example On MCLV-2 and dsPIC33CK256MP508

This is a Simulink Models to Demonstrate Regenerative Braking Using Microchip's MCLV-2 Board and dsPIC33CK256MP508 External Op-Amp PIM
54 Downloads
Updated 3 Oct 2022

image

MATLAB MCLV-2 dsPIC33CK256MP508 REGENERATIVE BRAKING

1. INTRODUCTION

This document describes the setup requirements for running the Regenerative Braking algorithm, using MATLAB Simulink, MCLV-2 Development Board and dsPIC33CK256MP508 External Op-Amp Motor Control Plug-In Module (PIM).

2. SUGGESTED DEMONSTRATION REQUIREMENTS

2.1 MATLAB Model Required for the Demonstration

  • MATLAB model can be cloned or downloaded as zip file from the Github repository (link).

2.2 Software Tools Used for Testing the MATLAB/Simulink Model

  1. MPLAB X IDE and IPE (v6.0)
  2. XC16 compiler (v2.00)
  3. MATLAB R2022a
  4. Required MATLAB add-on packages
    • Simulink
    • Simulink Coder
    • Stateflow
    • MATLAB Coder
    • Embedded Coder (v7.8)
    • MPLAB Device blocks for Simulink (v3.50.27)
    • Motor Control Blockset (v1.4)

NOTE: The software used for testing the model during release is listed above. It is recommended to use the version listed above, or later versions, for building the model.

2.3 Hardware Tools Required for the Demonstration

Hardware Tool Part Number Quantity
dsPICDEM™ MCLV-2 Development Board DM330021-2 2
dsPIC33CK256MP508 External Op-Amp Motor Control Plug-In Module MA330041-1 2
Benchtop power supply (compatible 24V, 5A) - 1
24V 3-Phase Brushless DC Motor with Encoder AC300022 2
USB to RS-232 cable - 2

NOTE:

The two motors shafts are coupled together. The fixture of both motors coupled together is not sold by Microchip Technology. The fixture was created only for this demonstration purpose. Any standard motor shaft coupler can be used with 8mm diameter on both the sides.

3. HARDWARE SETUP

This section describes the hardware setup needed for the demonstration. In this demonstration two MCV-2 boards are used to control the motor and the generator. The MCLV-2 board connected to the motor is referred as ‘the motor side MCLV-2 board’ and the MCLV-2 board connected to the generator is referred as ‘the generator side MCLV-2 board’

  1. Disconnect power to the MCLV-2 Boards and set up the following jumpers:

  2. On both the boards, insert the ‘External Op Amp Configuration Matrix board’ into matrix board header J14. Ensure the matrix board is correctly oriented before proceeding.

  3. Insert the dsPIC33CK256MP508 External Op-Amp Motor Control PIM into the PIM Socket U9 provided on the MCLV-2 Boards. Make sure the PIM is correctly placed and oriented before proceeding.

  4. Connect the three phase wires from the motor to M1, M2, and M3 terminals of connector J7, on ‘the motor side MCLV-2 Board’ in the sequence as shown below.

  5. Connect the three phase wires from the generator to M1, M2, and M3 terminals of connector J7, on the ‘generator side MCLV-2 Board’. Please note that for sequence of 3 phase wires and the encoder wires sequence must be as shown below.

  6. Set 24V on the benchtop power supply and connect it to the connectors BP1 and BP2 provided on both the MCLV-2 Boards (The single power supply is used for both the MCLV-2 boards). Couple the motors shafts using a coupler and connected to MCLV-2 boards. Make sure the setup is as shown below.

  7. The Microchip MPLAB PICkit 4 In-Circuit Debugger needs to connected to the Connector J12 of the MCLV-2 Board, as shown below. Also connect to the Host PC used for programming the device.. Ensure the arrows indicated on the board and PICkit 4 orient as shown in the picture.

NOTE: It is recommended to use a right-angled pin header to use J12 for programming. A straight header mounted with PICkit 4 may result in mechanical stresses on the programmer con-nector or the development board in use.

Alternatively, the programmer/debugger can be connected to J11 using a RJ-11 to ICSP adapter (AC164110).

4. BASIC DEMONSTRATION

Follow the below instructions step-by-step, to set up and run the motor control demo application:

  1. Launch MATLAB (refer the section “2.2 Sofware Tools Used for Testing the MATLAB/Simulink Model").

  2. Open the folder dowmloaded from the repository, in which MATLAB files are saved (refer the section "2.1 MATLAB Model Required for the Demonstration").

    In this folder there will be five files used for the demonstration,

    File Name Description
    dsPIC33CK256MP508_MCLV2_Generator_data.m Data file for generator side Simulink model
    dsPIC33CK256MP508_MCLV2_QEI_Generator.slx Simulink model for ‘the generator side MCLV-2 board’ using optical encoder
    dsPIC33CK256MP508_MCLV2_SMO_data.m Data file for motor side Simulink model
    dsPIC33CK256MP508_MCLV2_SMO_Motor.slx Simulink model for ‘the motor side MCLV-2 board’ using Sliding motor observer
    mcb_host_common.slx Simulink model to monitor real time parameters from the hardware
  3. Connect the PICkit 4 In-Circuit Debugger to the Connector J12 of ‘motor side MCLV-2 Board’, as mentioned in the step 7 of the "3.3 Hardware Setup" section and turn on the power supply.

  4. Double click and open the dsPIC33CK256MP508_MCLV2_SMO_data.m file. This file contains the configuration parameter for the motor and board. By default, the file is configured to run Hurst 300 motor and MCLV-2 board. Run the file by clicking the “Run” icon and wait till all variables get loaded on the ‘Workspace’ tab.

  5. Double click on dsPIC33CK256MP508_MCLV2_SMO_Motor.slx Simulink model.

  6. This opens the Simulink model, as shown below.

  7. From this Simulink model an MPLAB X project is generated, and it can be used to run the motor using MCLV-2 board. To generate the code from the Simulink model, go to the “MICROCHIP” tab, and enable the tabs shown in the figure below.

  8. To generate the code and program the dsPIC33CK256MP508 device, click on ‘Build Model’ or ‘Clean Build Model’ option under the “Microchip” tab. This will generate the MPLAB X project from the Simulink model.

  9. After completing the process, the ‘Operation Succeeded’ message will be displayed on the ‘Diagnostics Viewer’.

  10. If the device is successfully programmed, LED- LD10 and LD11 will be blinking.

  11. Now connect the PICkit 4 In-Circuit Debugger to the Connector J12 of generator side MCLV-2 Development Board.

  12. To program the generator side dsPIC33CK256MP508 device repeat the step 4 to 10, using the dsPIC33CK256MP508_MCLV2_Generator_data.m and dsPIC33CK256MP508_MCLV2_QEI_Generator.slx files.

  13. To run the setup, press the push button S2of the motor side MCLV-2 board first and then the generator side MCLV-2 board.

  14. The motor speed can be varied using the potentiometer (labeled “POT1”) of the motor side MCLV-2 board. The regenerative torque can be varied using the potentiometer (labeled “POT1”) of the generator side MCLV-2 board.

  15. Press the push button S2 of the motor side and generator side MCLV-2 to stop the operation.

5. DATA MONITORING USING MOTOR CONTROL BLOCKSET (MCB) HOST MODEL

The regenerative braking simulink models comes with the initialization required for data monitoring using Motor Control Blockset Host Model (MCB Host Model). The MCB Host Model is a Simulink model which facilitates data monitoring through the UART Serial Interface.

  1. To establish serial communication with the host PC, connect a USB to RS-232 cable between the host PC and the MCLV-2 Board (J10 connector) of both motor and generator side.

  2. Ensure the sensorless FOC model is programmed and running as described under section "4. Basic Demonstration" by following steps 1 through 14.

  3. Open the MCB Host model (mcb_host_common.slx)

  4. Double click on the the “Motor_Rx” block. Then select the appropriate COM port which is connected to the motor side MCLV-2 board from the drop-down menu and set the baud rate as 115207. Please note that the same baud rate has been set in the motor side Simulink model (the baud rate can be viewed on the “UART Configuration block” in the “Hardware Init” subsystem).

  5. Open the “Motor_Rx” subsystem to configure the COM port. This can be done by configuring the “Host Serial Receive” block of the “Motor_Rx” subsystem. Ensure to select the same COM port configured in step 4.

  6. Similarly, double click on the “Generator Serial Setup” block. Then select the appropriate COM port which is connected to the genrator side MCLV-2 board from the drop-down menu and set the baud rate as 115207. Please note that the same baud rate has been set in the generator side Simulink model (the baud rate can be viewed on the “UART Configuration block” in the “Hardware Init” subsystem).

  7. Open the “Generator_Rx” subsystem to configure the COM port. This can be done by configuring the “Host Serial Receive” block of the “Generator_Rx” subsystem. Ensure to se-lect the same COM port configured in step 6.

  8. Click the run icon of the MCB Host model to open the scope window and monitor the signals.

  9. Figure below shows an example of monitored signals using the MCB Host Model.

REFERENCES:

For more information, refer to the following documents or links.

  1. AN1078 Application Note “Sensorless Field Oriented Control of a PMSM”.
  2. dsPICDEM™ MCLV-2 Development Board User’s Guide (DS52080A)
  3. dsPIC33CK256MP508 Motor Control Plug-In Module (PIM) Information Sheet for External Op Amp Configuration (DS50002757A)
  4. MPLAB® X IDE installation
  5. MPLAB® XC16 Compiler installation
  6. Motor Control Blockset
  7. MPLAB Device Blocks for Simulink :dsPIC, PIC32 and SAM mcu

Cite As

Microchip Support Team (2024). Regenerative Braking Example On MCLV-2 and dsPIC33CK256MP508 (https://github.com/microchip-pic-avr-solutions/matlab-mclv2-dspic33ck256mp508-regenerativebraking/releases/tag/1.0.0), GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2022a
Compatible with R2022a and later releases
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

matlab-mclv2-dspic33ck256mp508-regenerativebraking

Version Published Release Notes
1.0.0

To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.