RA Flexible Software Package Documentation
Release v5.6.0
|
|
Control a SPM motor on RA MCUs. This module implements the Motor Encoder Vector Control (rm_motor_encoder).
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.
The motor encoder module has below features.
The below figure shows an example of target hardware of this Motor Encoder Module.
The below figure shows block diaram of encoder vector motor control.
The below figure shows a state transition diagram. Internal state is managed by "SYSTEM MODE".
(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 |
The below figures show flowcharts of motor encoder module.
Configuration | Options | Default | Description |
---|---|---|---|
Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
Configuration | Options | Default | Description |
---|---|---|---|
General | |||
Name | Name must be a valid C symbol | g_motor_encoder0 | Module name. |
Limit of over current (A) | Must be a valid value | 2.0F | Limit of over current.(Detection threshold) |
Limit of over voltage (V) | Must be a valid value | 28.0F | Limit of over voltage.(Detection threshold) |
Limit of over speed (rpm) | Must be a valid value | 2100.0F | Limit of over speed.(Detection threshold) |
Limit of low voltage (V) | Must be a valid value | 18.0F | Limit of low voltage.(Detection threshold) |
Interrupts | |||
Callback | Name must be a valid C symbol | NULL | A user callback function. If this callback function is provided, it is called at speed control cyclic interrupt. |
This module doesn't depend on clock setting, because this module is a simple status transition process.
This module does not use I/O pins. Please set used pins on configuration of each hardware modules.
This is a basic example of minimal use of the motor encoder module in an application.
Enumerations | |
enum | motor_encoder_ctrl_t |
enum | motor_encoder_ctrl_event_t |
enum motor_encoder_ctrl_t |
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:
FSP_SUCCESS | MOTOR successfully configured. |
FSP_ERR_ASSERTION | Null pointer, or one or more configuration options is invalid. |
FSP_ERR_ALREADY_OPEN | Module is already open. This module can only be opened once. |
FSP_ERR_INVALID_ARGUMENT | Configuration parameter error. |
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:
FSP_SUCCESS | Successfully closed. |
FSP_ERR_ASSERTION | Null pointer. |
FSP_ERR_NOT_OPEN | Module is not open. |
fsp_err_t RM_MOTOR_ENCODER_Reset | ( | motor_ctrl_t *const | p_ctrl | ) |
Reset Motor Encoder Control block. Implements motor_api_t::reset.
Example:
FSP_SUCCESS | Successfully resetted. |
FSP_ERR_ASSERTION | Null pointer. |
FSP_ERR_NOT_OPEN | Module is not open. |
fsp_err_t RM_MOTOR_ENCODER_Run | ( | motor_ctrl_t *const | p_ctrl | ) |
Run Motor (Start motor rotation). Implements motor_api_t::run.
Example:
FSP_SUCCESS | Successfully resetted. |
FSP_ERR_ASSERTION | Null pointer. |
FSP_ERR_NOT_OPEN | Module is not open. |
fsp_err_t RM_MOTOR_ENCODER_Stop | ( | motor_ctrl_t *const | p_ctrl | ) |
Stop Motor (Stop motor rotation). Implements motor_api_t::stop.
Example:
FSP_SUCCESS | Successfully resetted. |
FSP_ERR_ASSERTION | Null pointer. |
FSP_ERR_NOT_OPEN | Module is not open. |
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:
FSP_SUCCESS | Successfully resetted. |
FSP_ERR_ASSERTION | Null pointer. |
FSP_ERR_NOT_OPEN | Module is not open. |
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:
FSP_SUCCESS | Successfully resetted. |
FSP_ERR_ASSERTION | Null pointer. |
FSP_ERR_NOT_OPEN | Module is not open. |
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:
FSP_SUCCESS | Successfully resetted. |
FSP_ERR_ASSERTION | Null pointer. |
FSP_ERR_NOT_OPEN | Module is not open. |
FSP_ERR_INVALID_ARGUMENT | Data set pointer is invalid.. |
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:
FSP_SUCCESS | Successfully resetted. |
FSP_ERR_ASSERTION | Null pointer. |
FSP_ERR_NOT_OPEN | Module is not open. |
FSP_ERR_INVALID_ARGUMENT | Data received pointer is invalid.. |
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:
FSP_SUCCESS | Successfully resetted. |
FSP_ERR_ASSERTION | Null pointer. |
FSP_ERR_NOT_OPEN | Module is not open. |
FSP_ERR_INVALID_ARGUMENT | Data received pointer is invalid.. |
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:
FSP_SUCCESS | Successfully resetted. |
FSP_ERR_ASSERTION | Null pointer. |
FSP_ERR_NOT_OPEN | Module is not open. |
FSP_ERR_INVALID_ARGUMENT | Data received pointer is invalid.. |
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:
FSP_SUCCESS | Successfully resetted. |
FSP_ERR_ASSERTION | Null pointer. |
FSP_ERR_NOT_OPEN | Module is not open. |
FSP_ERR_INVALID_ARGUMENT | Data received pointer is invalid.. |
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:
FSP_ERR_UNSUPPORTED | Unsupported. |
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.
FSP_SUCCESS | Successfully resetted. |
FSP_ERR_ASSERTION | Null pointer. |
FSP_ERR_NOT_OPEN | Module is not open. |
FSP_ERR_INVALID_MODE | Mode unmatch |
fsp_err_t RM_MOTOR_ENCODER_InertiaEstimateStart | ( | motor_ctrl_t *const | p_ctrl | ) |
Start inertia estimation function.
FSP_SUCCESS | Successfully resetted. |
FSP_ERR_ASSERTION | Null pointer. |
FSP_ERR_NOT_OPEN | Module is not open. |
FSP_ERR_INVALID_MODE | Mode unmatch |
fsp_err_t RM_MOTOR_ENCODER_InertiaEstimateStop | ( | motor_ctrl_t *const | p_ctrl | ) |
Stop(Cancel) inertia estimation function.
FSP_SUCCESS | Successfully resetted. |
FSP_ERR_ASSERTION | Null pointer. |
FSP_ERR_NOT_OPEN | Module is not open. |
FSP_ERR_INVALID_MODE | Mode unmatch |
fsp_err_t RM_MOTOR_ENCODER_ReturnOriginStart | ( | motor_ctrl_t *const | p_ctrl | ) |
Start return origin function.
FSP_SUCCESS | Successfully resetted. |
FSP_ERR_ASSERTION | Null pointer. |
FSP_ERR_NOT_OPEN | Module is not open. |
FSP_ERR_INVALID_MODE | Mode unmatch |
fsp_err_t RM_MOTOR_ENCODER_ReturnOriginStop | ( | motor_ctrl_t *const | p_ctrl | ) |
Stop(Cancel) return origin function.
FSP_SUCCESS | Successfully resetted. |
FSP_ERR_ASSERTION | Null pointer. |
FSP_ERR_NOT_OPEN | Module is not open. |
FSP_ERR_INVALID_MODE | Mode unmatch |