Skip to content

microchip-pic-avr-solutions/mclv48v300w-33ak512mc510-pmsm-position-control-abs-enc-tamagawa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Microchip Logo.

Position Control FOC for PMSM with Tamagawa Absolute Encoder Protocol: MCLV-48V-300W and dsPIC33AK512MC510 Motor Control DIM

1. INTRODUCTION

This document describes the setup requirements for performing position control of a Permanent Magnet Synchronous Motor (PMSM) with Tamagawa Absolute Encoder Protocol on the hardware platform EV18H47A "MCLV-48V-300W Development Board" and EV67N21A "dsPIC33AK512MC510 Motor Control Dual In-line Module (DIM)".

Refer to the Appendix: Tamagawa Protocol for the protocol description. For more details about Position Control of PMSMs, refer to the product brief document: “Position Control of Permanent Magnet Synchronous Motors” [DS70005608A].

Enhance your embedded applications with Microchip's high-performance dsPIC® Digital Signal Controllers (DSCs). Visit our Motor Control and Drive page to stay updated on the latest motor control solutions from Microchip.

2. SUGGESTED DEMONSTRATION REQUIREMENTS

2.1 Motor Control Application Firmware Required for the Demonstration

To clone or download this application firmware on GitHub,

  • Navigate to the main page of this repository and
  • On the tab <> Code, above the list of files in the right-hand corner, click Code, then from the menu, click Download ZIP or copy the repository URL to clone.

Note:
In this document, hereinafter this firmware package is referred as firmware.

2.2 Software Tools Used for Testing the firmware

  • MPLAB® X IDE v6.25
  • Device Family Pack (DFP): dsPIC33AK-MC_DFP v1.4.172
  • Curiosity/Starter Kits Tool Pack : PKOB4_TP v1.22.1668
  • MPLAB® XC-DSC Compiler v3.30
  • MPLAB® X IDE Plugin: X2C-Scope v1.7.0

Note:
The software used for testing the firmware prior to release is listed above. It is recommended to use these or later versions of the tool for building the firmware. All previous versions of Device Family Packs (DFP) and Tool Packs can be downloaded from Microchip Packs Repository.

2.3 Hardware Tools Required for the Demonstration

Note:
Items (EV18H47A), (EV67N21A) and (AC002013) are available at microchip DIRECT


3. HARDWARE SETUP

This section describes the hardware setup required for the demonstration.

Note:
In this document, hereinafter the MCLV-48V-300W Development Board is referred as development board.

  1. Motor currents are amplified on the MCLV-48V-300W development board; it can also be amplified by the amplifiers internal to the dsPIC33AK512MC510 on the DIM. The firmware and DIM are configured to sample and convert internal amplifier outputs ('internal op-amp configuration') by default to measure the motor currents needed to implement FOC. Table-1 summarizes the resistors to be populated and removed to convert the DIM from ‘internal op-amp configuration’ to ‘external op-amp configuration’ or vice versa.

  2. Insert the dsPIC33AK512MC510 Motor Control DIM into the DIM Interface connector J8 on the development board. Make sure the DIM is placed correctly and oriented before going ahead.

  3. Connect the 3-phase wires from the motor to PHC, PHB, and PHA of the connector J4, provided on the development board as mentioned in the below table.

    Development Board Leadshine 24V Motor
    CABLE-RZD1M5-143 (Color) Power Connector
    PHA Red Pin 1 (U)
    PHB White Pin 2 (V)
    PHC Black Pin 3 (W)

  4. The ELVM6020V24EH-M17-HD Leadshine Servo Motor is equipped with a power-off brake. Connect the brake terminals to a 24 V DC supply to disengage the brake.

  5. Interface the encoder signals from the motor to the XPRO2 (J13) pins on the Development Board through an RS485 transceiver (ADM485), as shown in the table below.

    Development Board to ADM485 Connections

    Development Board ADM485 Pin
    +5V Vcc
    GND GND
    XPRO2 Pin-12 (UART-TX) DI
    XPRO2 Pin-11 (UART-RX) RO
    XPRO2 Pin-5 (Enable) RE DE

    Encoder Signal Connections

    Encoder Connection
    Signal CABLE-BMAD1M5-223 (Color, Pin)
    SD+ Blue (Pin 4) ADM485 Driver Output A
    SD- Blue-Black (Pin 5) ADM485 Driver Output B
    VCC Black (Pin 2) Power Supply 5V
    GND Black-White (Pin 3) Power Supply Ground
    BAT+ Red (Pin 6) External Battery +ve (3.7V)
    BAT- Red-White (Pin 7) External batery -ve

    Note: Battery connection is required only for operating in multi-turn absolute data mode.


  6. Dynamic Brake Circuit - This step is required only if braking functionality is needed. By default, the brake circuit components are not populated on the development board.

    • Populate the following components on the development board: Brake switch Q11 (SUM60020E-GE3), Resistor -R220, Diode- D26, Diode- D27, and the brake resistor terminal connectors (TP42, TP43).
    • Connect an external brake resistor between terminals TP42 and TP43.

    Note: Refer to MCLV-48V-300W Development Board User’s Guide (DS50003297) for brake circuit schematic.

  7. Plug the 24V power supply to connector J1 on the development board. Alternatively, the development board can also be powered through connector J3.

  8. The board has an onboard programmer PICkit™ On Board (PKoBv4) , which can be used for programming or debugging the microcontroller or dsPIC DSC on the DIM. To use the onboard programmer, connect a micro-USB cable between the Host PC and connector J16 on the development board.

    Alternatively, connect the Microchip programmer/debugger MPLAB® PICkit™ 5 In-Circuit Debugger(PG164150) between the Host PC used for programming the device and the ICSP header J9 on the development board (as shown). Ensure that PICkit 5 is oriented correctly before proceeding.


4. SOFTWARE SETUP AND RUN

4.1 Setup: MPLAB X IDE and MPLAB XC-DSC Compiler

Install MPLAB X IDE and MPLAB XC-DSC Compiler versions that support the device dsPIC33AK512MC510 and PKoBv4. The MPLAB X IDE, MPLAB XC-DSC Compiler, and X2C-Scope plug-in used for testing the firmware are mentioned in the Motor Control Application Firmware Required for the Demonstration section.

To get help on

  • MPLAB X IDE installation, refer link
  • MPLAB XC-DSC Compiler installation steps, refer link

If MPLAB IDE v8 or earlier is already installed on your computer, then run the MPLAB driver switcher (Installed when MPLAB®X IDE is installed) to switch from MPLAB IDE v8 drivers to MPLAB X IDE drivers. If you have Windows 8 or 10, you must run the MPLAB driver switcher in Administrator Mode. To run the Device Driver Switcher GUI application as administrator, right-click on the executable (or desktop icon) and select Run as Administrator. For more details, refer to the MPLAB X IDE help topic “Before You Begin: Install the USB Device Drivers (For Hardware Tools): USB Driver Installation for Windows Operating Systems.”

4.2 Setup: X2C-SCOPE

X2C-Scope is a MPLAB X IDE plugin that allows developers to interact with an application while it runs. X2C-Scope enables you to read, write, and plot global variables (for motor control) in real-time. It communicates with the target using the UART. To use X2C-Scope, the plugin must be installed. To set up and use X2C-Scope, refer to the instructions provided on the web page.

5. BASIC DEMONSTRATION

5.1 Firmware Description

The firmware version needed for the demonstration is mentioned in the section Motor Control Application Firmware Required for the Demonstration section. This firmware is implemented to work on Microchip’s Digital signal controller (dsPIC® DSC) dsPIC33AK512MC510. For more information, see the dsPIC33AK512MPS512 Family datasheet (DS70005591).

The Motor Control Demo application uses a push button to start or stop the motor and a potentiometer to vary the position of the motor. This Motor Control Demo Application configures and uses peripherals like PWM, ADC, UART, OP-AMP, DMA, CMP, DAC etc. For more details, refer to the Microchip product brief document "Position Control of Permanent Magnet Synchronous Motors [DS70005608A]".

Note:
The project may not build correctly in Windows OS if the Maximum path length of any source file in the project is more than 260 characters. In case the absolute path exceeds or nears the maximum length, do any (or both) of the following:

  • Shorten the directory name containing the firmware used in this demonstration. If you renamed the directory, consider the new name while reading the instructions provided in the upcoming sections of the document.
  • Place firmware in a location such that the total path length of each file included in the projects does not exceed the Maximum Path length specified.
    Refer to MPLAB X IDE help topic “Path, File, and Folder Name Restrictions” for details.

5.2 Basic Demonstration

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

  1. Start MPLAB X IDE and open the project pmsm.X (File > Open Project) with device selection dsPIC33AK512MC510.

  2. Set the project pmsm.X as the main project by right-clicking on the project name and selecting Set as Main Project as shown. The project pmsm.X will then appear in bold.

  3. Open mc1_user_params.h (pmsm.X > Header Files) in the project pmsm.X.

    • Firmware is configured to run with Leadshine Servo Motor (ELVM6020V24EH-M17-HD) by default.

    • Ensure that the macro INTERNAL_OPAMP_CONFIG is defined to utilize internal amplifiers for current amplification.

    • Ensure that the macro CONTROL_MODE is set to 1 for position control mode.

    • The macro ENCODER_OPERATION_MODE selects the encoder operation mode:

      • 1 = Single-Turn Absolute mode: Single-turn absolute position measurement (default operation).
      • 2 = Multi-turn mode: Multi-turn position measurement (requires battery connection). On first use after connecting the battery, a Reset Error operation (ENCODER_OPERATION_MODE = 3) must be performed to clear the Battery Error flag.
      • 3 = Reset all error operation: Clears all the encoder error flags.

    • The macro POSITION_COMMAND_MODE selects the position input mode: set to 1(default) for repeat mode where the target toggles between START_POSITION and END_POSITION, or set to 0 for continuous tracking via potentiometer.

    • The macro MOTION_PROFILE defines the motion trajectory shape: Set to 1 for a flat profile (step response, typically used for PID tuning), 2 for a Ramp (first-order motion profile), 3 for a Trapezoidal (second-order motion profile), or 4 (default) for an S-Curve (third-order, jerk-limited motion profile).

  4. Open braking.h (pmsm.X > Header Files > motion_control) in the project pmsm.X.

    • Define ENABLE_DYNAMIC_BRAKING to enable brake PWM control when the DC link voltage exceeds the specified limit. Undefine ENABLE_DYNAMIC_BRAKING to disable brake PWM functionality.

    Note: The brake circuit in MCLV-48V-300W Development Board is not populated by default. Refer to Point 6 in the Hardware Setup section for details on the required hardware configuration.

Note: Feedforward control can be optionally enabled by defining the macros SPEED_LOOP_FEEDFORWARD in CURRENT_LOOP_FEEDFORWARD in foc.c (pmsm.X > Source Files > foc) to improve speed-loop and current-loop tracking performance.

  1. Right-click on the project pmsm.X and select Properties to open its Project Properties Dialog. Click the Conf:[default] category to reveal the general project configuration information. The development tools used for testing the firmware are listed in section 2.2 Software Tools Used for Testing the firmware.

    In the Conf:[default] category window:

    • Ensure the selected Device is dsPIC33AK512MC510.
    • Select the Connected Hardware Tool to be used for programming and debugging.
    • Select the specific Device Family Pack (DFP) from the available list of Packs. In this case, dsPIC33AK-MC_DFP v1.4.172 is selected.
    • Select the specific Compiler Toolchain from the available list of XC-DSC compilers. In this case, XC-DSC(v3.30) is selected.
    • After selecting Hardware Tool and Compiler Toolchain, Device Pack, click the button Apply

    Please ensure that the selected MPLAB® XC-DSC Compiler and Device Pack support the device configured in the firmware

  2. Ensure that the checkbox Load symbols when programming or building for production (slows process) is checked under the Loading category of the Project Properties window.

    Also, go to Tools > Options , and

    Open the Embedded > Generic Settings tab and ensure that the ELF debug session symbol load methodology (MIPS/ARM) is selected as Pre-procesed (Legacy) from the drop down.

  3. To build the project (in this case, pmsm.X) and program the device dsPIC33AK512MC510, click Make and Program Device Main project on the toolbar

  4. If the device is successfully programmed, LED1 (LD2) will be blinking, indicating that the dsPIC® DSC is enabled.

  5. Run or stop the motor by pressing the push button SW1.. The LED LED2(LD3) is turned ON to show the button is pressed to start the motor.

  6. Press the push button SW2 to toggle the position command mode:

    • In Tracking Mode (POSITION_COMMAND_MODE = 0), the motor position follows the potentiometer (POT1) input.

    • In Repeat Mode (POSITION_COMMAND_MODE = 1), the motor alternates between the predefined positions START_POSITION and END_POSITION using the selected motion profile.

  7. Press the push button SW1 to stop the motor.

5.3 Data visualization through X2C-Scope Plug-in of MPLAB X

X2C-Scope is a third-party plug-in in MPLAB X, which helps in real-time diagnostics. The application firmware comes with the initialization needed to interface the controller with the host PC to enable data visualization through the X2C-Scope plug-in. Ensure the X2C-Scope plug-in is installed. For more information on how to set up a plug-in, refer to either the Microchip Developer Help page or the web page.

  1. To establish serial communication with the host PC, connect a micro-USB cable between the host PC and connector J16 on the development board. This interface is also used for programming.

  2. Ensure the application is configured and running as described under section 5.2 Basic Demonstration by following steps 1 through 10.

  3. Open the X2C-Scope window by selecting Tools>Embedded>X2CScope.

  4. In the X2C-Scope Configuration window, open the Connection Setup tab and click Select Project. This opens the drop-down menu Select Project with a list of opened projects. Select the specific project pmsm from the list of projects and click OK.

  5. To configure and establish the serial communication for X2C-Scope, open the X2CScope Configuration window, click on the Connection Setup tab and:

    • Set Baudrate as 115200, which is configured in the application firmware.
    • Click on the Refresh button to refresh and update the list of the available Serial COM ports connected to the Host PC.
    • Select the specific Serial port detected when interfaced with the development board. The Serial port depends on the system settings

  6. Once the Serial port is detected, click on Disconnected and turn to Connected, to establish serial communication between the Host PC and the board.

  7. Open the Project Setup tab in the X2CScope Configuration window and,

    • Set Scope Sampletime as the interval at which X2CScopeUpdate() is called. In this application, it is every 62µs.
    • Then, click Set Values to save the configuration.

  8. Click on Open Scope View (in the Data Views tab of the X2CScope Configuration Window); this opens Scope Window.

  9. In the Scope Window, select the variables that must be watched. To do this, click on the Source against each channel, and a window Select Variables opens on the screen. From the available list, the required variable can be chosen. Ensure checkboxes Enable and Visible are checked for the variables to be plotted. To view data plots continuously, uncheck Single-shot. When Single-shot is checked, it captures the data once and stops. The Sample time factor value multiplied by Sample time decides the time difference between any two consecutive data points on the plot.

  10. Click on SAMPLE, then the X2C-Scope window plots variables in real-time, which updates automatically.

  11. Click on ABORT to stop.

Appendix:

Tamagawa Protocol

Tamagawa(T-Format) Protocol is a serial communication protocol from Tamagawa Seiki Co. based on the RS485 physical layer, for transferring digital data between encoders and controllers. T-Format enables reliable transmission of absolute position values, diagnostic information, and supports both reading and writing of the encoder’s internal memory.

Encoder Specifications:

The general encoder specifications are summarized in the table below:

Communication Types

The T-Format protocol defines multiple communication transaction types:

Frame Format

A typical communication frame in T-Format consists of structured fields, each transmitted as 10-bit packets (1 start bit + 8 data bits + 1 delimiter bit).

The bit structure of each fields are defined below.

Field Definitions

1. Control Field:

Carries the Data ID information

2. Status Field

Carries the diagnostic information

Encoder error

Communication alarm

3. Data Field

  • ABS0 - ABS2: Absolute data in one revolution
  • ABM0 - ABM2: Multi turn data
  • ENID : Encoder ID
  • ALMC : Encoder error and alarm data. ALMC bit structure:

The structure of each data field is shown below:

4. CRC Field:

Ensures data integrity using a cyclic redundancy check (CRC).

EEPROM Access

The protocol provides access to the encoder’s EEPROM for both read and write operations.

Writing to EEPROM

  • ADF (Address Field) : Address of EEPROM with LSB first

  • EDF (EEPROM Field) : 8-bit data with LSB first

Readout from EEPROM

Note: The completion of writing data to EEPROM is at 18ms max after receiving its request.

Hardware Interface

The communication physical layer is implemented using RS485 differential signaling, as illustrated in the figure below.

Implementation with dsPIC Device

Implementation of the T-Format protocol on dsPIC33A Digital Signal Controllers (DSCs) leverages the on-chip UART for serial communication, DMA for data handling, and CCP module for accurate timing control. The timing diagram of the implementation is shown below.

6. REFERENCES:

For additional information, refer following documents or links.

  1. Position Control of Permanent Magnet Synchronous Motors (DS70005608A)
  2. MCLV-48V-300W Development Board User’s Guide (DS50003297)
  3. dsPIC33AK512MC510 Motor Control Dual In-Line Module (DIM) Information Sheet (DS70005553)
  4. dsPIC33AK512MPS512 Family datasheet (DS70005591)
  5. MPLAB® X IDE User’s Guide (DS50002027) or MPLAB® X IDE help
  6. MPLAB® X IDE installation
  7. MPLAB® XC-DSC Compiler installation
  8. Installation and setup of X2Cscope plugin for MPLAB X
  9. Microchip Packs Repository
  10. Programming and Debugging the dsPIC33A on MPLAB X IDE v6.20 and IPE v6.20

About

Position Control FOC for PMSM with Tamagawa Absolute Encoder : MCLV-48V-300W and dsPIC33AK512MC510 Motor Control DIM

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •