Renesas RA6T2 Installation and operating instructions

APPLICATION NOTE
R01AN6208EJ0101 Rev.1.01 Page
1
of 71
Oct 18, 2022
RA6T2
Vector control for permanent magnetic synchronous motor with encoder - AB
incremental type encoder
Abstract
This application note describes the sample program for a permanent magnetic synchronous motor drive with
vector control using encoder based on Renesas RA6T2 microcontroller. This application note also describes
how to use the motor control development support tool, ’Renesas Motor Workbench’.
The targeted software for this application is only to be used as reference purposes only and Renesas
Electronics Corporation does not guarantee the operations. Please use this 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.
- RA6T2 (R7FA6T2BD3CFP)
Contents
1. Overview .................................................................................................................................3
1.1 Development environment ......................................................................................................................3
2. System overview .....................................................................................................................4
2.1 Hardware configuration ...........................................................................................................................4
2.2 Hardware specifications ..........................................................................................................................5
2.2.1 User interface........................................................................................................................................5
2.2.2 Peripheral functions...............................................................................................................................7
2.3 Software configuration...........................................................................................................................18
2.3.1 Software file configuration...................................................................................................................18
2.3.2 Module configuration...........................................................................................................................19
2.4 Software specifications..........................................................................................................................20
2.5 Interrupt Priority.....................................................................................................................................21
3. Descriptions of the control program.......................................................................................22
3.1 Contents of control ................................................................................................................................22
3.1.1 Motor start/stop....................................................................................................................................22
3.1.2 A/D Converter......................................................................................................................................22
3.1.3 Modulation...........................................................................................................................................23
3.1.4 State transition.....................................................................................................................................25
3.1.5 Start-up method...................................................................................................................................26
3.1.6 Position Profile Generation..................................................................................................................27
(Position Profile of Trapezoidal Curve for Speed Command Value)...............................................................27

RA6T2 Vector control for permanent magnetic synchronous motor with encoder - AB incremental type encoder
R01AN6208EJ0101 Rev.1.01 Page
2
of 71
Oct 18, 2022
3.1.7 Speed Measurement...........................................................................................................................28
3.1.8 System protection function..................................................................................................................30
3.1.9 AD triggers...........................................................................................................................................31
3.2 Function specifications of vector control with encoder software...........................................................32
3.3 Contents of control ................................................................................................................................39
3.3.1 Configuration Options..........................................................................................................................39
3.3.2 Configuration Options for included modules .......................................................................................39
3.4 Control flowcharts..................................................................................................................................50
3.4.1 Main process.......................................................................................................................................50
3.4.2 50[µs] Period Interrupt (Carrier synchronized Interrupt) Process .......................................................51
3.4.3 500 [µs] Period Interrupt Process........................................................................................................52
3.4.4 Over Current Detection Interrupt Process...........................................................................................53
3.4.5 Encoder signal interrupt processing....................................................................................................54
4. Evaluation environment explanation......................................................................................55
4.1 Operating Environment .........................................................................................................................55
4.2 Importing the Demo Project...................................................................................................................55
4.3 Building and Debugging ........................................................................................................................56
4.4 Motor Demonstration Project Overview.................................................................................................57
4.4.1 Quick Start...........................................................................................................................................57
4.5 Motor Control Development Support Tool ‘Renesas Motor Workbench’ ..............................................58
4.5.1 Overview..............................................................................................................................................58
4.5.2 Easy function operation example ........................................................................................................59
4.5.3 List of variables for Analyzer function .................................................................................................63
4.5.4 Operation Example for Analyzer .........................................................................................................64
4.5.5 Tuner function......................................................................................................................................65
4.5.6 Example of changing communication speed.......................................................................................66
4.5.7 How to use the built-in communication library.....................................................................................67
5. Reference Documents...........................................................................................................70
Revision History............................................................................................................................71

RA6T2 Vector control for permanent magnetic synchronous motor with encoder - AB incremental type encoder
R01AN6208EJ0101 Rev.1.01 Page
3
of 71
Oct 18, 2022
1. Overview
This application note explains how to implement the vector control with encoder software that drives
permanent magnetic synchronous motor (PMSM) using the RA6T2 microcontroller and how to use the motor
control development support tool, ‘Renesas Motor Workbench’.
Note that this software uses the algorithm described in the application note ‘Vector control with encoder for
permanent magnet synchronous motor (Algorithm)’(R01AN3789), so please refer to that for the details of
the algorithm.
1.1 Development environment
Table 1-1 and Table 1-2 show development environment of the software explained in this application note.
Table 1-1 Hardware Development Environment
Microcontroller
Evaluation board (Note 1)
Motor (Note 2)
Sensor (Note 3)
RA6T2
(R7FA6T2BD3CFP)
MCK-RA6T2
BLY171D-24V-4000
AMT102-V
Table 1-2 Software Development Environment
e2studio version
FSP version
Toolchain version
V2022-10
V4.1.0 and later
GCC ARM Embedded:
V10.3.1.20210824
For purchase and technical support,contact Sales representatives and dealers of Renesas Electronics
Corporation.
Notes:
1. MCK-RA6T2 (RTK0EMA270S00020BJ) is included in the kit products RTK0EM0000B12020BJ,
RTK0EMA270C00000BJ and RTK0EMXC90Z00000BJ, and it is a product of Renesas Electronics
Corporation.
RA6T2 CPU board (RTK0EMA270C00000BJ) is a product of Renesas Electronics Corporation.
2.BLY171D-24V-4000 is a product of Anaheim Automation.
Anaheim Automation (https://www.anaheimautomation.com/)
3.AMT102-V is a product of CUI Devices.
CUI Devices (https://www.cuidevices.com/)

RA6T2 Vector control for permanent magnetic synchronous motor with encoder - AB incremental type encoder
R01AN6208EJ0101 Rev.1.01 Page
4
of 71
Oct 18, 2022
2. System overview
Overview of this system is explained below.
2.1 Hardware configuration
The hardware configuration is shown below.
RA6T2
Vdc
GND
VR1
SW1 SW2
LED1 LED2
Up
Vp
Wp
Vn
Un
Wn
OC Vu
Vv
Vw
PD04
PD07
PA06 / AN006
PB00 / AN008
PD01
PD02
PB04 / GTIOC4A(Up)
PB06 / GTIOC5A(Vp)
PC13 / GTETRGC
PMSM
PA04 / AN004 IU_AIN
PA00 / AN000 IW_AIN
PC14 / GTIOC3A
PC15 / GTIOC3B
PB08 / GTIOC6A(Wp)
PB05 / GTIOC4B(Un)
PB07 / GTIOC5B(Vn)
PB09 / GTIOC6B(Wn)
PD03
LED3
PA02 / AN002 IV_AIN
Power supply circuit
A/D converter input
Bus voltage
Phase
current
Rotation speed command
Motor rotation start/stop
Error reset
Inverter circuit
Phase current
detection
Iu Iw
Iv
Switch input
LED output
GPT output
Over current detectioninput
Encoder output
Over current detection
ENC_Z port
ENC_A port
ENC_B port
GND port
Vcc port
U port
W port
V port
HU port
HW port
HV port
GND port
Vcc port
Figure 2-1 Hardware Configuration Diagram

RA6T2 Vector control for permanent magnetic synchronous motor with encoder - AB incremental type encoder
R01AN6208EJ0101 Rev.1.01 Page
5
of 71
Oct 18, 2022
2.2 Hardware specifications
2.2.1 User interface
Table 2-1 and Table 2-2 is lists of user interfaces of this system.
Table 2-1 User Interface
Item
Interface component
Function
Rotation speed
command
Variable resistor (VR)
Reference value of rotation speed input (analog
value)
START/STOP
Toggle switch (SW1)
Motor rotation start/stop command
ERROR RESET
Push switch (SW2)
Command of recovery from error status
LED1
Orange LED
- At the time of motor rotation: ON
- At the time of stop: OFF
LED2
Orange LED
- At the time of error detection: ON
- At the time of normal operation: OFF
LED2
Orange LED
- Positioning completed: ON
- Positioning not completed: OFF
Table 2-2 CPU card user interface
Item
Interface component
Function
LED1
Orange LED
- At the time of motor rotation: ON
- At the time of stop: OFF
LED2
Orange LED
- At the time of error detection: ON
- At the time of normal operation: OFF
LED2
Orange LED
- Positioning completed: ON
- Positioning not completed: OFF
RESET
Push switch (RESET)
System reset

RA6T2 Vector control for permanent magnetic synchronous motor with encoder - AB incremental type encoder
R01AN6208EJ0101 Rev.1.01 Page
6
of 71
Oct 18, 2022
List of port interfaces of this system is given in Table 2-3.
Table 2-3 Port Interfaces
R7FA6T2BD3CFP port name
Function
PA06 / AN006
Inverter bus voltage measurement
PB00 / AN008
For rotation speed command value input (analog value)
PD04
START/STOP toggle switch (SW1)
PD07
ERROR RESET push switch (SW2)
PD01
LED1 ON/OFF control
PD02
LED2 ON/OFF control
PD03
LED3 ON/OFF control
PA04 / AN004
U phase current measurement
PA02 / AN002
V phase current measurement
PA00 / AN000
W phase current measurement
PB04 / GTIOC4A
PWM output (Up)
PB06 / GTIOC5A
PWM output (Vp)
PB08 / GTIOC6A
PWM output (Wp)
PB05 / GTIOC4B
PWM output (Un)
PB07 / GTIOC5B
PWM output (Vn)
PB09 / GTIOC6B
PWM output (Wn)
PC14 / GTIOC3A
Encoder A phase input
PC15 / GTIOC3B
Encoder B phase input
PC13 / GTETRGD
PWM emergency stop input at the time of overcurrent detection

RA6T2 Vector control for permanent magnetic synchronous motor with encoder - AB incremental type encoder
R01AN6208EJ0101 Rev.1.01 Page
7
of 71
Oct 18, 2022
2.2.2 Peripheral functions
List of the peripheral functions used in this system is given in Table 2-4.
Table 2-4 List of the Peripheral Functions
Peripheral
Resource
Purpose
12-bit A/D Converter
AN000, AN002, AN004,
AN006, AN008
Measure electric current of phase U and W
Measure inverter bus voltage
Rotational speed or position command input
AGT
AGT0
500 [µs] interval timer
GPT
CH1, CH3, CH4, CH5,
CH6
Complementary PWM outputs
Encoder phase counter
Encoder count capture
POEG
Group D
Sets ports executing PWM output to high
impedance state when an overcurrent is
detected by external circuit.

RA6T2 Vector control for permanent magnetic synchronous motor with encoder - AB incremental type encoder
R01AN6208EJ0101 Rev.1.01 Page
8
of 71
Oct 18, 2022
(1) 12-bit A/D Converter (12ADC)
U-phase current (Iu), V-phase current (Iv), W-phase current (Iw), inverter bus voltage1 (Vdc), and speed
command (VR) are measured in "Single scan mode" (use a hardware trigger).
A/D conversion is implemented to be synchronized with carrier synchronized interrupt as GPT underflow
(PWM valley) by using GPT trigger function.
Figure 2-2 FSP Configuration of ADC Driver (FSP 3.5.0) [1/3]

RA6T2 Vector control for permanent magnetic synchronous motor with encoder - AB incremental type encoder
R01AN6208EJ0101 Rev.1.01 Page
9
of 71
Oct 18, 2022
Figure 2-3 FSP Configuration of ADC Driver (FSP 3.5.0) [2/3]

RA6T2 Vector control for permanent magnetic synchronous motor with encoder - AB incremental type encoder
R01AN6208EJ0101 Rev.1.01 Page
10
of 71
Oct 18, 2022
Figure 2-4 FSP Configuration of ADC Driver (FSP 3.5.0) [3/3]

RA6T2 Vector control for permanent magnetic synchronous motor with encoder - AB incremental type encoder
R01AN6208EJ0101 Rev.1.01 Page
11
of 71
Oct 18, 2022
(2) Low Power Asynchronous General-Purpose Timer (AGT)
The AGT is used as 500 [µs] interval timer.
Figure 2-5 FSP Configuration of AGT Driver (FSP 3.5.0)
(3) General PWM Timer (GPT)
On the channel 4, 5, and 6, output with dead time is performed by using the complementary PWM Output
Operating Mode.

RA6T2 Vector control for permanent magnetic synchronous motor with encoder - AB incremental type encoder
R01AN6208EJ0101 Rev.1.01 Page
12
of 71
Oct 18, 2022
Figure 2-6 FSP Configuration of GPT Driver for PWM output (FSP 3.5.0)
(4) Phase Counting Timer (GPT)
Channel 3 is used as phase counting mode2 to measure the phase difference between encoder phase A
and B signal and counts the encoder input.

RA6T2 Vector control for permanent magnetic synchronous motor with encoder - AB incremental type encoder
R01AN6208EJ0101 Rev.1.01 Page
13
of 71
Oct 18, 2022
Figure 2-7 FSP Configuration of GPT Driver for phase counting timer (FSP 3.5.0) [1/5]
Figure 2-8 FSP Configuration of GPT Driver for phase counting timer (FSP 3.5.0) [2/5]

RA6T2 Vector control for permanent magnetic synchronous motor with encoder - AB incremental type encoder
R01AN6208EJ0101 Rev.1.01 Page
14
of 71
Oct 18, 2022
Figure 2-9 FSP Configuration of GPT Driver for phase counting timer (FSP 3.5.0) [3/5]
Figure 2-10 FSP Configuration of GPT Driver for phase counting timer (FSP 3.5.0) [4/5]

RA6T2 Vector control for permanent magnetic synchronous motor with encoder - AB incremental type encoder
R01AN6208EJ0101 Rev.1.01 Page
15
of 71
Oct 18, 2022
Figure 2-11 FSP Configuration of GPT Driver for phase counting timer (FSP 3.5.0) [5/5]

RA6T2 Vector control for permanent magnetic synchronous motor with encoder - AB incremental type encoder
R01AN6208EJ0101 Rev.1.01 Page
16
of 71
Oct 18, 2022
(5) Free run timer (GPT)
Channel 1 is used as a free run timer for speed measurement.
Figure 2-12 FSP Configuration of GPT Driver for free run timer (FSP 3.5.0)

RA6T2 Vector control for permanent magnetic synchronous motor with encoder - AB incremental type encoder
R01AN6208EJ0101 Rev.1.01 Page
17
of 71
Oct 18, 2022
(6) Port Output Enable for GPT (POEG)
The port executing PWM output are set to high impedance state when an overcurrent is detected (when a
low level of the GTETRGD port is detected)
Figure 2-13 FSP Configuration of POEG Driver (FSP 3.5.0)

RA6T2 Vector control for permanent magnetic synchronous motor with encoder - AB incremental type encoder
R01AN6208EJ0101 Rev.1.01 Page
18
of 71
Oct 18, 2022
2.3 Software configuration
2.3.1 Software file configuration
Folder and file configuration of the software is given below.
Figure 2-14 Folder and file configuration
ra
arm
board
fsp
(Project Folder)
Function definition for board
CMSIS source code
Note 1 : Regarding the specification of Analyzer function in the motor control development support tool “Renesas Motor Workbench”,
please refer to the chapter 4.5 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”.
user_interface
application
main
ics
mtr_main.h, mtr_main.c: User main function
r_mtr_control_parameter.h : Control parameters definition
r_mtr_motor_parameter.h : Motor parameters definition
r_mtr_ics.h, r_mtr_ics.c : Function definition for Analyzer(Note1)
ICS2_RA6T2.o : Communication library for GUI tool
ICS2_RA6T2.h : Function definition for GUI tool
ra_cfg
ra_gen
Generated config header
Generated register setting, main function etc
lib
src
bsp_api.h : BSP API definition
r_adc_api.h : AD API definition
r_ioport_api.h : I/O API definition
r_poeg_api.h : POEG API definition
r_three_phase_api.h : 3phase PWM API definition
r_timer_api.h : Timer API definition
rm_motor_angle_api.h : Angle API definition
rm_motor_api.h : Motor API definition
rm_motor_current_api.h : Current API definition
rm_motor_driver_api.h : Motor driver API definition
rm_motor_speed_api.h : Speed API definition
rm_motor_position_api.h : Position API definition
inc
Library files
instances
api
bsp : BSP driver
r_adc_b/r_adc_b.c : AD driver
r_agt/r_agt.c : AGT driver
r_gpt/r_gpt.c : GPT driver
r_gpt_three_phase/r_gpt_three_phase.c : 3 phase PWM driver
r_ioport/r_ioport.c : I/O driver
r_poeg/r_poeg.c : POEG driver
rm_motor_current/rm_motor_current.c : Current control driver
rm_motor_current/rm_motor_current_library.h : Current control library
API definition
rm_motor_driver/rm_motor_driver.c : Motor driver
rm_motor_driver/rm_motor_driver_library.h : Motor driver library
API definition
rm_motor_sense_encoder/rm_motor_sense_encoder.c
: Encoder input process driver
rm_motor_encoder/rm_motor_encoder.c : Encoder driver
rm_motor_speed/rm_motor_speed.c : Speed control driver
rm_motor_speed/rm_motor_speed_library.h : Speed control driver
API definition
rm_motor_position/rm_motor_position.c : Position control driver
rm_motor_position/rm_motor_position_library.h
: Position control library API definition
r_adc_b.h : Function definition for AD
r_ioport.h : Function definition for I/O
r_poeg.h : Function definition for POEG
r_three_phase.h : Function definition for 3 phase PWM
r_agt.h : Function definition for AGT
r_gpt.h : Function definition for GPT
rm_motor_sense_encoder.h
: Function definition for encoder input process
rm_motor_enoder.h : Function definition for encoder control
rm_motor_current.h : Function definition for current control
rm_motor_driver.h : Function definition for motor driver
rm_motor_speed.h : Function definition for speed control
rm_motor_position.h : Function definition for position control
src

RA6T2 Vector control for permanent magnetic synchronous motor with encoder - AB incremental type encoder
R01AN6208EJ0101 Rev.1.01 Page
19
of 71
Oct 18, 2022
2.3.2 Module configuration
Module configuration of the software is described below.
Figure 2-15 Module Configuration
Application Layer (User Application)
mtr_main.c
User Interface Module
Main
r_mtr_ics.c
Middle Layer (Motor Control Process)
rm_motor_encoder.c
Interface Module
Control Module
rm_motor_sense_encoder.c
rm_motor_speed.c
Device Layer
MCU Module
r_adc_b.c
r_agt.c
H/W Layer (MCU / Inverter)
Set User Command to Buffer
Set Control Gain & Command
Set PWM duty
Get Voltage, Current & Angle/Speed
Get A/D Converter Data & Sensor Signal
Output PWM Signal
rm_motor_current.c
rm_motor_driver.c
r_gpt.c
r_poeg.c
rm_motor_position.c

RA6T2 Vector control for permanent magnetic synchronous motor with encoder - AB incremental type encoder
R01AN6208EJ0101 Rev.1.01 Page
20
of 71
Oct 18, 2022
2.4 Software specifications
Table 2-5 shows basic software specification of this system. For details of the vector control with encoder,
refer to the application note ‘Vector control with encoder for permanent magnet synchronous motor
(Algorithm)’(R01AN3789).
Table 2-5 Basic Specifications of Vector Control with encoder Software
Item
Content
Control method
Vector control
Position detection
method
Incremental encoder (A-B Phase)
Motor rotation start/stop
SW1 input or input from ‘Renesas Motor Workbench’
Input voltage
DC 24 [V]
Main clock frequency
120 [MHz]
Carrier frequency
(PWM)
20 [kHz] (Carrier period: 50 [μs])
Dead time
2 [μs]
Control period
Current control: 50 [μs] (the carrier period)
Speed control: 500 [μs]
Rotation speed control
range
CW: 0 [rpm] to 4000 [rpm]
CCW: 0 [rpm] to 4000 [rpm]
Position control range
At board_ui
Position command generation: Voltage input divided by VR
(input range) -180° to 180°
At ics_ui
Position command generation: Position profile of
trapezoidal curve for speed command value
(input range) -32768° to 32767°
(Max speed) CW / CCW: 4000[rpm]
Dead band of position*
Encoder count ±1 [cpr] (±0.09degree)
Natural frequency
of each control system
Current control system : 300 [Hz]
Speed control system : 30 [Hz]
Position estimation system : 5 [Hz]
Optimization setting
of compiler
Optimization level
Optimize more(-O2) (default setting)
Processing stop for
protection
Disables the motor control signal output (six outputs), under any of the following conditions.
1. Instantaneous value of current of any phase exceeds 3.82(=1.8*sqrt (2)*1.5) [A] (monitored
every 50 [μs])
2. Inverter bus voltage exceeds 60 [V] (monitored every 50 [μs])
3. Inverter bus voltage is less than 8 [V] (monitored every 50 [μs])
4. Rotation speed exceeds 4500 [rpm] (monitored every 50 [μs])
When an external over current signal is detected (when a low level of the GTETRGD port is
detected), the PWM output ports are set to high impedance state.
* Dead band is provided to avoid hunting at the detection of target position.
Other manuals for RA6T2
1
Table of contents
Other Renesas Media Converter manuals

Renesas
Renesas R0E53036ACFG40 User manual

Renesas
Renesas RL78/G13 User manual

Renesas
Renesas ISL6310EVAL1Z User manual

Renesas
Renesas R0E420000CFJ30 User manual

Renesas
Renesas AB-050-Fx4-MB-L-Q-TCT-V2 User manual

Renesas
Renesas R0E53032GCSJC0 User manual

Renesas
Renesas RAA3064002GFP User manual

Renesas
Renesas M3A-ZA53 User manual

Renesas
Renesas H8S/2427 User manual

Renesas
Renesas dialog semiconductor DA913 30 Series User manual