APPLICATION NOTE
R01AN4721EJ0100 Rev.1.00 Page 1 of 37
Mar 29. 2019
RX72T
Vector Control for Permanent Magnet Synchronous Motor with Encoder
(Implementation)
Abstract
This application note aims to explain the sample programs for a permanent magnet synchronous motor with encoder, by
using functions of RX72T. The explanation includes, how to use the library of ‘Renesas Motor Workbench’ tool, that is
support tool for motor control development.
The target software of this application note is only to be used as reference and Renesas Electronics Corporation does not
guarantee the operations. Please use them after carrying out a thorough evaluation in a suitable environment.
Operation Checking Device
Operations of the target software of this application note are checked by using the following device.
- RX72T (R5F572TKCDFB)
Target Software
The target programs of this application note are as follows.
- RX72T_MRSSK_SPM_ENCD_FOC_CSP_RV100 (IDE: CS+)
- RX72T_MRSSK_SPM_ENCD_FOC_E2S_RV100 (IDE: e2studio)
Vector control with encoder software for ‘24V Motor Control Evaluation System for RX23T’ and ‘RX72T CPU Card’
Reference
- RX72T Group User’s Manual: Hardware (R01UH0803)
- Application note: ‘Vector control for permanent magnet synchronous motor with encoder (Algorithm)’
(R01AN3789)
- Renesas Motor Workbench V.1.00 User’s Manual (R21UZ0004)
- Renesas Solution Starter Kit 24V Motor Control Evaluation System for RX23T User’s Manual (R20UT3697)
R01AN4721EJ0100
Rev.1.00
Mar 29. 2019
RX72T Vector Control for Permanent Magnet Synchronous Motor with Encoder (Implementation)
R01AN4721EJ0100 Rev.1.00 Page 2 of 37
Mar 29. 2019
Contents
1. Overview .......................................................................................................................................... 3
2. System overview ............................................................................................................................. 4
3. Descriptions of the Control Program .......................................................................................... 10
4. Motor Control Development Support Tool ‘Renesas Motor Workbench’ ................................ 29
RX72T Vector Control for Permanent Magnet Synchronous Motor with Encoder (Implementation)
R01AN4721EJ0100 Rev.1.00 Page 3 of 37
Mar 29. 2019
1. Overview
This application note aims to explain the sample programs for a permanent magnet synchronous motor with encoder, by
using functions of RX72T. The explanation includes, how to use the library of ‘Renesas Motor Workbench’ tool, that is
support tool for motor control development.
Note that these sample programs use the algorithm described in the application note ‘Vector control for permanent
magnet synchronous motor with encoder (Algorithm)’.
1.1 Development environment
Table 1-1 and Table 1-2 show development environment of the sample programs explained in this application note.
Table 1-1 Hardware Development Environment
24V inverter board & RX72T CPU Card
(Note 1)
Table 1-2 Software Development Environment
For purchase and technical support, contact sales representatives and dealers of Renesas Electronics Corporation.
Notes:1. 24V inverter board & RX72T CPU Card are product of Renesas Electronics Corporation.
2. FH6S20E-X81 is a product of NIDEC SERVO CORPORATION.
NIDEC SERVO (http://www.nidec-servo.com/)
RX72T Vector Control for Permanent Magnet Synchronous Motor with Encoder (Implementation)
R01AN4721EJ0100 Rev.1.00 Page 4 of 37
Mar 29. 2019
2. System overview
Overview of this system is explained below.
2.1 Hardware configuration
The hardware configuration is shown below.
A/D converter input
Bus voltage
Rotation speed command
PWM output
Over current detection
Power supply circuit
Switch input
Motor rotation start/stop
Error reset
LED output
Over current detection input
Inverter circuit
Phase current
detection
Phase
current
Encoder input
RX72T
V
dc
GND
Input DC24V
VR1
SW1
SW2
LED1 LED2
U
p
V
p
W
p
V
n
U
n
W
n
OC
V
u
V
vVw
I
u
I
w
P35
PA0
P63 / AN209
P43 / AN003
PC5
PC6
P71 / MTIOC3B / GTIOC4A(Up)
P72 / MTIOC4A / GTIOC5A(Vp)
P73 / MTIOC4B / GTIOC6A(Wp)
P74 / MTIOC3D / GTIOC4B(Un)
P75 / MTIOC4C / GTIOC5B(Vn)
P76 / MTIOC4D / GTIOC6B(Wn)
P70 / POE0#
PMSM
P40 / AN000
IU_AIN
I
v
P42 / AN002
IW_AIN
LED3
P34
PA7 / MTCLKA
PA6 / MTCLKB
Hall Input
P23 / IRQ11
P24 / IRQ4
P25 / IRQ10
U port
W port
V port
HU port
HW port
HV port
GND port
V
cc
port
ENC_Z port
ENC_A port
ENC_B port
GND port
V
cc
port
Figure 2-1 Hardware Configuration Diagram
RX72T Vector Control for Permanent Magnet Synchronous Motor with Encoder (Implementation)
R01AN4721EJ0100 Rev.1.00 Page 5 of 37
Mar 29. 2019
2.2 Hardware specifications
2.2.1 User interfaces
List of user interfaces of this system is given in Table 2-1.
Table 2-1 User Interfaces
Rotation position /
speed
Reference value of rotation position / speed input
(analog value)
Motor rotation start/stop command
Command of recovery from error status
- At the time of motor rotation: ON
- At the time of stop: OFF
- At the time of error detection: ON
- At the time of normal operation: OFF
- Complete of positioning: ON
- Uncomplete of positioning: OFF
RESET
List of port interfaces of this system is given in Table 2-2.
Table 2-2 Port Interfaces
Inverter bus voltage measurement
For position / speed command value input (analog value)
ERROR RESET toggle switch
U phase current measurement
W phase current measurement
Hall Phase-U signal input
Hall Phase-V signal input
Hall Phase-W signal input
Encoder Phase-A signal input
Encoder Phase-B signal input
PWM emergency stop input at the time of over-current detection
RX72T Vector Control for Permanent Magnet Synchronous Motor with Encoder (Implementation)
R01AN4721EJ0100 Rev.1.00 Page 6 of 37
Mar 29. 2019
2.2.2 Peripheral functions
List of the peripheral functions used in this system is given in Table 2-3.
Table 2-3 List of the Peripheral Functions
- Rotation speed command value
input
- Current of each phase U and W
measurement
- Inverter bus voltage measurement
- Complementary PWM output
- Encoder phase counter
- Encoder count capture
Set PWM output ports to high
impedance state to stop the PWM
output.
(1) 12-bit A/D converter (S12ADH)
U phase current (Iu), W phase current (Iw), inverter bus voltage (Vdc) and rotation speed reference are measured by
using the single scan mode (use hardware trigger). The sample-and-hold function is used for U phase current (Iu) and W
phase current (Iw) measurement.
(2) Compare match timer (CMT)
The channel 0 of the compare match timer is used as 500 [µs] interval timer.
(3) Multi-function timer pulse unit 3 (MTU3d)
The operation mode varies depending on channels. On the channels 3 and 4, output (active level: high) with dead time
is performed by using the complementary PWM mode.
The channel 1 of MTU3 operate in phase counting mode, the counter is incremented or decremented according to the
phase difference between Phase-A and Phase-B signals from the encoder.
(4) General PWM Timer (GPTW)
The operation mode varies depending on channels. On the channels 4, 5 and 6, output (active level: high) with dead
time is performed by using the PWM Output Operating mode.
The channel 3 operate in phase counting mode, the counter is incremented or decremented according to the phase
difference between Phase-A and Phase-B signals from the encoder.
The channel 9 is used as free-run timer for speed measurement.
(5) Port output enable 3 (POE3B)
PWM output ports are set to high impedance state when an overcurrent is detected (when a falling edge of the POE0#
port is detected) and when an output short circuit is detected.
The setting of the PWM output timer is selected by the following macro definition.
Table 2-4 List of Macro Definitions ‘r_mtr_ctrl_rx72t.h’
RX72T Vector Control for Permanent Magnet Synchronous Motor with Encoder (Implementation)
R01AN4721EJ0100 Rev.1.00 Page 7 of 37
Mar 29. 2019
2.3 Software configuration
2.3.1 Software file configuration
Folder and file configuration of the sample programs are given below.
Figure 2-2 Folder and file configuration
main.h, main.c: main function
r_mtr_ics.h, r_mtr_ics.c: Function definition of Analyzer
note1
UI
r_mtr_board.h, r_mtr_board.c: Function definition of board UI
ICS2_RX72T.lib: Tool communication library
ICS2_RX72T.h: Function definition of tool communication
r_mtr_driver_access.h, r_mtr_driver_access.c: Function definition of user access
r_mtr_common.h: Common definition
r_mtr_filter.h, r_mtr_filter.c: Function definition of general purpose filter
r_mtr_fluxwkn.h, r_mtr_fluxwkn.objc : Function definition for flux weakening control
r_mtr_pi_control.h, r_mtr_pi_control.c: Function definition of PI controller
r_mtr_transform.h, r_mtr_transform.c: Function definition of coordinate transformation
r_mtr_volt_err_comp.h, r_mtr_volt_err_comp.obj: Function definition of voltage error
compensation
r_mtr_mod.h, r_mtr_mod.c: Function definition of modulation
r_mtr_statemachine.h, r_mtr_statemachine.c: Function definition of state machine
r_mtr_parameter.h: Function definition of various parameter
r_mtr_ctrl_gain_calc.obj: Function definition of control gain calculation
r_mtr_foc_action.c: Function definition of event action
r_mtr_interrupt_carrier.c: Function definition of carrier interrupt
r_mtr_interrupt_timer.c: Function definition of periodic interrupt
r_mtr_interrupt_sensor.c: Function definition of sensor signal interrupt
r_mtr_foc_control_encd_position.h, r_mtr_foc_control_encd_position.c
: Function definition of FOC control
r_mtr_foc_current.h, r_mtr_foc_current.c: Function definition of current control
r_mtr_foc_speed.h, r_mtr_foc_speed.c: Function definition of speed control
r_mtr_foc_position.h, r_mtr_foc_position.c: Function definition of position control
r_mtr_position_profiling.h, r_mtr_position_profiling.c
:
Function definition of position profiling
r_mtr_speed_observer.h, r_mtr_speed_observer.obj:
Function definition of speed observer
r_mtr_ipd.h, r_mtr_ipd.obj: Function definition of IPD controller
r_mtr_ctrl_mrssk.h, r_mtr_ctrl_mrssk.c: Function definition depends on inverter board
r_mtr_ctrl_encoder.h, r_mtr_ctrl_encoder.c: Function definition of encoder
r_mtr_ctrl_hall.h, r_mtr_ctrl_hall.c: Function definition of hall
Notes: 1. Regarding the specification of Analyzer function in the motor control development support tool
‘Renesas Motor Workbench’, please refer to the chapter 4. The identifier ‘ics/ICS’(ICS is
previous motor control development support tool ‘In Circuit Scope’) is attached to the name of
folders, files, functions, variables related to ‘Renesas Motor Workbench’.
r_mtr_config.h: Common definition for software configuration
r_mtr_motor_parameter.h: Configuration definition for motor parameters
r_mtr_inverter_parameter.h: Configuration definition for inverter parameters
r_mtr_control_parameter.h: Configuration definition for control parameters
r_mtr_encoder_parameter.h: Configuration definition for encoder parameters
r_mtr_interrupt.c: Interrupt function definition
r_mtr_ctrl_rx72t.h, mtr_ctrl_rx72t.c: Function definition depends on MCU
r_mtr_ctrl_mcu.h: Common definition depends on MCU
auto_generation: Folder for auto generation files
RX72T Vector Control for Permanent Magnet Synchronous Motor with Encoder (Implementation)
R01AN4721EJ0100 Rev.1.00 Page 8 of 37
Mar 29. 2019
2.3.2 Module configuration
Module configuration of the sample programs is described below.
Figure 2-3 Module Configuration
Application Layer (User Application)
Middle Layer (Motor Control Process)
Control Module (FOC, Feedback Loop Control)
r_mtr_interrupt_carrier.c
r_mtr_foc_control_encd_position.c
Device Layer (MCU Register Access, Inverter Driver, Sensor Driver)
Set User Command to Buffer
Set Control Gain & Command
Get Voltage, Current & Angle/Speed
Interrupt Process Modules
Get A/D Converter Data & Sensor Signal
RX72T Vector Control for Permanent Magnet Synchronous Motor with Encoder (Implementation)
R01AN4721EJ0100 Rev.1.00 Page 9 of 37
Mar 29. 2019
2.4 Software specifications
Table 2-5 shows basic software specification of this system. For details of the vector control, refer to the application
note ‘Vector control of permanent magnet synchronous motor with encoder: algorithm’.
Table 2-5 Basic Specifications of Vector Control PMSM with Encoder Software
Determined depending on the level of SW1 (“Low”: control start “High”: stop) or input
from Analyzer
Position detection of rotor
magnetic pole
Incremental encoder (A-B Phase), Hall sensor (UVW Phase)
Input voltage
20 [kHz] (carrier cycle: 50[µs])
Control cycle
(Current loop)
Control cycle
(Speed and Position loop)
Management of position
command value
Position command generation: Direct input of VR1
(input range)
-180°~180°
Position command generation: Position profile of
trapezoidal curve for speed command value
(input range)
- 32768°~32767°
(Max speed)
CW / CCW: 2000[rpm]
Management of speed
command value
CW: 0 [rpm] to 2000rpm]
CCW: 0 [rpm] to 2000rpm]
0.3° (Encoder pulse: 300[ppr] 4 for multiplying 1200[cpr])
Dead band of position
(Note)
Encoder count ±1 [cpr] (±0.3°)
Natural frequency of each
control system
Current control system:300Hz
Speed control system:30Hz
Position control system:10Hz
Optimization setting for
compiler
2 (-optimize=2) (default)
Processing stop for protection
Motor control signal outputs (six outputs) will be disabled, under any of the following
conditions.
1. Current of each phase exceeds 3.28 [A] (monitored every 50 [μs])
2. Inverter bus voltage exceeds 28 [V] (monitored every 50 [μs])
3. Inverter bus voltage is less than 14 [V] (monitored every 50 [μs])
4. Rotation speed exceeds 3000 [rpm] (monitored every 50 [μs])
When an external over current signal is detected (when a falling edge of the POE0# port
is detected) and when the output short circuit is detected, the PWM output ports are set
to high impedance state.
Note: Dead zone is provided to prevent hunting in positioning.
RX72T Vector Control for Permanent Magnet Synchronous Motor with Encoder (Implementation)
R01AN4721EJ0100 Rev.1.00 Page 10 of 37
Mar 29. 2019
3. Descriptions of the Control Program
The target sample programs of this application note are explained here.
3.1 Contents of Control
3.1.1 Motor Start/Stop
The start and stop of the motor are controlled by input from Analyzer function of ‘Renesas Motor Workbench’ or SW1
switch of RSSK board.
A general-purpose port is assigned to SW1. The port is read within the main loop. When the port is at a ‘Low’ level, the
software determines that the motor should be started. Conversely, when the level is switched to ‘High’, the program
determines that the motor should be stopped.
3.1.2 A/D Converter
(1) Motor Rotation Position and Speed Command Value
The motor rotation position and speed command value can be set by Analyzer input or A/D conversion of the VR1
output value (analog value). The A/D converted VR1 value is used as rotation speed command value, as shown below.
Table 3-1 Conversion Ratio of the Rotation Position and Speed Command Value
Conversion ratio
(Command value: A/D conversion value)
Rotation position
command value
Rotation speed
command value
0 [rpm]~2000[rpm]:0800H~0FFFH
0 [rpm]~2000[rpm]:07FFH~0000H
(2) Inverter Bus Voltage
Inverter bus voltage is measured as given in エラー! 参照元が見つかりません。.
It is used for modulation factor calculation, under-voltage detection and over-voltage detection. (When an abnormality
is detected, PWM is stopped.)
Table 3-2 Inverter Bus Voltage Conversion Ratio
Conversion ratio
(Inverter bus voltage: A/D conversion value)
0 [V] to 111 [V]: 0000H to 0FFFH
(3) U, W Phase Current
The U and W phase currents are measured as shown in エラー! 参照元が見つかりません。 and used for vector
control.
Table 3-3 Conversion Ratio of U and W Phase Current
Conversion ratio
(U, W phase current: A/D conversion value)
-10 [A] to 10 [A]: 0000H to 0FFFH
(Note 1)
Notes:1 For more details of A/D conversion characteristics, refer to RX72T Group User’s Manual: Hardware.
.
RX72T Vector Control for Permanent Magnet Synchronous Motor with Encoder (Implementation)
R01AN4721EJ0100 Rev.1.00 Page 11 of 37
Mar 29. 2019
3.1.3 Position Profile Generation
(Position Profile of Trapezoidal Curve for Speed Command Value)
In vector control software for PMSM with encoder, the position profile generation is used to create command value
(input position value). The implementation of command value is each control cycle is used as method of managing
acceleration and the maximum speed value with respect to target position value.
Figure 3-1 Position Profile Generation
Enter the following variables from the Analyzer to create a command value.
‐Position reference [degree] (com_s2_ref_position_deg)
‐Acceleration time (com_f4_accel_time)
‐Maximum speed command value (com_f4_accel_max_ref_speed_rad)
‐Position stabilization wait time (com_u2_ref_pos_interval_time)
com_u2_ref_pos_interval_time
MTR_CTRL_TRIANGLE :f4_accel_max_ref_speed_rad * f4_accel_time >= f4_dt_pos_rad
MTR_CTRL_TRAPEZOIDAL :f4_accel_max_ref_speed_rad * f4_accel_time < f4_dt_pos_rad
MTR_POSITION_STEADY_STATE
MTR_POSITION_TRANSITION_STATEE
MTR_POSITION_STEADY_STATE
MTR_POSITION_TRANSITION_STATE
RX72T Vector Control for Permanent Magnet Synchronous Motor with Encoder (Implementation)
R01AN4721EJ0100 Rev.1.00 Page 12 of 37
Mar 29. 2019
3.1.4 Speed Measurement
In order to obtain better real-time performance and higher speed resolution at low speed, this system use encoder signal
edge interval to calculate speed, the speed extrapolation is used in PI control calculation. In addition, taking the
difference between rise time and fall time and the accuracy of quadrature of encoder signal into consideration, the speed
is calculated with time elapsed and angle changed in one period of encoder Phase-A or Phase-B signals.
(1) Speed Calculation
2π/Pulses per Rotation
Timer Counter
Capture Capture
Counter Difference
Phase-A
Encoder Signal
Phase-B
Encoder Signal
2π/Pulses per Rotation
CaptureCaptureCaptureCaptureCapture
Figure 3-2 Speed Calculation using Encoder