RA Flexible Software Package Documentation  Release v5.2.0

 
ADC and PWM modulation (rm_motor_120_driver)

Functions

fsp_err_t RM_MOTOR_120_DRIVER_Open (motor_120_driver_ctrl_t *const p_ctrl, motor_120_driver_cfg_t const *const p_cfg)
 Opens and configures the motor 120 driver module. Implements motor_120_driver_api_t::open. More...
 
fsp_err_t RM_MOTOR_120_DRIVER_Close (motor_120_driver_ctrl_t *const p_ctrl)
 Disables specified motor 120 driver module. Implements motor_120_driver_api_t::close. More...
 
fsp_err_t RM_MOTOR_120_DRIVER_Run (motor_120_driver_ctrl_t *const p_ctrl)
 Run motor (Start motor rotation). Implements motor_120_driver_api_t::run. More...
 
fsp_err_t RM_MOTOR_120_DRIVER_Stop (motor_120_driver_ctrl_t *const p_ctrl)
 Stop motor (Stop motor rotation). Implements motor_120_driver_api_t::stop. More...
 
fsp_err_t RM_MOTOR_120_DRIVER_Reset (motor_120_driver_ctrl_t *const p_ctrl)
 Reset variables of motor 120 driver module. Implements motor_120_driver_api_t::reset. More...
 
fsp_err_t RM_MOTOR_120_DRIVER_PhaseVoltageSet (motor_120_driver_ctrl_t *const p_ctrl, float const u_voltage, float const v_voltage, float const w_voltage)
 Set phase voltage data to calculate PWM duty. Implements motor_120_driver_api_t::phaseVoltageSet. More...
 
fsp_err_t RM_MOTOR_120_DRIVER_PhasePatternSet (motor_120_driver_ctrl_t *const p_ctrl, motor_120_driver_phase_pattern_t const pattern)
 Set phase voltage pattern. Implements motor_120_driver_api_t::phasePatternSet. More...
 
fsp_err_t RM_MOTOR_120_DRIVER_CurrentGet (motor_120_driver_ctrl_t *const p_ctrl, motor_120_driver_current_status_t *const p_current_status)
 Get calculated phase current, Vdc & Va_max data. Implements motor_120_driver_api_t::currentGet. More...
 
fsp_err_t RM_MOTOR_120_DRIVER_CurrentOffsetCalc (motor_120_driver_ctrl_t *const p_ctrl)
 current offset detection. Implements motor_120_driver_api_t::currentOffsetCalc More...
 
fsp_err_t RM_MOTOR_120_DRIVER_FlagCurrentOffsetGet (motor_120_driver_ctrl_t *const p_ctrl, motor_120_driver_flag_offset_calc_t *const p_flag_offset)
 Get the flag of finish current offset detection. Implements motor_120_driver_api_t::flagCurrentOffsetGet. More...
 
fsp_err_t RM_MOTOR_120_DRIVER_ParameterUpdate (motor_120_driver_ctrl_t *const p_ctrl, motor_120_driver_cfg_t const *const p_cfg)
 Update the parameters of 120 driver module. Implements motor_120_driver_api_t::parameterUpdate. More...
 

Detailed Description

Calculation process for the motor control on RA MCUs. This module implements the Motor 120-Degree Driver Interface.

Overview

The motor 120 degree driver module is used to translate phase voltage to PWM duty and output PWM, and detect phase current, voltage and main line voltage. This module should be called cyclically at included A/D conversion finish interrupt.

motor_control_block_diagram.svg
Image of Current Control Module(yellow block)

Features

The motor 120 degree driver module has below features.

Configuration

Build Time Configurations for rm_motor_120_driver

The following build time configurations are defined in fsp_cfg/rm_motor_120_driver_cfg.h:

ConfigurationOptionsDefaultDescription
Parameter Checking
  • Default (BSP)
  • Enabled
  • Disabled
Default (BSP) If selected code for parameter checking is included in the build.
ADC_B Support
  • Enabled
  • Disabled
Disabled Select ADC_B module support.
Shared ADC support
  • Enabled
  • Disabled
Disabled Select Shared ADC support.
Support Motor NumberMust be greater than 1.1

Configurations for Motor > ADC and PWM modulation (rm_motor_120_driver)

This module can be added to the Stacks tab via New Stack > Motor > ADC and PWM modulation (rm_motor_120_driver).

ConfigurationOptionsDefaultDescription
General
NameName must be a valid C symbolg_motor_120_driver0 Module name.
120 degree control type
  • Sensorless
  • Hall
Sensorless 120 degree control type
PWM output port UPManual EntryBSP_IO_PORT_06_PIN_01 PWM output port UP
PWM output port UNManual EntryBSP_IO_PORT_06_PIN_00 PWM output port UN
PWM output port VPManual EntryBSP_IO_PORT_01_PIN_13 PWM output port VP
PWM output port VNManual EntryBSP_IO_PORT_01_PIN_14 PWM output port VN
PWM output port WPManual EntryBSP_IO_PORT_01_PIN_11 PWM output port WP
PWM output port WNManual EntryBSP_IO_PORT_01_PIN_12 PWM output port WN
PWM timer frequency (MHz)Must be a valid non-negative value.120.0 GPT PWM timer frequency
PWM carrier period (Microseconds)Must be a valid non-negative value.50.0 GPT PWM carrier period
Dead time (Raw counts)Must be a valid non-negative value.240 GPT PWM dead time
Current range (A)Must be a valid non-negative value.27.5 Current range to measure(Maximum input current)
Voltage range (V)Must be a valid non-negative value.111.0 Voltage range to measure(Maximum input main line voltage)
Resolution of A/D conversionMust be a valid Resolution of ADC.0xFFF Resolution of A/D conversion
Offset of A/D conversion for currentMust be a valid non-negative value.0x745 Offset of A/D conversion for current
Conversion level of A/D conversion for voltageMust be a valid non-negative value.0.66 Conversion level of A/D conversion for voltage
Counts for current offset measurementMust be a valid non-negative value.500 How many times to measure current offset
Input voltageMust be a valid non-negative value.24.0 Input voltage
A/D conversion channel for U phase currentValue must be a supported channel number0 Specify the A/D channel for U phase current
A/D conversion channel for W phase currentValue must be a supported channel number2 Specify the A/D channel for W phase current
A/D conversion channel for main line voltageValue must be a supported channel number5 Specify the A/D channel for main line voltage
A/D conversion channel for U phase voltageValue must be a supported channel number18 Specify the A/D channel for U phase voltage
A/D conversion channel for V phase voltageValue must be a supported channel number20 Specify the A/D channel for V phase voltage
A/D conversion channel for W phase voltageValue must be a supported channel number6 Specify the A/D channel for W phase voltage
A/D conversion unit for U phase currentMust be a valid non-negative value.0 Specify the A/D unit for U phase current
A/D conversion unit for W phase currentMust be a valid non-negative value.0 Specify the A/D unit for W phase current
A/D conversion unit for main line voltageMust be a valid non-negative value.0 Specify the A/D unit for main line voltage
A/D conversion unit for U phase voltageMust be a valid non-negative value.0 Specify the A/D unit for U phase voltage
A/D conversion unit for V phase voltageMust be a valid non-negative value.0 Specify the A/D unit for V phase voltage
A/D conversion unit for W phase voltageMust be a valid non-negative value.0 Specify the A/D unit for W phase voltage
GTIOCA stop level
  • Pin Level Low
  • Pin Level High
Pin Level High Select the behavior of the output pin when the timer is stopped.
GTIOCB stop level
  • Pin Level Low
  • Pin Level High
Pin Level High Select the behavior of the output pin when the timer is stopped.
ADC interrupt module
  • 1st
  • 2nd
1st Select from which module ADC intterupt happens
Modulation
Maximum dutyMust be a valid non-negative value.0.9375 Maximum duty of PWM
Interrupts
CallbackName must be a valid C symbolNULL A user callback function. If this callback function is provided, it is called at A/D conversion finish interrupt.

Clock Configuration

Set used clock with included GPT timer.

Pin Configuration

Depend on included GPT three phase module and ADC module.

Usage Notes

Limitations

Basically no limitation exists.

Examples

Basic Example

This is a basic example of minimal use of the Motor 120 degree driver in an application.

void motor_120_driver_basic_example (void)
{
fsp_err_t err = FSP_SUCCESS;
/* Initializes the module. */
err = RM_MOTOR_120_DRIVER_Open(&g_motor_120_driver0.p_ctrl, &g_motor_120_driver0.p_cfg);
/* Start PWM output */
err = RM_MOTOR_120_DRIVER_Run(&g_motor_120_driver0.p_ctrl);
assert(FSP_SUCCESS == err);
/* Basically run this module at cyclic interrupt (e.g. included GPT PWM carrier intterupt).
* This implementation is an example. */
// while (true)
{
/* Application work here. */
/* Caclutarion of current offset */
(void) RM_MOTOR_120_DRIVER_CurrentOffsetCalc(&g_motor_120_driver0.p_ctrl);
/* Get electric current, main line voltage and maximum voltage component */
(void) RM_MOTOR_120_DRIVER_CurrentGet(&g_motor_120_driver0.p_ctrl, &g_current_status);
/* Get the flag of A/D convderted current offset */
(void) RM_MOTOR_120_DRIVER_FlagCurrentOffsetGet(&g_motor_120_driver0.p_ctrl, &u1_get_flg_offset);
// Perform current control process here
/* Set phase voltage */
(void) RM_MOTOR_120_DRIVER_PhaseVoltageSet(&g_motor_120_driver0.p_ctrl, 1.0F, 1.0F, 1.0F);
/* Set phase pattern */
(void) RM_MOTOR_120_DRIVER_PhasePatternSet(&g_motor_120_driver0.p_ctrl, MOTOR_120_DRIVER_API_VP_ON_WN_PWM);
(void) RM_MOTOR_120_DRIVER_ParameterUpdate(&g_motor_120_driver0.p_ctrl, &g_motor_120_driver0.p_cfg);
}
(void) RM_MOTOR_120_DRIVER_Stop(&g_motor_120_driver0.p_ctrl);
(void) RM_MOTOR_120_DRIVER_Reset(&g_motor_120_driver0.p_ctrl);
//
(void) RM_MOTOR_120_DRIVER_Close(&g_motor_120_driver0.p_ctrl);
}

Data Structures

struct  motor_120_driver_shared_instance_ctrl_t
 
struct  motor_120_driver_modulation_t
 
struct  motor_120_driver_extended_cfg_t
 

Enumerations

enum  motor_120_driver_select_adc_instance_t
 
enum  motor_120_driver_status_t
 
enum  motor_120_driver_type_t
 

Data Structure Documentation

◆ motor_120_driver_shared_instance_ctrl_t

struct motor_120_driver_shared_instance_ctrl_t

For multiple ADC module

Data Fields
uint32_t open
uint8_t registered_motor_count Registered motor counts.
void const * p_context[MOTOR_120_DRIVER_CFG_SUPPORT_MOTOR_NUM]

◆ motor_120_driver_modulation_t

struct motor_120_driver_modulation_t

Modulation parameter

Data Fields
float f4_vdc Main line voltage (Vdc) (V)
float f4_max_duty Maximum duty cycle.
float f4_min_duty Minimum duty cycle.
float f4_neutral_duty Duty cycle that represents 0 (V)

◆ motor_120_driver_extended_cfg_t

struct motor_120_driver_extended_cfg_t

Extended configurations for motor 120 driver

Data Fields
adc_instance_t const * p_adc_instance ADC module instance.
three_phase_instance_t const * p_three_phase_instance PWM output module instance (GPT three phase)
motor_120_driver_type_t motor_120_type 120 degree control type
adc_channel_t iu_ad_ch A/D channel for U phase current.
adc_channel_t iw_ad_ch A/D channel for W phase current.
adc_channel_t vdc_ad_ch A/D channel for main line voltage.
adc_channel_t vu_ad_ch A/D channel for U phase voltage.
adc_channel_t vv_ad_ch A/D channel for V phase voltage.
adc_channel_t vw_ad_ch A/D channel for W phase voltage.
uint8_t iu_ad_unit Used A/D unit number for U phase current.
uint8_t iw_ad_unit Used A/D unit number for W phase current.
uint8_t vdc_ad_unit Used A/D unit number for main line voltage.
uint8_t vu_ad_unit Used A/D unit number for U phase voltage.
uint8_t vv_ad_unit Used A/D unit number for V phase voltage.
uint8_t vw_ad_unit Used A/D unit number for W phase voltage.
bsp_io_port_pin_t port_up PWM output port UP.
bsp_io_port_pin_t port_un PWM output port UN.
bsp_io_port_pin_t port_vp PWM output port VP.
bsp_io_port_pin_t port_vn PWM output port VN.
bsp_io_port_pin_t port_wp PWM output port WP.
bsp_io_port_pin_t port_wn PWM output port WN.
uint32_t u4_pwm_timer_freq PWM timer frequency (MHz)
uint32_t u4_pwm_carrier_freq PWM carrier frequency (kHz)
uint32_t u4_deadtime PWM deadtime (usec)
float f_current_range A/D current measure range (max current) (A)
float f_vdc_range A/D main line voltage measure range (max voltage) (V)
float f_ad_resolution A/D resolution.
float f_ad_current_offset A/D offset (Center value)
float f_ad_voltage_conversion A/D conversion level.
uint32_t u4_offset_calc_count Calculation counts for current offset.
motor_120_driver_modulation_t mod_param Modulation parameter.
motor_120_driver_select_adc_instance_t interrupt_adc Select which interrupt to use.
motor_120_driver_extended_shared_cfg_t
const *
p_shared_cfg shared extended config

Enumeration Type Documentation

◆ motor_120_driver_select_adc_instance_t

Support two ADC instance valid for adc

Enumerator
MOTOR_120_DRIVER_SELECT_ADC_INSTANCE_1ST 

Use 1st ADC instance.

MOTOR_120_DRIVER_SELECT_ADC_INSTANCE_2ND 

Use 2nd ADC instanse.

◆ motor_120_driver_status_t

120 driver active flag

Enumerator
MOTOR_120_DRIVER_STATUS_INACTIVE 

120 driver status inactive

MOTOR_120_DRIVER_STATUS_ACTIVE 

120 driver status active

◆ motor_120_driver_type_t

120 degree control type

Enumerator
MOTOR_120_DRIVER_TYPE_SENSORLESS 

120 degree sensorless control

MOTOR_120_DRIVER_TYPE_HALL 

120 degree hall control

Function Documentation

◆ RM_MOTOR_120_DRIVER_Open()

fsp_err_t RM_MOTOR_120_DRIVER_Open ( motor_120_driver_ctrl_t *const  p_ctrl,
motor_120_driver_cfg_t const *const  p_cfg 
)

Opens and configures the motor 120 driver module. Implements motor_120_driver_api_t::open.

Example:

/* Initializes the module. */
err = RM_MOTOR_120_DRIVER_Open(&g_motor_120_driver0.p_ctrl, &g_motor_120_driver0.p_cfg);
Return values
FSP_SUCCESSMotor 120 driver successfully configured.
FSP_ERR_ASSERTIONNull pointer, or one or more configuration options is invalid.
FSP_ERR_ALREADY_OPENModule is already open. This module can only be opened once.
FSP_ERR_INVALID_ARGUMENTInput parameter error.

◆ RM_MOTOR_120_DRIVER_Close()

fsp_err_t RM_MOTOR_120_DRIVER_Close ( motor_120_driver_ctrl_t *const  p_ctrl)

Disables specified motor 120 driver module. Implements motor_120_driver_api_t::close.

Example:

(void) RM_MOTOR_120_DRIVER_Close(&g_motor_120_driver0.p_ctrl);
Return values
FSP_SUCCESSSuccessfully closed.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_120_DRIVER_Run()

fsp_err_t RM_MOTOR_120_DRIVER_Run ( motor_120_driver_ctrl_t *const  p_ctrl)

Run motor (Start motor rotation). Implements motor_120_driver_api_t::run.

Example:

/* Start PWM output */
err = RM_MOTOR_120_DRIVER_Run(&g_motor_120_driver0.p_ctrl);
Return values
FSP_SUCCESSSuccessfully resetted.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_120_DRIVER_Stop()

fsp_err_t RM_MOTOR_120_DRIVER_Stop ( motor_120_driver_ctrl_t *const  p_ctrl)

Stop motor (Stop motor rotation). Implements motor_120_driver_api_t::stop.

Example:

(void) RM_MOTOR_120_DRIVER_Stop(&g_motor_120_driver0.p_ctrl);
Return values
FSP_SUCCESSSuccessfully resetted.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_120_DRIVER_Reset()

fsp_err_t RM_MOTOR_120_DRIVER_Reset ( motor_120_driver_ctrl_t *const  p_ctrl)

Reset variables of motor 120 driver module. Implements motor_120_driver_api_t::reset.

Example:

(void) RM_MOTOR_120_DRIVER_Reset(&g_motor_120_driver0.p_ctrl);
Return values
FSP_SUCCESSSuccessfully reset.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_120_DRIVER_PhaseVoltageSet()

fsp_err_t RM_MOTOR_120_DRIVER_PhaseVoltageSet ( motor_120_driver_ctrl_t *const  p_ctrl,
float const  u_voltage,
float const  v_voltage,
float const  w_voltage 
)

Set phase voltage data to calculate PWM duty. Implements motor_120_driver_api_t::phaseVoltageSet.

Example:

/* Set phase voltage */
(void) RM_MOTOR_120_DRIVER_PhaseVoltageSet(&g_motor_120_driver0.p_ctrl, 1.0F, 1.0F, 1.0F);
Return values
FSP_SUCCESSSuccessfully data is set.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_120_DRIVER_PhasePatternSet()

fsp_err_t RM_MOTOR_120_DRIVER_PhasePatternSet ( motor_120_driver_ctrl_t *const  p_ctrl,
motor_120_driver_phase_pattern_t const  pattern 
)

Set phase voltage pattern. Implements motor_120_driver_api_t::phasePatternSet.

Example:

/* Set phase pattern */
(void) RM_MOTOR_120_DRIVER_PhasePatternSet(&g_motor_120_driver0.p_ctrl, MOTOR_120_DRIVER_API_VP_ON_WN_PWM);
Return values
FSP_SUCCESSSuccessfully data is set.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_120_DRIVER_CurrentGet()

fsp_err_t RM_MOTOR_120_DRIVER_CurrentGet ( motor_120_driver_ctrl_t *const  p_ctrl,
motor_120_driver_current_status_t *const  p_current_status 
)

Get calculated phase current, Vdc & Va_max data. Implements motor_120_driver_api_t::currentGet.

Example:

/* Get electric current, main line voltage and maximum voltage component */
(void) RM_MOTOR_120_DRIVER_CurrentGet(&g_motor_120_driver0.p_ctrl, &g_current_status);
Return values
FSP_SUCCESSSuccessful data get.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTInput parameter error.

◆ RM_MOTOR_120_DRIVER_CurrentOffsetCalc()

fsp_err_t RM_MOTOR_120_DRIVER_CurrentOffsetCalc ( motor_120_driver_ctrl_t *const  p_ctrl)

current offset detection. Implements motor_120_driver_api_t::currentOffsetCalc

Example:

/* Caclutarion of current offset */
(void) RM_MOTOR_120_DRIVER_CurrentOffsetCalc(&g_motor_120_driver0.p_ctrl);
Return values
FSP_SUCCESSSuccessful data get.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTInput parameter error.

◆ RM_MOTOR_120_DRIVER_FlagCurrentOffsetGet()

fsp_err_t RM_MOTOR_120_DRIVER_FlagCurrentOffsetGet ( motor_120_driver_ctrl_t *const  p_ctrl,
motor_120_driver_flag_offset_calc_t *const  p_flag_offset 
)

Get the flag of finish current offset detection. Implements motor_120_driver_api_t::flagCurrentOffsetGet.

Example:

/* Get the flag of A/D convderted current offset */
(void) RM_MOTOR_120_DRIVER_FlagCurrentOffsetGet(&g_motor_120_driver0.p_ctrl, &u1_get_flg_offset);
Return values
FSP_SUCCESSSuccessful data get.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTInput parameter error.

◆ RM_MOTOR_120_DRIVER_ParameterUpdate()

fsp_err_t RM_MOTOR_120_DRIVER_ParameterUpdate ( motor_120_driver_ctrl_t *const  p_ctrl,
motor_120_driver_cfg_t const *const  p_cfg 
)

Update the parameters of 120 driver module. Implements motor_120_driver_api_t::parameterUpdate.

Example:

(void) RM_MOTOR_120_DRIVER_ParameterUpdate(&g_motor_120_driver0.p_ctrl, &g_motor_120_driver0.p_cfg);
Return values
FSP_SUCCESSSuccessfully data was updated.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTInput parameter error.