Renesas rl78/g1g User Manual

Page 1
APPLICATION NOTE
R01AN3582EJ0100
Rev.1.00
Jan 13, 2017
RL78/G1G
Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
Summary
This application note aims at explains sample programs driving a permanent magnetic synchronous motor in the 120-
degree conducting method using the RL78/G1G microcontroller.
These control programs are 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 control programs have been checked by using the following device. RL78/G1G (R5F11EBAAFP)
Target control programs
The target control programs of this application note are as follows. RL78G1G_MRSSK_SPM_LESS_120_CSP_CA_V100 (IDECS+ for CA,CX) RL78G1G_MRSSK_SPM_LESS_120_CSP_CC_V100 (IDECS+ for CC) RL78G1G_MRSSK_SPM_LESS_120_E2S_CC_V100 (IDEe2studio)
RL78/G1G Sensorless 120-degree conducting control program for
24V Motor Control Evaluation System and RL78/G1G CPU CARD
Reference
RL78/G1G Group Users Manual: Hardware (R01UH0499EJ0130) Application note: 120-degree conducting control of permanent magnetic synchronous motor: algorithm
(R01AN2657EJ0120)
Renesas Solution Starter Kit 24V Motor Control Evaluation System for RX23T Users Manual
(R20UT3697EJ0100)
R01AN3582EJ0100 Rev.1.00 Page 1 of 46 Jan 13, 2017
Page 2
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
Contents
1. Overview ........................................................................................................................................... 3
2. System overview ............................................................................................................................... 7
3. Descriptions of the control program ................................................................................................ 14
R01AN3582EJ0100 Rev.1.00 Page 2 of 46 Jan 13, 2017
Page 3
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
Microcontroller
Evaluation board
Motor
RL78/G1G
(R5F11EBAAFP)
24V inverter board
(Note 1)
and RL78/G1G CPU Card
(Note 2)
TSUKASA
(Note 3)
TG-55L-KA-24V
CS+ version
Tool chain version
V3.03.00
CA78K0R V5.00.00.03
V4.01.00
CC-RL V1.03.00.00
e2studio version
Tool chain version
5.2.1.016
CC-RL V1.03.00.00

1. Overview

This application note explains how to implement the 120-degree conducting control programs of permanent magnetic synchronous motor (PMSM) using the RL78/G1G microcontroller. Note that this control programs use the algorithm described in the application note 120-degree conducting control of permanent magnetic synchronous motor: algorithm.

1.1 Development environment

Table 1-1 and Table 1-2 show development environment of the control programs explained in this application note.
Table 1-1 Development Environment (H/W)
Table 1-2 Development Environment (S/W)
For purchase and technical support contact, Sales representatives and dealers of Renesas Electronics Corporation.
Notes: 1. 24V inverter board (RTK0EM0006S01212BJ) is a product of Renesas Electronics Corporation.
2. RL78/G1G CPU Card (T5104) is a product of Desk Top Laboratories Inc.
Desk Top Laboratories Inc. (http://desktoplab.co.jp/)
3. TG-55L-KA-24V is a product of TSUKASA ELECTRIC. TSUKASA ELECTRIC. (https://www.tsukasa-d.co.jp/en/)
R01AN3582EJ0100 Rev.1.00 Page 3 of 46 Jan 13, 2017
Page 4
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
R8 (1) Remove
100/0.1W
(2) Connnect
R7
R15 (1) Remove
100/0.1W 0/1A
(1) Remove
C9
C8
100pF /50V/J
100pF /50V/J
2930CNB5 (IU)
CNB15 (VR1)
(2) Connect
(1) Remove

1.2 Modifying the Evaluation Board

To support the control programs in this application note, the 24V Inverter Board and RL78/G1G CPU Card should be
modified per below explanations.

1.2.1 Modification of the VR1 input port

(1) Remove R8, R15, C9. (2) Connect CPU side of R7 and CPU side of R8.
Figure 1-1 Modification of the CPU Card
R01AN3582EJ0100 Rev.1.00 Page 4 of 46 Jan 13, 2017
Figure 1-2 Modification example on the CPU card.
Page 5
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
TH
Q2
TH2
Q4
TH3
Q6
R50
R72
R97
(2) Remove
(1) Connect
(1) Connect
(2) Remove

1.2.2 Modification when overcurrent detection method is changed

When the overcurrent detection method is changed to "PGA+CMP0, CMP1" from default (INTP0), the 24V Inverter
Board and RL78/G1G CPU Card should be modified per below explanations.
(1) Modification of the 24V Inverter Board
Change 3-Shunt to 1-Shunt.
(1) Connect TH1, TH2 and TH3. (2) Remove R72 and R97.
Figure 1-3 Change 3-shunt to 1-shunt
R01AN3582EJ0100 Rev.1.00 Page 5 of 46 Jan 13, 2017
Figure 1-4 Modification example on the 24V Inverter Board
Page 6
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
R8
100/0.1W
R7
R15
100/0.1W 0/1A
R10 (2) Change R16
100/0.1W
NC 0/1A
1k/0.1W (1) Mount
C9
C8 C11
(3) Change
100pF/50V/J
470pF/50V/J
2930CNB5 (IU)
CNB15 (VR1)
CNB7 (IW)
100pF/50V/J
100pF /50V/J
(3) Change
(1) Mount
(2) Change
(2) Modification of the RL78/G1G CPU Card
Modification for the filter circuit of comparator input
(1) Mount 0 Ohms on R16. (2) Change resister R10 from 100 Ohms to 1k Ohms (3) Change capacitor C11 from 100pF to 470pF.
Figure 1-5 Modification of the CPU Card
Figure 1-6 Modification example on the CPU card.
R01AN3582EJ0100 Rev.1.00 Page 6 of 46 Jan 13, 2017
Page 7
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
not used in this system.
LED output
P60
P61
V
dc
VR1
GND
LED1
LED2
Inverter circuit
DC 24V input
Up
Vp
Wp
Un
Vn
Wn
TRD output
P15 / TRDIOB0 (Up)
P13 / TRDIOA1 (Vp) P12 / TRDIOB1 (Wp)
P14 / TRDIOD0 (Un)
P11 / TRDIOC1 (Vn)
P10 / TRDIOD1 (Wn)
Vu
Vv
Vw
Over current
detection input
P01 / PGAI
HV port
HW port
GND port
Vcc port
HU port ENC_Z port
ENC_B
port
ENC_A
port
GND port
Vcc port
U port
V port
W port
PSPM
A/D converter input
P23 / ANI3
P00 / ANI17
P147 / ANI18
P120 / ANI19
P20 / ANI0
Bus voltage
VU_AIN VV_AIN
Speed reference
(Note)
Phase voltage
(filtering)
VW_AIN
SW1
SW2
Switch input
P70
P17
Motor start / stop
Error status reset
Phase voltage
(filtering)
VU_AIN
VV_AIN
VW_AIN
RL78/G1G
P137 / INTP0
OC
Over current detection
(by Hardware) Over current detection
(by PGA+CMP0, CMP1)
Iu
Iv
Iw
Power supply circuit

2. System overview

Overview of this system is explained below.

2.1 Hardware configuration

The hardware configuration is shown below.
Figure 2-1 Hardware Configuration Diagram
Note: the VR1 signal is input to port 20 by modification on the CPU card. (See 1.2.1)
R01AN3582EJ0100 Rev.1.00 Page 7 of 46 Jan 13, 2017
Page 8
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
Item
Interface component
Function
Rotational speed
Variable resistance (VR1)
Rotational speed command value input (analog values)
START / STOP
Toggle switch (SW1)
Motor rotation start / stop command
ERROR RESET
Toggle switch (SW2)
Command of recovery from error status
LED1
Yellow green LED
- At the time of Motor rotation: ON
- At the time of stop: OFF
LED2
Yellow green LED
- At the time of error detection: ON
- At the time of normal operation: OFF
RESET
Push switch (RESET1)
System reset
R5F11EBAAFP Port name
Function
P23 / ANI3
Inverter bus voltage measurement
P01 / PGAI
Shunt current input for over-current detection (use PGA+CMP0, CMP1)
(Note1)
P20 / ANI0
For inputting rotational speed command values (analog values)
(Note2)
P70
START / STOP toggle switch
P17
ERROR RESET toggle switch
P60
LED1 ON / OFF control
P61
LED2 ON / OFF control
P00 / ANI17
U Phase voltage measurement (A/D)
P147 / ANI18
V Phase voltage measurement (A/D)
P120 / ANI19
W Phase voltage measurement (A/D)
P10 / TRDIOD1
PORT output / PWM output (Wn)
P11 / TRDIOC1
PORT output / PWM output (Vn)
P12 / TRDIOB1
PORT output / PWM output (Wp)
P13 / TRDIOA1
PORT output / PWM output (Vp)
P14 / TRDIOD0
PORT output / PWM output (Un)
P15 / TRDIOB0
PORT output / PWM output (Up)
P137 / INTP0
PWM emergency stop input at the time of overcurrent detection (use an external circuit)
(Note1)

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
Table 2-2 is a list of port interfaces of RL78/G1G microcontroller of this system.
Table 2-2 Port Interface
Note: 1. Selection of the external circuit or “PGA+CMP1, CMP0” for the detection of overcurrent is set by
compile option.
2. For details on input port, see "1.2 Modifying the Evaluation Board".
R01AN3582EJ0100 Rev.1.00 Page 8 of 46 Jan 13, 2017
Page 9
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
Peripheral Function
Purpose
10bit A/D converter
- Rotational speed command value input
- Inverter bus voltage measurement
- Voltage of each phase U, V, and W measurement
Timer Array Unit (TAU)
- 1 [ms] interval timer
- Free-running timer for rotational speed measurement
Timer RD (TRD)
Complementary PWM output
Comparator0 (CMP0)
Overcurrent detection
(Note)
Comparator1 (CMP1)
Overcurrent detection
(Note)
Programmable Gain Amp (PGA)
Overcurrent detection
(Note)
External Interrupt (INTP0)
Overcurrent detection
(Note)

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
Note: INTP0 and “PGA+CMP0, CMP1are used exclusive. (These are selectable by compile option.)
(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’.
The operation mode is set as below. The channel selection mode: the select-mode.
The conversion operation mode: the one-shot conversion mode. And software trigger is used.
(2) Timer Array Unit (TAU)
a. 1 [ms] interval timer
The channel 0 of Timer Array Unit (TAU) is used as 1 millisecond interval timer.
b. Free-running timer for measuring speed
The channel 1 of Timer Array Unit (TAU) is used as free-running timer for speed measurement. Note that interrupt is not used.
(3) Timer RD (TRD)
Three-phase PWM output of chopping at the first 60 degrees with dead time (complementary) or without dead time (non-complementary) is performed using the Complementary PWM Mode. When detecting an overcurrent, the PWM output ports are set to high impedance output using the pulse output forced cutoff function.
(4) Comparator0 (CMP0)
CMP0 is used to detect overcurrent with PGA (detect falling edge) (when selected).
(5) Comparator1 (CMP1)
CMP1 is used to detect overcurrent with PGA (detect rising edge) (when selected).
R01AN3582EJ0100 Rev.1.00 Page 9 of 46 Jan 13, 2017
Page 10
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
(6) Programmable Gain Amp (PGA)
PGA is used to detect overcurrent with CMP0, CMP1 (when selected).
(7) External interrupt (INTP0)
An overcurrent is detected by an external circuit. (when selected).
R01AN3582EJ0100 Rev.1.00 Page 10 of 46 Jan 13, 2017
Page 11
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
Project
Folder
File
Content
RL78G1G_MRSSK_ SPM_LESS_120_C SP_CA_V100
RL78G1G_MRSSK_ SPM_LESS_120_C SP_CC_V100
RL78G1G_MRSSK_ SPM_LESS_120_E 2S_CC_V100
inc
main.h
Main function, user interface control header
mtr_common.h
Common definition header
mtr_ctrl_mrssk.h
Board dependent processing part header
mtr_ctrl_rl78g1g.h
RL78/G1G dependent processing part header
mtr_spm_less_120.h
Sensorless 120-degree conducting control dependent part header
control_parameter.h
Control characteristic dependent processing part header
motor_parameter.h
Motor characteristic dependent processing part header
mtr_ctrl_rl78g1g_mrssk.h
RL78/G1G and board dependent processing part header
mtr_feedback.h
Feedback control processing part header
mtr_gmc.h
General motor control function part header
mtr_driver_access.h
Driver access function on part header
mtr_filter.h
Filters processing part header (not used)
lib
R_dsp_rl78_CA.lib
Digital signal controller library for CA tool-chain
(Note)
R_dsp_rl78_CC.lib
Digital signal controller library for CC-RL tool-chain
(Note)
src
main.c
Main function, user interface control
mtr_ctrl_mrssk.c
Board dependent processing part
mtr_ctrl_rl78g1g.c
RL78/G1G dependent processing part
mtr_interrupt.c
Interrupt handler
mtr_spm_less_120.c
Sensorless 120-degree conducting control dependent part
mtr_ctrl_rl78g1g_mrssk.c
RL78/G1G and board dependent processing part
mtr_feedback.c
Feedback control processing
mtr_gmc.c
General motor control function
mtr_driver_access.c
Driver access function
mtr_filter.c
Filters processing (not used)

2.3 Software structure

2.3.1 Software file structure

The folder and file configurations of the control programs are given below.
Table 2-4 Folder and File Configuration
Notes: R_dsp_rl78_CA.lib is included only in RL78G1G_MRSSK_SPM_LESS_120_CSP_CA_V100.
R_dsp_rl78_CC.lib is included in RL78G1G_MRSSK_SPM_LESS_120_CSP_CC_V100 and RL78G1G_MRSSK_SPM_LESS_120_E2S_CC_V100.
R01AN3582EJ0100 Rev.1.00 Page 11 of 46 Jan 13, 2017
Page 12
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
Layers
File name
Application layer
main.c
Motor control layer
mtr_spm_less_120.c mtr_feedback.c mtr_gmc.c mtr_filter.c mtr_driver_access.c mtr_interrupt.c
(Note)
H/W control layer
mtr_ctrl_rl78g1g_mrssk.c mtr_ctrl_rl78g1g.c mtr_ctrl_mrssk.c mtr_interrupt.c
(Note)
Application layer
User application
H/W control layer
Microcontroller dependent processing part,
Inverter board dependent processing part
H/W
Inverter board, microcontroller
Motor control layer
Motor-control-processing-part

2.3.2 Module configuration

Figure 2-2 and Table 2-5 show module configuration of the control programs.
Figure 2-2 Module Configuration
Table 2-5 Module Configuration
Note: “mtr_interrupt.c” is belong to the motor control layer and H/W control layer.
R01AN3582EJ0100 Rev.1.00 Page 12 of 46 Jan 13, 2017
Page 13
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
Item
Content
Control method
120-degree conducting method (chopping at the first 60 degrees) (Complementary / Non-Complementary)
Motor rotation start / stop
Determined depending on the level of SW1 (P70) (”Low”: rotation start “High”: stop)
Position detection of rotor magnetic pole
Position detection by induced voltage with A/D converters. (by 60 degrees) Input voltage
DC24[V]
Main clock frequency
CPU clock: f
CLK
24[MHz]
TRD clock: f
HOCO
48[MHz]
Carrier frequency (PWM)
20 [kHz]
Dead time
2 [μs]
Control cycle
Speed PI control: every 1 [ms]
Rotational speed control range
1200 [rpm] to 2650 [rpm] Both CW and CCW are supported
Optimization
Default
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 3500 rpm (monitored per 1 [ms])
4. At the time of sensorless drive, zero-crossing is not detected for 50 [ms].
5. Fault detection of virtual Hall sensor pattern (position information)
- The ports executing PWM output are set to high impedance state when an overcurrent is detected by external circuit (low level edge input occurs in INTP0 port) or by internal PGA+CMP0, CMP1.

2.4 Software specifications

Table 2-6 shows the basic software specification of this system. For details of 120-degree conducting control, refer to
the application note 120-degree conducting control of permanent magnetic synchronous motor: algorithm.
Table 2-6 Basic Specifications of Software
R01AN3582EJ0100 Rev.1.00 Page 13 of 46 Jan 13, 2017
Page 14
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
Item
Conversion ratio (Command value: A/D conversion value)
Channel
Rotational speed command value
CW
0 rpm to 3072 rpm: 0200H to 03FFH
ANI0
(Note)
CCW
-3072 rpm to 0 rpm: 0000H to 01FFH
Item
Conversion ratio (Inverter bus voltage: A/D conversion value)
Channel
Inverter bus voltage
0 V to 111 V: 0000H to 03FFH
ANI3
Item
Conversion ratio (U, V, and W phase voltage: A/D conversion value)
Channel
U, V, W phase voltage
0 V to 111 V: 0000H to 03FFH
ANI17, ANI18, ANI19

3. Descriptions of the control program

The target control 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 SW1 & VR1.
A general-purpose port is assigned to SW1. The port is read within the main loop. When the port is at a “Low” level, it is determined that the start switch is being pressed. Conversely, when the level is switched to “High”, the program determines that the motor should be stopped.
Also, 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 command value is less than 1200 [rpm], the program determines that the motor should be stopped.

3.1.2 A/D Converter

(1) Motor rotational speed command value
The motor rotational speed command value can be set by 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.
The maximum of the command value is set as the value from which maximum rotational speed is generated by the
resolution of the A/D converter.
Table 3-1 Conversion Ratio of the Rotational Speed Command Value
Note: The input channel is ANI0 because the CPU card which is modified as a VR1 signal is input to port 20.
(2) Inverter bus voltage
Inverter bus voltage is measured as given in Table 3-2. It is used for modulation factor calculation and over/under
voltage detection. (When an abnormality is detected, PWM is stopped).
Table 3-2 Inverter Bus Voltage Conversion Ratio
(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 used for determining zero-crossing.
Table 3-3 Conversion Ratio of U, V, and W Phase Voltage
For more details of A/D conversion characteristics, refer to RL78/G1G User’s Manual: Hardware.
R01AN3582EJ0100 Rev.1.00 Page 14 of 46 Jan 13, 2017
Page 15
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
Pattern created from
U phase induced voltage
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)
Pattern created from
V phase induced voltage
Pattern created from
W phase induced voltage
2p
2p
 󰇛

󰇜󰇛 󰇜
: Voltage command value : Speed command value : Rotational speed

: Speed PI proportional gain : Speed PI integral gain : Laplace operator

3.1.3 Speed control

In this system, the motor rotational speed is calculated from a difference of the current timer value and the timer value 2π [rad] before. The timer values are obtained when patterns are switched after zero-crossing detection, while having the timer of Timer Array Unit (TAU) channel 1 performed free running.
Figure 3-1 Method of Calculation for Rotational Speed
The control program uses PI control for speed control. A voltage command value is calculated by the following formula of speed PI control.
For more details of PI control, please refer to specialized books.
R01AN3582EJ0100 Rev.1.00 Page 15 of 46 Jan 13, 2017
Page 16
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
Average
voltage
t
V
T
ON
T
OFF
T
ON
+ T
OFF
T
ON
Duty = × 100 [%]
E
V
m
U+
V+
W+
U­V-
W-
m: Modulation factor V: Command value voltage E: Inverter bus voltage

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.
Figure 3-2 PWM Control
Modulation factor m is defined as follows.
This modulation factor is reflected in the setting value of the register that determines the PWM duty.
In the target control program, first-60-degree chopping is used to control the output voltage and speed. Figure 3-3 shows an example of motor control signal output waveforms at Non-complimentary first-60-degree chopping. Figure 3-4 shows an example of motor control signal output waveforms at Complimentary first-60-degree chopping.
Figure 3-3 Non-complimentary first-60-degree Chopping
R01AN3582EJ0100 Rev.1.00 Page 16 of 46 Jan 13, 2017
Page 17
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
U+
V+
W+
U-
V-
W-
Figure 3-4 Complimentary first-60-degree Chopping
R01AN3582EJ0100 Rev.1.00 Page 17 of 46 Jan 13, 2017
Page 18
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
SYSTEM MODE
INACTIVE
ERROR
POWER ON/
RESET
[RESET EVENT]
[ACTIVE EVENT]
[INACTIVE EVENT]
[ERROR EVENT]
RUN MODE
INIT
BOOT
Configuration
Control
Cu r re nt
Sp e e d
Po s iti o n
To r q ue
Vol t age
Method
FO C
18 0
WI D E
12 0
Sensor
Le s s
Hall
En c o de r
Re s o lve r
Configuration
Control
Cu r re nt
Sp e e d
Po s iti o n
To r q ue
Vol t age
Method
Sensor
Le s s
Hall
En c o de r
Re s olve r
DRIVE
ACTIVE
[MTR_DRAW_IN_FINISH ==
g_u1_state_draw_in]
[MTR_VOFF_SET_STATUS_FINISH ==
g_u1_state_v_offset]
[ERROR EVENT]
[RESET EVENT]
FO C
18 0
WI D E
12 0
INACTIVE
ACTIVE
ERROR
RESET
SYSTEM MODE
INACTIVE ACTIVE ERROR
INACTIVE
INACTIVE INACTIVE
ACTIVE
ERROR ERROR
ERROR
ERROR
ERROR
INACTIVE
ACTIVE
ERROR
[MTR_V_PI_OUTPUT
== g_u2_state_voltage_ref]
EVENT
EVENT name
Occurrence factor
INACTIVE
by user operation
ACTIVE
by user operation
ERROR
when the system detects an error
RESET
by user operation

3.1.5 State transition

Figure 3-5 shows state transition diagrams of sensorless 120-degree conducting control software.
Figure 3-5 State Transition Diagram of Sensorless 120-degree Conducting Control Software
(1) SYSTEM MODE
“SYSTEM MODE” indicates the operating states of the system. The state transits on occurrence of each event (EVENT). “SYSTEM MODE” has 3 states that are motor drive stop (INACTIVE), motor drive (ACTIVE), and
abnormal condition (ERROR).
(2) RUN MODE
“RUN MODE” indicates the condition of the motor control. “RUN MODE” transits sequentially as shown in Figure 3-5 when “SYSTEM MODE” is “ACTIVE”.
(3) EVENT
When “EVENT” occurs in each “SYSTEM MODE”, “SYSTEM MODE” changes as shown table in Figure 3-5, per that “EVENT”.
Table 3-4 List of EVENT
R01AN3582EJ0100 Rev.1.00 Page 18 of 46 Jan 13, 2017
Page 19
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
MTR_V_OPENLOOP
(3)
Voltage
[V]
RUN MODE
0
0
Voltage reference status
Speed reference status
MTR_SPEED_OPENLOOP_1
(1)
Speed
[rad/s]
MTR_MODE_DRIVE
MTR_OL_MODE1_CHANGE_RPM
MTR_SPEEDOPEN_LOOP_2
(2)
MTR_SPEED_OPENLOOP3
(3)
MTR_SPEED_CHANGE
(4)
MTR_V_PI_OUTPUT
(4)
MTR_OL_START_REFV
MTR_OL_MODE2_CHANGE_RPM
g_u2_ref_speed_rad
Openloop Speed PI control
MTR_OL_MODE3_MAX_REFV
MTR_BOOT_REF_V
MTR_V_UP
(1)
MTR_V_UP
(1)
MTR_V_CONST
(2)
MTR_V_CONST
(2)
MTR_V_ZERO_CONST
(0)
MTR_SPEED_ZERO_CONST
(0)
MTR_MODE_BOOTMTR_MODE_INIT

3.1.6 Start-up method

In Sensorless 120-degree conducting control, the position of the magnetic poles (the rotor) is estimated every 60 degrees per the induced voltage which is generated the change of magnetic flux due to the rotation of the permanent magnet (rotor). However, the induced voltage is not generated when the rotor doesn’t move. Therefore, it is impossible to estimate the position of the rotor at start-up, and enough rotational speed is necessary to estimate the position of the rotor (because the induced voltage cannot be caught without enough speed).
Therefore, as a start-up method, there is a method to lead the synchronous speed by generating a rotating magnetic field by forcibly switching conduction patterns regardless of position of the permanent magnet.
Figure 3-6 shows the start-up method in the control program. In “MTR_MODE_BOOT”, the rotor is drawn in and the overcurrent at start-up is prevented.
Figure 3-6 Start-up Method (Example)
R01AN3582EJ0100 Rev.1.00 Page 19 of 46 Jan 13, 2017
Page 20
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
Threshold value
Comparator internal reference setting
Channel
PGA Gain
CMP1: 2 [A]
CMP1: 120
PGA out
× 4 is selected CMP0: -2 [A]
CMP0: 83

3.1.7 System protection function

This system has the following types of error status and enables emergency stop functions in case of occurrence of
respective error. Refer to Table 3-5, Table 3-6 for settings.
- Overcurrent error
The overcurrent is detected with the method using the external circuit or the method using the internal PGA+CMP0,
CMP1. Using method is selectable by a compile option.
a. External hardware
High impedance output is made to the PWM output port in response to an emergency stop signal (overcurrent
detection) from the hardware.
b. Internal PGA+CMP0, CMP1
High impedance output is made to the PWM output port in response to an emergency stop signal (overcurrent
detection) from the internal PGA+CMP0, CMP1 detection.
The setting of PGA+CMP0, CMP1 are given below.
Table 3-5 Setting for overcurrent detection
- Overvoltage error
The inverter bus voltage is monitored at the overvoltage monitoring cycle. When an over voltage is detected (when the voltage exceeds the limit), CPU performs an emergency stop. 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 under voltage monitoring cycle. When an under voltage is detected (when the voltage lowers the limit), CPU performs an emergency stop. 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 speed exceeds the limit, CPU performs an emergency stop.
- Timeout error of zero-cross detection
When no pattern switching is happened by zero-crossing during timeout period, CPU performs an emergency stop.
- Virtual Hall sensor pattern (position information) error
When an error is detected in virtual Hall sensor patterns (position information) generated from each of U, V, and W phase voltage, CPU performs an emergency stop.
R01AN3582EJ0100 Rev.1.00 Page 20 of 46 Jan 13, 2017
Page 21
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
Error name
Threshold
Overcurrent error
(Note)
Overcurrent limit [A]
±2.0
Overvoltage error Overvoltage limit [V]
28
Monitoring cycle [ms]
1
Low voltage error Under voltage limit [V]
15
Monitoring cycle [ms]
1
Rotational speed error Speed limit [rpm]
3500
Monitoring cycle [ms]
1
Timeout error of zero-cross detection
Timeout value [ms]
50
Table 3-6 Setting Value of Each System Protection Function
Note: The threshold when detecting an overcurrent by PGA+CMP0,1.
R01AN3582EJ0100 Rev.1.00 Page 21 of 46 Jan 13, 2017
Page 22
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
File name
Function name
Process overview
main.c
main Input: None
Output: None
- Hardware initialization function call
- User interface initialization function call
- Initialization function call of the variables used in the main process
- Waiting for stability of the bus voltage function call
- Status transition and event execution function call
- Main process
User interface call Watchdog timer clear function call
board_ui Input: None
Output: None
- Motor status change
- Determination of rotational speed command value
software_init Input: None
Output: None
Initialization of variables used in the main process
File name
Function name
Process overview
mtr_ctrl_mrssk.c
R_MTR_ChargeCapacitor Input: None Output: None
Wait for stability of the bus voltage
get_vr1 Input: None Output: (uint16) u2_ad_data / A/D conversion result
VR1 status acquisition
get_sw1 Input: None Output: (uint8) u1_temp / SW1 level
SW1 status acquisition
get_sw2 Input: None Output: (uint8) u1_temp / SW2 level
SW2 status acquisition
led1_on Input: None
Output: None
Turning LED1 ON
led2_on Input: None
Output: None
Turning LED2 ON
led1_off Input: None
Output: None
Turning LED1 OFF
led2_off Input: None
Output: None
Turning LED2 OFF

3.2 Function specifications of 120-degree conducting control software

Multiple control functions are used in this control program. However, functions which are not used in this system are
undescribed.
Table 3-7 List of Functions “main.c”
Table 3-8 List of Functions “mtr_ctrl_mrssk.c”
R01AN3582EJ0100 Rev.1.00 Page 22 of 46 Jan 13, 2017
Page 23
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
File name
Function name
Process overview
mtr_ctrl_rl78g1g.c
R_MTR_InitHardware Input: None Output: None
Initialization of the clock and peripheral functions
mtr_init_clock Input: None Output: None
Initialization of clock
mtr_init_tau Input: None Output: None
Initialization of the Timer Array Unit (TAU)
mtr_init_intp Input: None Output: None
Initialization of external interrupt
mtr_init_cmp_pga Input: None Output: None
Initialization of Comparator0,1 and PGA
clear_wdt Input: None Output: None
Clear the watchdog timer (WDT)
mtr_clear_oc_flag Input: None Output: None
Clear the high impedance state
mtr_clear_trd0_imfa Input: None Output: None
Clear the Compare Match Timer A (IMFA)
File name
Function name
Process overview
mtr_ctrl_rl78g1g_mrssk.c
mtr_init_trd Input: None
Output: None
Initialization of Timer RD (TRD)
mtr_init_ad_converter Input: None
Output: None
Initialization of the A/D converter
init_ui Input: None Output: None
Initialization of user interface
mtr_ctrl_stop Input: None Output: None
Motor stop processing
mtr_change_pattern Input: (uint8) u1_pattern / conduction pattern
Output: None
- Change conduction pattern
- Set PWM duty
mtr_get_adc Input: (uint8) u1_ad_ch / target A/D conversion channel
Output: (int16) s2_temp / A/D conversion value
Get A/D conversion value
Table 3-9 List of Functions “mtr_ctrl_rl78g1g.c”
Table 3-10 List of Functions “mtr_ctrl_rl78g1g_mrssk.c”
R01AN3582EJ0100 Rev.1.00 Page 23 of 46 Jan 13, 2017
Page 24
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
File name
Function name
Process overview
mtr_driver_access.c
R_MTR_SetSpeed Input: (uint16) u2_ref_speed / speed command value Output: None
Set the speed command value
R_MTR_SetDir Input: (uint8) u1_dir / rotation direction Output: None
Set the rotation direction
R_MTR_GetSpeed Input: None Output: (uint16) u2_speed_rpm / rotational speed
Obtain the calculated rotational speed
R_MTR_GetDir Input: None Output: (uint8) g_u1_direction / rotation direction
Obtain the rotation direction
R_MTR_GetStatus Input: None Output: (uint8) g_u1_mode_system / motor status
Obtain the motor status
File name
Function name
Process overview
mtr_feedback.c
mtr_pi_ctrl Input: (MTR_PI_CTRL*) pi_ctrl / PI control structure Output: (int16) s2_ref / PI control output value
PI control
Table 3-11 List of Functions “mtr_driver_access.c”
Table 3-12 List of Functions “mtr_feedback.c”
R01AN3582EJ0100 Rev.1.00 Page 24 of 46 Jan 13, 2017
Page 25
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
File name
Function name
Process overview
mtr_gmc.c
mtr_get_vdc Input: None Output: (int16) s2_temp / the bus voltage value
Obtain the bus voltage
mtr_check_over_voltage_error Input: (int16) s2_vdc / bus voltage value
(int16) s2_limit_voltage / over voltage limit
Output: (uint16) u2_temp0 / over voltage error flag (when error happens)
Check over voltage error
mtr_check_under_voltage_error Input: (int16) s2_vdc / bus voltage value
(int16) s2_limit_voltage / under voltage limit
Output: (uint16) u2_temp0 / under voltage error flag (when error happens)
Check low voltage error
mtr_check_over_speed_error Input: (uint16) u2_speed_rad / rotational speed
(uint16) u2_speed_limit / speed limit
Output: (uint16) u2_temp0 / over speed error flag (when error happens)
Check over speed error
mtr_get_duty Input: (volatile int16) s2_v_ref / reference voltage
(volatile int16) s2_vdc_ad / bus voltage A/D conversion value
Output: (int16) s2_temp / rate of PWM duty
Calculate PWM duty
mtr_generate_pattern Input: (uint16) u2_vu_ad / U phase voltage A/D conversion value
(uint16) u2_vv_ad / V phase voltage A/D conversion value (uint16) u2_vw_ad / W phase voltage A/D conversion value (uint16) u2_vn_ad / 3 phase average A/D conversion value
Output: (uint8) u1_temp / pseudo Hall sensor pattern
Generate pseudo Hall sensor pattern
mtr_check_timeout_error Input: (uint16) u2_cnt_timeout / counter of timeout
(uint16) u2_timeout_limit / timeout limit
Output: (uint16) u2_temp0 / flag of timeout error (when error happens)
Check timeout error
Table 3-13 List of Functions “mtr_gmc.c”
R01AN3582EJ0100 Rev.1.00 Page 25 of 46 Jan 13, 2017
Page 26
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
File name
Function name
Process overview
mtr_interrupt.c
mtr_oc_intp0_interrupt Input: None
Output: None
Overcurrent detection process (Hardware detection)
- Disable INTP0 interrupt servicing
- Event processing selection function call (Generate error event)
- Changing the motor status (Set the flag of error about overcurrent)
mtr_oc_cmp0_interrupt Input: None Output: None
Overcurrent detection process (CMP0 interrupt)
- Disable CMP0, CMP1 interrupt servicing
- Event processing selection function call (Generate error event)
- Changing the motor status (Set the flag of error about overcurrent)
mtr_oc_cmp1_interrupt Input: None Output: None
Overcurrent detection process (CMP1 interrupt)
- Disable CMP0, CMP1 interrupt servicing
- Event processing selection function call (Generate error event)
- Changing the motor status (Set the flag of error about overcurrent)
mtr_carrier_interrupt Input: None Output: None
Calling every 50 [μs]
- Measure invertor bus voltage
- Measure voltage of each phase and cancel offset
- Calculate pseudo center voltage
- Detect zero-cross
- Calculate the rotational speed
- Set delay to change pattern
- Change pattern per pseudo Hall pattern call
- Drive process for open loop call
- Clearing compare match flag A function call
mtr_1ms_interrupt Input: None
Output: None
Calling every 1 [ms]
- Run mode management
Setting speed reference Setting voltage reference Setting PWM duty
- Error check function call
- Motor stop detection function call
Table 3-14 List of Functions “mtr_interrupt.c”
R01AN3582EJ0100 Rev.1.00 Page 26 of 46 Jan 13, 2017
Page 27
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
File name
Function name
Process overview
mtr_spm_less_120.c
R_MTR_InitSequence Input: None Output: None
Initialization of the sequence process
R_MTR_ExecEvent Input: (uint8) u1_event / occurred event Output: None
- Change the status
- Call an appropriate process execution
function for the occurred event
mtr_act_active Input: (uint8) u1_state / motor status Output: (uint8) u1_state / motor status
Enable PWM output
mtr_act_inactive Input: (uint8) u1_state / motor status Output: (uint8) u1_state / motor status
Disable PWM output
mtr_act_none Input: (uint8) u1_state / motor status Output: (uint8) u1_state / motor status
No process is performed.
mtr_act_reset Input: (uint8) u1_state / motor status Output: (uint8) u1_state / motor status
Global variables initialization
mtr_act_error Input: (uint8) u1_state / motor status Output: (uint8) u1_state / motor status
Call motor control stop function
mtr_ol_signal_set Input: None Output: (uint8) u1_pattern / forced conduction pattern
Set conduction pattern at open loop mode
mtr_pattern_set Input: (uint8) u1_pattern / conduction pattern Output: None
- Clear counter for timeout error
- Set conduction pattern
mtr_speed_calc Input: None Output: None
Speed calculation process with a detection of zero-cross
mtr_start_init Input: None Output: None
Initialize the variables required at motor start-up
mtr_error_check Input: None Output: None
Error monitoring
mtr_wait_motorstop Input: None Output: None
Check motor stop
mtr_drive_openloop Input: None Output: None
Change pattern forcedly at open loop
mtr_set_voltage_ref Input: None Output: None
Set reference voltage
mtr_set_speed_ref Input: None Output: None
Set reference speed
mtr_measure_voltage_offset Input: None Output: None
- Measure the offset of voltage
- Cancel the offset of voltage
Table 3-15 List of Functions “mtr_spm_less_120.c” [1/2]
R01AN3582EJ0100 Rev.1.00 Page 27 of 46 Jan 13, 2017
Page 28
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
File name
Function name
Process overview
mtr_spm_less_120.c
mtr_draw_in_signal_set Input: None Output: None
Set the conduction pattern at draw in the rotor
mtr_set_angle_shift Input: None Output: None
Calculate the counts for phase shift based on the detection of zero-cross
mtr_check_pattern Input: None Output: None
Check the validity of zero-cross which is detected
mtr_pattern_first60 Input: (uint8) u1_pattern / conduction pattern
Output: None
Set voltage pattern non-complementary first 60 degree PWM
mtr_pattern_first60_comp Input: (uint8) u1_pattern / conduction pattern
Output: None
Set voltage pattern complementary first 60 degree PWM
Table 3-16 List of Functions “mtr_spm_less_120.c” [2/2]
R01AN3582EJ0100 Rev.1.00 Page 28 of 46 Jan 13, 2017
Page 29
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
Variable name
Type
Scale
Content
Remarks
g_u2_max_speed_rpm
uint16
Rotational speed command maximum value
Mechanical angle [rpm]
g_u2_min_speed_rpm
uint16
Rotational speed command minimum value
Mechanical angle [rpm]
g_u2_margin_min_speed_rpm
uint16
Rotational speed command minimum value for motor stop
Mechanical angle [rpm] g_u2_ref_speed_rpm
uint16
User setting rotational speed
Mechanical angle [rpm]
g_u1_rot_dir
uint8 - User setting rotation direction
0: CW 1: CCW
g_u1_motor_status
uint8 - User motor status management
0: Stop 1: Rotating 2: Error
g_u1_reset_req
uint8 - Reset request flag
0: Turning SW2 ON in error status 1: Turning SW2 OFF in error status
g_u1_sw1_cnt
uint8 - SW1 determination counter
Chattering removal
g_u1_sw2_cnt
uint8 - SW2 determination counter
Chattering removal
g_u1_stop_req
uint8 - VR1 stop command flag
g_s2_v_ref
int16
Q7
Voltage command value
Speed PI control output value [V]
g_s2_vdc_ad
int16
Q7
Inverter bus voltage A/D value
[V]
g_u2_pwm_duty
uint16
PWM duty
g_u2_ref_speed_rad
uint16
Q3
Speed reference (user selected) value
Electrical angle [rad/s] g_u2_speed_rad
uint16
Q3
Measured rotational speed
Electrical angle [rad/s]
g_s2_speed_lpf_k
int16
Q14
Speed LPF parameter
st_speed
MTR_PI _CTRL
Structure for speed PI control g_u2_vu_ad
uint16
U phase voltage A/D value
g_u2_vv_ad
uint16
V phase voltage A/D value
g_u2_vw_ad
uint16
W phase voltage A/D value
g_u2_vn_ad
uint16
Three-phase voltage average A/D value
g_u2_cnt_ol_ctrl
uint16
Counter for open-loop process

3.3 List of variables of sensorless 120-degree conducting control software

Lists of variables used in this control program are given below. However, note that the local variables are not
mentioned.
In the control programs in this application note use fixed-point calculation. Therefore, some variables are already established with fixed-point calculation. Bits number in fractional part of fixed-point number is expressed in the Q format. For example, a "Q3" number has 3 fractional bits. "Qn" number is indicated on "Scale" column in below table.
Table 3-17 List of variables [1/4]
R01AN3582EJ0100 Rev.1.00 Page 29 of 46 Jan 13, 2017
Page 30
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
Variable name
Type
Scale
Content
Remarks
g_u2_run_mode
uint16
Operation mode management
0x00: Initialize mode 0x01: Boot mode 0x02: Drive mode 0x03: Analysis mode 0x04: Tune mode
g_u2_error_status
uint16
Error status management
0x00: None error 0x01: Overcurrent error 0x02: Over voltage error 0x04: Over speed error 0x08: Hall signal time out error 0x10: BEMF time out error 0x20: Hall pattern error 0x40: BEMF pattern error 0x80: Under voltage error 0xFF: Undefined error
g_u1_mode_system
uint8 - State management
0x00: Inactive mode 0x01: Active mode 0x02: Error mode
g_u1_state_v_offset
uint8 - State management of voltage offset process
0x00: None 0x01: Measure with PWM off 0x02: Measure with PWM on 0x03: Finish measurement
(Reflect offset value)
g_u1_state_draw_in
uint8 - State management of draw-in at start-up
0x00: None 0x01: Draw-in 1st time 0x02: Draw-in 2nd time 0x03: Finish
g_u2_state_voltage_ref
uint16
State management of voltage setting
0: Voltage zero 1: Increase voltage 2: Voltage constant 3: Open loop 4: PI output
g_u2_state_speed_ref
uint16
State management of speed setting
0: Speed zero 1: Open loop mode1 2: Open loop mode2 3: Open loop mode3 4: Speed controlled
g_u2_sensor_conf
uint16
Sensor configuration
0x01: Sensorless 0x02: Hall sensor 0x04: Encoder 0x08: Resolver
g_u2_method_conf
uint16
Control method configuration
0x00: FOC (Fields Oriented Control) 0x01: 180 degree control
0x02: Wide angle electricity control 0x03: 120 degree control
Table 3-18 List of variables [2/4]
R01AN3582EJ0100 Rev.1.00 Page 30 of 46 Jan 13, 2017
Page 31
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
Variable name
Type
Scale
Content
Remarks
g_u2_ctrl_conf
uint16
Control configuration
0x01: Current control 0x02: Speed control 0x04: Position control 0x08: Torque control 0x10: Voltage control
g_u1_cnt_speed_pi
uint8 - Decimation counter for speed PI control function call
g_u1_flg_wait_stop
uint8 - Flag to wait motor rotation stop
0x00: motor stopped 0x01: waiting motor stop
g_u1_flag_charge_cap
uint8 - Flag of finish capacitor charge
g_u2_ref_speed_rad_ctrl
uint16
Q3
Speed command value
Electrical angle [rad/s]
g_s2_kp_speed
int16
Q16
Speed PI control proportional gain
g_s2_ki_speed
int16
Q22
Speed PI control integral gain
g_s2_lim_v
int16
Q7
Limit of speed PI control
[V]
g_s4_ilim_v
int32
Q26
Limit for integral part of speed PI control
[V]
g_s2_limit_speed_change
int16
Q3
Increase step of speed command
Electrical angle [rad/s]
g_s2_ol_freq
int16 - Frequency of open loop
[Hz]
g_u2_cnt_zerocross
uint16
Counter to start speed calculation
g_s2_ol_speed_rpm
int16 - Speed of open loop
Mechanical angle [rpm]
g_u2_cnt_ol_pattern_set
uint16
Counter for open loop
g_s2_ol_start_rpm
int16 - Start speed of open loop
Mechanical angle [rpm]
g_s2_ol_mode1_change_rpm
int16 - Change speed of open loop mode1
Mechanical angle [rpm]
g_s2_ol_mode2_change_rpm
int16 - Change speed of open loop mode2
Mechanical angle [rpm]
g_s2_ol_start_refv
int16
Q7
Reference voltage of start open loop
[V]
g_s2_ol_mode1_rate_rpm
int16 - Increase step of speed at open loop mode1
Mechanical angle [rpm]
g_s2_ol_mode2_rate_refv
int16
Q7
Increase step of voltage at open loop mode2
[V]
g_s2_ol_mode2_rate_rpm
int16 - Increase step of speed at open loop mode2
Mechanical angle [rpm]
g_s2_ol_mode3_rate_refv
int16
Q7
Increase step of voltage at open loop mode3
[V]
g_s2_ol_mode3_max_refv
int16
Q7
Maximum voltage of open loop3
[V]
g_s2_ol_start_freq
int16 - Start frequency of open loop
[Hz]
g_s2_ol_mode1_change_freq
int16 - Change frequency of open loop mode1
[Hz]
g_s2_ol_mode2_change_freq
int16 - Change frequency of open loop mode2
[Hz]
g_u2_cnt_draw_in
uint16
Counter for draw-in
g_s2_boot_ref_v
int16
Q7
Voltage reference at draw-in
[V]
g_u2_v_up_time
uint16
Time to increase voltage step at draw-in
g_s2_v_up_step
int16 - Voltage step at draw-in
g_u2_v_const_period
uint16
Period of constant voltage at draw-in
[ms]
g_u1_bemf_signal
uint8 - Pseudo Hall pattern generated
g_u1_pre_bemf_signal
uint8 - Previous Hall pattern generated
g_u1_v_pattern
uint8 - Conduction pattern
g_u1_flag_pattern_change
uint8 - Zero-cross detection flag
g_u2_cnt_timeout
uint16
Counter for timeout
g_u1_direction
uint8 - Rotation direction
CW: 0 CCW: 1
g_u2_motor_pp
uint16
Motor pole pairs
Table 3-19 List of variables [3/4]
R01AN3582EJ0100 Rev.1.00 Page 31 of 46 Jan 13, 2017
Page 32
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
Variable name
Type
Scale
Content
Remarks
g_u2_bemf_timer_cnt
uint16
Free run timer count
g_u2_pre_bemf_timer_cnt
uint16
Previous free run timer count
g_u2_timer_cnt_sum
uint16
Sum of free runt timer count as 2π
g_u2_timer_cnt_buf[6]
uint16
Free run timer count buffer for 6 times
g_u1_timer_cnt_num
uint8 - Counter for g_u2_timer_cnt_buf
g_u2_bemf_delay
uint16
Delay counts for change pattern from the zero­cross detected
g_s2_angle_shift_adjust
int16 - Adjustment value for delay from zero-cross detected
g_u2_cnt_carrier
uint16
Carrier cycle interruption counter
g_u2_pre_cnt_carrier
uint16
Previous carrier interruption counter value
g_u1_v_pattern_num
uint8 - Control number for forced conduction pattern at open loop
g_u1_v_pattern_open[2][7]
uint8 - Array of forced conduction patterns at open loop
g_u2_offset_calc_time
uint16
Counts for measurement of voltage offset
g_u2_offset_calc_cnt
uint16
Counter for measurement of voltage offset
g_u2_offset_vu
uint16
Voltage offset value of U phase at PWM on
g_u2_offset_vv
uint16
Voltage offset value of V phase at PWM on
g_u2_offset_vw
uint16
Voltage offset value of W phase at PWM on
g_u2_offset_off_vu
uint16
Voltage offset value of U phase at PWM off
g_u2_offset_off_vv
uint16
Voltage offset value of V phase at PWM off
g_u2_offset_off_vw
uint16
Voltage offset value of W phase at PWM off
g_u2_sum_vu_ad
uint16
Sum of voltage offset value of U phase
g_u2_sum_vv_ad
uint16
Sum of voltage offset value of V phase
g_u2_sum_vw_ad
uint16
Sum of voltage offset value of W phase
g_u4_inv_offset_calc
uint32
Variable to calculate voltage offset
Inverse of g_u2_offset_calc_time
Table 3-20 List of variables [4/4]
R01AN3582EJ0100 Rev.1.00 Page 32 of 46 Jan 13, 2017
Page 33
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
Structure
Member
Type
Scale
Content
Remarks
MTR_PI_CTRL
s2_err
int16
Q3
Error
s2_kp
int16
Q16
PI control proportional gain
s2_ki
int16
Q22
PI control integral gain
s4_refi
int32
Q7
Integral output value
s4_ilimit
int32
Q26
Integral output limit

3.4 List of sensorless 120-degree conducting control software structure

Lists of structure used in this control program are given below.
Table 3-21 List of structure
R01AN3582EJ0100 Rev.1.00 Page 33 of 46 Jan 13, 2017
Page 34
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
File name
Macro name
Definition value
Remarks
motor_parameter.h
MP_POLE_PAIRS
2
Number of pole pairs
MP_MAGNETIC_FLUX
0.02159f
Flux [Wb] (not used)
MP_RESISTANCE
6.447f
Resistance [Ω] (not used)
MP_D_INDUCTANCE
0.0045f
d-axis Inductance [H] (not used)
MP_Q_INDUCTANCE
0.0045f
q-axis Inductance [H] (not used)
File name
Macro name
Definition value
Remarks
control_parameter.h
CP_OFFSET_CALC_TIME
10000
Counts for measurement of voltage offset
CP_BOOT_REF_V
5.0f * 0x80
Voltage reference at draw-in [V]
CP_V_UP_TIME
250
Time to increase voltage step at draw-in [ms]
CP_V_CONST_TIME
125
Period of constant voltage at draw-in [ms]
CP_MAX_SPEED_RPM
2650
Maximum of rotational speed command Mechanical angle [rpm]
CP_MIN_SPEED_RPM
1200
Minimum of rotational speed command Mechanical angle [rpm]
CP_LIMIT_SPEED_CHANGE
0.30f * 0x08
Step to increase speed reference Electrical angle [rad/s]
CP_OL_START_RPM
185
Speed of open loop at start-up Mechanical angle [rpm]
CP_OL_MODE1_CHANGE_RPM
400
Speed to change open loop mode1 Mechanical angle [rpm]
CP_OL_MODE2_CHANGE_RPM
600
Speed to change open loop mode2 Mechanical angle [rpm]
CP_OL_START_REFV
5.0f * 0x80
Voltage reference of open loop at start-up [V]
CP_OL_MODE1_RATE_RPM
8
Increase step of speed at open loop mode1 [rpm/control period]
CP_OL_MODE2_RATE_REFV
0.01f * 0x80
Increase step of voltage at open loop mode2 [V]
CP_OL_MODE2_RATE_RPM
6
Increase step of speed at open loop mode2 [rpm/control period]
CP_OL_MODE3_RATE_REFV
0.01f * 0x80
Increase step of voltage at open loop mode3 [V]
CP_OL_MODE3_MAX_REFV
5.00f * 0x80
Maximum voltage of open loop [V]
CP_SPEED_PI_KP
0.0200f * 0xFFFF
Proportional gain
CP_SPEED_PI_KI
0.0006f * 0x400000
Integral gain
CP_SPEED_LPF_K
1.0f * 0x40
Speed LPF parameter
MTR_FIRST60
1
Non-Complementary First 60 degree PWM (default)
MTR_FIRST60_COMP
0
Complementary First 60 degree PWM

3.5 Macro definitions of sensorless 120-degree conducting control software

Lists of macro definitions used in this control program are given below.
Table 3-22 List of Macro definitions “motor_parameter.h”
Table 3-23 List of Macro definitions “control_parameter.h”
R01AN3582EJ0100 Rev.1.00 Page 34 of 46 Jan 13, 2017
Page 35
File name
Macro name
Definition value
Remarks
main.h
M_CW
0
Rotation direction M_CCW
1
VOFFSET_MEASURE_CNT
CP_OFFSET_CALC_TIME
Counts for measurement of voltage offset [ms]
BOOT_REF_V
CP_BOOT_REF_V
Voltage reference at draw-in [V]
V_UP_PERIOD
CP_V_UP_TIME
Time to increase voltage step at draw-in [ms]
V_CONST_PERIOD
CP_V_CONST_TIME
Period of constant voltage at draw-in [ms]
MAX_SPEED
CP_MAX_SPEED_RPM
Maximum of rotational speed command Mechanical angle [rpm]
MIN_SPEED
CP_MIN_SPEED_RPM
Minimum of rotational speed command Mechanical angle [rpm]
MARGIN_SPEED
50.0f
Rotational speed command minimum value creation constants for stop Mechanical angle [rpm]
MARGIN_MIN_SPEED
MIN_SPEED - MARGIN_SPEED
Minimum of rotational speed to control motor stop Mechanical angle [rpm]
OL_START_RPM
CP_OL_START_RPM
Speed of open loop at start-up Mechanical angle [rpm]
OL_MODE1_CHANGE_RPM
CP_OL_MODE1_CHANGE_RPM
Speed to change open loop mode1 Mechanical angle [rpm]
OL_MODE2_CHANGE_RPM
CP_OL_MODE2_CHANGE_RPM
Speed to change open loop mode2 Mechanical angle [rpm]
OL_START_REFV
(int16) CP_OL_START_REFV
Voltage reference of open loop at start-up [V]
OL_MODE1_RATE_RPM
CP_OL_MODE1_RATE_RPM
Increase step of speed at open loop mode1 [rpm/control period]
OL_MODE2_RATE_REFV
(int16) CP_OL_MODE2_RATE_REFV
Increase step of voltage at open loop mode2 [V]
OL_MODE2_RATE_RPM
CP_OL_MODE2_RATE_RPM
Increase step of speed at open loop mode2 [rpm/control period]
OL_MODE3_RATE_REFV
(int16) CP_OL_MODE3_RATE_REFV
Increase step of voltage at open loop mode3 [V]
OL_MODE3_MAX_REFV
(int16) CP_OL_MODE3_MAX_REFV
Maximum voltage of open loop [V]
LIMIT_SPEED_CHANGE
(int16) CP_LIMIT_SPEED_CHANGE
Step to increase speed reference Electrical angle [rad/s]
SPEED_PI_KP
(int16) CP_SPEED_PI_KP
Speed proportional gain
SPEED_PI_KI
(int16) CP_SPEED_PI_KI
Speed Integral gain
SPEED_LPF_K
(int16) CP_SPEED_LPF_K
Speed LPF parameter
SW_ON
0
Active in case of “Low” SW_OFF
1
CHATTERING_CNT
10
Counts to remove chattering
VR1_SCALING
(MAX_SPEED + 422) / 0x200
Speed command value creation constant
ADJUST_OFFSET
0x1FF
Speed command value offset adjustment constant
POLE_PAIR
MP_POLE_PAIRS
Pole pairs
REQ_CLR
0
Clear VR1 stop command flag
REQ_SET
1
Set VR1 stop command flag
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
Table 3-24 List of Macro definitions “main.h”
R01AN3582EJ0100 Rev.1.00 Page 35 of 46 Jan 13, 2017
Page 36
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
File name
Macro name
Definition value
Remarks
mtr_ctrl_rl78g1g.h
MTR_OC_USE_INTP
1
Select the external circuit to detect overcurrent (default)
MTR_OC_USE_PGACMP
0
Select PGA+CMP0, CMP1 to detect overcurrent
MTR_OC_DETECT_CMP0
83
Comparator internal reference voltage to detect overcurrent (CMP0)
MTR_OC_DETECT_CMP1
120
Comparator internal reference voltage to detect overcurrent (CMP1)
File name
Macro name
Definition value
Remarks
mtr_ctrl_rl78g1g_ mrssk.h
MTR_PWM_TIMER_FREQ
48.0f
PWM timer count frequency [MHz]
MTR_CARRIER_FREQ
20.0f
Carrier frequency [kHz]
MTR_DEADTIME
2000
Dead time [ns]
MTR_DEADTIME_SET
(int16)(MTR_DEADTIME * MTR_PWM_TIMER_FREQ / 1000)
Dead time setting value
MTR_CARRIER_SET
(MTR_PWM_TIMER_FREQ * 1000 / MTR_CARRIER_FREQ / 2) + MTR_DEADTIME_SET - 2
Carrier setting value
MTR_HALF_CARRIER_SET
MTR_CARRIER_SET / 2
Half of “MTR_CARRIER_SET”
MTR_NDT_CARRIER_SET
MTR_CARRIER_SET ­MTR_DEADTIME_SET
MTR_PORT_UP
CA
P1.5
CC
-RL
P1_bit.no5
U phase (positive phase) output port
MTR_PORT_UN
P1.4
P1_bit.no4
U phase (negative phase) output port
MTR_PORT_VP
P1.3
P1_bit.no3
V phase (positive phase) output port
MTR_PORT_VN
P1.1
P1_bit.no1
V phase (negative phase) output port
MTR_PORT_WP
P1.2
P1_bit.no2
W phase (positive phase) output port
MTR_PORT_WN
P1.0
P1_bit.no0
W phase (negative phase) output port
MTR_PORT_SW1
P0.5
P0_bit.no5
SW1 input port
MTR_PORT_SW2
P0.6
P0_bit.no6
SW2 input port
MTR_PORT_LED1
P14.1
P14_bit.no1
LED1 output port
MTR_PORT_LED2
P14.0
P14_bit.no0
LED2 output port
MTR_LED_ON
0
LED active in case of “Low” MTR_LED_OFF
1
MTR_INPUT_V
(int16) 24 * 0x80
input DC voltage [V] (scale: Q7)
MTR_MCU_ON_V
(int16) MTR_INPUT_V * 0.8
MCU power on voltage (scale: Q7)
MTR_VDC_SCALING
3555
Calculate parameter for scaling invertor bus voltage from A/D converted value (scale: Q7)
MTR_RECIVDC_SCALING
64
Reciprocal value of MTR_VDC_SCALING (scale: Q7)
MTR_OVERVOLTAGE_LIMIT
(int16) 28 * 0x80
High voltage limit [V]
MTR_UNDERVOLTAGE_LIMIT
(int16) 15 * 0x80
Low voltage limit [V]
MTR_TAU1_CNT
TCR01
Counter register of Free-run timer to measure rotational speed
Table 3-25 List of Macro definitions “mtr_ctrl_rl78g1g.h”
Table 3-26 List of Macro definitions “mtr_ctrl_rl78g1g_mrssk.h” [1/2]
R01AN3582EJ0100 Rev.1.00 Page 36 of 46 Jan 13, 2017
Page 37
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
File name
Macro name
Definition value
Remarks
mtr_ctrl_rl78g1g _mrssk.h
MTR_ADCCH_VR1
0
A/D Converter channel of VR1
MTR_ADCCH_VDC
3
A/D Converter channel of inverter bus voltage
MTR_ADCCH_VU
17
A/D Converter channel of U phase voltage
MTR_ADCCH_VV
18
A/D Converter channel of V phase voltage
MTR_ADCCH_VW
19
A/D Converter channel of W phase voltage
MTR_OC_HW_FLG
TRDSHUTS
Forced cutoff flag
MTR_OC_INTP_MASK
PMK0
INTP0 interrupt mask flag
MTR_OC_CMP0_MASK
CMPMK0
CMPMK0 interrupt mask flag
MTR_OC_CMP1_MASK
CMPMK1
CMPMK1 interrupt mask flag
MTR_DISABLE_OC_INTR
1
Disable interrupt service
Table 3-27 List of Macro definitions “mtr_ctrl_rl78g1g_mrssk.h” [2/2]
R01AN3582EJ0100 Rev.1.00 Page 37 of 46 Jan 13, 2017
Page 38
File name
Macro name
Definition value
Remarks
mtr_spm_less_
120.h
MTR_POLE_PAIRS
MP_POLE_PAIRS
Motor Pole pairs
MTR_TWOPI
2 * 3.14159265f
2π
MTR_RPM_RAD
13726
Calculate parameter for [rpm]→[rad/s] (scale: Q3)
MTR_RAD_RPM
4889
Calculate parameter for [rad/s][rpm] (scale: Q12)
MTR_SPEED_LIMIT_RPM
3500
Speed limit Mechanical angle [rpm]
MTR_SPEED_LIMIT
MTR_SPEED_LIMIT_RPM * MTR_TWOPI / 60
Speed limit Electrical angle [rad/s]
MTR_SPEED_PI_DECIMATION
0
Number of interrupt decimation times for speed PI control
MTR_SPEED_PI_KP
(int16) CP_SPEED_PI_KP
Speed PI proportional gain
MTR_SPEED_PI_KI
(int16) CP_SPEED_PI_KI
Speed PI Integral gain
MTR_SPEED_PI_LIMIT_V
24 * 0x80
Voltage PI control output limit [V] (scale: Q7)
MTR_SPEED_PI_I_LIMIT_V
24 * 0x80 * 0x80000
Voltage PI control output limit [V] Integral part (for calculation) (scale: Q12)
MTR_SPEED_CALC_BASE
576
Calculate parameter to translate the timer counter to rotational speed [rad/s] (scale: Q3)
MTR_CNT_START_CALC
30
Wait speed measurement still zero­cross is detected become this counts
MTR_SPEED_LPF_K
(int16) CP_SPEED_LPF_K
Speed LPF parameter
MTR_LIMIT_SPEED_CHANGE
CP_LIMIT_SPEED_CHANGE
Step to increase speed reference Electrical angle [rad/s]
MTR_MAX_DRIVE_V
(int16) 22 * 0x80
Maximum command voltage [V] (scale: Q7)
MTR_MIN_DRIVE_V
(int16) 0.10 * 0x80
Minimum command voltage [V] (scale: Q7)
MTR_MAX_BOOT_V
8.0 * 0x80
Maximum command voltage at draw-in [V] (scale: Q7)
MTR_TIMEOUT_CNT
50
Timeout limit [ms]
MTR_STOP_BEMF
122
Value to judge motor stopped
MTR_SHIFT_ADJUST
2
Value of angle shift adjusting
MTR_OL_CTRL_PERIOD
15
Control period of open loop [ms]
MTR_OL_START_RPM
CP_OL_START_RPM
Speed of open loop at start-up Mechanical angle [rpm]
MTR_OL_MODE1_CHANGE_RPM
CP_OL_MODE1_CHANGE_RPM
Speed to change open loop mode1 Mechanical angle [rpm]
MTR_OL_MODE2_CHANGE_RPM
CP_OL_MODE2_CHANGE_RPM
Speed to change open loop mode2 Mechanical angle [rpm]
MTR_OL_START_REFV
(int16) CP_OL_START_REFV
Voltage reference of open loop at start­up [V]
MTR_OL_MODE1_RATE_RPM
CP_OL_MODE1_RATE_RPM
Increase step of speed at open loop mode1 [rpm/control period]
MTR_OL_MODE2_RATE_REFV
(int16) CP_OL_MODE2_RATE_REFV
Increase step of voltage at open loop mode2 [V]
MTR_OL_MODE2_RATE_RPM
CP_OL_MODE2_RATE_RPM
Increase step of speed at open loop mode2 [rpm/control period]
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
Table 3-28 List of Macro definitions “mtr_spm_less_120.h” [1/4]
R01AN3582EJ0100 Rev.1.00 Page 38 of 46 Jan 13, 2017
Page 39
File name
Macro name
Definition value
Remarks
mtr_spm_less_
120.h
MTR_OL_MODE3_RATE_REFV
(int16) CP_OL_MODE3_RATE_REFV
Increase step of voltage at open loop mode3 [V]
MTR_OL_MODE3_MAX_REFV
(int16) CP_OL_MODE3_MAX_REFV
Maximum voltage of open loop [V]
MTR_OL_FREQ_CALC
MTR_CARRIER_FREQ * 60000/6
Calculate parameter to translate [rpm] to [Hz]
MTR_OL_START_FREQ
(int16) MTR_OL_FREQ_CALC/MTR_POLE_PAI RS / MTR_OL_START_RPM
Frequency for start-up [Hz]
MTR_OL_MODE1_CHANGE_FREQ
(int16) MTR_OL_FREQ_CALC/MTR_POLE_PAI RS / MTR_OL_MODE1_CHANGE_RPM
Frequency to change open loop mode1 [Hz]
MTR_OL_MODE2_CHANGE_FREQ
(int16) MTR_OL_FREQ_CALC/MTR_POLE_PAI RS / MTR_OL_MODE2_CHANGE_RPM
Frequency to change open loop mode2 [Hz] MTR_PATTERN_CW_V_U
2
CW pseudo Hall sensor pattern
MTR_PATTERN_CW_W_U
3
MTR_PATTERN_CW_W_V
1
MTR_PATTERN_CW_U_V
5
MTR_PATTERN_CW_U_W
4
MTR_PATTERN_CW_V_W
6
MTR_PATTERN_CCW_V_U
3
CCW pseudo Hall sensor pattern
MTR_PATTERN_CCW_V_W
2
MTR_PATTERN_CCW_U_W
6
MTR_PATTERN_CCW_U_V
4
MTR_PATTERN_CCW_W_V
5
MTR_PATTERN_CCW_W_U
1
MTR_PATTERN_ERROR
0
Conduction pattern
MTR_UP_PWM_VN_ON
1
MTR_UP_PWM_WN_ON
2
MTR_VP_PWM_UN_ON
3
MTR_VP_PWM_WN_ON
4
MTR_WP_PWM_UN_ON
5
MTR_WP_PWM_VN_ON
6
MTR_UP_ON_VN_PWM
7
MTR_UP_ON_WN_PWM
8
MTR_VP_ON_UN_PWM
9
MTR_VP_ON_WN_PWM
10
MTR_WP_ON_UN_PWM
11
MTR_WP_ON_VN_PWM
12
MTR_U_PWM_VN_ON
13
MTR_U_PWM_WN_ON
14
MTR_V_PWM_UN_ON
15
MTR_V_PWM_WN_ON
16
MTR_W_PWM_UN_ON
17
MTR_W_PWM_VN_ON
18
MTR_UP_ON_V_PWM
19
MTR_UP_ON_W_PWM
20
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
Table 3-29 List of Macro definitions “mtr_spm_less_120.h” [2/4]
R01AN3582EJ0100 Rev.1.00 Page 39 of 46 Jan 13, 2017
Page 40
File name
Macro name
Definition value
Remarks
mtr_spm_less _120.h
MTR_VP_ON_U_PWM
21
Conduction pattern
MTR_VP_ON_W_PWM
22
MTR_WP_ON_U_PWM
23
MTR_WP_ON_V_PWM
24
MTR_OFFSET_CALC_TIME
CP_OFFSET_CALC_TIME
Time to calculate voltage offset [ms]
MTR_BOOT_REF_V
CP_BOOT_REF_V
Voltage reference at draw-in [V]
MTR_V_UP_PERIOD
CP_V_UP_TIME
Time to increase voltage step at draw-in [ms]
MTR_V_UP_STEP
(int16) MTR_BOOT_REF_V / MTR_V_UP_PERIOD
Increase step of voltage at draw-in MTR_V_CONST_TIME
CP_V_CONST_TIME
Period of constant voltage at draw-in [ms]
MTR_CW
0
Rotation direction MTR_CCW
1
MTR_FLG_CLR
0
Constant for flag management MTR_FLG_SET
1
MTR_MODE_INACTIVE
0x00
Inactive mode
MTR_MODE_ACTIVE
0x01
Active mode
MTR_MODE_ERROR
0x02
Error mode
MTR_SIZE_STATE
3
State size
MTR_EVENT_INACTIVE
0x00
Inactive event
MTR_EVENT_ACTIVE
0x01
Active event
MTR_EVENT_ERROR
0x02
Error event
MTR_EVENT_RESET
0x03
Reset event
MTR_SIZE_EVENT
4
Event size
MTR_MODE_INIT
0x00
Initialize mode
MTR_MODE_BOOT
0x01
Boot mode
MTR_MODE_DRIVE
0x02
Drive mode
MTR_MODE_ANALYSIS
0x03
Analysis mode
MTR_MODE_TUNE
0x04
Tune mode
MTR_SENSOR_LESS
0x01
Sensorless
MTR_SENSOR_HALL
0x02
Hall sensor
MTR_SENSOR_ENCD
0x04
Encoder
MTR_SENSOR_RESO
0x08
Resolver
MTR_METHOD_FOC
0x00
Fields oriented control
MTR_METHOD_180
0x01
180 degree control
MTR_METHOD_WIDE
0x02
Wide angle electricity control
MTR_METHOD_120
0x03
120 degree control
MTR_CONTROL_CURRENT
0x01
Current control
MTR_CONTROL_SPEED
0x02
Speed control
MTR_CONTROL_POSITION
0x04
Position control
MTR_CONTROL_TORQUE
0x08
Torque control
MTR_CONTROL_VOLTAGE
0x10
Voltage control
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
Table 3-30 List of Macro definitions “mtr_spm_less_120.h” [3/4]
R01AN3582EJ0100 Rev.1.00 Page 40 of 46 Jan 13, 2017
Page 41
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
File name
Macro name
Definition value
Remarks
mtr_spm_less _120.h
MTR_ERROR_NONE
0x00
No error
MTR_ERROR_OVER_CURRENT
0x01
Overcurrent error
MTR_ERROR_OVER_VOLTAGE
0x02
Over voltage error
MTR_ERROR_OVER_SPEED
0x04
Over speed error
MTR_ERROR_HALL_TIMEOUT
0x08
Hall timeout error
MTR_ERROR_BEMF_TIMEOUT
0x10
BEMF timeout error
MTR_ERROR_HALL_PATTERN
0x20
Hall pattern error
MTR_ERROR_BEMF_PATTERN
0x40
BEMF pattern error
MTR_ERROR_UNDER_VOLTAGE
0x80
Under voltage error
MTR_ERROR_UNKNOWN
0xff
Unknown error
MTR_DRAW_IN_NONE
0
initial state (not work)
MTR_DRAW_IN_1ST
1
draw-in the 1st initial position
MTR_DRAW_IN_2ND
2
draw-in the 2nd initial position
MTR_DRAW_IN_FINISH
3
draw-in finished
MTR_V_ZERO_CONST
0
zero voltage constant
MTR_V_UP
1
increase of voltage
MTR_V_CONST
2
voltage constant
MTR_V_OPENLOOP
3
Open-loop voltage setting mode
MTR_V_PI_OUTPUT
4
Speed PI output voltage setting mode
MTR_SPEED_ZERO_CONST
0
Speed zero constant
MTR_SPEED_OPENLOOP_1
1
Open loop MODE1
MTR_SPEED_OPENLOOP_2
2
Open loop MODE2
MTR_SPEED_OPENLOOP_3
3
Open loop MODE3
MTR_SPEED_CHANGE
4
Speed changing
MTR_VOFFSET_STATUS_NONE
0
The measurement of voltage offset doesn’t work
MTR_VOFFSET_STATUS_MEASURE_OFF
1
Measure voltage offset with PWM off
MTR_VOFFSET_STATUS_MEASURE_ON
2
Measure voltage offset with PWM on
MTR_VOFFSET_STATUS_FINISH
3
Finish the measurement of voltage offset
Table 3-31 List of Macro definitions “mtr_spm_less_120.h” [4/4]
R01AN3582EJ0100 Rev.1.00 Page 41 of 46 Jan 13, 2017
Page 42
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
Main process
Initialization of
peripheral functions
Initialization of user interface
Initialization of variables used
in the main process
Initialization of sequence process
Reset process
Wait the stability of bus voltage
Change motor operation according
to switch status
LED control
Determine rotational speed according
to VR1 value
Set rotational speed
command value
Clear watchdog timer

3.6 Control flows (flow charts)

3.6.1 Main process

Figure 3-7 Main Process Flowchart
R01AN3582EJ0100 Rev.1.00 Page 42 of 46 Jan 13, 2017
Page 43
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
Carrie r cycle interrupt
Get inver ter bus voltage value
Measur e the voltage
of thr ee phase
Cancel voltage offset
SYSTEM MODE
speed r efer ence
PI co ntr ol?
Comm utation with
pseudo Hall pattern
Detect zero-cross?
End
[INACTIVE]
[ACTIVE]
[before MODE2]
[aftor MODE2]
[valid]
[invalid]
[detection]
Transition timi ng of
PI control?
Set values of PI co ntrol
and go t o PI con tro l state
[YES]
[non-detection]
[NO]
voltage r efer ence
Drive at open loop
[OPEN LOOP]
[PI OUTPUT]
Detection
of zero-
cross proce ss
Set delay to change pattern
Calculate the rotational speed

3.6.2 Carrier cycle interrupt handling

Figure 3-8 50 [μs] Cycle Interrupt Handling (Sensorless 120-degree control)
R01AN3582EJ0100 Rev.1.00 Page 43 of 46 Jan 13, 2017
Page 44
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
[DRIVE MODE]
[BOOT MODE]
Calculatespeed reference
Calculate voltage reference
Set PWM duty
Set conduction pattern
to draw-in the rotor
Finish draw-in?
Go to DRIVE MODE
Go to BOOT MODE
Finish offset
process?
Calculate voltage reference
Calculate speed reference
Mode of voltage
reference
Set PWM duty
[INIT MODE]
1 ms interrupt
SYSTEM MODE
RUM MODE
Error check
Wait motor stop
End
[INACTIVE]
[ACTIVE]
[NO]
[OPEN LOOP]
[YES]
[PI control]
[Yet]
[Finished]

3.6.3 1 [ms] interrupt handling

Figure 3-9 1 [ms] Interrupt Handling
R01AN3582EJ0100 Rev.1.00 Page 44 of 46 Jan 13, 2017
Page 45
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)
Overcurrent detectioninterrupt
(Hardware)
End
Generate error event
Disable INTP0 interrupt servicing
Set the flag of error about overcurrent
Overcurrent detection interrupt
( internal PGA+CMP0, CMP1)
End
Generate error event
Disable CMP0, 1 interrupt servicing
Set the flag of error about overcurrent

3.6.4 Overcurrent interrupt handling

Figure 3-10 Overcurrent detection process (Hardware detection)
Figure 3-11 Overcurrent detection process (PGA+CMP0, 1 interrupt)
R01AN3582EJ0100 Rev.1.00 Page 45 of 46 Jan 13, 2017
Page 46
RL78/G1G Sensorless Speed control of 120-degree conducting controlled permanent magnetic synchronous motor (Implementation)

Website and Support

Renesas Electronics Website
http://www.renesas.com/
Inquiries
http://www.renesas.com/contact/
All trademarks and registered trademarks are the property of their respective owners.
R01AN3582EJ0100 Rev.1.00 Page 46 of 46 Jan 13, 2017
Page 47
Rev.
Date
Description
Page
Summary
1.00
Jan.13.2017
First edition issued

Revision History

Page 48
1. Handling of Unused Pins Handle unused pins in accordance with the directions given under Handling of Unused Pins in the
manual. The input pins of CMOS products are generally in the high-impedance state. In operation with
an unused pin in the open-circuit state, extra electromagnetic noise is induced in the vicinity of LSI, an associated shoot-through current flows internally, and malfunctions occur due to the false recognition of the pin state as an input signal become possible. Unused pins should be handled as described under Handling of Unused Pins in the manual.
2. Processing at Power-on The state of the product is undefined at the moment when power is supplied. The states of internal circuits in the LSI are indeterminate and the states of register settings
and pins are undefined at the moment when power is supplied. In a finished product where the reset signal is applied to the external reset pin, the states of pins are not guaranteed from the moment when power is supplied until the reset process is completed. In a similar way, the states of pins in a product that is reset by an on-chip power-on reset function are not guaranteed from the moment when power is supplied until the power reaches the level at which resetting has been specified.
3. Prohibition of Access to Reserved Addresses Access to reserved addresses is prohibited. The reserved addresses are provided for the possible future expansion of functions. Do not
access these addresses; the correct operation of LSI is not guaranteed if they are accessed.
4. Clock Signals After applying a reset, only release the reset line after the operating clock signal has become
stable. When switching the clock signal during program execution, wait until the target clock signal has stabilized.
When the clock signal is generated with an external resonator (or from an external oscillator)
during a reset, ensure that the reset line is only released after full stabilization of the clock signal. Moreover, when switching to a clock signal produced with an external resonator (or by an external oscillator) while program execution is in progress, wait until the target clock signal is stable.
5. Differences between Products Before changing from one product to another, i.e. to a product with a different part number, confirm
that the change will not lead to problems. The characteristics of Microprocessing unit or Microcontroller unit products in the same group
but having a different part number may differ in terms of the internal memory capacity, layout pattern, and other factors, which can affect the ranges of electrical characteristics, such as characteristic values, operating margins, immunity to noise, and amount of radiated noise. When changing to a product with a different part number, implement a system-evaluation test for the given product.

General Precautions in the Handling of Microprocessing Unit and Microcontroller Unit Products

The following usage notes are applicable to all Microprocessing unit and Microcontroller unit products from Renesas. For detailed usage notes on the products covered by this document, refer to the relevant sections of the document as well as any technical updates that have been issued for the products.
Page 49
Notice
1. Descriptions of circuits, software and other related information in this document are provided only to illustrate the operation of semiconductor products and application examples. You are fully responsible for the incorporation of these circuits, software, and information in the design of your equipment. Renesas Electronics assumes no responsibility for any losses incurred by you or third parties arising from the use of these circuits, software, or information.
2. Renesas Electronics has used reasonable care in preparing the information included in this document, but Renesas Electronics does not warrant that such information is error free. Renesas Electronics assumes no liability whatsoever for any damages incurred by you resulting from errors in or omissions from the information included herein.
3. Renesas Electronics does not assume any liability for infringement of patents, copyrights, or other intellectual property rights of third parties by or arising from the use of Renesas Electronics products or technical information described in this document. No license, express, implied or otherwise, is granted hereby under any patents, copyrights or other intellectual property rights of Renesas Electronics or others.
4. You should not alter, modify, copy, or otherwise misappropriate any Renesas Electronics product, whether in whole or in part. Renesas Electronics assumes no responsibility for any losses incurred by you or third parties arising from such alteration, modification, copy or otherwise misappropriation of Renesas Electronics product.
5. Renesas Electronics products are classified according to the following two quality grades: "Standard" and "High Quality". The recommended applications for each Renesas Electronics product depends on the product's quality grade, as indicated below. "Standard": Computers; office equipment; communications equipment; test and measurement equipment; audio and visual equipment; home electronic appliances; machine tools; personal electronic equipment; and industrial robots etc. "High Quality": Transportation equipment (automobiles, trains, ships, etc.); traffic control systems; anti-disaster systems; anti-crime systems; and safety equipment etc. Renesas Electronics products are neither intended nor authorized for use in products or systems that may pose a direct threat to human life or bodily injury (artificial life support devices or systems, surgical implantations etc.), or may cause serious property damages (nuclear reactor control systems, military equipment etc.). You must check the quality grade of each Renesas Electronics product before using it in a particular application. You may not use any Renesas Electronics product for any application for which it is not intended. Renesas Electronics shall not be in any way liable for any damages or losses incurred by you or third parties arising from the use of any Renesas Electronics product for which the product is not intended by Renesas Electronics.
6. You should use the Renesas Electronics products described in this document within the range specified by Renesas Electronics, especially with respect to the maximum rating, operating supply voltage range, movement power voltage range, heat radiation characteristics, installation and other product characteristics. Renesas Electronics shall have no liability for malfunctions or damages arising out of the use of Renesas Electronics products beyond such specified ranges.
7. Although Renesas Electronics endeavors to improve the quality and reliability of its products, semiconductor products have specific characteristics such as the occurrence of failure at a certain rate and malfunctions under certain use conditions. Further, Renesas Electronics products are not subject to radiation resistance design. Please be sure to implement safety measures to guard them against the possibility of physical injury, and injury or damage caused by fire in the event of the failure of a Renesas Electronics product, such as safety design for hardware and software including but not limited to redundancy, fire control and malfunction prevention, appropriate treatment for aging degradation or any other appropriate measures. Because the evaluation of microcomputer software alone is very difficult, please evaluate the safety of the final products or systems manufactured by you.
8. Please contact a Renesas Electronics sales office for details as to environmental matters such as the environmental compatibility of each Renesas Electronics product. Please use Renesas Electronics products in compliance with all applicable laws and regulations that regulate the inclusion or use of controlled substances, including without limitation, the EU RoHS Directive. Renesas Electronics assumes no liability for damages or losses occurring as a result of your noncompliance with applicable laws and regulations.
9. Renesas Electronics products and technology may not be used for or incorporated into any products or systems whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. You should not use Renesas Electronics products or technology described in this document for any purpose relating to military applications or use by the military, including but not limited to the development of weapons of mass destruction. When exporting the Renesas Electronics products or technology described in this document, you should comply with the applicable export control laws and regulations and follow the procedures required by such laws and regulations.
10. It is the responsibility of the buyer or distributor of Renesas Electronics products, who distributes, disposes of, or otherwise places the product with a third party, to notify such third party in advance of the contents and conditions set forth in this document, Renesas Electronics assumes no responsibility for any losses incurred by you or third parties as a result of unauthorized use of Renesas Electronics products.
11. This document may not be reproduced or duplicated in any form, in whole or in part, without prior written consent of Renesas Electronics.
12. Please contact a Renesas Electronics sales office if you have any questions regarding the information contained in this document or Renesas Electronics products, or if you have any other inquiries.
(Note 1) "Renesas Electronics" as used in this document means Renesas Electronics Corporation and also includes its majority-owned subsidiaries. (Note 2) "Renesas Electronics product(s)" means any product developed or manufactured by or for Renesas Electronics.
http://www.renesas.com
Refer to "http://www.renesas.com/" for the latest and detailed information.
Renesas Electronics America Inc.
2801 Scott Boulevard Santa Clara, CA 95050-2549, U.S.A. Tel: +1-408-588-6000, Fax: +1-408-588-6130
Renesas Electronics Canada Limited
9251 Yonge Street, Suite 8309 Richmond Hill, Ontario Canada L4C 9T3 Tel: +1-905-237-2004
Renesas Electronics Europe Limited
Dukes Meadow, Millboard Road, Bourne End, Buckinghamshire, SL8 5FH, U.K Tel: +44-1628-585-100, Fax: +44-1628-585-900
Renesas Electronics Europe GmbH
Arcadiastrasse 10, 40472 Düsseldorf, Germany Tel: +49-211-6503-0, Fax: +49-211-6503-1327
Renesas Electronics (China) Co., Ltd.
Room 1709, Quantum Plaza, No.27 ZhiChunLu Haidian District, Beijing 100191, P.R.China Tel: +86-10-8235-1155, Fax: +86-10-8235-7679
Renesas Electronics (Shanghai) Co., Ltd.
Unit 301, Tower A, Central Towers, 555 Langao Road, Putuo District, Shanghai, P. R. China 200333 Tel: +86-21-2226-0888, Fax: +86-21-2226-0999
Renesas Electronics Hong Kong Limited
Unit 1601-1611, 16/F., Tower 2, Grand Century Place, 193 Prince Edward Road West, Mongkok, Kowloon, Hong Kong Tel: +852-2265-6688, Fax: +852 2886-9022
Renesas Electronics Taiwan Co., Ltd.
13F, No. 363, Fu Shing North Road, Taipei 10543, Taiwan Tel: +886-2-8175-9600, Fax: +886 2-8175-9670
Renesas Electronics Singapore Pte. Ltd.
80 Bendemeer Road, Unit #06-02 Hyflux Innovation Centre, Singapore 339949 Tel: +65-6213-0200, Fax: +65-6213-0300
Renesas Electronics Malaysia Sdn.Bhd.
Unit 1207, Block B, Menara Amcorp, Amcorp Trade Centre, No. 18, Jln Persiaran Barat, 46050 Petaling Jaya, Selangor Darul Ehsan, Malaysia Tel: +60-3-7955-9390, Fax: +60-3-7955-9510
Renesas Electronics India Pvt. Ltd.
No.777C, 100 Feet Road, HALII Stage, Indiranagar, Bangalore, India Tel: +91-80-67208700, Fax: +91-80-67208777
Renesas Electronics Korea Co., Ltd.
12F., 234 Teheran-ro, Gangnam-Gu, Seoul, 135-080, Korea Tel: +82-2-558-3737, Fax: +82-2-558-5141
SALES OFFICES
© 2017 Renesas Electronics Corporation. All rights reserved.
Colophon 5.0
Loading...