RA Flexible Software Package Documentation  Release v5.2.0

 
120-degree conduction control with Hall sensors (rm_motor_120_control_hall)

Functions

fsp_err_t RM_MOTOR_120_CONTROL_HALL_Open (motor_120_control_ctrl_t *const p_ctrl, motor_120_control_cfg_t const *const p_cfg)
 Opens and configures the motor hall 120 detection module. Implements motor_120_control_api_t::open. More...
 
fsp_err_t RM_MOTOR_120_CONTROL_HALL_Close (motor_120_control_ctrl_t *const p_ctrl)
 Disables specified motor hall 120 detection module. Implements motor_120_control_api_t::close. More...
 
fsp_err_t RM_MOTOR_120_CONTROL_HALL_Run (motor_120_control_ctrl_t *const p_ctrl)
 Run motor (Start motor rotation). Implements motor_120_control_api_t::run. More...
 
fsp_err_t RM_MOTOR_120_CONTROL_HALL_Stop (motor_120_control_ctrl_t *const p_ctrl)
 Stop motor (Stop motor rotation). Implements motor_120_control_api_t::stop. More...
 
fsp_err_t RM_MOTOR_120_CONTROL_HALL_Reset (motor_120_control_ctrl_t *const p_ctrl)
 Reset variables of motor hall 120 detection module. Implements motor_120_control_api_t::reset. More...
 
fsp_err_t RM_MOTOR_120_CONTROL_HALL_SpeedSet (motor_120_control_ctrl_t *const p_ctrl, float const speed_rpm)
 Set speed[rpm]. Implements motor_120_control_api_t::speedSet. More...
 
fsp_err_t RM_MOTOR_120_CONTROL_HALL_SpeedGet (motor_120_control_ctrl_t *const p_ctrl, float *const p_speed_rpm)
 Get speed. Implements motor_120_control_api_t::speedGet. More...
 
fsp_err_t RM_MOTOR_120_CONTROL_HALL_CurrentGet (motor_120_control_ctrl_t *const p_ctrl, motor_120_driver_current_status_t *const p_current_status)
 Get current. Implements motor_120_control_api_t::currentGet. More...
 
fsp_err_t RM_MOTOR_120_CONTROL_HALL_WaitStopFlagGet (motor_120_control_ctrl_t *const p_ctrl, motor_120_control_wait_stop_flag_t *const p_flag)
 Get wait stop flag. Implements motor_120_control_api_t::waitStopFlagGet. More...
 
fsp_err_t RM_MOTOR_120_CONTROL_HALL_TimeoutErrorFlagGet (motor_120_control_ctrl_t *const p_ctrl, motor_120_control_timeout_error_flag_t *const p_timeout_error_flag)
 Get timeout error flag. Implements motor_120_control_api_t::timeoutErrorFlagGet. More...
 
fsp_err_t RM_MOTOR_120_CONTROL_HALL_PatternErrorFlagGet (motor_120_control_ctrl_t *const p_ctrl, motor_120_control_pattern_error_flag_t *const p_pattern_error_flag)
 Get pattern error flag. Implements motor_120_control_api_t::patternErrorFlagGet. More...
 
fsp_err_t RM_MOTOR_120_CONTROL_HALL_VoltageRefGet (motor_120_control_ctrl_t *const p_ctrl, motor_120_control_voltage_ref_t *const p_voltage_ref)
 Get voltage ref. Implements motor_120_control_api_t::voltageRefGet. More...
 
fsp_err_t RM_MOTOR_120_CONTROL_HALL_ParameterUpdate (motor_120_control_ctrl_t *const p_ctrl, motor_120_control_cfg_t const *const p_cfg)
 Update the parameters of hall 120 detection module. Implements motor_120_control_api_t::parameterUpdate. More...
 

Detailed Description

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

Overview

The motor current is used to control the electric current of motor rotation in an appication. This module should be called cyclically after the A/D conversion of electric current of each phase in an application. This module calculates each phase voltage with input current reference, electric current and rotor angle.

Features

The motor 120 control hall module has below features.

Configuration

Build Time Configurations for rm_motor_120_control_hall

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

ConfigurationOptionsDefaultDescription
Parameter Checking
  • Default (BSP)
  • Enabled
  • Disabled
Default (BSP) If selected code for parameter checking is included in the build.

Configurations for Motor > 120-degree conduction control with Hall sensors (rm_motor_120_control_hall)

This module can be added to the Stacks tab via New Stack > Motor > 120-degree conduction control with Hall sensors (rm_motor_120_control_hall).

ConfigurationOptionsDefaultDescription
General
NameName must be a valid C symbolg_motor_120_control_hall0 Module name.
Conduction type
  • First 60 degree PWM
  • Complementary First 60 degree PWM
First 60 degree PWM Select conduction type
Timeout counts (msec)Must be a valid non-negative value.200 Counts to judge rotor unrotate
Maximum voltage (V)Must be a valid non-negative value.20.0 Maximum output voltage (V)
Minimum voltage (V)Must be a valid non-negative value.3.0 Minimum output voltage (V)
Speed PI decimationMust be a valid non-negative value.0 Speed PI control decimation count
Freerun timer frequency (MHz)Must be a valid non-negative value.120 Freerun timer frequency (MHz)
Speed LPFMust be a valid non-negative value.1.0 Speed LPF parameter
Step of speed reference changeMust be a valid non-negative value.0.2 Speed ref change step
Start reference voltage (V)Must be a valid non-negative value.5.8 Reference voltage for boot mode (V)
Hall wait countsMust be a valid non-negative value.12 Wait counts of hall interrupts to start speed calculation
Stop judge timeMust be a valid non-negative value.1000 Stop judge time
Minimum limit speed (rpm)Must be a valid non-negative value.550 Minimum limit speed (rpm) (mechanical angle)
PI control KPMust be a valid non-negative value.0.02 PI control gain of proportional term
PI control KIMust be a valid non-negative value.0.0005 PI control gain of integral term
PI control limitMust be a valid non-negative value.24.0 PI control limit of integral term
Hall interrupt mask valueMust be a valid non-negative value.15 For limiting hall interrupt processing. Limited by the number of ADC interrupts
Motor Parameter
Pole pairsMust be a valid non-negative value.2 Pole pairs
Resistance (ohm)Must be a valid non-negative value.6.447 Resistance
Inductance of d-axis (H)Must be a valid non-negative value.0.0045 Inductance of d-axis
Inductance of q-axis (H)Must be a valid non-negative value.0.0045 Inductance of q-axis
Permanent magnetic flux (Wb)Must be a valid non-negative value.0.02159 Permanent magnetic flux
Motor Parameter > Rotor inertia (kgm^2)Must be a valid non-negative value.1.8 Rotor inertia
Interrupts
CallbackName must be a valid C symbolNULL Callback function
Hall sensor port UManual EntryBSP_IO_PORT_04_PIN_11 Hall sensor port U
Hall sensor port VManual EntryBSP_IO_PORT_04_PIN_10 Hall sensor port V
Hall sensor port WManual EntryBSP_IO_PORT_04_PIN_09 Hall sensor port W

Clock Configuration

This module doesn't depend on clock setting, because this module is a simple calculation process.

Pin Configuration

Depend on included ICU module.

Usage Notes

Limitations

Examples

Basic Example

This is a basic example of minimal use of the motor 120 control hall in an application.

void motor_120_control_hall_basic_example (void)
{
fsp_err_t err = FSP_SUCCESS;
/* Initializes the module. */
err = RM_MOTOR_120_CONTROL_HALL_Open(g_motor_120_control_hall0.p_ctrl, g_motor_120_control_hall0.p_cfg);
assert(FSP_SUCCESS == err);
/* Set speed reference before motor run */
(void) RM_MOTOR_120_CONTROL_HALL_SpeedSet(g_motor_120_control_hall0.p_ctrl, DEF_120_CONTROL_HALL_TEST_SPEED_REF);
/* Start motor rotation */
(void) RM_MOTOR_120_CONTROL_HALL_Run(g_motor_120_control_hall0.p_ctrl);
/* Get current motor speed */
(void) RM_MOTOR_120_CONTROL_HALL_SpeedGet(g_motor_120_control_hall0.p_ctrl, &smpl_speed);
/* Get current */
(void) RM_MOTOR_120_CONTROL_HALL_CurrentGet(g_motor_120_control_hall0.p_ctrl, &smpl_current_status);
/* Get wait stop flag */
(void) RM_MOTOR_120_CONTROL_HALL_WaitStopFlagGet(g_motor_120_control_hall0.p_ctrl, &smpl_wait_stop_flag);
/* Get timeout error flag */
(void) RM_MOTOR_120_CONTROL_HALL_TimeoutErrorFlagGet(g_motor_120_control_hall0.p_ctrl, &smpl_timeout_error_flag);
/* Get pattern error flag */
(void) RM_MOTOR_120_CONTROL_HALL_PatternErrorFlagGet(g_motor_120_control_hall0.p_ctrl, &smpl_pattern_error_flag);
/* Get voltage ref */
(void) RM_MOTOR_120_CONTROL_HALL_VoltageRefGet(g_motor_120_control_hall0.p_ctrl, &smpl_voltage_ref);
(void) RM_MOTOR_120_CONTROL_HALL_ParameterUpdate(g_motor_120_control_hall0.p_ctrl, g_motor_120_control_hall0.p_cfg);
/* Stop motor rotation */
(void) RM_MOTOR_120_CONTROL_HALL_Stop(g_motor_120_control_hall0.p_ctrl);
/* Reset the process. */
(void) RM_MOTOR_120_CONTROL_HALL_Reset(g_motor_120_control_hall0.p_ctrl);
/* Close the module. */
(void) RM_MOTOR_120_CONTROL_HALL_Close(g_motor_120_control_hall0.p_ctrl);
}

Data Structures

struct  motor_120_control_hall_extended_cfg_t
 
struct  motor_120_control_hall_instance_ctrl_t
 

Data Structure Documentation

◆ motor_120_control_hall_extended_cfg_t

struct motor_120_control_hall_extended_cfg_t

Extended configurations for motor 120 control hall

Data Fields
bsp_io_port_pin_t port_hall_sensor_u Hall sensor port U.
bsp_io_port_pin_t port_hall_sensor_v Hall sensor port V.
bsp_io_port_pin_t port_hall_sensor_w Hall sensor port W.
float f4_start_refv Reference voltage for boot mode.
uint32_t u4_hall_wait_cnt Wait counts of hall interrupts for speed calculation.
uint32_t u4_stop_judge_time Stop judge time.
uint32_t u4_min_speed_rpm Minimum limit speed (rpm) (mechanical angle)
uint32_t u4_hall_interrupt_mask_value For limiting hall interrupt processing. Limited by the number of ADC interrupts.
motor_120_driver_instance_t
const *
p_motor_120_driver_instance Motor 120 driver access module.
timer_instance_t const * p_speed_cyclic_timer_instance Cyclic process of speed control timer module.
timer_instance_t const * p_speed_calc_timer_instance Speed calculate timer module.
external_irq_instance_t const * p_u_hall_irq_instance U phase hall interrupt.
external_irq_instance_t const * p_v_hall_irq_instance V phase hall interrupt.
external_irq_instance_t const * p_w_hall_irq_instance W phase hall interrupt.

◆ motor_120_control_hall_instance_ctrl_t

struct motor_120_control_hall_instance_ctrl_t

120 control hall instance control block

Data Fields
uint32_t open Used to determine if the channel is configured.
motor_120_control_status_t active Flag to set active/inactive the motor 120 control.
motor_120_control_run_mode_t run_mode Drive mode.
motor_120_control_timeout_error_flag_t timeout_error_flag Timeout error status.
motor_120_control_pattern_error_flag_t pattern_error_flag Hall pattern error status.
motor_120_control_rotation_direction_t direction Rotational direction (0:CW ,1:CCW)
float f4_speed_calc_base Base counts to calculate rotation speed.
float f_rpm2rad Translate value to radian/second to rpm.
float f4_v_ref Voltage reference (output of speed PI control)
float f4_ref_speed_rad Motor speed reference.
float f4_ref_speed_rad_ctrl Motor speed reference for speed PI control.
float f4_speed_rad Motor speed.
uint32_t u4_cnt_speed_pi Counter for period of speed PI control.
motor_120_control_wait_stop_flag_t flag_wait_stop Flag for waiting for motor stop.
uint32_t u4_cnt_wait_stop Counter for waiting motor stop.
motor_120_driver_phase_pattern_t v_pattern Voltage pattern.
motor_120_control_speed_ref_t flag_speed_ref Speed reference flag.
motor_120_control_voltage_ref_t flag_voltage_ref Voltage reference flag.
uint32_t u4_cnt_timeout Counter for timeout error.
uint32_t u4_hall_timer_cnt Value of timer counter.
uint32_t u4_pre_hall_timer_cnt Previous value of timer counter.
int32_t s4_timer_cnt_ave Counts for 360 degrees.
uint32_t u4_timer_cnt_buf[MOTOR_120_CONTROL_HALL_TIMES] Counts for 60 degrees.
uint32_t u4_timer_cnt_num Array element number before 360 degrees.
float f4_pi_ctrl_err PI control error.
float f4_pi_ctrl_refi PI control buffer of integral term.
uint32_t u4_hall_intr_cnt For start timing of speed calculation.
uint32_t u4_adc_interrupt_cnt Number of ADC interrupt processing.
motor_120_control_cfg_t const * p_cfg Pointer of configuration structure.
timer_direction_t timer_direction Hold timer direction.
external_irq_callback_args_t hall_interrupt_args For call IRQ callbackSet function.
timer_callback_args_t timer_args For call timer callbackSet function.

Function Documentation

◆ RM_MOTOR_120_CONTROL_HALL_Open()

fsp_err_t RM_MOTOR_120_CONTROL_HALL_Open ( motor_120_control_ctrl_t *const  p_ctrl,
motor_120_control_cfg_t const *const  p_cfg 
)

Opens and configures the motor hall 120 detection module. Implements motor_120_control_api_t::open.

Example:

/* Initializes the module. */
err = RM_MOTOR_120_CONTROL_HALL_Open(g_motor_120_control_hall0.p_ctrl, g_motor_120_control_hall0.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_CONTROL_HALL_Close()

fsp_err_t RM_MOTOR_120_CONTROL_HALL_Close ( motor_120_control_ctrl_t *const  p_ctrl)

Disables specified motor hall 120 detection module. Implements motor_120_control_api_t::close.

Example:

/* Close the module. */
(void) RM_MOTOR_120_CONTROL_HALL_Close(g_motor_120_control_hall0.p_ctrl);
Return values
FSP_SUCCESSSuccessfully closed.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_120_CONTROL_HALL_Run()

fsp_err_t RM_MOTOR_120_CONTROL_HALL_Run ( motor_120_control_ctrl_t *const  p_ctrl)

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

Example:

/* Start motor rotation */
(void) RM_MOTOR_120_CONTROL_HALL_Run(g_motor_120_control_hall0.p_ctrl);
Return values
FSP_SUCCESSSuccessfully resetted.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_120_CONTROL_HALL_Stop()

fsp_err_t RM_MOTOR_120_CONTROL_HALL_Stop ( motor_120_control_ctrl_t *const  p_ctrl)

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

Example:

/* Stop motor rotation */
(void) RM_MOTOR_120_CONTROL_HALL_Stop(g_motor_120_control_hall0.p_ctrl);
Return values
FSP_SUCCESSSuccessfully resetted.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_120_CONTROL_HALL_Reset()

fsp_err_t RM_MOTOR_120_CONTROL_HALL_Reset ( motor_120_control_ctrl_t *const  p_ctrl)

Reset variables of motor hall 120 detection module. Implements motor_120_control_api_t::reset.

Example:

/* Reset the process. */
(void) RM_MOTOR_120_CONTROL_HALL_Reset(g_motor_120_control_hall0.p_ctrl);
Return values
FSP_SUCCESSSuccessfully reset.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_120_CONTROL_HALL_SpeedSet()

fsp_err_t RM_MOTOR_120_CONTROL_HALL_SpeedSet ( motor_120_control_ctrl_t *const  p_ctrl,
float const  speed_rpm 
)

Set speed[rpm]. Implements motor_120_control_api_t::speedSet.

Example:

/* Set speed reference before motor run */
(void) RM_MOTOR_120_CONTROL_HALL_SpeedSet(g_motor_120_control_hall0.p_ctrl, DEF_120_CONTROL_HALL_TEST_SPEED_REF);
Return values
FSP_SUCCESSSuccessfully resetted.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_120_CONTROL_HALL_SpeedGet()

fsp_err_t RM_MOTOR_120_CONTROL_HALL_SpeedGet ( motor_120_control_ctrl_t *const  p_ctrl,
float *const  p_speed_rpm 
)

Get speed. Implements motor_120_control_api_t::speedGet.

Example:

/* Get current motor speed */
(void) RM_MOTOR_120_CONTROL_HALL_SpeedGet(g_motor_120_control_hall0.p_ctrl, &smpl_speed);
Return values
FSP_SUCCESSSuccessfully resetted.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTInput parameter error.

◆ RM_MOTOR_120_CONTROL_HALL_CurrentGet()

fsp_err_t RM_MOTOR_120_CONTROL_HALL_CurrentGet ( motor_120_control_ctrl_t *const  p_ctrl,
motor_120_driver_current_status_t *const  p_current_status 
)

Get current. Implements motor_120_control_api_t::currentGet.

Example:

/* Get current */
(void) RM_MOTOR_120_CONTROL_HALL_CurrentGet(g_motor_120_control_hall0.p_ctrl, &smpl_current_status);
Return values
FSP_SUCCESSSuccessfully resetted.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTInput parameter error.

◆ RM_MOTOR_120_CONTROL_HALL_WaitStopFlagGet()

fsp_err_t RM_MOTOR_120_CONTROL_HALL_WaitStopFlagGet ( motor_120_control_ctrl_t *const  p_ctrl,
motor_120_control_wait_stop_flag_t *const  p_flag 
)

Get wait stop flag. Implements motor_120_control_api_t::waitStopFlagGet.

Example:

/* Get wait stop flag */
(void) RM_MOTOR_120_CONTROL_HALL_WaitStopFlagGet(g_motor_120_control_hall0.p_ctrl, &smpl_wait_stop_flag);
Return values
FSP_SUCCESSSuccessfully resetted.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTInput parameter error.

◆ RM_MOTOR_120_CONTROL_HALL_TimeoutErrorFlagGet()

fsp_err_t RM_MOTOR_120_CONTROL_HALL_TimeoutErrorFlagGet ( motor_120_control_ctrl_t *const  p_ctrl,
motor_120_control_timeout_error_flag_t *const  p_timeout_error_flag 
)

Get timeout error flag. Implements motor_120_control_api_t::timeoutErrorFlagGet.

Example:

/* Get timeout error flag */
(void) RM_MOTOR_120_CONTROL_HALL_TimeoutErrorFlagGet(g_motor_120_control_hall0.p_ctrl, &smpl_timeout_error_flag);
Return values
FSP_SUCCESSSuccessfully resetted.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTInput parameter error.

◆ RM_MOTOR_120_CONTROL_HALL_PatternErrorFlagGet()

fsp_err_t RM_MOTOR_120_CONTROL_HALL_PatternErrorFlagGet ( motor_120_control_ctrl_t *const  p_ctrl,
motor_120_control_pattern_error_flag_t *const  p_pattern_error_flag 
)

Get pattern error flag. Implements motor_120_control_api_t::patternErrorFlagGet.

Example:

/* Get pattern error flag */
(void) RM_MOTOR_120_CONTROL_HALL_PatternErrorFlagGet(g_motor_120_control_hall0.p_ctrl, &smpl_pattern_error_flag);
Return values
FSP_SUCCESSSuccessfully resetted.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTInput parameter error.

◆ RM_MOTOR_120_CONTROL_HALL_VoltageRefGet()

fsp_err_t RM_MOTOR_120_CONTROL_HALL_VoltageRefGet ( motor_120_control_ctrl_t *const  p_ctrl,
motor_120_control_voltage_ref_t *const  p_voltage_ref 
)

Get voltage ref. Implements motor_120_control_api_t::voltageRefGet.

Example:

/* Get voltage ref */
(void) RM_MOTOR_120_CONTROL_HALL_VoltageRefGet(g_motor_120_control_hall0.p_ctrl, &smpl_voltage_ref);
Return values
FSP_SUCCESSSuccessfully resetted.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTInput parameter error.

◆ RM_MOTOR_120_CONTROL_HALL_ParameterUpdate()

fsp_err_t RM_MOTOR_120_CONTROL_HALL_ParameterUpdate ( motor_120_control_ctrl_t *const  p_ctrl,
motor_120_control_cfg_t const *const  p_cfg 
)

Update the parameters of hall 120 detection module. Implements motor_120_control_api_t::parameterUpdate.

Example:

(void) RM_MOTOR_120_CONTROL_HALL_ParameterUpdate(g_motor_120_control_hall0.p_ctrl, g_motor_120_control_hall0.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.