Motor Driver Evaluation Kit NEVB-MTR1-t01-1.1.0
Firmware for NEVB-MTR1-KIT1 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 F_MOSFET_MAX   100000UL
 Maximum allowed gate switching frequency.
 
#define F_MOSFET_MIN   7183UL
 Minimum allowed gate switching frequency.
 
#define F_MOSFET   20000UL
 Desired Switching Frequency for MOSFET Gate Signals.
 
#define DEAD_TIME   350UL
 Dead Time Specification.
 
#define HALL_PULLUP_ENABLE   TRUE
 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_RAMP
 Turn Off Mode.
 
#define IPHASE_GAIN   20
 In-line Phase Current Gain for Current Measurement.
 
#define IPHASE_SENSE_RESISTOR   2500
 Hi-side Current (IBUS) Sense Resistor Value.
 
#define IBUS_GAIN   50
 Hi-side Current (IBUS) Gain for Current Measurement.
 
#define IBUS_SENSE_RESISTOR   4000
 Hi-side Current (IBUS) Sense Resistor Value.
 
#define IBUS_WARNING_THRESHOLD   307
 Hi-side Current (IBUS) Warning Threshold (Register Value)
 
#define IBUS_ERROR_THRESHOLD   410
 Hi-side Current (IBUS) Error Threshold (Register Value)
 
#define IBUS_FAULT_ENABLE   TRUE
 Hi-side Current (IBUS) 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 VBUS_RTOP   100000
 Top resistor value in the VBUS voltage potential divider.
 
#define VBUS_RBOTTOM   6200
 Bottom resistor value in the VBUS voltage potential divider.
 
#define WAIT_FOR_BOARD   TRUE
 Wait for inverter board connection before starting execution.
 
#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 246 of file config.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 186 of file config.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 220 of file config.h.

◆ F_MOSFET

#define F_MOSFET   20000UL

Desired Switching Frequency for MOSFET Gate Signals.

This macro defines the desired switching frequency for the MOSFET gate signals. Timer 4 (TIM4) is used to generate the PWM signals that drive the MOSFET gates. The resolution of the duty cycle changes with the selected switching frequency. The best TIM4 pre-scaler is chosen automatically to provide the best resolution.

The absolute PWM Resolution is calculated using the following formula:

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

Where:

  • F_HST : High-speed system clock frequency, configured to be 64 MHz.
  • F_MOSFET : 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 (F_MOSFET):

  • 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\) 7183 Hz, the pre-scaler is set to 4.
Figure: Absolute PWM resolution across all supported gate switching frequencies.
Warning
The maximum recommended value for F_MOSFET 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 F_MOSFET is 7183 Hz as the higher pre-scalers needed to support this have not been implemented.
Todo
Specify the desired gate switching frequency.
See also
F_MOSFET_MAX, F_MOSFET_MIN, TIM4_PRESCALER

Definition at line 157 of file config.h.

◆ F_MOSFET_MAX

#define F_MOSFET_MAX   100000UL

Maximum allowed gate switching frequency.

This macro defines the maximum allowed gate switching frequency for the MOSFET gate signals. The value is used to validate the user input for the gate switching frequency and to set the range for allowed frequencies in remote mode with SCPI commands.

Todo
Specify the maximum allowed gate switching frequency.
See also
F_MOSFET, F_MOSFET_MIN, TIM4_PRESCALER

Definition at line 99 of file config.h.

◆ F_MOSFET_MIN

#define F_MOSFET_MIN   7183UL

Minimum allowed gate switching frequency.

This macro defines the minimum allowed gate switching frequency for the MOSFET gate signals. The value is used to validate the user input for the gate switching frequency and to set the range for allowed frequencies in remote mode with SCPI commands.

Todo
Specify the minimum allowed gate switching frequency.
Note
To support lower frequencies than 7183 Hz, you'll have to modify the code to allow for a higher pre-scaler value for Timer4.
See also
F_MOSFET, F_MOSFET_MAX, TIM4_PRESCALER

Definition at line 115 of file config.h.

◆ HALL_PULLUP_ENABLE

#define HALL_PULLUP_ENABLE   TRUE

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 201 of file config.h.

◆ IBUS_ERROR_THRESHOLD

#define IBUS_ERROR_THRESHOLD   410

Hi-side Current (IBUS) 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{IBUS_SENSE_RESISTOR} \times \text{IBUS_GAIN}}{0.004888 \times 1000000} \]

Where:

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

The NEVB-MTR1-I56-1 comes with a default current gain factor of 50 and a current sense resistor of value 4 mΩ. This corresponds to approximately 0.0244 amperes (A) per register value. The default value is 410 which corresponds to approximately 10 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
IBUS_WARNING_THRESHOLD, IBUS_FAULT_ENABLE, IBUS_GAIN, IBUS_SENSE_RESISTOR

Definition at line 406 of file config.h.

◆ IBUS_FAULT_ENABLE

#define IBUS_FAULT_ENABLE   TRUE

Hi-side Current (IBUS) Fault Enable.

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

Note
This does not affect fault reporting for IBUS_WARNING_THRESHOLD.
See also
IBUS_ERROR_THRESHOLD

Definition at line 419 of file config.h.

◆ IBUS_GAIN

#define IBUS_GAIN   50

Hi-side Current (IBUS) 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-MTR1-I56-1 comes with two current op-amps with different gain factors:

  1. Gain factor of 50 - This is the default value.
  2. Gain factor of 20 - This is the alternative value.
Note
Ensure that the gain value is correct.
See also
IBUS_SENSE_RESISTOR

Definition at line 314 of file config.h.

◆ IBUS_SENSE_RESISTOR

#define IBUS_SENSE_RESISTOR   4000

Hi-side Current (IBUS) 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-MTR1-I56-1 comes with a current sense resistor of value 4 mΩ. This is the default value.

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

Definition at line 332 of file config.h.

◆ IBUS_WARNING_THRESHOLD

#define IBUS_WARNING_THRESHOLD   307

Hi-side Current (IBUS) 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{IBUS_SENSE_RESISTOR} \times \text{IBUS_GAIN}}{0.004888 \times 1000000} \]

Where:

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

The NEVB-MTR1-I56-1 comes with a default current gain factor of 50 and a current sense resistor of value 4 mΩ. This corresponds to approximately 0.0244 amperes (A) per register value. The default value is 307 which corresponds to approximately 7.5 A.

Todo
Calculate and set the register value for the current warning threshold.
See also
IBUS_ERROR_THRESHOLD, IBUS_FAULT_ENABLE, IBUS_GAIN, IBUS_SENSE_RESISTOR

Definition at line 367 of file config.h.

◆ IPHASE_GAIN

#define IPHASE_GAIN   20

In-line Phase 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-MTR1-I56-1 comes with a single gain factor option for the in-line phase current measurement circuit - 20.

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

Definition at line 276 of file config.h.

◆ IPHASE_SENSE_RESISTOR

#define IPHASE_SENSE_RESISTOR   2500

Hi-side Current (IBUS) 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-MTR1-I56-1 comes with a in-line phase current sense resistors of value 2.5 mΩ. This is the default value.

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

Definition at line 294 of file config.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 85 of file config.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 566 of file config.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 547 of file config.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 528 of file config.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 509 of file config.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 644 of file config.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 433 of file config.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 469 of file config.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 490 of file config.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 448 of file config.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 236 of file config.h.

◆ TURN_OFF_MODE

#define TURN_OFF_MODE   TURN_OFF_MODE_RAMP

Turn Off Mode.

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

Todo
Select the turn mode by assigning TURN_OFF_MODE_COAST or TURN_OFF_MODE_RAMP.
See also
TURN_OFF_MODE_RAMP, TURN_OFF_MODE_COAST

Definition at line 259 of file config.h.

◆ VBUS_RBOTTOM

#define VBUS_RBOTTOM   6200

Bottom resistor value in the VBUS voltage potential divider.

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

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

NEVB-MTR1-C-1 has a resistor divider with RTOP of 100 kΩ and RBOTTOM of 6.2 kΩ.

Note
Ensure that the resistor value matches the actual hardware component used.
See also
VBUS_RTOP, vbusVref

Definition at line 606 of file config.h.

◆ VBUS_RTOP

#define VBUS_RTOP   100000

Top resistor value in the VBUS voltage potential divider.

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

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

NEVB-MTR1-C-1 has a resistor divider with RTOP of 100 kΩ and RBOTTOM of 6.2 kΩ.

Note
Ensure that the resistor value matches the actual hardware component used.
See also
VBUS_RBOTTOM, vbusVref

Definition at line 586 of file config.h.

◆ WAIT_FOR_BOARD

#define WAIT_FOR_BOARD   TRUE

Wait for inverter board connection before starting execution.

When set to TRUE the firmware will wait for the inverter board to be connected (detected via the IBUS measurement) before enabling motor functionality and proceeding with normal operation. This helps prevent accidental startup when the inverter is not present.

Set to FALSE to skip the check and start immediately.

Note
If IBUS_FAULT_ENABLE is set to TRUE and WAIT_FOR_BOARD is set to FALSE, the IBUS ADC input can be floating when the inverter board is not connected. A floating IBUS input may produce spurious ADC readings and trigger false over-current (IBUS) faults. To avoid false faults either:
  • Enable WAIT_FOR_BOARD so the firmware waits for the inverter before enabling IBUS-based fault handling, or
  • Disable IBUS_FAULT_ENABLE if you cannot ensure a valid IBUS measurement when the board is disconnected, or
  • Provide a defined pull-down/hold on the IBUS ADC pin when the inverter is absent.
Todo
Enable or disable board-wait behavior by assigning TRUE or FALSE.
See also
IBUS_PIN, IBUS_SENSE_RESISTOR, IBUS_GAIN, IBUS_FAULT_ENABLE

Definition at line 633 of file config.h.