HPM SDK
HPMicro Software Development Kit
hpm_mcl_loop.h File Reference
#include "hpm_mcl_common.h"
#include "hpm_mcl_encoder.h"
#include "hpm_mcl_analog.h"
#include "hpm_mcl_control.h"
#include "hpm_mcl_drivers.h"
#include "hpm_mcl_path_plan.h"
#include "hpm_mcl_debug.h"
#include "hpm_mcl_hw_loop.h"

Go to the source code of this file.

Data Structures

struct  mcl_loop_cfg_t
 Loop Configuration. More...
 
struct  mcl_hardware_clc_cfg_t
 Hardware configuration for CLC. More...
 
struct  mcl_offline_param_detection_rundata_t
 
struct  mcl_loop_t
 Loop operation data. More...
 
struct  mcl_motor_alignment_basic_cfg_t
 Basic alignment configuration (single-stage) More...
 
struct  mcl_motor_alignment_three_stage_cfg_t
 Three-stage alignment configuration. More...
 
union  mcl_motor_alignment_algorithm_cfg_t
 Motor alignment configuration union for different algorithms. More...
 
struct  mcl_motor_alignment_cfg_t
 Motor angle alignment configuration parameters. More...
 

Macros

#define GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, NAME, ...)   NAME
 
#define hpm_mcl_loop_init(...)   GET_MACRO(__VA_ARGS__, hpm_mcl_loop_init_v2, hpm_mcl_loop_init_v1, dummy, dummy, dummy, dummy, dummy, dummy)(__VA_ARGS__)
 Overloaded hpm_mcl_loop_init macro that supports both v1.9.0 and v1.10.0+ API. More...
 

Enumerations

enum  mcl_loop_status_t { loop_status_null = 0 , loop_status_init = 1 , loop_status_run = 2 , loop_status_fail = 3 }
 
enum  mcl_loop_mode_t {
  mcl_mode_foc = 1 , mcl_mode_block = 2 , mcl_mode_hardware_foc = 3 , mcl_mode_step_foc = 4 ,
  mcl_mode_offline_param_detection = 5 , mcl_mode_hybrid_foc = 6
}
 Algorithms used in loops. More...
 
enum  mcl_loop_chn_t { loop_chn_id = 0 , loop_chn_iq = 1 }
 CLC channel. More...
 
enum  mcl_offline_param_detection_mode_t {
  offline_param_detection_mode_init = 0 , offline_param_detection_mode_rs = 1 , offline_param_detection_mode_ld = 2 , offline_param_detection_mode_lq = 3 ,
  offline_param_detection_mode_ls = 4 , offline_param_detection_mode_flux = 5 , offline_param_detection_mode_wait = 6 , offline_param_detection_mode_end = 7 ,
  offline_param_detection_mode_error = 8
}
 Internal use, process control in the process. More...
 
enum  mcl_motor_alignment_algorithm_t { mcl_alignment_algorithm_basic = 0 , mcl_alignment_algorithm_three_stage = 1 , mcl_alignment_algorithm_adaptive = 2 }
 Motor alignment algorithm types. More...
 

Functions

hpm_mcl_stat_t hpm_mcl_motor_angle_alignment (mcl_loop_t *loop, mcl_motor_alignment_cfg_t *cfg)
 Enhanced motor angle alignment algorithm with multiple algorithm support. More...
 
hpm_mcl_stat_t hpm_mcl_loop_init_v2 (mcl_loop_t *loop, mcl_loop_cfg_t *cfg, mcl_cfg_t *mcl_cfg, mcl_encoder_t *encoder, mcl_analog_t *analog, mcl_control_t *control, mcl_drivers_t *drivers, mcl_path_plan_t *path, mcl_hw_loop_t *hw_loop)
 Initialisation loop data (API introduced in v1.10.0 with hw_loop parameter) More...
 
static hpm_mcl_stat_t hpm_mcl_loop_init_v1 (mcl_loop_t *loop, mcl_loop_cfg_t *cfg, mcl_cfg_t *mcl_cfg, mcl_encoder_t *encoder, mcl_analog_t *analog, mcl_control_t *control, mcl_drivers_t *drivers, mcl_path_plan_t *path)
 Backward compatibility function for API used in v1.9.0 and earlier (without hw_loop parameter) More...
 
hpm_mcl_stat_t hpm_mcl_loop_set_current_d (mcl_loop_t *loop, mcl_user_value_t id)
 Setting the d-axis current. More...
 
hpm_mcl_stat_t hpm_mcl_loop_set_current_q (mcl_loop_t *loop, mcl_user_value_t iq)
 Setting the q-axis current. More...
 
hpm_mcl_stat_t hpm_mcl_loop_set_speed (mcl_loop_t *loop, mcl_user_value_t speed)
 Setting the speed loop speed feed. More...
 
hpm_mcl_stat_t hpm_mcl_loop_set_position (mcl_loop_t *loop, mcl_user_value_t position)
 Setting the position parameters. More...
 
hpm_mcl_stat_t hpm_mcl_loop_disable_all_user_set_value (mcl_loop_t *loop)
 Invalid user-set values in all loops. More...
 
hpm_mcl_stat_t hpm_mcl_loop (mcl_loop_t *loop)
 Motor Loop, Periodic Recall. More...
 
hpm_mcl_stat_t hpm_mcl_loop_refresh_block (mcl_loop_t *loop)
 Call this function in the interrupt function to update the motor's sector. More...
 
hpm_mcl_stat_t hpm_mcl_loop_start_block (mcl_loop_t *loop)
 Call this function in the interrupt function to start the motor's sector. More...
 
static void hpm_mcl_loop_enable (mcl_loop_t *loop)
 Enable Loop. More...
 
static void hpm_mcl_loop_disable (mcl_loop_t *loop)
 Disable Loop. More...
 
static void hpm_mcl_loop_enable_offline_param_detecion (mcl_loop_t *loop)
 Enables the loop's offline parameter detection. More...
 
static bool hpm_mcl_loop_offline_param_detection_is_done (mcl_loop_t *loop)
 Get offline parameter is done. More...
 
static bool hpm_mcl_loop_offline_param_detection_is_error (mcl_loop_t *loop)
 Get offline parameter is error. More...
 
static void hpm_mcl_loop_offline_param_detection_get_result (mcl_loop_t *loop, mcl_offline_param_detection_result_t *result)
 Get offline parameter detection result. More...
 
static void hpm_mcl_loop_mode_set (mcl_loop_t *loop, mcl_loop_mode_t mode)
 Set loop mode. More...
 
static void hpm_mcl_enable_position_loop (mcl_loop_t *loop)
 Enable position loop. More...
 
static void hpm_mcl_disable_position_loop (mcl_loop_t *loop)
 Disable position loop. More...
 
static void hpm_mcl_enable_speed_loop (mcl_loop_t *loop)
 Enable speed loop. More...
 
static void hpm_mcl_disable_speed_loop (mcl_loop_t *loop)
 Disable speed loop. More...
 
static hpm_mcl_stat_t hpm_mcl_disable_dead_area_compensation (mcl_loop_t *loop)
 disable dead area compensation More...
 
static hpm_mcl_stat_t hpm_mcl_enable_dead_area_compensation (mcl_loop_t *loop)
 enable dead area compensation More...
 
static hpm_mcl_stat_t hpm_mcl_disable_dq_axis_decoupling (mcl_loop_t *loop)
 disable dq axis decoupling More...
 
static hpm_mcl_stat_t hpm_mcl_enable_dq_axis_decoupling (mcl_loop_t *loop)
 enable dq axis decoupling More...
 
static uint32_t hpm_mcl_get_current_loop_run_tick (mcl_loop_t *loop)
 Get current loop run tick. More...
 

Macro Definition Documentation

◆ GET_MACRO

#define GET_MACRO (   _1,
  _2,
  _3,
  _4,
  _5,
  _6,
  _7,
  _8,
  _9,
  NAME,
  ... 
)    NAME

◆ hpm_mcl_loop_init

#define hpm_mcl_loop_init (   ...)    GET_MACRO(__VA_ARGS__, hpm_mcl_loop_init_v2, hpm_mcl_loop_init_v1, dummy, dummy, dummy, dummy, dummy, dummy)(__VA_ARGS__)

Overloaded hpm_mcl_loop_init macro that supports both v1.9.0 and v1.10.0+ API.

Usage:

Enumeration Type Documentation

◆ mcl_loop_chn_t

CLC channel.

Enumerator
loop_chn_id 
loop_chn_iq 

◆ mcl_loop_mode_t

Algorithms used in loops.

Enumerator
mcl_mode_foc 
mcl_mode_block 
mcl_mode_hardware_foc 
mcl_mode_step_foc 
mcl_mode_offline_param_detection 
mcl_mode_hybrid_foc 

◆ mcl_loop_status_t

Enumerator
loop_status_null 
loop_status_init 
loop_status_run 
loop_status_fail 

◆ mcl_motor_alignment_algorithm_t

Motor alignment algorithm types.

Enumerator
mcl_alignment_algorithm_basic 

Basic single-stage alignment

mcl_alignment_algorithm_three_stage 

Enhanced three-stage alignment

mcl_alignment_algorithm_adaptive 

Future: Adaptive alignment algorithm

◆ mcl_offline_param_detection_mode_t

Internal use, process control in the process.

Enumerator
offline_param_detection_mode_init 
offline_param_detection_mode_rs 
offline_param_detection_mode_ld 
offline_param_detection_mode_lq 
offline_param_detection_mode_ls 
offline_param_detection_mode_flux 
offline_param_detection_mode_wait 
offline_param_detection_mode_end 
offline_param_detection_mode_error 

Function Documentation

◆ hpm_mcl_disable_dead_area_compensation()

static hpm_mcl_stat_t hpm_mcl_disable_dead_area_compensation ( mcl_loop_t loop)
inlinestatic

disable dead area compensation

Parameters
loopmcl_loop_t

◆ hpm_mcl_disable_dq_axis_decoupling()

static hpm_mcl_stat_t hpm_mcl_disable_dq_axis_decoupling ( mcl_loop_t loop)
inlinestatic

disable dq axis decoupling

Parameters
loopmcl_loop_t

◆ hpm_mcl_disable_position_loop()

static void hpm_mcl_disable_position_loop ( mcl_loop_t loop)
inlinestatic

Disable position loop.

Parameters
loopmcl_loop_t

◆ hpm_mcl_disable_speed_loop()

static void hpm_mcl_disable_speed_loop ( mcl_loop_t loop)
inlinestatic

Disable speed loop.

Parameters
loopmcl_loop_t

◆ hpm_mcl_enable_dead_area_compensation()

static hpm_mcl_stat_t hpm_mcl_enable_dead_area_compensation ( mcl_loop_t loop)
inlinestatic

enable dead area compensation

Parameters
loopmcl_loop_t

◆ hpm_mcl_enable_dq_axis_decoupling()

static hpm_mcl_stat_t hpm_mcl_enable_dq_axis_decoupling ( mcl_loop_t loop)
inlinestatic

enable dq axis decoupling

Parameters
loopmcl_loop_t

◆ hpm_mcl_enable_position_loop()

static void hpm_mcl_enable_position_loop ( mcl_loop_t loop)
inlinestatic

Enable position loop.

Parameters
loopmcl_loop_t

◆ hpm_mcl_enable_speed_loop()

static void hpm_mcl_enable_speed_loop ( mcl_loop_t loop)
inlinestatic

Enable speed loop.

Parameters
loopmcl_loop_t

◆ hpm_mcl_get_current_loop_run_tick()

static uint32_t hpm_mcl_get_current_loop_run_tick ( mcl_loop_t loop)
inlinestatic

Get current loop run tick.

Parameters
loopmcl_loop_t
Returns
uint32_t tick

◆ hpm_mcl_loop()

hpm_mcl_stat_t hpm_mcl_loop ( mcl_loop_t loop)

Motor Loop, Periodic Recall.

Parameters
loopmcl_loop_t
Returns
hpm_mcl_stat_t

◆ hpm_mcl_loop_disable()

static void hpm_mcl_loop_disable ( mcl_loop_t loop)
inlinestatic

Disable Loop.

Parameters
loopmcl_loop_t

◆ hpm_mcl_loop_disable_all_user_set_value()

hpm_mcl_stat_t hpm_mcl_loop_disable_all_user_set_value ( mcl_loop_t loop)

Invalid user-set values in all loops.

Parameters
loopmcl_loop_t
Returns
hpm_mcl_stat_t

◆ hpm_mcl_loop_enable()

static void hpm_mcl_loop_enable ( mcl_loop_t loop)
inlinestatic

Enable Loop.

Parameters
loopmcl_loop_t

◆ hpm_mcl_loop_enable_offline_param_detecion()

static void hpm_mcl_loop_enable_offline_param_detecion ( mcl_loop_t loop)
inlinestatic

Enables the loop's offline parameter detection.

Parameters
loopmcl_loop_t

◆ hpm_mcl_loop_init_v1()

static hpm_mcl_stat_t hpm_mcl_loop_init_v1 ( mcl_loop_t loop,
mcl_loop_cfg_t cfg,
mcl_cfg_t mcl_cfg,
mcl_encoder_t encoder,
mcl_analog_t analog,
mcl_control_t control,
mcl_drivers_t drivers,
mcl_path_plan_t path 
)
inlinestatic

Backward compatibility function for API used in v1.9.0 and earlier (without hw_loop parameter)

Deprecated:
This function is provided for backward compatibility. Use hpm_mcl_loop_init_v2 instead.

◆ hpm_mcl_loop_init_v2()

hpm_mcl_stat_t hpm_mcl_loop_init_v2 ( mcl_loop_t loop,
mcl_loop_cfg_t cfg,
mcl_cfg_t mcl_cfg,
mcl_encoder_t encoder,
mcl_analog_t analog,
mcl_control_t control,
mcl_drivers_t drivers,
mcl_path_plan_t path,
mcl_hw_loop_t hw_loop 
)

Initialisation loop data (API introduced in v1.10.0 with hw_loop parameter)

Parameters
loopmcl_loop_t
cfgmcl_loop_cfg_t
mcl_cfgmcl_cfg_t
encodermcl_encoder_t
analogmcl_analog_t
controlmcl_control_t
driversmcl_drivers_t
pathmcl_path_plan_t
hw_loopmcl_hw_loop_t (can be NULL for backward compatibility)
Returns
hpm_mcl_stat_t

◆ hpm_mcl_loop_mode_set()

static void hpm_mcl_loop_mode_set ( mcl_loop_t loop,
mcl_loop_mode_t  mode 
)
inlinestatic

Set loop mode.

Parameters
loopmcl_loop_t
modemcl_loop_mode_t

◆ hpm_mcl_loop_offline_param_detection_get_result()

static void hpm_mcl_loop_offline_param_detection_get_result ( mcl_loop_t loop,
mcl_offline_param_detection_result_t result 
)
inlinestatic

Get offline parameter detection result.

Parameters
loopmcl_loop_t
resultmcl_offline_param_detection_result_t

◆ hpm_mcl_loop_offline_param_detection_is_done()

static bool hpm_mcl_loop_offline_param_detection_is_done ( mcl_loop_t loop)
inlinestatic

Get offline parameter is done.

Parameters
loopmcl_loop_t
Returns
bool

◆ hpm_mcl_loop_offline_param_detection_is_error()

static bool hpm_mcl_loop_offline_param_detection_is_error ( mcl_loop_t loop)
inlinestatic

Get offline parameter is error.

Parameters
loopmcl_loop_t
Returns
true or false

◆ hpm_mcl_loop_refresh_block()

hpm_mcl_stat_t hpm_mcl_loop_refresh_block ( mcl_loop_t loop)

Call this function in the interrupt function to update the motor's sector.

Parameters
loopmcl_loop_t
Returns
hpm_mcl_stat_t

◆ hpm_mcl_loop_set_current_d()

hpm_mcl_stat_t hpm_mcl_loop_set_current_d ( mcl_loop_t loop,
mcl_user_value_t  id 
)

Setting the d-axis current.

Parameters
loopmcl_loop_t
idmcl_user_value_t
Returns
hpm_mcl_stat_t

◆ hpm_mcl_loop_set_current_q()

hpm_mcl_stat_t hpm_mcl_loop_set_current_q ( mcl_loop_t loop,
mcl_user_value_t  iq 
)

Setting the q-axis current.

Parameters
loopmcl_loop_t
iqmcl_user_value_t
Returns
hpm_mcl_stat_t

◆ hpm_mcl_loop_set_position()

hpm_mcl_stat_t hpm_mcl_loop_set_position ( mcl_loop_t loop,
mcl_user_value_t  position 
)

Setting the position parameters.

Parameters
loopmcl_loop_t
positionmcl_user_value_t
Returns
hpm_mcl_stat_t

◆ hpm_mcl_loop_set_speed()

hpm_mcl_stat_t hpm_mcl_loop_set_speed ( mcl_loop_t loop,
mcl_user_value_t  speed 
)

Setting the speed loop speed feed.

Parameters
loopmcl_loop_t
speedmcl_user_value_t
Returns
hpm_mcl_stat_t

◆ hpm_mcl_loop_start_block()

hpm_mcl_stat_t hpm_mcl_loop_start_block ( mcl_loop_t loop)

Call this function in the interrupt function to start the motor's sector.

Parameters
loopmcl_loop_t
Returns
hpm_mcl_stat_t

◆ hpm_mcl_motor_angle_alignment()

hpm_mcl_stat_t hpm_mcl_motor_angle_alignment ( mcl_loop_t loop,
mcl_motor_alignment_cfg_t cfg 
)

Enhanced motor angle alignment algorithm with multiple algorithm support.

This function provides a flexible framework for motor alignment that supports various alignment algorithms. Users can choose from built-in algorithms or implement custom alignment strategies.

Supported algorithms:

  • Basic: Single-stage alignment with configurable parameters
  • Three-stage: Enhanced three-stage alignment for robust positioning
    • Stage 1: High current coarse alignment
    • Stage 2: Moderate current fine alignment
    • Stage 3: Low current stabilization
Parameters
loopMotor control loop structure mcl_loop_t
cfgAlignment configuration parameters mcl_motor_alignment_cfg_t
Returns
hpm_mcl_stat_t Success or error status