Application Note
R01AN5516EJ0100 Rev.1.00 Page 1 of 48
2020.08.01
RL78/G1M
120-degree conducting control of permanent magnetic synchronous motor
(Implementation)
Summary
This application note explains the sample programs driving a permanent magnet synchronous motor in the
120-degree conducting method using the RL78/G1M microcontroller. This note also explains how to use the
motor control development support tool, ’Renesas Motor Workbench (RMW)’.
These sample programs are only able to be used as references, and Renesas Electronics Corporation
does not guarantee their operation. Please use them after carrying out a thorough evaluation in a suitable
environment.
Operation checking device
Operations of the sample programs have been checked using the following device.
RL78/G1M (R5F11W68ASM)
Target sample programs
This application note regards the following sample programs.
RL78G1M_MRSSK_120_CSP_CC_V100 (IDE: CS+ for CC)
RL78G1M_MRSSK_120_E2S_CC_V100 (IDE: e2studio)
For the 24 V Motor Control Evaluation System & RL78/G1M CPU card:
RL78/G1M 120-degree conducting control sample program
The Hall effect sensor and sensorless mode can be changed by rewriting “MTRCONF_SENSOR_MODE”
in the configuration definition file “r_mtr_config.h” to 0: HALL and 1: LESS, and compiling.
Reference
RL78/G1M User's Manual: Hardware (R01UH0904EJ0100)
Application note: ‘120-degree conducting control of permanent magnet synchronous motor: algorithm’
(R01AN2657EJ0120)
Renesas Motor Workbench V.2.00 User’s Manual (R21UZ0004EJ0202: Renesas-Motor-Workbench-
V2-0d)
Renesas Solution Starter Kit 24V Motor Control Evaluation System for RX23T User’s Manual
(R20UT3697EJ0120)
R01AN5516EJ0100
Rev.1.00
2020.08.01
RL78/G1M 120-degree conducting control of permanent magnetic synchronous motor (Implementation)
R01AN5516EJ0100 Rev.1.00 Page 2 of 48
2020.08.01
Contents
1. Overview .......................................................................................................................................3
2. System overview ..........................................................................................................................4
3. Descriptions of the control program ...........................................................................................10
4. Usage of Motor Control Development Support Tool, ‘Renesas Motor Workbench’..................45
RL78/G1M 120-degree conducting control of permanent magnetic synchronous motor (Implementation)
R01AN5516EJ0100 Rev.1.00 Page 3 of 48
2020.08.01
1. Overview
This application note explains how to implement the 120-degree conducting control sample programs of the
permanent magnet synchronous motor (PMSM) using the RL78/G1M microcontroller, and how to use the
motor control development support tool, “Renesas Motor Workbench”. Note that these sample programs use
the algorithm described in the application note “120degree conducting control of permanent magnet
synchronous motor: algorithm”.
1.1 Development environment
Table 1-1 and Table 1-2 show the development environment of the sample programs explained in this
application note.
Table 1-1 – Development Environment of the Sample Programs (H/W)
24V inverter board1 & RL78/G1M CPU card2
Table 1-2 – Development Environment of the Sample Programs (S/W)
For purchase and technical support, please contact sales representatives and dealers of Renesas
Electronics Corporation.
Notes:
1. 24V inverter board (RTK0EM0001B00012BJ) is a product of Renesas Electronics Corporation.
2. The following RL78/G1M CPU cards can be used.
T5108: Desk Top Laboratories Inc. (http://desktoplab.co.jp/)
3. TG-55L is a product of TSUKASA ELECTRIC.
TSUKASA ELECTRIC. (https://www.tsukasa-d.co.jp/en/)
RL78/G1M 120-degree conducting control of permanent magnetic synchronous motor (Implementation)
R01AN5516EJ0100 Rev.1.00 Page 4 of 48
2020.08.01
2. System overview
An overview of this system is provided below.
2.1 Hardware configuration
The hardware configuration is shown below.
RL78G1M
A/D converter input
Bus voltage
Rotational speed command
RTO output
Over current detection
Hall sensor input
V
dc
GND
Power supply circuit(5V/12V)
DC24V input
U port
W port
V port
HU port
HW port
HV port
GND port
V
cc
port
VR1
SW1
SW2
Switch input
LED output
LED1 LED2
過電流検出 入力
U
p
V
p
W
p
V
n
U
n
W
n
Inverter circuit
OC
P15 / ANI6
P16 / ANI7
P40
P10 / RTIO00
P11 / RTIO01
P12 / RTIO02
P13 / RTIO03
P14 / RTIO04
P15 / RTIO05
P137 / INTP0
P12
P13
P14
PMSM
P13 / ANI4
P12 / ANI3
P14 / ANI5
Hall control mode
V
u
V
v
V
w
W V U
V
w
V
u
V
v
Sensorless control mode
P125
P137
JP4
JP5
JP5
JP3
JP2
JP1
JP3
JP1
JP2
OPamp IC
P11 / ANI2
P10 / ANI1
I
u
I
v
I
u
I
v
A/D converter
A/D converter
(not used in this system)
LED1 and P40 are disconnected at the time of purchase.
Figure 2-1 – Hardware Configuration Diagram
RL78/G1M 120-degree conducting control of permanent magnetic synchronous motor (Implementation)
R01AN5516EJ0100 Rev.1.00 Page 5 of 48
2020.08.01
2.2 Hardware specifications
2.2.1 User interface
Table 2-1 is a list of user interfaces of this system.
Table 2-1 – User Interface
Rotational speed command value
input (analog values)
Command of recovery from error
status
(Not used in this system)
(Not used in this system)
(Not used in this system)
(Not used in this system)
(Not used in this system)
The system's RL78/G1M microcontroller port interfaces are listed in Table 2-2.
Table 2-2 – Port Interface
Inverter bus voltage measurement
Rotational speed command values input (analog values)
ERROR RESET toggle switch 3
Toggle switch (not used in this system) 4
LED1 on/off control (not used in this system)
U phase voltage measurement (A/D) 2
V phase voltage measurement (A/D) 2
W phase voltage measurement (A/D) 2
Hall effect sensor input
1,2
(HU)
Hall effect sensor input
1,2
(HV)
Hall effect sensor input
1,2
(HW)
PORT output / PWM output (Up)
PORT output / PWM output (Vp)
PORT output / PWM output (Wp)
PORT output / PWM output (Un)
PORT output / PWM output (Vn)
PORT output / PWM output (Wn)
System reset (not used in this system)
3
PWM emergency stop input at the time of overcurrent detection
4
1
: When Hall effect sensors on the motor included in the 24V inverter kit are used, equip the ferrite core included in this
kit with cables for 3 Hall effect sensors to avoid sensor noise.
2
: Short 2-3 of JP1-3 in Hall effect sensor control mode, or 1-2 in senseless control mode.
3
: In this system, because P125 is used to detect the status of SW1, short 2-3 of JP4. (However, when writing a program
to the microcontroller, by using the E1emulator, short 1-2.)
4
: In this system, P137 is used for overcurrent detection, so short 1-2 of JP5.
RL78/G1M 120-degree conducting control of permanent magnetic synchronous motor (Implementation)
R01AN5516EJ0100 Rev.1.00 Page 6 of 48
2020.08.01
2.2.2 Peripheral functions
Table 2-3 is a list of peripheral functions used in this system.
Table 2-3 – List of Peripheral Functions
Rotational speed command value input (Board UI
mode)
Inverter bus voltage measurement
Voltage of each phase U, V, and W measurement
PWM output
Free-running timer for rotational speed measurement
Delay timer for changing conducting pattern
(sensorless control mode)
12-bit Interval timer (IT)
Real-time output control circuit
Output waveform and output port control
External interrupt (INTP0)
(1) 10-bit A/D converter
The rotational speed command value input, U phase voltage (Vu), V phase voltage (Vv), W phase
voltage (Vw), and inverter bus voltage (Vdc) are measured by using the “10-bit A/D converter”.
(2) Timer Array Unit (TAU)
a. PWM output
Used to output non-complementary PWM.
b. Free-running timer for rotational speed measurement
This channel 1 of TAU is used as a free-running counter for rotational speed calculation.
c. Delay timer for changing conducting pattern
The channel 3 of TAU is used as delay timer for changing conducting pattern with π/6 phase from
the zero-crossing point.
(3) 12-bit Interval timer (IT)
Used as a 1 millisecond interval timer.
(4) Real-time output control circuit (RTO)
Sets the Up to Wn PWM, high level and low output.
In addition, by using the forced cutoff function, all output terminals are set to low level output when
overcurrent is detected.
(5) External interrupt (INTP0)
An overcurrent is detected by an external circuit.
RL78/G1M 120-degree conducting control of permanent magnetic synchronous motor (Implementation)
R01AN5516EJ0100 Rev.1.00 Page 7 of 48
2020.08.01
2.3 Software structure
2.3.1 Software file structure
The folder and file configurations of the sample programs Table 2-4 are given below.
Table 2-4 – Folder and File Configuration of the Sample Program
Common definition for software configuration
Configuration definition for motor parameters
r_mtr_control_parameter.h
Configuration definition for control parameters
r_mtr_inverter_parameter.h
Configuration definition for inverter parameters
r_mtr_board.h
r_mtr_board.c
Function definition for board UI
Function definition for Analyzer
(Note1)
UI
Interrupt vector function definition for RMW
Function declaration for RMW
Communication library for RMW
cstart.asm
hdwinit.asm
iodefine.h
Auto generation files
mtr_ctrl_mrssk.h,
Function definition for inverter board control
r_mtr_ctrl_rl78g1m.h,
r_mtr_ctrl_rl78g1m.c
Function definition for MCU control
Various parameter definition
r_mtr_driver_access.h,
r_mtr_driver_access.c
Function definition for User access
r_mtr_statemachine.h,
r_mtr_statemachine.c
Function definition for state transition
Function definition for 120-degree conducting control
r_mtr_interrupt.c
Interrupt function definition
Note 1: Regarding the specification of the Analyzer function in the motor control development support tool “Renesas Motor Workbench
(RMW)”, please refer to Chapter 4.
The identifier ‘ics/ICS (ICS is the previous motor control development support tool, ‘In Circuit Scope’) is attached to the name of
folders, files, functions, and variables related to ‘Renesas Motor Workbench’.
RL78/G1M 120-degree conducting control of permanent magnetic synchronous motor (Implementation)
R01AN5516EJ0100 Rev.1.00 Page 8 of 48
2020.08.01
2.3.2 Module configuration
Figure 2-2 shows module configuration of the sample programs.
Function Call
driver_access
Set Control Parameter & Command
Motor Control Process Modules
interrupt
Function Call
Other Control Modules
MCU Inverter
Set PWM duty
Voltage, Sensor signals
H/W Layer (MCU, Inverter)
Output PWM Signal A/D Convertor, PORT
Figure 2-2 – Module Configuration of the Sample Programs
RL78/G1M 120-degree conducting control of permanent magnetic synchronous motor (Implementation)
R01AN5516EJ0100 Rev.1.00 Page 9 of 48
2020.08.01
2.4 Software specifications
Table 2-5 shows the basic specifications of target software of this application note. For details on 120degree conducting control, refer to the application note “120-degree conducting control of permanent magnet
synchronous motor: algorithm”.
Table 2-5 – Basic Specifications of Software
120-degree conducting method (chopping upper arm)
Motor rotation start/stop
Determined based on the input value of VR1 (P16) (minimum speed or
more: rotation starts, less than minimum speed: stop)
or input from Renesas Motor Workbench
Position detection of rotor
magnetic pole
Hall effect sensor: Position detection based on signal from Hall effect
sensors (every 60 degrees)
Sensorless: Position detection based on induced voltage measured by A/D
converters (every 60 degrees)
・When position of rotor is detected, PWM duty and conducting pattern are
set.
CPU clock: f
CLK
20 [MHz]
Speed PI control: every 1 [ms]
Rotational speed control
range
Hall effect sensor control mode: 530 [rpm] to 3200 [rpm]
(Note1)
Sensorless control mode: 265 [rpm] to 3200 [rpm]
(Note1)
Both CW and CCW are supported
Perform the default optimization (None)
Processing stop for
protection
・Disables the motor control signal output (six outputs), under any of the
following conditions.
1. Inverter bus voltage exceeds 28 V (monitored per 1 [ms])
2. Inverter bus voltage is less than 15 V (monitored per 1 [ms])
3. Rotational speed exceeds 3900 rpm (monitored per 1 [ms])
4. Hall pattern change or zero-crossing are not detected for 200 [ms].
5. Detection of unexpected output voltage pattern
6. Detection of overcurrent by external circuit (low level input in INTP0
port)
Note1 : Please refrain from driving motor over rated speed for a long period.
2.5 User option bytes
The settings of the user option byte area of the RL78/G1M flash memory are shown below.
Table 2-6 – User option byte settings
Enable watchdog timer counter operation
(Starts counting after reset is released)
Overflow time: 7.36 [ms]
・P125/KR1/RESET pin: Port function
・Selectable power-on reset detection voltage
Rising edge: 4.28 [V]
Falling edge: 4.20 [V]
RL78/G1M 120-degree conducting control of permanent magnetic synchronous motor (Implementation)
R01AN5516EJ0100 Rev.1.00 Page 10 of 48
2020.08.01
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
Starting and stopping of the motor are controlled by input from Renesas Motor Workbench or VR1. In
addition, an analog input port is assigned to VR1. The input is A/D converted within the main loop to generate a
rotational speed command value. When the rotation command value exceeds the minimum speed (Hall
control mode: 530 [rpm], sensorless control mode: 265 [rpm]), the rotation starts, and when it is less than the
minimum speed, the rotation stops.
3.1.2 A/D Converter
(1) Motor rotational speed command value
The motor rotational speed command value can be set by Renesas Motor Workbench input or A/D
conversion of the VR1 output value (analog value). The A/D converted VR1 value is used as rotational speed
command value, as shown below. Maximum value of conversion ratio is set to achieve maximum speed by
VR1 input. Only higher 8bits are used for calculation of rotational speed command value.
Table 3-1 – Conversion Ratio of the Rotation Speed Command Value
Conversion ratio
(Command value: A/D conversion value)
Rotational speed
command value
0 [rpm] to 3200 [rpm] : 01FFH to 03FFH
-3200 [rpm] to 0 [rpm] : 0000H to 01FFH
(2) Inverter bus voltage
Inverter bus voltage is measured as given in Table 3-2. It is used for modulation factor calculation and
over/low voltage detection. (When an abnormality is detected, PWM is stopped). Only higher 8bits are used
for calculation of bus voltage.
Table 3-2 – Inverter Bus Voltage Conversion Ratio
Conversion ratio
(Inverter bus voltage: A/D conversion value)
0 [V] to 111 [V] : 0000H to 03FFH
(3) U phase, V phase, and W phase voltage
The U, V and W phase voltages are measured as shown in Table 3-3 and are used for determining zerocrossing of induced voltage.
Table 3-3 – Conversion Ratio of U, V, and W Phase Voltage
Conversion ratio
(U, V, and W phase voltage: A/D conversion value)
0 [V] to 111 [V] : 0000H to 03FFH
Note: For more details on A/D conversion, refer to RL78/G1M User’s Manual: Hardware.
RL78/G1M 120-degree conducting control of permanent magnetic synchronous motor (Implementation)
R01AN5516EJ0100 Rev.1.00 Page 11 of 48
2020.08.01
3.1.3 Speed control
In this system, rotational speed is calculated from the difference between the current timer value and the
previous timer value 2π [rad]. The timer values are obtained when patterns are switched after Hall effect
sensor pattern change at Hall effect sensor control mode or zero-crossing of induced voltage at sensorless
control mode, while having the timer of performed free running.
U phase pattern
2p
Timer counter
Check Check Check Check Check Check Check
Counter value difference
Motor rotational speed [rad/s] = (2π × frequency of timer) / (difference of timer counts)
V phase pattern
W phase pattern
2p
2p
Figure 3-1 – Method of Calculation for Rotational Speed
The target sample software of this application note uses PI control for speed control. A voltage command
value is calculated by the following formula of speed PI control.
))((
*
−+=
s
K
Kv
I
P
𝑣
∗
: Voltage command value : Speed command value : Rotation speed
: Speed PI proportional gain : Speed PI integral gain 𝑠: Laplace operator
For more details on PI control, please refer to specialized books.
RL78/G1M 120-degree conducting control of permanent magnetic synchronous motor (Implementation)
R01AN5516EJ0100 Rev.1.00 Page 12 of 48
2020.08.01
3.1.4 Voltage control by PWM
PWM control is used for controlling output voltage. The PWM control is a control method that continuously
adjusts the average voltage by varying the duty of pulse, as shown in Figure 3-2.
Average
voltage
t
V
T
ON
T
OFF
T
ON
+ T
OFF
T
ON
Duty = × 100 [%]
Figure 3-2 – PWM Control
Here, modulation factor “m” is defined as follows.
𝑚 =
𝑉
𝐸
This modulation factor is set to resisters for PWM duty in TAU.
In the target software of this application note, non-complementary upper arm chopping is used to control
the output voltage and speed. Figure 3-3 shows an example of output waveforms when upper arm chopping
is used.
Figure 3-3 – Non-Complementary Upper Arm Chopping
𝑚: Modulation factor 𝑉: Command value voltage 𝐸: Inverter bus voltage
RL78/G1M 120-degree conducting control of permanent magnetic synchronous motor (Implementation)
R01AN5516EJ0100 Rev.1.00 Page 13 of 48
2020.08.01
3.1.5 State transitions
Figure 3-4 shows state transition diagrams of 120-degree conducting control software.
SYSTEM MODE (User System)
INACTIVE
ERROR
POWER ON/
HARDWAE RESET
[INIT ERROR]
RUN MODE (Motor Control)
INIT
STOP
DRIVE
ACTIVE
[ERROR]
[RESET]
STOP
DRIVE
ERROR
RESET
RUN MODE
INIT DRIVE STOP
STOP
INIT INIT
INIT
STOP STOP
DRIVE
STOP
DRIVE
STOP
DRIVE
STOP
EVENT
[HW INIT END]
[RESET EVENT]
[DRIVE EVENT]
[ERROR EVENT]
[STOP EVENT]
[STOP EVENT]
[INIT EVENT]
[ERROR STATUS]
Figure 3-4 – State Transition Diagram 120-degree Conducting Control Software
(1) SYSTEM MODE
“SYSTEM MODE” indicates the operating states of the system. “SYSTEM MODE” has 3 states, which are
motor drive stop (INACTIVE), motor drive (ACTIVE), and abnormal condition (ERROR).
(2) RUN MODE
“RUN MODE” indicates the condition of the motor control. The state is changed by occurrence of “EVENT”.
(3) EVENT
“Event” indicates the change of “RUN MODE”. When “EVENT” occurs, “RUN MODE” changes as shown
table in Figure 3-4. Each “Event” is caused by occurrence as shown in Table 3-4.
Table 3-4 – List of “EVENT”
When the system detects an error
RL78/G1M 120-degree conducting control of permanent magnetic synchronous motor (Implementation)
R01AN5516EJ0100 Rev.1.00 Page 14 of 48
2020.08.01
3.1.6 Start-up method
(1) Hall effect sensor control mode
In the Hall effect sensor control mode, after changing to “MTR_MODE_DRIVE”, the output pattern is
selected from the initial Hall effect sensor signal. Then, voltage is applied and the state is changed to PI
control mode. The rotational speed is calculated after the second hall effect sensor interruption.
Voltage
[V]
RUN MODE
0
0
Reference voltage status
Reference speed status
MTR_SPEED_MANUAl
(1)
Speed
[rad/s]
g_st_120.st_hall_
s2_start_ref_v
g_st_120.s2_ref_speed_rad_ctrl
Speed PI control
MTR_V_PI_OUTPUT
(2)
MTR_V_ZERO_CONST
(0)
MTR_SPEED_ZERO_CONST
(0)
MTR_MODE_DRIVEMTR_MODE_STOP
Figure 3-5 – Start-up sequence (hall effect sensor control mode)
(2) Sensorless control mode
In sensorless control mode, the position of the magnetic poles is estimated every 60 degrees from induced
voltage that is generated from the variation of magnetic flux due to the rotation of the permanent magnet
(rotor). However, since the induced voltage is generated by the rotation, at low speed it is difficult to estimate
the position of the rotor.
Therefore, the method to generate a rotating magnetic field by forcibly switching conducting pattern in the
synchronous speed regardless of the position of the rotor, is often used.
Figure 3-6 shows the start-up method in the sample software. In “MTR_MODE_DRIVE”, at first, the rotor is
drawn in. Second, mode is changed to open-loop drive mode. When reference control speed reaches to
change speed, mode is changed to PI control mode.
Voltage
[V]
RUN MODE
0
0
Reference voltage status
Reference speed status
MTR_SPEED_MANUAl
(1)
Speed
[rad/s]
MTR_V_PI_OUTPUT
(2)
g_st_120.st_less.
s2_ol_ref_v
g_st_120.st_less.
s2_ol2less_speed_rad
g_st_120.s2_ref_speed_rad
Open-loop Speed PI control
g_st_120.st_less.
s2_draw_in_ref_v
MTR_V_MANUAL
(1)
MTR_V_ZERO_CONST
(0)
MTR_SPEED_ZERO_CONST
(0)
MTR_MODE_DRIVEMTR_MODE_STOP
Draw-in
Figure 3-6 – Startup Sequence (Sensorless Control Mode)
RL78/G1M 120-degree conducting control of permanent magnetic synchronous motor (Implementation)
R01AN5516EJ0100 Rev.1.00 Page 15 of 48
2020.08.01
3.1.7 System protection function
This system has the following types of error status and emergency stop functions in case of occurrence of
respective error. Refer to Table 3-5 for settings related to the system protection function.
・Overcurrent error for hardware
When an emergency stop signal (over current detection) from the external hardware is detected, voltage
output is stopped.
・Overvoltage error
The inverter bus voltage is monitored at the overvoltage monitoring cycle. When the inverter bus voltage
exceeds the overvoltage limit, voltage output is stopped. The threshold value of the overvoltage is set in
consideration of the error of resistance value of the detection circuit.
・Low voltage error
The inverter bus voltage is monitored at the low voltage monitoring cycle. When the inverter bus voltage
lowers undervoltage limit, voltage output is stopped. The threshold value of the low voltage is set in
consideration of the error of resistance value of the detection circuit.
・Rotational speed error
The rotational speed is monitored at the rotational speed monitoring cycle. When the rotational speed
exceeds the over speed limit, voltage output is stopped.
・Timeout error
The timeout counter is monitored at the timeout monitoring cycle. When pattern switching by Hall pattern
change in Hall effect sensor control mode or zero-crossing of induced voltage in sensorless control mode
don’t happen for a timeout period, voltage output is stopped.
・Pattern error
The output voltage pattern is monitored at the pattern monitoring cycle. When unexpected pattern is
detected in voltage pattern set from Hall effect sensor in Hall effect sensor control mode or induced
voltage in sensorless control mode, voltage output is stopped.
Table 3-5 – Setting Value of Each System Protection Function
Over voltage error
Overvoltage limit [V]
Under voltage error
Low voltage limit [V]
Rotational speed error
Speed limit [rpm]
Timeout error
Timeout value [ms]