RA Flexible Software Package Documentation  Release v5.2.0

 
Motor Angle and Speed Calculation with Hall sensors (rm_motor_sense_hall)

Functions

fsp_err_t RM_MOTOR_SENSE_HALL_Open (motor_angle_ctrl_t *const p_ctrl, motor_angle_cfg_t const *const p_cfg)
 Opens and configures the angle hall sensor module. Implements motor_angle_api_t::open. More...
 
fsp_err_t RM_MOTOR_SENSE_HALL_Close (motor_angle_ctrl_t *const p_ctrl)
 Disables specified Angle Estimation module. Implements motor_angle_api_t::close. More...
 
fsp_err_t RM_MOTOR_SENSE_HALL_Reset (motor_angle_ctrl_t *const p_ctrl)
 Reset variables of Angle Estimation module. Implements motor_angle_api_t::reset. More...
 
fsp_err_t RM_MOTOR_SENSE_HALL_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_HALL_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_HALL_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_HALL_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_HALL_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_HALL_ParameterUpdate (motor_angle_ctrl_t *const p_ctrl, motor_angle_cfg_t const *const p_cfg)
 Update the parameters of Angle&Speed Estimation. Implements motor_angle_api_t::parameterUpdate. More...
 
fsp_err_t RM_MOTOR_SENSE_HALL_InternalCalculate (motor_angle_ctrl_t *const p_ctrl)
 Calculate internal parameters. Implements motor_angle_api_t::internalCalculate. More...
 
fsp_err_t RM_MOTOR_SENSE_HALL_AngleAdjust (motor_angle_ctrl_t *const p_ctrl)
 Angle Adjustment Process. Implements motor_angle_api_t::angleAdjust. More...
 
fsp_err_t RM_MOTOR_SENSE_HALL_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_HALL_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...
 

Detailed Description

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

Overview

The motor angle and speed calculation with hall sensors 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 hall sensors module has the features listed below.

Configuration

Build Time Configurations for rm_motor_sense_hall

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

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

ConfigurationOptionsDefaultDescription
General
NameName must be a valid C symbolg_motor_angle0 Module name.
Hall sensor
U phase input portManual EntryBSP_IO_PORT_12_PIN_04 Hall sensor port U
V phase input portManual EntryBSP_IO_PORT_12_PIN_05 Hall sensor port V
W phase input portManual EntryBSP_IO_PORT_11_PIN_01 Hall sensor port W
sensor pattern #1Manual Entry1 Hall sensor pattern #1
sensor pattern #2Manual Entry5 Hall sensor pattern #2
sensor pattern #3Manual Entry4 Hall sensor pattern #3
sensor pattern #4Manual Entry6 Hall sensor pattern #4
sensor pattern #5Manual Entry2 Hall sensor pattern #5
sensor pattern #6Manual Entry3 Hall sensor pattern #6
Process Frequency (kHz)Must be a valid value20.0F Frequency to perform the process.
Correction parameter of rotor angleMust be a valid value0.0F Correction parameter of rotor angle
Default counts of carrier interruptMust be a valid non-negative value.300U Default counts of carrier interrupt during a period of Hall signal change
Maximum counts of one rotationMust be a valid non-negative value.500U Maximum counts of carrier interrupt during one rotor rotation
Target value for pseudo speed (rad/s)Must be a valid non-negative value.100.0 Target value for pseudo speed (rad/s).
Target time until the pseudo speed update reaches (msec)Must be a valid non-negative value.300.0 Target time until the pseudo speed update reaches (msec).
Rotation counts to start speed estimationMust be a valid non-negative value.2 Rotation counts to start of speed estimation.
Carrier counts at startupMust be a valid non-negative value.400 Carrier counts to wait the start timing of pseudo speed update
Speed to judge startMust be a valid non-negative value.250.0 Speed to judge start PI 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 hall sensors: 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 hall sensors in an application.

void motor_sense_hall_basic_example (void)
{
fsp_err_t err = FSP_SUCCESS;
/* Initializes the module. */
err = RM_MOTOR_SENSE_HALL_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. */
/* Get angle/speed data */
(void) RM_MOTOR_SENSE_HALL_AngleSpeedGet(&g_mtr_angle0_ctrl, &f_get_angle, &f_get_speed, &f_get_phase_err);
}
/* Reset the module */
(void) RM_MOTOR_SENSE_HALL_Reset(&g_mtr_angle0_ctrl);
/* Close the module */
(void) RM_MOTOR_SENSE_HALL_Close(&g_mtr_angle0_ctrl);
}

Data Structures

struct  motor_sense_hall_input_t
 
struct  motor_sense_hall_extended_cfg_t
 
struct  motor_sense_hall_instance_ctrl_t
 

Enumerations

enum  motor_sense_hall_direction_t
 
enum  motor_sense_hall_signal_status_t
 

Data Structure Documentation

◆ motor_sense_hall_input_t

struct motor_sense_hall_input_t

This stucture is provided to receive speed information.

Data Fields
float f4_ref_speed_rad_ctrl Speed Reference [rad/sec].

◆ motor_sense_hall_extended_cfg_t

struct motor_sense_hall_extended_cfg_t

Optional Motor sense hall extension data structure.

Data Fields
bsp_io_port_pin_t port_hall_sensor_u Hall U-signal input port.
bsp_io_port_pin_t port_hall_sensor_v Hall V-signal input port.
bsp_io_port_pin_t port_hall_sensor_w Hall W-signal input port.
uint8_t u1_hall_pattern[MOTOR_SENSE_HALL_SPEED_COUNTS+1] The order of hall signal pattern.
float f_pwm_carrier_freq PWM carrier frequency (or Decimated frequency at decimation of current process)
float f_angle_correct Coefficent to correct angle.
uint8_t u1_trigger_hall_signal_count Rotation counts to wait the stability.
float f4_target_pseudo_speed_rad Target value for pseudo speed estimates [radian/second].
float f4_reach_time_msec Time until the pseudo speed estimate reaches the target value [msec].
uint16_t u2_trigger_carrier_count Estimated speed 0 until this trigger.
uint16_t u2_default_counts Default counts for period of hall signal to reset.
uint16_t u2_maximum_period Maximum counts of hall signal period.
uint8_t u1_hall_polepairs Hall pole pairs.
float f4_start_speed_rad Speed to judge start [radian/second].

◆ motor_sense_hall_instance_ctrl_t

struct motor_sense_hall_instance_ctrl_t

SENSE_HALL control block. DO NOT INITIALIZE. Initialization occurs when motor_angle_api_t::open is called.

Data Fields
uint32_t open
uint8_t u1_hall_signal Hall signal pattern.
uint8_t u1_last_hall_signal Last hall signal pattern.
motor_sense_hall_direction_t direction Rotation direction.
motor_sense_hall_direction_t last_direction Last rotation direction.
uint16_t u2_carrier_count Carrier count.
uint16_t u2_hall_period[MOTOR_SENSE_HALL_SPEED_COUNTS] Array of carrier count to calculate 2PI.
uint8_t u1_period_counter Counter for above array.
float f_angle Rotor angle [radian].
float f_angle_per_count Angle per 1 count.
float f_calculated_speed Calculated speed [radian/second].
uint8_t u1_hall_signal_memory Memorized hall signal at startup.
motor_sense_hall_signal_status_t hall_signal_status Hall signal status.
uint8_t u1_hall_signal_count Rotation counter.
float f4_pseudo_speed_rad Pseudo speed used for startup [radian/second].
float f4_add_pseudo_speed_rad Step of pseudo speed to update [radian/second].
uint16_t u2_startup_carrier_count Counter of carrier interrupt for startup.
motor_sense_hall_input_t st_input Input parameter structure.
uint8_t u1_startup_flag Flag for startup.
motor_angle_cfg_t const * p_cfg

Enumeration Type Documentation

◆ motor_sense_hall_direction_t

Enumerator
MOTOR_SENSE_HALL_DIRECTION_CW 

Rotation direction clockwise.

MOTOR_SENSE_HALL_DIRECTION_CCW 

Rotation direction counter clockwise.

◆ motor_sense_hall_signal_status_t

Enumerator
MOTOR_SENSE_HALL_SIGNAL_STATUS_INITIAL 

Hall signal isn't captured. (Initial)

MOTOR_SENSE_HALL_SIGNAL_STATUS_CAPTURED 

Hall signal is captured.

Function Documentation

◆ RM_MOTOR_SENSE_HALL_Open()

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

Opens and configures the angle hall sensor module. Implements motor_angle_api_t::open.

Return values
FSP_SUCCESSMTR_ANGL_EST 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.

◆ RM_MOTOR_SENSE_HALL_Close()

fsp_err_t RM_MOTOR_SENSE_HALL_Close ( motor_angle_ctrl_t *const  p_ctrl)

Disables specified Angle Estimation 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_HALL_Reset()

fsp_err_t RM_MOTOR_SENSE_HALL_Reset ( motor_angle_ctrl_t *const  p_ctrl)

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

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

◆ RM_MOTOR_SENSE_HALL_CurrentSet()

fsp_err_t RM_MOTOR_SENSE_HALL_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_UNSUPPORTEDUnsupported.

◆ RM_MOTOR_SENSE_HALL_SpeedSet()

fsp_err_t RM_MOTOR_SENSE_HALL_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_SUCCESSData get successfully.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_SENSE_HALL_FlagPiCtrlSet()

fsp_err_t RM_MOTOR_SENSE_HALL_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_UNSUPPORTEDUnsupported.

◆ RM_MOTOR_SENSE_HALL_AngleSpeedGet()

fsp_err_t RM_MOTOR_SENSE_HALL_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_SUCCESSSuccessful data get.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTOutput pointer is invalid.

◆ RM_MOTOR_SENSE_HALL_EstimatedComponentGet()

fsp_err_t RM_MOTOR_SENSE_HALL_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_UNSUPPORTEDUnsupported.

◆ RM_MOTOR_SENSE_HALL_ParameterUpdate()

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

Update the parameters of Angle&Speed Estimation. 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_HALL_InternalCalculate()

fsp_err_t RM_MOTOR_SENSE_HALL_InternalCalculate ( motor_angle_ctrl_t *const  p_ctrl)

Calculate internal parameters. Implements motor_angle_api_t::internalCalculate.

Return values
FSP_ERR_UNSUPPORTEDUnsupported.

◆ RM_MOTOR_SENSE_HALL_AngleAdjust()

fsp_err_t RM_MOTOR_SENSE_HALL_AngleAdjust ( motor_angle_ctrl_t *const  p_ctrl)

Angle Adjustment Process. Implements motor_angle_api_t::angleAdjust.

Return values
FSP_ERR_UNSUPPORTEDUnsupported.

◆ RM_MOTOR_SENSE_HALL_EncoderCyclic()

fsp_err_t RM_MOTOR_SENSE_HALL_EncoderCyclic ( motor_angle_ctrl_t *const  p_ctrl)

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

Return values
FSP_ERR_UNSUPPORTEDUnsupported.

◆ RM_MOTOR_SENSE_HALL_InfoGet()

fsp_err_t RM_MOTOR_SENSE_HALL_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_ERR_UNSUPPORTEDUnsupported.