RA Flexible Software Package Documentation  Release v6.0.0

 
Motor Angle (rm_motor_sense_encoder)

Functions

fsp_err_t RM_MOTOR_SENSE_ENCODER_Open (motor_angle_ctrl_t *const p_ctrl, motor_angle_cfg_t const *const p_cfg)
 Opens and configures the Angle Encoder module. Implements motor_angle_api_t::open. More...
 
fsp_err_t RM_MOTOR_SENSE_ENCODER_Close (motor_angle_ctrl_t *const p_ctrl)
 Disables specified Angle Encoder module. Implements motor_angle_api_t::close. More...
 
fsp_err_t RM_MOTOR_SENSE_ENCODER_Reset (motor_angle_ctrl_t *const p_ctrl)
 Reset variables of Angle Encoder module. Implements motor_angle_api_t::reset. More...
 
fsp_err_t RM_MOTOR_SENSE_ENCODER_InternalCalculate (motor_angle_ctrl_t *const p_ctrl)
 Calculate internal parameters. Implements motor_angle_api_t::internalCalculate. More...
 
fsp_err_t RM_MOTOR_SENSE_ENCODER_AngleSpeedGet (motor_angle_ctrl_t *const p_ctrl, float *const p_angle, float *const p_speed, float *const p_phase_err)
 Gets the current rotor's angle and rotation speed. Implements motor_angle_api_t::angleSpeedGet. More...
 
fsp_err_t RM_MOTOR_SENSE_ENCODER_AngleAdjust (motor_angle_ctrl_t *const p_ctrl)
 Angle Adjustment Process. Implements motor_angle_api_t::angleAdjust. More...
 
fsp_err_t RM_MOTOR_SENSE_ENCODER_EncoderCyclic (motor_angle_ctrl_t *const p_ctrl)
 Encoder Cyclic Process (Call in cyclic timer). Implements motor_angle_api_t::encoderCyclic. More...
 
fsp_err_t RM_MOTOR_SENSE_ENCODER_CyclicProcess (motor_angle_ctrl_t *const p_ctrl)
 Perform cyclic process. Implements motor_angle_api_t::cyclicProcess. More...
 
fsp_err_t RM_MOTOR_SENSE_ENCODER_InfoGet (motor_angle_ctrl_t *const p_ctrl, motor_angle_encoder_info_t *const p_info)
 Gets information of Encoder Angle Module. Implements motor_angle_api_t::infoGet. More...
 
fsp_err_t RM_MOTOR_SENSE_ENCODER_ParameterUpdate (motor_angle_ctrl_t *const p_ctrl, motor_angle_cfg_t const *const p_cfg)
 Update the parameters of Angle&Speed calculation with an encoder. Implements motor_angle_api_t::parameterUpdate. More...
 
fsp_err_t RM_MOTOR_SENSE_ENCODER_CurrentSet (motor_angle_ctrl_t *const p_ctrl, motor_angle_current_t *const p_st_current, motor_angle_voltage_reference_t *const p_st_voltage)
 Set d/q-axis Current Data & Voltage Reference. Implements motor_angle_api_t::currentSet. More...
 
fsp_err_t RM_MOTOR_SENSE_ENCODER_SpeedSet (motor_angle_ctrl_t *const p_ctrl, float const speed_ctrl, float const damp_speed)
 Set Speed Information. Implements motor_angle_api_t::speedSet. More...
 
fsp_err_t RM_MOTOR_SENSE_ENCODER_FlagPiCtrlSet (motor_angle_ctrl_t *const p_ctrl, uint32_t const flag_pi)
 Set the flag of PI Control runs. Implements motor_angle_api_t::flagPiCtrlSet. More...
 
fsp_err_t RM_MOTOR_SENSE_ENCODER_EstimatedComponentGet (motor_angle_ctrl_t *const p_ctrl, float *const p_ed, float *const p_eq)
 Gets estimated d/q-axis component. Implements motor_angle_api_t::estimatedComponentGet. More...
 
fsp_err_t RM_MOTOR_SENSE_ENCODER_SensorDataSet (motor_angle_ctrl_t *const p_ctrl, motor_angle_ad_data_t *const p_ad_data)
 Set sensor data. Implements motor_angle_api_t::sensorDataSet. More...
 

Detailed Description

Calculation process for the motor control on RA MCUs. This module implements the Motor angle Interface.

Overview

The motor angle and speed calculation with an encoder module is used to calculate rotor angle and rotational speed in an application. This module is designed to be used with the motor current module (rm_motor_current).

Features

The motor angle and speed calculation with an encoder module has the features listed below.

Configuration

Build Time Configurations for rm_motor_sense_encoder

The following build time configurations are defined in fsp_cfg/rm_motor_sense_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 Angle and Speed Calculation with encoder (rm_motor_sense_encoder)

This module can be added to the Stacks tab via New Stack > Motor > Motor Angle and Speed Calculation with encoder (rm_motor_sense_encoder).

ConfigurationOptionsDefaultDescription
General
NameName must be a valid C symbolg_motor_sense_encoder0 Module name.
Motor Parameter
Pole pairsMust be a valid positive integer.7 Pole pairs
Resistance (ohm)Must be a valid non-negative value0.453F Resistance
Inductance of d-axis (H)Must be a valid non-negative value0.0009447F Inductance of d-axis
Inductance of q-axis (H)Must be a valid non-negative value0.0009447F Inductance of q-axis
Permanent magnetic flux (Wb)Must be a valid non-negative value0.006198F Permanent magnetic flux
Motor Parameter > Rotor inertia (kgm^2)Must be a valid non-negative value0.00000962F Rotor inertia
Control Type
  • Speed
  • Position
Position Select control Type
Period of Current control (kHz)Must be a valid non-negative value20.0F Period of Current control
Period of Speed control (sec)Must be a valid non-negative value0.0005F Period of Speed control
PWM Carrier Frequency (kHz)Must be a valid non-negative value20.0F PWM Carrier Frequency
Decimation of InterruptMust be a valid positive integer.0U Decimation of Interrupt
Counts per RotationMust be a valid positive integer.1200U Encoder Counts per One Rotation
Counts for Angle AdjustMust be a valid positive integer.512U Counts for Angle Adjust (as working time)
Zero speed countsMust be a valid positive integer.20000000U Threshold counts to judge zero speed
Occupancy TimeMust be a valid non-negative value0.30F Occupancy time of carrier interrup
Carrier TimeMust be a valid non-negative value0.000013F Processing time of carrier interrupt
Process TimeMust be a valid non-negative value0.000001F Processing time of encoder interrupt
Highspeed Change Margin (rpm)Must be a valid positive integer.150U Margin of toggle speed for high speed mode
LPF parameter for Highspeed FilterMust be a valid non-negative value0.1F Highspeed mode speed LPF parameter
Counts to change speedMust be a valid positive integer.8U Counts for mode change of position speed calculation

Clock Configuration

Pin Configuration

Usage Notes

Limitations

Developers should be aware of the following limitations when using the motor angle and speed calculation with an encoder: all configurations should be set as positive values.

Examples

Basic Example

This is a basic example of minimal use of the motor angle and speed calculation with an encoder in an application.

void motor_sense_encoder_basic_example (void)
{
fsp_err_t err = FSP_SUCCESS;
/* Initializes the module. */
err = RM_MOTOR_SENSE_ENCODER_Open(&g_mtr_angle0_ctrl, &g_mtr_angle_set0_cfg);
assert(FSP_SUCCESS == err);
/* Basically run this module at A/D conversion finish interrupt.
* This implementation is an example. */
// while (true)
{
/* Application work here. */
/* Initialize motor with the encoder */
(void) RM_MOTOR_SENSE_ENCODER_AngleAdjust(&g_mtr_angle0_ctrl);
/* Perform cyclic encoder process*/
(void) RM_MOTOR_SENSE_ENCODER_CyclicProcess(&g_mtr_angle0_ctrl);
/* Calculate information with encoder signal input */
(void) RM_MOTOR_SENSE_ENCODER_InternalCalculate(&g_mtr_angle0_ctrl);
/* Get angle/speed data */
(void) RM_MOTOR_SENSE_ENCODER_AngleSpeedGet(&g_mtr_angle0_ctrl, &f_get_angle, &f_get_speed, &f_get_phase_err);
/* Get calculated component */
(void) RM_MOTOR_SENSE_ENCODER_InfoGet(&g_mtr_angle0_ctrl, &temp_info);
}
/* Reset the module */
(void) RM_MOTOR_SENSE_ENCODER_Reset(&g_mtr_angle0_ctrl);
/* Close the module */
(void) RM_MOTOR_SENSE_ENCODER_Close(&g_mtr_angle0_ctrl);
}

Enumerations

enum  motor_sense_encoder_loop_t
 
enum  motor_sense_encoder_mode_t
 

Enumeration Type Documentation

◆ motor_sense_encoder_loop_t

Enumerator
MOTOR_SENSE_ENCODER_LOOP_SPEED 

Speed control mode.

MOTOR_SENSE_ENCODER_LOOP_POSITION 

Position control mode.

◆ motor_sense_encoder_mode_t

Enumerator
MOTOR_SENSE_ENCODER_MODE_INIT 

Initialize mode (Start status)

MOTOR_SENSE_ENCODER_MODE_BOOT 

Boot mode (Angle adjustment status)

MOTOR_SENSE_ENCODER_MODE_DRIVE 

Drive mode (Normal work status)

Function Documentation

◆ RM_MOTOR_SENSE_ENCODER_Open()

fsp_err_t RM_MOTOR_SENSE_ENCODER_Open ( motor_angle_ctrl_t *const  p_ctrl,
motor_angle_cfg_t const *const  p_cfg 
)

Opens and configures the Angle Encoder module. Implements motor_angle_api_t::open.

Return values
FSP_SUCCESSAngle Encoder module 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.

◆ RM_MOTOR_SENSE_ENCODER_Close()

fsp_err_t RM_MOTOR_SENSE_ENCODER_Close ( motor_angle_ctrl_t *const  p_ctrl)

Disables specified Angle Encoder module. Implements motor_angle_api_t::close.

Return values
FSP_SUCCESSSuccessfully closed.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_SENSE_ENCODER_Reset()

fsp_err_t RM_MOTOR_SENSE_ENCODER_Reset ( motor_angle_ctrl_t *const  p_ctrl)

Reset variables of Angle Encoder module. Implements motor_angle_api_t::reset.

Return values
FSP_SUCCESSSuccessfully closed.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_SENSE_ENCODER_InternalCalculate()

fsp_err_t RM_MOTOR_SENSE_ENCODER_InternalCalculate ( motor_angle_ctrl_t *const  p_ctrl)

Calculate internal parameters. Implements motor_angle_api_t::internalCalculate.

Return values
FSP_SUCCESSSuccessfully closed.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_SENSE_ENCODER_AngleSpeedGet()

fsp_err_t RM_MOTOR_SENSE_ENCODER_AngleSpeedGet ( motor_angle_ctrl_t *const  p_ctrl,
float *const  p_angle,
float *const  p_speed,
float *const  p_phase_err 
)

Gets the current rotor's angle and rotation speed. Implements motor_angle_api_t::angleSpeedGet.

Return values
FSP_SUCCESSSuccessfully data calculated.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_SENSE_ENCODER_AngleAdjust()

fsp_err_t RM_MOTOR_SENSE_ENCODER_AngleAdjust ( motor_angle_ctrl_t *const  p_ctrl)

Angle Adjustment Process. Implements motor_angle_api_t::angleAdjust.

Return values
FSP_SUCCESSSuccessfully data calculated.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_SENSE_ENCODER_EncoderCyclic()

fsp_err_t RM_MOTOR_SENSE_ENCODER_EncoderCyclic ( motor_angle_ctrl_t *const  p_ctrl)

Encoder Cyclic Process (Call in cyclic timer). Implements motor_angle_api_t::encoderCyclic.

Return values
FSP_SUCCESSSuccessfully data calculated.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_SENSE_ENCODER_CyclicProcess()

fsp_err_t RM_MOTOR_SENSE_ENCODER_CyclicProcess ( motor_angle_ctrl_t *const  p_ctrl)

Perform cyclic process. Implements motor_angle_api_t::cyclicProcess.

Return values
FSP_SUCCESSSuccessfully data calculated.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_SENSE_ENCODER_InfoGet()

fsp_err_t RM_MOTOR_SENSE_ENCODER_InfoGet ( motor_angle_ctrl_t *const  p_ctrl,
motor_angle_encoder_info_t *const  p_info 
)

Gets information of Encoder Angle Module. Implements motor_angle_api_t::infoGet.

Return values
FSP_SUCCESSSuccessfully data calculated.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_SENSE_ENCODER_ParameterUpdate()

fsp_err_t RM_MOTOR_SENSE_ENCODER_ParameterUpdate ( motor_angle_ctrl_t *const  p_ctrl,
motor_angle_cfg_t const *const  p_cfg 
)

Update the parameters of Angle&Speed calculation with an encoder. Implements motor_angle_api_t::parameterUpdate.

Return values
FSP_SUCCESSSuccessfully data is update.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_SENSE_ENCODER_CurrentSet()

fsp_err_t RM_MOTOR_SENSE_ENCODER_CurrentSet ( motor_angle_ctrl_t *const  p_ctrl,
motor_angle_current_t *const  p_st_current,
motor_angle_voltage_reference_t *const  p_st_voltage 
)

Set d/q-axis Current Data & Voltage Reference. Implements motor_angle_api_t::currentSet.

Return values
FSP_ERR_UNSUPPORTEDMotor sense encoder software currentSet is not supported.

◆ RM_MOTOR_SENSE_ENCODER_SpeedSet()

fsp_err_t RM_MOTOR_SENSE_ENCODER_SpeedSet ( motor_angle_ctrl_t *const  p_ctrl,
float const  speed_ctrl,
float const  damp_speed 
)

Set Speed Information. Implements motor_angle_api_t::speedSet.

Return values
FSP_ERR_UNSUPPORTEDMotor sense encoder software speedSet is not supported.

◆ RM_MOTOR_SENSE_ENCODER_FlagPiCtrlSet()

fsp_err_t RM_MOTOR_SENSE_ENCODER_FlagPiCtrlSet ( motor_angle_ctrl_t *const  p_ctrl,
uint32_t const  flag_pi 
)

Set the flag of PI Control runs. Implements motor_angle_api_t::flagPiCtrlSet.

Return values
FSP_ERR_UNSUPPORTEDMotor sense encoder software flagPiCtrlSet is not supported.

◆ RM_MOTOR_SENSE_ENCODER_EstimatedComponentGet()

fsp_err_t RM_MOTOR_SENSE_ENCODER_EstimatedComponentGet ( motor_angle_ctrl_t *const  p_ctrl,
float *const  p_ed,
float *const  p_eq 
)

Gets estimated d/q-axis component. Implements motor_angle_api_t::estimatedComponentGet.

Return values
FSP_ERR_UNSUPPORTEDMotor sense encoder software estimatedComponentGet is not supported.

◆ RM_MOTOR_SENSE_ENCODER_SensorDataSet()

fsp_err_t RM_MOTOR_SENSE_ENCODER_SensorDataSet ( motor_angle_ctrl_t *const  p_ctrl,
motor_angle_ad_data_t *const  p_ad_data 
)

Set sensor data. Implements motor_angle_api_t::sensorDataSet.

Return values
FSP_ERR_UNSUPPORTEDUnsupported.