RA Flexible Software Package Documentation  Release v5.7.0

 
ADC and PWM Modulation (rm_motor_driver)

Functions

fsp_err_t RM_MOTOR_DRIVER_Open (motor_driver_ctrl_t *const p_ctrl, motor_driver_cfg_t const *const p_cfg)
 Opens and configures the Motor Driver module. Implements motor_driver_api_t::open. More...
 
fsp_err_t RM_MOTOR_DRIVER_Close (motor_driver_ctrl_t *const p_ctrl)
 Disables specified Motor Driver Module. Implements motor_driver_api_t::close. More...
 
fsp_err_t RM_MOTOR_DRIVER_Reset (motor_driver_ctrl_t *const p_ctrl)
 Reset variables of Motor Driver Module. Implements motor_driver_api_t::reset. More...
 
fsp_err_t RM_MOTOR_DRIVER_PhaseVoltageSet (motor_driver_ctrl_t *const p_ctrl, float const u_voltage, float const v_voltage, float const w_voltage)
 Set Phase Voltage Data to calculate PWM duty. Implements motor_driver_api_t::phaseVoltageSet. More...
 
fsp_err_t RM_MOTOR_DRIVER_CurrentGet (motor_driver_ctrl_t *const p_ctrl, motor_driver_current_get_t *const p_current_get)
 Get calculated phase Current, Vdc & Va_max data. Implements motor_driver_api_t::currentGet. More...
 
fsp_err_t RM_MOTOR_DRIVER_FlagCurrentOffsetGet (motor_driver_ctrl_t *const p_ctrl, uint8_t *const p_flag_offset)
 Get the flag of finish current offset detection. Implements motor_driver_api_t::flagCurrentOffsetGet. More...
 
fsp_err_t RM_MOTOR_DRIVER_CurrentOffsetRestart (motor_driver_ctrl_t *const p_ctrl)
 Restart the current offset detection. Implements motor_driver_api_t::currentOffsetRestart. More...
 
fsp_err_t RM_MOTOR_DRIVER_ParameterUpdate (motor_driver_ctrl_t *const p_ctrl, motor_driver_cfg_t const *const p_cfg)
 Update the parameters of Driver Module. Implements motor_driver_api_t::parameterUpdate. More...
 

Detailed Description

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

Overview

The motor driver module is used to translate phase voltage to PWM duty and output PWM, and detect phase current and main line voltage. This module should be called cyclically at included A/D Conversion finish interrupt.

Features

The Motor Driver Module has below features.

Configuration

Build Time Configurations for rm_motor_driver

The following build time configurations are defined in fsp_cfg/rm_motor_driver_cfg.h:

ConfigurationOptionsDefaultDescription
Parameter Checking
  • Default (BSP)
  • Enabled
  • Disabled
Default (BSP) If selected code for parameter checking is included in the build.
ADC_B Support
  • Enabled
  • Disabled
Disabled Select ADC_B module support.
Shared ADC support
  • Enabled
  • Disabled
Disabled Select Shared ADC support.
Supported Motor NumberMust be greater than 1.1

Configurations for Motor > ADC and PWM Modulation (rm_motor_driver)

This module can be added to the Stacks tab via New Stack > Motor > ADC and PWM Modulation (rm_motor_driver).

ConfigurationOptionsDefaultDescription
General
NameName must be a valid C symbolg_motor_driver0 Module name.
Shunt type
  • 1 shunt
  • 2 shunt
  • 3 shunt
2 shunt Select shunt type
Modulation method
  • SVPWM
  • SPWM
SVPWM Select PWM modulation method
PWM output port UPManual Entry0 PWM output port UP
PWM output port UNManual Entry0 PWM output port UN
PWM output port VPManual Entry0 PWM output port VP
PWM output port VNManual Entry0 PWM output port VN
PWM output port WPManual Entry0 PWM output port WP
PWM output port WNManual Entry0 PWM output port WN
PWM Timer Frequency (MHz)Must be a valid non-negative value.120 GPT PWM timer frequency
PWM Carrier Period (Microseconds)Must be a valid non-negative value.50 GPT PWM carrier period
Dead Time (Raw Counts)Must be a valid non-negative value.240 GPT PWM dead time
Current Range (A)Must be a valid value27.5F Current range to measure(Maximum input current)
Voltage Range (V)Must be a valid value111.0F Voltage range to measure(Maximum input Main Line Voltage)
Counts for current offset measurementMust be a valid non-negative value.500 How many times to measure current offset
A/D conversion channel for U Phase currentValue must be a supported channel number0 Specify the A/D channel for U phase current (channel availability varies by MCU)
A/D conversion channel for W Phase currentValue must be a supported channel number2 Specify the A/D channel for W phase current (channel availability varies by MCU)
A/D conversion channel for Main Line VoltageValue must be a supported channel number5 Specify the A/D channel for main line voltage (channel availability varies by MCU)
A/D conversion channel for V Phase currentValue must be a supported channel number1 Specify the A/D channel for V phase current (channel availability varies by MCU)
A/D conversion channel for sin signalValue must be a supported channel number27 Specify the A/D channel for sin signal of induction sensor (channel availability varies by MCU)
A/D conversion channel for cos signalValue must be a supported channel number28 Specify the A/D channel for cos signal of induction sensor (channel availability varies by MCU)
Using ADC Scan GroupValue should be between 0 to 8 (valid only with ADC_B module)0 For MCUs with ADC_B, select the scan group used.
A/D conversion unit for U Phase currentMust be a valid non-negative value.0 Select the A/D conversion module for U phase current (only valid with adc module)
A/D conversion unit for W Phase currentMust be a valid non-negative value.0 Select the A/D conversion module for W phase current (only valid with adc module)
A/D conversion unit for main line voltageMust be a valid non-negative value.0 Select the A/D conversion module for main line voltage (only valid with adc module)
A/D conversion unit for V Phase currentMust be a valid non-negative value.0 Select the A/D conversion module for V phase current (only valid with adc module)
A/D conversion unit for sin signalMust be a valid non-negative value.0 Select the A/D conversion module for sin signal of induction sensor (only valid with adc module)
A/D conversion unit for cos signalMust be a valid non-negative value.0 Select the A/D conversion module for cos signal of induction sensor (only valid with adc module)
ADC interrupt module
  • 1st
  • 2nd
1st Select from which module ADC intterupt happens (only valid with adc module)
Adjustment value to current A/DMust be a valid non-negative value.20.0 Value to adjust 1shunt A/D double buffer
Minimum difference of PWM dutyMust be a valid non-negative value.300 Minimum difference of PWM duty
Adjustment delay of A/D conversionMust be a valid non-negative value.240 Adjustment delay of A/D conversion
1shunt interrupt phase
  • PHASE_U
  • PHASE_V
  • PHASE_W
PHASE_U Select the phase which occures ADC end interrupt. (Only valid with 1shunt)
Input Voltage (V)Must be a valid value24.0F Input voltage
Resolution of A/D conversionMust be a valid Resolution of ADC.0xFFF Resolution of A/D conversion
Offset of A/D conversion for currentMust be a valid non-negative value.0x745 Offset of A/D conversion for current
Conversion level of A/D conversion for voltageMust be a valid value0.66F Conversion level of A/D conversion for voltage
GTIOCA Stop Level
  • Pin Level Low
  • Pin Level High
Pin Level High Select the behavior of the output pin when the timer is stopped.
GTIOCB Stop Level
  • Pin Level Low
  • Pin Level High
Pin Level High Select the behavior of the output pin when the timer is stopped.
Modulation
Maximum DutyMust be a valid value0.9375F Maximum duty of PWM
Interrupts
CallbackName must be a valid C symbolNULL A user callback function. If this callback function is provided, it is called at A/D conversion finish interrupt.

Clock Configuration

Set used clock with included GPT timer.

Pin Configuration

Depend on included GPT Three Phase Module and ADC Module.

Usage Notes

When shared ADC instance is used, please perform below sequence.

  1. Add (New) shared ADC instance.
  2. Set configurations of below ADC module for your use.
  3. Select "Common | Shared ADC support" to "Enabled".

Limitations

Basically no limitation exists.

Examples

Basic Example

This is a basic example of minimal use of the Motor Driver in an application.

void motor_driver_basic_example (void)
{
fsp_err_t err = FSP_SUCCESS;
/* Initializes the module. */
err = RM_MOTOR_DRIVER_Open(&g_motor_driver0.p_ctrl, &g_motor_driver0.p_cfg);
assert(FSP_SUCCESS == err);
/* Basically run this module at cyclic interrupt (e.g. included GPT PWM Carrier intterupt).
* This implementation is an example. */
// while (true)
{
/* Application work here. */
/* Get electric current, main line voltage and maximum voltage component */
(void) RM_MOTOR_DRIVER_CurrentGet(&g_motor_driver0.p_ctrl, &f_get_iu, &f_get_iw, &f_get_vdc, &f_get_va_max);
/* Get the flag of A/D convderted current offset */
(void) RM_MOTOR_DRIVER_FlagCurrentOffsetGet(&g_motor_driver0.p_ctrl, &u1_get_flg_offset);
// Perform current control process here
/* Set phase voltage */
(void) RM_MOTOR_DRIVER_PhaseVoltageSet(&g_motor_driver0.p_ctrl, 1.0F, 1.0F, 1.0F);
(void) RM_MOTOR_DRIVER_ParameterUpdate(&g_motor_driver0.p_ctrl, &g_motor_driver0.p_cfg);
}
(void) RM_MOTOR_DRIVER_Reset(&g_motor_driver0.p_ctrl);
//
(void) RM_MOTOR_DRIVER_Close(&g_motor_driver0.p_ctrl);
}

Data Structures

struct  motor_driver_shared_instance_ctrl_t
 
struct  motor_driver_extended_shared_cfg_t
 

Enumerations

enum  motor_driver_select_adc_instance_t
 
enum  motor_driver_modulation_method_t
 

Data Structure Documentation

◆ motor_driver_shared_instance_ctrl_t

struct motor_driver_shared_instance_ctrl_t

For multiple motor

Data Fields
uint32_t open
uint8_t registered_motor_count Registered motor counts.
void const * p_context[MOTOR_DRIVER_CFG_SUPPORT_MOTOR_NUM]

◆ motor_driver_extended_shared_cfg_t

struct motor_driver_extended_shared_cfg_t

For multiple motor

Data Fields
adc_instance_t const * p_adc_instance_first first ADC instance
adc_instance_t const * p_adc_instance_second second ADC instance
motor_driver_shared_instance_ctrl_t
*const
p_shared_instance_ctrl

Enumeration Type Documentation

◆ motor_driver_select_adc_instance_t

Support two ADC instance valid for adc

Enumerator
MOTOR_DRIVER_SELECT_ADC_INSTANCE_FIRST 

Use first ADC instance.

MOTOR_DRIVER_SELECT_ADC_INSTANCE_SECOND 

Use second ADC instanse.

◆ motor_driver_modulation_method_t

Enumerator
MOTOR_DRIVER_MODULATION_METHOD_SPWM 

Sinusoidal pulse-width-modulation.

MOTOR_DRIVER_MODULATION_METHOD_SVPWM 

Space vector pulse-width-modulation.

Function Documentation

◆ RM_MOTOR_DRIVER_Open()

fsp_err_t RM_MOTOR_DRIVER_Open ( motor_driver_ctrl_t *const  p_ctrl,
motor_driver_cfg_t const *const  p_cfg 
)

Opens and configures the Motor Driver module. Implements motor_driver_api_t::open.

Return values
FSP_SUCCESSMotor Driver 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_DRIVER_Close()

fsp_err_t RM_MOTOR_DRIVER_Close ( motor_driver_ctrl_t *const  p_ctrl)

Disables specified Motor Driver Module. Implements motor_driver_api_t::close.

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

◆ RM_MOTOR_DRIVER_Reset()

fsp_err_t RM_MOTOR_DRIVER_Reset ( motor_driver_ctrl_t *const  p_ctrl)

Reset variables of Motor Driver Module. Implements motor_driver_api_t::reset.

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

◆ RM_MOTOR_DRIVER_PhaseVoltageSet()

fsp_err_t RM_MOTOR_DRIVER_PhaseVoltageSet ( motor_driver_ctrl_t *const  p_ctrl,
float const  u_voltage,
float const  v_voltage,
float const  w_voltage 
)

Set Phase Voltage Data to calculate PWM duty. Implements motor_driver_api_t::phaseVoltageSet.

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

◆ RM_MOTOR_DRIVER_CurrentGet()

fsp_err_t RM_MOTOR_DRIVER_CurrentGet ( motor_driver_ctrl_t *const  p_ctrl,
motor_driver_current_get_t *const  p_current_get 
)

Get calculated phase Current, Vdc & Va_max data. Implements motor_driver_api_t::currentGet.

Return values
FSP_SUCCESSSuccessful data get.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTInput parameter error.

◆ RM_MOTOR_DRIVER_FlagCurrentOffsetGet()

fsp_err_t RM_MOTOR_DRIVER_FlagCurrentOffsetGet ( motor_driver_ctrl_t *const  p_ctrl,
uint8_t *const  p_flag_offset 
)

Get the flag of finish current offset detection. Implements motor_driver_api_t::flagCurrentOffsetGet.

Return values
FSP_SUCCESSSuccessful data get.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTInput parameter error.

◆ RM_MOTOR_DRIVER_CurrentOffsetRestart()

fsp_err_t RM_MOTOR_DRIVER_CurrentOffsetRestart ( motor_driver_ctrl_t *const  p_ctrl)

Restart the current offset detection. Implements motor_driver_api_t::currentOffsetRestart.

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

◆ RM_MOTOR_DRIVER_ParameterUpdate()

fsp_err_t RM_MOTOR_DRIVER_ParameterUpdate ( motor_driver_ctrl_t *const  p_ctrl,
motor_driver_cfg_t const *const  p_cfg 
)

Update the parameters of Driver Module. Implements motor_driver_api_t::parameterUpdate.

Return values
FSP_SUCCESSSuccessfully data was updated.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.