RA Flexible Software Package Documentation  Release v5.6.0

 
Motor Encoder Vector Control (rm_motor_encoder)

Functions

fsp_err_t RM_MOTOR_ENCODER_Open (motor_ctrl_t *const p_ctrl, motor_cfg_t const *const p_cfg)
 
fsp_err_t RM_MOTOR_ENCODER_Close (motor_ctrl_t *const p_ctrl)
 Disables specified Motor Encoder Control block. Implements motor_api_t::close. More...
 
fsp_err_t RM_MOTOR_ENCODER_Reset (motor_ctrl_t *const p_ctrl)
 Reset Motor Encoder Control block. Implements motor_api_t::reset. More...
 
fsp_err_t RM_MOTOR_ENCODER_Run (motor_ctrl_t *const p_ctrl)
 Run Motor (Start motor rotation). Implements motor_api_t::run. More...
 
fsp_err_t RM_MOTOR_ENCODER_Stop (motor_ctrl_t *const p_ctrl)
 Stop Motor (Stop motor rotation). Implements motor_api_t::stop. More...
 
fsp_err_t RM_MOTOR_ENCODER_ErrorSet (motor_ctrl_t *const p_ctrl, motor_error_t const error)
 Set error information. Implements motor_api_t::errorSet. More...
 
fsp_err_t RM_MOTOR_ENCODER_SpeedSet (motor_ctrl_t *const p_ctrl, float const speed_rpm)
 Set speed reference[rpm]. Implements motor_api_t::speedSet. More...
 
fsp_err_t RM_MOTOR_ENCODER_PositionSet (motor_ctrl_t *const p_ctrl, motor_speed_position_data_t const *const p_position)
 Set position reference[degree]. Implements motor_api_t::positionSet. More...
 
fsp_err_t RM_MOTOR_ENCODER_StatusGet (motor_ctrl_t *const p_ctrl, uint8_t *const p_status)
 Get current control status. Implements motor_api_t::statusGet. More...
 
fsp_err_t RM_MOTOR_ENCODER_AngleGet (motor_ctrl_t *const p_ctrl, float *const p_angle_rad)
 Get current rotor angle. Implements motor_api_t::angleGet. More...
 
fsp_err_t RM_MOTOR_ENCODER_SpeedGet (motor_ctrl_t *const p_ctrl, float *const p_speed_rpm)
 Get rotational speed. Implements motor_api_t::speedGet. More...
 
fsp_err_t RM_MOTOR_ENCODER_ErrorCheck (motor_ctrl_t *const p_ctrl, uint16_t *const p_error)
 Check the occurunce of Error. Implements motor_api_t::errorCheck. More...
 
fsp_err_t RM_MOTOR_ENCODER_WaitStopFlagGet (motor_ctrl_t *const p_ctrl, motor_wait_stop_flag_t *const p_flag)
 Get wait stop flag. Implements motor_api_t::waitStopFlagGet. More...
 
fsp_err_t RM_MOTOR_ENCODER_FunctionSelect (motor_ctrl_t *const p_ctrl, motor_function_select_t const function)
 Select using function. Implements motor_api_t::functionSelect. More...
 
fsp_err_t RM_MOTOR_ENCODER_InertiaEstimateStart (motor_ctrl_t *const p_ctrl)
 Start inertia estimation function. More...
 
fsp_err_t RM_MOTOR_ENCODER_InertiaEstimateStop (motor_ctrl_t *const p_ctrl)
 Stop(Cancel) inertia estimation function. More...
 
fsp_err_t RM_MOTOR_ENCODER_ReturnOriginStart (motor_ctrl_t *const p_ctrl)
 Start return origin function. More...
 
fsp_err_t RM_MOTOR_ENCODER_ReturnOriginStop (motor_ctrl_t *const p_ctrl)
 Stop(Cancel) return origin function. More...
 

Detailed Description

Control a SPM motor on RA MCUs. This module implements the Motor Encoder Vector Control (rm_motor_encoder).

Overview

The motor encoder vector control is used to control motor rotation in an application. This module is meant to be used with Surface Permanent Magnet (SPM) motors and allows applications to start or stop motor rotation easily.

Features

The motor encoder module has below features.

Target Hardware

The below figure shows an example of target hardware of this Motor Encoder Module.

rm_motor_encoder_hardware.png
Example of target hardware of motor encoder module

Block Diagram

The below figure shows block diaram of encoder vector motor control.

rm_motor_encoder_block_diagram.png
Block diagram of encoder vector control (PI feedback loop)

Modulation

rm_motor_sensorless_moduration.png
Modulation factor
rm_motor_sensorless_svpwm.png
Space vector modulation

State transition

The below figure shows a state transition diagram. Internal state is managed by "SYSTEM MODE".

rm_motor_sensorless_mode_transition.png
State transition diagram

(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) EVENT When "EVENT" occurs in each "SYSTEM MODE", "SYSTEM MODE" changes as shown the table in above figure, according to that "EVENT". The occurrence factors of each event are shown below.

EVENT name Occurrence factor
STOP by user operation
RUN by user operation
ERROR when the system detects an error
RESET by user operation

Flowchart

The below figures show flowcharts of motor encoder module.

rm_motor_sensorless_main_flowchart.png
Main process
rm_motor_encoder_current_cyclic.png
Current control process
rm_motor_encoder_speed_cyclic.png
Speed control process
rm_motor_encoder_interrupt.png
Encoder interrupt process
rm_motor_sensorless_overcurrent_flowchart.png
Over current detection interrupt process

Configuration

Build Time Configurations for rm_motor_encoder

The following build time configurations are defined in fsp_cfg/rm_motor_encoder_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 > Motor Encoder Vector Control (rm_motor_encoder)

This module can be added to the Stacks tab via New Stack > Motor > Motor Encoder Vector Control (rm_motor_encoder).

ConfigurationOptionsDefaultDescription
General
NameName must be a valid C symbolg_motor_encoder0 Module name.
Limit of over current (A)Must be a valid value2.0F Limit of over current.(Detection threshold)
Limit of over voltage (V)Must be a valid value28.0F Limit of over voltage.(Detection threshold)
Limit of over speed (rpm)Must be a valid value2100.0F Limit of over speed.(Detection threshold)
Limit of low voltage (V)Must be a valid value18.0F Limit of low voltage.(Detection threshold)
Interrupts
CallbackName must be a valid C symbolNULL A user callback function. If this callback function is provided, it is called at speed control cyclic interrupt.

Clock Configuration

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

Pin Configuration

This module does not use I/O pins. Please set used pins on configuration of each hardware modules.

Usage Notes

Limitations

Examples

Basic Example

This is a basic example of minimal use of the motor encoder module in an application.

void motor_encoder_basic_example (void)
{
fsp_err_t err = FSP_SUCCESS;
/* Initializes the module. */
err = RM_MOTOR_ENCODER_Open(g_motor_encoder0.p_ctrl, g_motor_encoder0.p_cfg);
handle_error(err);
/* Set speed reference before motor run */
(void) RM_MOTOR_ENCODER_SpeedSet(g_motor_encoder0.p_ctrl, RM_MOTOR_ENCODER_TEST_OVER_SPEED_LIMIT);
/* Set position reference before motor run */
(void) RM_MOTOR_ENCODER_PositionSet(g_motor_encoder0.p_ctrl, &g_posref_sample1);
/* Start motor rotation */
(void) RM_MOTOR_ENCODER_Run(g_motor_encoder0.p_ctrl);
/* Get current status */
(void) RM_MOTOR_ENCODER_StatusGet(g_motor_encoder0.p_ctrl, &smpl_status);
/* Get current rotor angle */
(void) RM_MOTOR_ENCODER_AngleGet(g_motor_encoder0.p_ctrl, &smpl_angle);
/* Get current motor speed */
(void) RM_MOTOR_ENCODER_SpeedGet(g_motor_encoder0.p_ctrl, &smpl_speed);
/* Check error */
(void) RM_MOTOR_ENCODER_ErrorCheck(g_motor_encoder0.p_ctrl, &smpl_error);
/* Stop motor rotation */
(void) RM_MOTOR_ENCODER_Stop(g_motor_encoder0.p_ctrl);
/* Stop motor rotation */
(void) RM_MOTOR_ENCODER_ErrorSet(g_motor_encoder0.p_ctrl, MOTOR_ERROR_OVER_CURRENT_HW);
/* Reset Speed Control */
(void) RM_MOTOR_ENCODER_Reset(g_motor_encoder0.p_ctrl);
/* Close Speed Control */
(void) RM_MOTOR_ENCODER_Close(g_motor_encoder0.p_ctrl);
}

Enumerations

enum  motor_encoder_ctrl_t
 
enum  motor_encoder_ctrl_event_t
 

Enumeration Type Documentation

◆ motor_encoder_ctrl_t

Enumerator
MOTOR_ENCODER_CTRL_STOP 

Stop mode.

MOTOR_ENCODER_CTRL_RUN 

Run mode.

MOTOR_ENCODER_CTRL_ERROR 

Error mode.

◆ motor_encoder_ctrl_event_t

Enumerator
MOTOR_ENCODER_CTRL_EVENT_STOP 

Stop event.

MOTOR_ENCODER_CTRL_EVENT_RUN 

Run event.

MOTOR_ENCODER_CTRL_EVENT_ERROR 

Error event.

MOTOR_ENCODER_CTRL_EVENT_RESET 

Reset event.

Function Documentation

◆ RM_MOTOR_ENCODER_Open()

fsp_err_t RM_MOTOR_ENCODER_Open ( motor_ctrl_t *const  p_ctrl,
motor_cfg_t const *const  p_cfg 
)

Configure the MOTOR in register start mode. Implements motor_api_t::open.

This function should only be called once as MOTOR configuration registers can only be written to once so subsequent calls will have no effect.

Example:

/* Initializes the module. */
err = RM_MOTOR_ENCODER_Open(g_motor_encoder0.p_ctrl, g_motor_encoder0.p_cfg);
Return values
FSP_SUCCESSMOTOR 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_ARGUMENTConfiguration parameter error.
Note

◆ RM_MOTOR_ENCODER_Close()

fsp_err_t RM_MOTOR_ENCODER_Close ( motor_ctrl_t *const  p_ctrl)

Disables specified Motor Encoder Control block. Implements motor_api_t::close.

Example:

/* Close Speed Control */
(void) RM_MOTOR_ENCODER_Close(g_motor_encoder0.p_ctrl);
Return values
FSP_SUCCESSSuccessfully closed.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
Note

◆ RM_MOTOR_ENCODER_Reset()

fsp_err_t RM_MOTOR_ENCODER_Reset ( motor_ctrl_t *const  p_ctrl)

Reset Motor Encoder Control block. Implements motor_api_t::reset.

Example:

/* Reset Speed Control */
(void) RM_MOTOR_ENCODER_Reset(g_motor_encoder0.p_ctrl);
Return values
FSP_SUCCESSSuccessfully resetted.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
Note

◆ RM_MOTOR_ENCODER_Run()

fsp_err_t RM_MOTOR_ENCODER_Run ( motor_ctrl_t *const  p_ctrl)

Run Motor (Start motor rotation). Implements motor_api_t::run.

Example:

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

◆ RM_MOTOR_ENCODER_Stop()

fsp_err_t RM_MOTOR_ENCODER_Stop ( motor_ctrl_t *const  p_ctrl)

Stop Motor (Stop motor rotation). Implements motor_api_t::stop.

Example:

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

◆ RM_MOTOR_ENCODER_ErrorSet()

fsp_err_t RM_MOTOR_ENCODER_ErrorSet ( motor_ctrl_t *const  p_ctrl,
motor_error_t const  error 
)

Set error information. Implements motor_api_t::errorSet.

Example:

/* Stop motor rotation */
(void) RM_MOTOR_ENCODER_ErrorSet(g_motor_encoder0.p_ctrl, MOTOR_ERROR_OVER_CURRENT_HW);
Return values
FSP_SUCCESSSuccessfully resetted.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
Note

◆ RM_MOTOR_ENCODER_SpeedSet()

fsp_err_t RM_MOTOR_ENCODER_SpeedSet ( motor_ctrl_t *const  p_ctrl,
float const  speed_rpm 
)

Set speed reference[rpm]. Implements motor_api_t::speedSet.

Example:

/* Set speed reference before motor run */
(void) RM_MOTOR_ENCODER_SpeedSet(g_motor_encoder0.p_ctrl, RM_MOTOR_ENCODER_TEST_OVER_SPEED_LIMIT);
Return values
FSP_SUCCESSSuccessfully resetted.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
Note

◆ RM_MOTOR_ENCODER_PositionSet()

fsp_err_t RM_MOTOR_ENCODER_PositionSet ( motor_ctrl_t *const  p_ctrl,
motor_speed_position_data_t const *const  p_position 
)

Set position reference[degree]. Implements motor_api_t::positionSet.

Example:

/* Set position reference before motor run */
(void) RM_MOTOR_ENCODER_PositionSet(g_motor_encoder0.p_ctrl, &g_posref_sample1);
Return values
FSP_SUCCESSSuccessfully resetted.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTData set pointer is invalid..
Note

◆ RM_MOTOR_ENCODER_StatusGet()

fsp_err_t RM_MOTOR_ENCODER_StatusGet ( motor_ctrl_t *const  p_ctrl,
uint8_t *const  p_status 
)

Get current control status. Implements motor_api_t::statusGet.

Example:

/* Get current status */
(void) RM_MOTOR_ENCODER_StatusGet(g_motor_encoder0.p_ctrl, &smpl_status);
Return values
FSP_SUCCESSSuccessfully resetted.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTData received pointer is invalid..
Note

◆ RM_MOTOR_ENCODER_AngleGet()

fsp_err_t RM_MOTOR_ENCODER_AngleGet ( motor_ctrl_t *const  p_ctrl,
float *const  p_angle_rad 
)

Get current rotor angle. Implements motor_api_t::angleGet.

Example:

/* Get current rotor angle */
(void) RM_MOTOR_ENCODER_AngleGet(g_motor_encoder0.p_ctrl, &smpl_angle);
Return values
FSP_SUCCESSSuccessfully resetted.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTData received pointer is invalid..
Note

◆ RM_MOTOR_ENCODER_SpeedGet()

fsp_err_t RM_MOTOR_ENCODER_SpeedGet ( motor_ctrl_t *const  p_ctrl,
float *const  p_speed_rpm 
)

Get rotational speed. Implements motor_api_t::speedGet.

Example:

/* Get current motor speed */
(void) RM_MOTOR_ENCODER_SpeedGet(g_motor_encoder0.p_ctrl, &smpl_speed);
Return values
FSP_SUCCESSSuccessfully resetted.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTData received pointer is invalid..
Note

◆ RM_MOTOR_ENCODER_ErrorCheck()

fsp_err_t RM_MOTOR_ENCODER_ErrorCheck ( motor_ctrl_t *const  p_ctrl,
uint16_t *const  p_error 
)

Check the occurunce of Error. Implements motor_api_t::errorCheck.

Example:

/* Check error */
(void) RM_MOTOR_ENCODER_ErrorCheck(g_motor_encoder0.p_ctrl, &smpl_error);
Return values
FSP_SUCCESSSuccessfully resetted.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTData received pointer is invalid..
Note

◆ RM_MOTOR_ENCODER_WaitStopFlagGet()

fsp_err_t RM_MOTOR_ENCODER_WaitStopFlagGet ( motor_ctrl_t *const  p_ctrl,
motor_wait_stop_flag_t *const  p_flag 
)

Get wait stop flag. Implements motor_api_t::waitStopFlagGet.

Example:

Return values
FSP_ERR_UNSUPPORTEDUnsupported.
Note

◆ RM_MOTOR_ENCODER_FunctionSelect()

fsp_err_t RM_MOTOR_ENCODER_FunctionSelect ( motor_ctrl_t *const  p_ctrl,
motor_function_select_t const  function 
)

Select using function. Implements motor_api_t::functionSelect.

Return values
FSP_SUCCESSSuccessfully resetted.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_MODEMode unmatch
Note

◆ RM_MOTOR_ENCODER_InertiaEstimateStart()

fsp_err_t RM_MOTOR_ENCODER_InertiaEstimateStart ( motor_ctrl_t *const  p_ctrl)

Start inertia estimation function.

Return values
FSP_SUCCESSSuccessfully resetted.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_MODEMode unmatch
Note

◆ RM_MOTOR_ENCODER_InertiaEstimateStop()

fsp_err_t RM_MOTOR_ENCODER_InertiaEstimateStop ( motor_ctrl_t *const  p_ctrl)

Stop(Cancel) inertia estimation function.

Return values
FSP_SUCCESSSuccessfully resetted.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_MODEMode unmatch
Note

◆ RM_MOTOR_ENCODER_ReturnOriginStart()

fsp_err_t RM_MOTOR_ENCODER_ReturnOriginStart ( motor_ctrl_t *const  p_ctrl)

Start return origin function.

Return values
FSP_SUCCESSSuccessfully resetted.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_MODEMode unmatch
Note

◆ RM_MOTOR_ENCODER_ReturnOriginStop()

fsp_err_t RM_MOTOR_ENCODER_ReturnOriginStop ( motor_ctrl_t *const  p_ctrl)

Stop(Cancel) return origin function.

Return values
FSP_SUCCESSSuccessfully resetted.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_MODEMode unmatch
Note