Motor Evaluation Kit NEVC-MCTRL-100-t01-1.0.0
Firmware for NEVB-MCTRL-100-01 for trapezoidal control of BLDC motors using Hall-effect sensors
Loading...
Searching...
No Matches
User Settable Defines

These defines can be modified by the user. More...

Collaboration diagram for User Settable Defines:

Macros

#define MOTOR_POLES   8
 Number of poles in the motor.
 
#define TIM4_FREQ   20000UL
 Desired Switching Frequency for MOSFET Gate Signals.
 
#define DEAD_TIME   350UL
 Dead Time Specification.
 
#define HALL_PULLUP_ENABLE   FALSE
 Internal Pull-up Resistor Configuration for Hall Sensor Inputs.
 
#define EMULATE_HALL   FALSE
 Emulate Motor Spinning.
 
#define TIM3_FREQ   200UL
 Desired Electrical Rotational Frequency for "Emulated" Motor.
 
#define COMMUTATION_TICKS_STOPPED   6000
 Commutation Stopped Limit.
 
#define TURN_OFF_MODE   TURN_OFF_MODE_COAST
 Turn Off Mode.
 
#define CURRENT_GAIN   50
 Current Gain for Current Measurement.
 
#define CURRENT_SENSE_RESISTOR   2000
 Current Sense Resistor Value.
 
#define CURRENT_WARNING_THRESHOLD   408
 Current Warning Threshold (Register Value)
 
#define CURRENT_ERROR_THRESHOLD   816
 Current Error Threshold (Register Value)
 
#define CURRENT_FAULT_ENABLE   FALSE
 Current Fault Enable.
 
#define SPEED_CONTROL_METHOD   SPEED_CONTROL_OPEN_LOOP
 Speed Control Method.
 
#define SPEED_CONTROLLER_TIME_BASE   200
 Speed Controller Time Base.
 
#define SPEED_CONTROLLER_MAX_DELTA   1
 Speed Controller Maximum Delta (Applicable for Open Loop Control)
 
#define SPEED_CONTROLLER_MAX_SPEED   400
 Speed Controller Maximum Speed.
 
#define PID_K_P   100
 PID Controller Proportional Gain Constant (Only for Closed Loop)
 
#define PID_K_I   10
 PID Controller Integral Gain Constant (Only for Closed Loop)
 
#define PID_K_D_ENABLE   TRUE
 PID Controller Derivative Control Enable Flag (Only for Closed Loop)
 
#define PID_K_D   0
 PID Controller Derivative Gain Constant (Only for Closed Loop)
 
#define GATE_RTOP   1000000
 Top resistor value in the gate voltage potential divider.
 
#define GATE_RBOTTOM   71500
 Bottom resistor value in the gate voltage potential divider.
 
#define REMOTE_DEBUG_MODE   FALSE
 Set the remote debug mode.
 

Detailed Description

These defines can be modified by the user.

Macro Definition Documentation

◆ COMMUTATION_TICKS_STOPPED

#define COMMUTATION_TICKS_STOPPED   6000

Commutation Stopped Limit.

This macro defines the number of commutation 'ticks' that must pass without any hall changes before the motor is considered to be stopped.

Todo
Define how many 'ticks' before the motor is considered stopped.

Definition at line 188 of file main.h.

◆ CURRENT_ERROR_THRESHOLD

#define CURRENT_ERROR_THRESHOLD   816

Current Error Threshold (Register Value)

This macro specifies the threshold value for current error as a register value. When the current measured by the controller exceeds this threshold, it triggers the controller to take protective action, by disabling all PWM outputs, essentially allowing the motor to coast.

The range is 0-1023.

This value is not scaled and represents the raw register value. To obtain the register value from the current in amperes, you can use the formula:

\[ \text{Register Value} = \frac{\text{CURRENT} \times \text{CURRENT_SENSE_RESISTOR} \times \text{CURRENT_GAIN}}{0.004887586 \times 1000000} \]

Where:

  • CURRENT : The current threshold in amperes.
  • 0.004887586 : The conversion factor for a 10-bit ADC with a Vref of 5V.
  • CURRENT_GAIN : The gain of the current sense operational amplifier.
  • CURRENT_SENSE_RESISTOR : The value of the shunt resistor in micro-ohms (μΩ).

The NEVB-3INV-001-01 comes with a current op-amp with a gain factor of 50 and a current sense resistor of value 2 mΩ. This corresponds to approximately 0.049 amperes (A) per register value. The default value is 816 which corresponds to approximately 40 A.

Note
Braking is not implemented yet for this fault, so the motor coasts when an error occurs.
Todo
Calculate and set the register value for the current error threshold.
See also
CURRENT_WARNING_THRESHOLD, CURRENT_FAULT_ENABLE, CURRENT_GAIN, CURRENT_SENSE_RESISTOR

Definition at line 312 of file main.h.

◆ CURRENT_FAULT_ENABLE

#define CURRENT_FAULT_ENABLE   FALSE

Current Fault Enable.

This macro sets if any action is taken if CURRENT_ERROR_THRESHOLD is exceeded.

Note
This does not affect fault reporting for CURRENT_WARNING_THRESHOLD.
See also
CURRENT_ERROR_THRESHOLD

Definition at line 325 of file main.h.

◆ CURRENT_GAIN

#define CURRENT_GAIN   50

Current Gain for Current Measurement.

This macro defines the gain factor used in the current measurement circuit. The gain is a unit-less multiplier that amplifies the signal from the current sensor before it is read by the controller. It is used in the calculation to convert the sensor reading into an actual current value.

The NEVB-3INV-001-01 comes with a current op-amp with a gain factor of 50. This is the default value.

Note
Ensure that the gain value is correct.
See also
CURRENT_SENSE_RESISTOR

Definition at line 220 of file main.h.

◆ CURRENT_SENSE_RESISTOR

#define CURRENT_SENSE_RESISTOR   2000

Current Sense Resistor Value.

This macro specifies the resistance value of the current sense resistor in the system, measured in micro-ohms (μΩ). The value is used in conjunction with the current gain to calculate the actual current based on the voltage across the current sense resistor.

The NEVB-3INV-001-01 comes with a current sense resistor of value 2 mΩ. This is the default value.

Note
Ensure that the resistor value matches the actual hardware component used.
See also
CURRENT_GAIN

Definition at line 238 of file main.h.

◆ CURRENT_WARNING_THRESHOLD

#define CURRENT_WARNING_THRESHOLD   408

Current Warning Threshold (Register Value)

This macro specifies the threshold value for current warning as a register value. When the current measured by the controller exceeds this threshold, it triggers the fault LED to be turned on.

The range is 0-1023.

This value is not scaled and represents the raw register value. To obtain the register value from the current in amperes, you can use the formula:

\[ \text{Register Value} = \frac{\text{CURRENT} \times \text{CURRENT_SENSE_RESISTOR} \times \text{CURRENT_GAIN}}{0.004887586 \times 1000000} \]

Where:

  • CURRENT : The current threshold in amperes.
  • 0.004887586 : The conversion factor for a 10-bit ADC with a Vref of 5V.
  • CURRENT_GAIN : The gain of the current sense operational amplifier.
  • CURRENT_SENSE_RESISTOR : The value of the shunt resistor in micro-ohms (μΩ).

The NEVB-3INV-001-01 comes with a current op-amp with a gain factor of 50 and a current sense resistor of value 2 mΩ. This corresponds to approximately 0.049 amperes (A) per register value. The default value is 408 which corresponds to approximately 20 A.

Todo
Calculate and set the register value for the current warning threshold.
See also
CURRENT_ERROR_THRESHOLD, CURRENT_FAULT_ENABLE, CURRENT_GAIN, CURRENT_SENSE_RESISTOR

Definition at line 273 of file main.h.

◆ DEAD_TIME

#define DEAD_TIME   350UL

Dead Time Specification.

This macro specifies the desired dead time between switching actions in nanoseconds (ns). The resolution of the dead time changes with the selected dead time. The best pre-scaler is chose to provide the best resolution.

The following are the resolution for different dead time ranges:

  • For 0 to 234 ns, resolution is 16 ns.
  • For 235 to 468 ns, resolution is 31 ns.
  • For 469 to 937 ns, resolution is 63 ns.
  • For 938 to 1875 ns, resolution is 125 ns.
Warning
The minimum recommended dead time in the set up provided is 350 ns. Please review this value and uncomment the advisory warning if necessary.
The maximum allowed dead time is 1875 ns. Larger dead times are not supported by the timer peripheral of ATMEGA32u4.
Todo
Specify the desired dead time in nanoseconds.

Definition at line 128 of file main.h.

◆ EMULATE_HALL

#define EMULATE_HALL   FALSE

Emulate Motor Spinning.

When enabled, this flag transforms Hall effect sensor inputs into hardware-generated outputs, initiating a motor sequencing process.

Note
This will not work if SPEED_CONTROL_METHOD is set to SPEED_CONTROL_CLOSED_LOOP.
Warning
Do not have hall sensors connected while this feature is set to TRUE.
Todo
Enable or disable motor emulation by setting to TRUE or FALSE.
See also
TIM3_FREQ

Definition at line 162 of file main.h.

◆ GATE_RBOTTOM

#define GATE_RBOTTOM   71500

Bottom resistor value in the gate voltage potential divider.

This macro defines the value of the bottom resistor (RBOTTOM) in the potential divider circuit used for measuring the gate voltage. It is specified in ohms (Ω).

The value of RBOTTOM is used to determine the scaling factor for the ADC conversion in the gate voltage measurement circuit.

NEVB-3INV-001-01 has a resistor divider with RTOP of 1 MΩ and RBOTTOM of 71.5 kΩ.

Note
Ensure that the resistor value matches the actual hardware component used.
See also
GATE_RTOP, gateVref

Definition at line 512 of file main.h.

◆ GATE_RTOP

#define GATE_RTOP   1000000

Top resistor value in the gate voltage potential divider.

This macro defines the value of the top resistor (RTOP) in the potential divider circuit used for measuring the gate voltage. It is specified in ohms (Ω).

The value of RTOP is used to determine the scaling factor for the ADC conversion in the gate voltage measurement circuit.

NEVB-3INV-001-01 has a resistor divider with RTOP of 1 MΩ and RBOTTOM of 71.5 kΩ.

Note
Ensure that the resistor value matches the actual hardware component used.
See also
GATE_RBOTTOM, gateVref

Definition at line 492 of file main.h.

◆ HALL_PULLUP_ENABLE

#define HALL_PULLUP_ENABLE   FALSE

Internal Pull-up Resistor Configuration for Hall Sensor Inputs.

This macro configures whether internal pull-up resistors should be enabled on hall sensor inputs.

Todo
Enable or disable internal pull-ups on hall sensor inputs by setting to TRUE or FALSE.

Definition at line 143 of file main.h.

◆ MOTOR_POLES

#define MOTOR_POLES   8

Number of poles in the motor.

This macro defines the number of poles in the motor. The value is used to calculate the motor speed.

The motor provided with the kit, 42BLS40-24-01, has 8 poles.

Todo
Specify the number of poles of the specific motor being used.

Definition at line 60 of file main.h.

◆ PID_K_D

#define PID_K_D   0

PID Controller Derivative Gain Constant (Only for Closed Loop)

This macro specifies the derivative gain constant for the PID controller. This parameter accepts signed integer values in the int16_t range.

Note
This parameter is applicable when SPEED_CONTROL_METHOD is set to SPEED_CONTROL_CLOSED_LOOP.
Todo
Adjust the value as needed for the derivative gain in the PID controller when operating in closed-loop speed control mode based on your system's control requirements.
See also
SPEED_CONTROL_METHOD, SPEED_CONTROLLER_TIME_BASE, SPEED_CONTROLLER_MAX_DELTA, SPEED_CONTROLLER_MAX_SPEED, PID_K_P, PID_K_I, PID_K_D_ENABLE

Definition at line 472 of file main.h.

◆ PID_K_D_ENABLE

#define PID_K_D_ENABLE   TRUE

PID Controller Derivative Control Enable Flag (Only for Closed Loop)

Set this flag to TRUE or FALSE to enable or disable derivative control in the PID controller.

Note
This parameter is applicable when SPEED_CONTROL_METHOD is set to SPEED_CONTROL_CLOSED_LOOP.
Todo
Enable or disable derivative control by assigning TRUE or FALSE based on your system's control requirements when operating in closed-loop speed control mode.
See also
SPEED_CONTROL_METHOD, SPEED_CONTROLLER_TIME_BASE, SPEED_CONTROLLER_MAX_DELTA, SPEED_CONTROLLER_MAX_SPEED, PID_K_P, PID_K_I, PID_K_D

Definition at line 453 of file main.h.

◆ PID_K_I

#define PID_K_I   10

PID Controller Integral Gain Constant (Only for Closed Loop)

This macro specifies the integral gain constant for the PID controller. This parameter accepts signed integer values in the int16_t range.

Note
This parameter is applicable when SPEED_CONTROL_METHOD is set to SPEED_CONTROL_CLOSED_LOOP.
Todo
Adjust the value as needed for the integral gain in the PID controller when operating in closed-loop speed control mode based on your system's control requirements.
See also
SPEED_CONTROL_METHOD, SPEED_CONTROLLER_TIME_BASE, SPEED_CONTROLLER_MAX_DELTA, SPEED_CONTROLLER_MAX_SPEED, PID_K_P, PID_K_D_ENABLE, PID_K_D

Definition at line 434 of file main.h.

◆ PID_K_P

#define PID_K_P   100

PID Controller Proportional Gain Constant (Only for Closed Loop)

This macro specifies the proportional gain constant for the PID controller. This parameter accepts signed integer values in the int16_t range.

Note
This parameter is applicable when SPEED_CONTROL_METHOD is set to SPEED_CONTROL_CLOSED_LOOP.
Todo
Adjust the value as needed for the proportional gain in the PID controller when operating in closed-loop speed control mode based on your system's control requirements.
See also
SPEED_CONTROL_METHOD, SPEED_CONTROLLER_TIME_BASE, SPEED_CONTROLLER_MAX_DELTA, SPEED_CONTROLLER_MAX_SPEED, PID_K_I, PID_K_D_ENABLE, PID_K_D

Definition at line 415 of file main.h.

◆ REMOTE_DEBUG_MODE

#define REMOTE_DEBUG_MODE   FALSE

Set the remote debug mode.

When in remote debug mode, errors are immediately reported back on the serial port without having to query using the "SYSTem:ERRor[:NEXT]?" command.

Definition at line 520 of file main.h.

◆ SPEED_CONTROL_METHOD

#define SPEED_CONTROL_METHOD   SPEED_CONTROL_OPEN_LOOP

Speed Control Method.

Select the type of speed control by setting this macro to either SPEED_CONTROL_OPEN_LOOP or SPEED_CONTROL_CLOSED_LOOP.

Todo
Select the speed control method by assigning SPEED_CONTROL_OPEN_LOOP or SPEED_CONTROL_CLOSED_LOOP.
See also
SPEED_CONTROLLER_TIME_BASE, SPEED_CONTROLLER_MAX_DELTA, SPEED_CONTROLLER_MAX_SPEED, PID_K_P, PID_K_I, PID_K_D_ENABLE, PID_K_D

Definition at line 339 of file main.h.

◆ SPEED_CONTROLLER_MAX_DELTA

#define SPEED_CONTROLLER_MAX_DELTA   1

Speed Controller Maximum Delta (Applicable for Open Loop Control)

This macro specifies the maximum allowed change in speed reference by the speed controller after each iteration of the speed loop when using open-loop speed control. Adjust this value as needed. When a user changes the requested speed input, this parameter limits the maximum allowed change per SPEED_CONTROLLER_TIME_BASE.

Note
This parameter is applicable when SPEED_CONTROL_METHOD is set to SPEED_CONTROL_OPEN_LOOP.
Todo
Adjust the value to set the desired maximum change in speed reference for open-loop control according to your system's speed response requirements.
See also
SPEED_CONTROL_METHOD, SPEED_CONTROLLER_TIME_BASE, SPEED_CONTROLLER_MAX_SPEED, PID_K_P, PID_K_I, PID_K_D_ENABLE, PID_K_D

Definition at line 375 of file main.h.

◆ SPEED_CONTROLLER_MAX_SPEED

#define SPEED_CONTROLLER_MAX_SPEED   400

Speed Controller Maximum Speed.

This macro specifies the maximum speed, to be used as a setpoint when the maximum speed reference value is input to the speed controller. This "speed" is given as rate of change of the hall effect sensors in Hz.

This parameter is crucial for ensuring that the speed controller does not attempt to change the motor speed beyond a safe and controlled rate.

Note
This parameter is applicable when SPEED_CONTROL_METHOD is set to SPEED_CONTROL_CLOSED_LOOP.
Todo
Set to the maximum speed based on the system's safety and operational requirements.
See also
SPEED_CONTROL_METHOD, SPEED_CONTROLLER_TIME_BASE, SPEED_CONTROLLER_MAX_DELTA, PID_K_P, PID_K_I, PID_K_D_ENABLE, PID_K_D

Definition at line 396 of file main.h.

◆ SPEED_CONTROLLER_TIME_BASE

#define SPEED_CONTROLLER_TIME_BASE   200

Speed Controller Time Base.

This macro specifies the number of ticks between each iteration of the speed loop. One 'tick' is one PWM period. Adjust this value to set the speed control loop time base. Range is 1-255.

Note
Minimum overhead of atleast 1 us due to a blocking delay placed inside the SpeedController function.
See also
SPEED_CONTROL_METHOD, SPEED_CONTROLLER_MAX_DELTA, SPEED_CONTROLLER_MAX_SPEED, PID_K_P, PID_K_I, PID_K_D_ENABLE, PID_K_D

Definition at line 354 of file main.h.

◆ TIM3_FREQ

#define TIM3_FREQ   200UL

Desired Electrical Rotational Frequency for "Emulated" Motor.

This macro specifies the desired electrical rotational frequency for the "emulated" motor. The valid range is from 5.08 Hz to 167.67 KHz.

Note
As a general rule of thumb, you should keep the electrical rotational frequency switching lower than at least 1/10th of the electrical rotational frequency.
Todo
Specify the desired electrical rotational frequency in Hz.
See also
EMULATE_HALL

Definition at line 178 of file main.h.

◆ TIM4_FREQ

#define TIM4_FREQ   20000UL

Desired Switching Frequency for MOSFET Gate Signals.

This macro defines the desired switching frequency for the MOSFET gate signals. The resolution of the duty cycle is changes with the selected switching frequency. The best pre-scaler is chose to provide the best resolution.

The absolute PWM Resolution is calculated using the following formula:

\[ \text{Absolute PWM Resolution (%)} = \frac{100}{(F_{HST} / (TIM4_{FREQ} \times TIM4_{PRESCALER} \times 2)) - 1} \]

Where:

  • F_HST : High-speed system clock frequency, configured to be 64 MHz.
  • TIM4_FREQ : The required gate switching frequency.
  • TIM4_PRESCALER : The pre-scaler value, which depends on the gate switching frequency as explained below.

The TIM4 Pre-scaler is selected based on the gate switching frequency (TIM4_FREQ):

  • For frequencies \(\geq\) 31250 Hz, the pre-scaler is set to 1.
  • For frequencies < 31250 Hz and \(\geq\) 15625 Hz, the pre-scaler is set to 2.
  • For frequencies < 15625 Hz and \(\geq\) 7813 Hz, the pre-scaler is set to 4.
Figure: Absolute PWM resolution across all supported gate switching frequencies.
Warning
The maximum recommended value for TIM4_FREQ is 100 kHz. Please review this value and uncomment the advisory warning if necessary. You may also need to change the values in the scpi.cpp file.
The minimum value for TIM4_FREQ is 7813 Hz as the higher pre-scalers needed to support this have not been implemented.
Todo
Specify the desired gate switching frequency.

Definition at line 99 of file main.h.

◆ TURN_OFF_MODE

#define TURN_OFF_MODE   TURN_OFF_MODE_COAST

Turn Off Mode.

Set this macro to either TURN_OFF_MODE_COAST or TURN_OFF_MODE_BRAKE to specify the desired turn mode.

Todo
Select the turn mode by assigning TURN_OFF_MODE_COAST or TURN_OFF_MODE_BRAKE.
Warning
TURN_OFF_MODE_BRAKE has not been implemented properly yet.
See also
TURN_OFF_MODE_BRAKE, TURN_OFF_MODE_COAST

Definition at line 203 of file main.h.