Motor Driver Evaluation Kit NEVB-MTR1-t01-1.0.0
Firmware for NEVB-MTR1-KIT1 for trapezoidal control of BLDC motors using Hall-effect sensors
Loading...
Searching...
No Matches
System Constant Defines

These defines should not be modified by the user. More...

Collaboration diagram for System Constant Defines:

Topics

 PLL Post-scaler Macros
 PLL post-scaler selection bits (PLLTM1:0) for High Speed Timer in PLLFRQ.
 
 Deadtime Pre-scaler Macros
 Deadtime generator pre-scaler selection bits (DTPS41:0) in TCCR4B.
 
 Timer 1 (and 3) Clock Select Macros
 Timer 1 (and 3) clock selection bits (CS12:0/CS12:0) for TCCR1B/TCCR3B.
 
 Timer 4 Clock Select Macros
 Timer 4 clock selection bits (CS43:0) for TCCR4B.
 
 ADC Multiplexer Select Macros
 ADC multiplexer selection bits (MUX5 and MUX4:0) in ADCSRB and ADMUX respectively.
 
 ADC Pre-scaler Macros
 ADC pre-scaler selection bits (ADPS2:0) in ADCSRA.
 
 ADC Reference Macros
 ADC voltage reference selection bits (REFS1:0) in ADMUX.
 
 ADC Auto Trigger Macros
 ADC auto trigger source selection bits (ADTS3:0) in ADCSRB.
 

Classes

struct  motorflags
 Collection of all motor control flags. More...
 
struct  faultflags
 Collection of all fault flags. More...
 
struct  motorconfigs
 Collection of motor configurations. More...
 

Macros

#define FALSE   0
 FALSE constant value.
 
#define TRUE   (!FALSE)
 TRUE constant value, defined to be compatible with comparisons.
 
#define F_HST   64000000UL
 High-speed system clock frequency.
 
#define AH_PIN   PB6
 PIN where high side gate PWM for phase A is connected.
 
#define BH_PIN   PC7
 PIN where high side gate PWM for phase B is connected.
 
#define CH_PIN   PD7
 PIN where high side gate PWM for phase C is connected.
 
#define AL_PIN   PB5
 PIN where low side gate PWM for phase A is connected.
 
#define BL_PIN   PC6
 PIN where low side gate PWM for phase B is connected.
 
#define CL_PIN   PD6
 PIN where low side gate PWM for phase C is connected.
 
#define PWM_PATTERN_PORTB   ((1 << AH_PIN) | (1 << AL_PIN))
 Bit pattern of PWM pins placed on PORTB (Phase A).
 
#define PWM_PATTERN_PORTC   ((1 << BH_PIN) | (1 << BL_PIN))
 Bit pattern of PWM pins placed on PORTC (Phase B).
 
#define PWM_PATTERN_PORTD   ((1 << CH_PIN) | (1 << CL_PIN))
 Bit pattern of PWM pins placed on PORTD (Phase C).
 
#define OC_ENABLE_PORTB   ((1 << OC4OE3) | (1 << OC4OE2))
 
#define OC_ENABLE_PORTC   ((1 << OC4OE1) | (1 << OC4OE0))
 
#define OC_ENABLE_PORTD   ((1 << OC4OE5) | (1 << OC4OE4))
 
#define DIRECTION_FORWARD   0
 Forward direction flag value.
 
#define DIRECTION_REVERSE   1
 Reverse direction flag value.
 
#define DIRECTION_UNKNOWN   3
 Unknown direction flag value.
 
#define HALL_PIN   PINB
 PIN register for Hall sensor input.
 
#define H1_PIN   PB1
 Pin where H1 is connected.
 
#define H2_PIN   PB2
 Pin where H2 is connected.
 
#define H3_PIN   PB3
 Pin where H3 is connected.
 
#define ADC_MUX_L_SPEED   ADC_MUX_L_ADC4
 
#define ADC_MUX_H_SPEED   ADC_MUX_H_ADC4
 
#define ADC_MUX_L_IBUS   ADC_MUX_L_ADC5
 Lower analog channel selection bits (MUX4:0) for motor current measurement.
 
#define ADC_MUX_H_IBUS   ADC_MUX_H_ADC5
 High analog channel selection bit (MUX5) for for motor current measurement.
 
#define ADC_MUX_L_IPHASE_U   ADC_MUX_L_ADC1
 Lower analog channel selection bits (MUX4:0) for motor current measurement.
 
#define ADC_MUX_H_IPHASE_U   ADC_MUX_H_ADC1
 High analog channel selection bit (MUX5) for for motor current measurement.
 
#define ADC_MUX_L_IPHASE_V   ADC_MUX_L_ADC7
 Lower analog channel selection bits (MUX4:0) for motor current measurement.
 
#define ADC_MUX_H_IPHASE_V   ADC_MUX_H_ADC7
 High analog channel selection bit (MUX5) for for motor current measurement.
 
#define ADC_MUX_L_IPHASE_W   ADC_MUX_L_ADC0
 Lower analog channel selection bits (MUX4:0) for motor current measurement.
 
#define ADC_MUX_H_IPHASE_W   ADC_MUX_H_ADC0
 High analog channel selection bit (MUX5) for for motor current measurement.
 
#define ADC_MUX_L_VBUSVREF   ADC_MUX_L_ADC6
 Lower analog channel selection bits (MUX4:0) for motor vbusVref measurement.
 
#define ADC_MUX_H_VBUSVREF   ADC_MUX_H_ADC6
 High analog channel selection bit (MUX5) for for motor vbusVref measurement.
 
#define ADC_PRESCALER   ADC_PRESCALER_DIV_128
 ADC clock pre-scaler used in this application.
 
#define ADC_REFERENCE_VOLTAGE   ADC_REFERENCE_VOLTAGE_VCC
 ADC voltage reference used in this application.
 
#define ADC_TRIGGER   ADC_TRIGGER_TIMER0_OVF
 ADC trigger used in this application.
 
#define DIRECTION_COMMAND_PIN   PD2
 Pin where direction command input is located.
 
#define ENABLE_PIN   PD0
 Enable input pin.
 
#define REMOTE_PIN   PD3
 Remote input pin.
 
#define SPEED_INPUT_SOURCE_LOCAL   0
 Speed input source - Local or speed input pin.
 
#define SPEED_INPUT_SOURCE_REMOTE   1
 Speed input source - Remote input.
 
#define FAULT_PIN_1   PD4
 Fault Pin 1.
 
#define FAULT_PIN_2   PB4
 Fault Pin 2.
 
#define FAULT_PIN_3   PB7
 Fault Pin 3.
 
#define WAVEFORM_BLOCK_COMMUTATION   0
 Waveform constant for block commutation.
 
#define WAVEFORM_UNDEFINED   3
 Waveform status flag used for coasting.
 
#define TURN_OFF_MODE_COAST   0
 TURN_OFF_MODE value for coasting (disabled drivers).
 
#define TURN_OFF_MODE_RAMP   1
 TURN_OFF_MODE value for ramping down (drivers ramp to zero speed reference).
 
#define SPEED_CONTROL_OPEN_LOOP   0
 Speed control selection for open loop control.
 
#define SPEED_CONTROL_CLOSED_LOOP   1
 Speed control selection for closed loop control.
 
#define SPEED_CONTROLLER_MAX_INPUT   255
 Maximum Speed Reference Input.
 
#define CHOOSE_TIM4_PRESCALER(tim4Freq)
 Macro to choose Timer4 pre-scaler.
 
#define CHOOSE_DT_PRESCALER(deadTime)
 Macro to choose Timer4 dead time pre-scaler based on the dead time.
 
#define FORCE_INLINE   inline __attribute__((always_inline))
 Macro for forcing inline expansion of functions.
 
#define FAST_ACCESS(register_address)
 Assign a specific memory address to a variable for fast access.
 

Typedefs

typedef struct motorflags motorflags_t
 Collection of all motor control flags.
 
typedef struct faultflags faultflags_t
 Collection of all fault flags.
 
typedef struct motorconfigs motorconfigs_t
 Collection of motor configurations.
 

Enumerations

enum  fault_flag_t {
  FAULT_RESERVED , FAULT_REVERSE_DIRECTION , FAULT_MOTOR_STOPPED , FAULT_OVER_CURRENT ,
  FAULT_NO_HALL_CONNECTIONS , FAULT_USER_FLAG1 , FAULT_USER_FLAG2 , FAULT_USER_FLAG3
}
 Enumeration of fault flags. More...
 

Detailed Description

These defines should not be modified by the user.

Macro Definition Documentation

◆ ADC_MUX_H_IBUS

#define ADC_MUX_H_IBUS   ADC_MUX_H_ADC5

High analog channel selection bit (MUX5) for for motor current measurement.

Definition at line 662 of file config.h.

◆ ADC_MUX_H_IPHASE_U

#define ADC_MUX_H_IPHASE_U   ADC_MUX_H_ADC1

High analog channel selection bit (MUX5) for for motor current measurement.

Definition at line 666 of file config.h.

◆ ADC_MUX_H_IPHASE_V

#define ADC_MUX_H_IPHASE_V   ADC_MUX_H_ADC7

High analog channel selection bit (MUX5) for for motor current measurement.

Definition at line 670 of file config.h.

◆ ADC_MUX_H_IPHASE_W

#define ADC_MUX_H_IPHASE_W   ADC_MUX_H_ADC0

High analog channel selection bit (MUX5) for for motor current measurement.

Definition at line 674 of file config.h.

◆ ADC_MUX_H_SPEED

#define ADC_MUX_H_SPEED   ADC_MUX_H_ADC4

High analog channel selection bit (MUX5) for analog speed reference measurement.

Definition at line 658 of file config.h.

◆ ADC_MUX_H_VBUSVREF

#define ADC_MUX_H_VBUSVREF   ADC_MUX_H_ADC6

High analog channel selection bit (MUX5) for for motor vbusVref measurement.

Definition at line 678 of file config.h.

◆ ADC_MUX_L_IBUS

#define ADC_MUX_L_IBUS   ADC_MUX_L_ADC5

Lower analog channel selection bits (MUX4:0) for motor current measurement.

Definition at line 660 of file config.h.

◆ ADC_MUX_L_IPHASE_U

#define ADC_MUX_L_IPHASE_U   ADC_MUX_L_ADC1

Lower analog channel selection bits (MUX4:0) for motor current measurement.

Definition at line 664 of file config.h.

◆ ADC_MUX_L_IPHASE_V

#define ADC_MUX_L_IPHASE_V   ADC_MUX_L_ADC7

Lower analog channel selection bits (MUX4:0) for motor current measurement.

Definition at line 668 of file config.h.

◆ ADC_MUX_L_IPHASE_W

#define ADC_MUX_L_IPHASE_W   ADC_MUX_L_ADC0

Lower analog channel selection bits (MUX4:0) for motor current measurement.

Definition at line 672 of file config.h.

◆ ADC_MUX_L_SPEED

#define ADC_MUX_L_SPEED   ADC_MUX_L_ADC4

Lower analog channel selection bits (MUX4:0) for analog speed reference measurement.

Definition at line 655 of file config.h.

◆ ADC_MUX_L_VBUSVREF

#define ADC_MUX_L_VBUSVREF   ADC_MUX_L_ADC6

Lower analog channel selection bits (MUX4:0) for motor vbusVref measurement.

Definition at line 676 of file config.h.

◆ ADC_PRESCALER

#define ADC_PRESCALER   ADC_PRESCALER_DIV_128

ADC clock pre-scaler used in this application.

Definition at line 682 of file config.h.

◆ ADC_REFERENCE_VOLTAGE

#define ADC_REFERENCE_VOLTAGE   ADC_REFERENCE_VOLTAGE_VCC

ADC voltage reference used in this application.

Definition at line 684 of file config.h.

◆ ADC_TRIGGER

#define ADC_TRIGGER   ADC_TRIGGER_TIMER0_OVF

ADC trigger used in this application.

Definition at line 686 of file config.h.

◆ AH_PIN

#define AH_PIN   PB6

PIN where high side gate PWM for phase A is connected.

Definition at line 605 of file config.h.

◆ AL_PIN

#define AL_PIN   PB5

PIN where low side gate PWM for phase A is connected.

Definition at line 611 of file config.h.

◆ BH_PIN

#define BH_PIN   PC7

PIN where high side gate PWM for phase B is connected.

Definition at line 607 of file config.h.

◆ BL_PIN

#define BL_PIN   PC6

PIN where low side gate PWM for phase B is connected.

Definition at line 613 of file config.h.

◆ CH_PIN

#define CH_PIN   PD7

PIN where high side gate PWM for phase C is connected.

Definition at line 609 of file config.h.

◆ CHOOSE_DT_PRESCALER

#define CHOOSE_DT_PRESCALER ( deadTime)
Value:
((deadTime) <= 234 ? 1 : (deadTime) <= 468 ? 2 \
: (deadTime) <= 937 ? 4 \
: (deadTime) <= 1875 ? 8 \
: 0)

Macro to choose Timer4 dead time pre-scaler based on the dead time.

This macro determines the appropriate dead time pre-scaler for Timer4 based on the provided deadTime value. The deadTime is expected to be an integer value representing nanoseconds.

The pre-scaler is chosen based on the following conditions:

  • For deadTime of 16 ns to 234 ns, pre-scaler 1 is chosen.
  • For deadTime of 235 ns to 468 ns, pre-scaler 2 is chosen.
  • For deadTime of 469 ns to 937 ns, pre-scaler 4 is chosen.
  • For deadTime of 938 ns to 1875 ns, pre-scaler 8 is chosen.
Parameters
deadTimeThe dead time in nanoseconds.
Returns
The chosen pre-scaler value.

Definition at line 761 of file config.h.

761#define CHOOSE_DT_PRESCALER(deadTime) \
762 ((deadTime) <= 234 ? 1 : (deadTime) <= 468 ? 2 \
763 : (deadTime) <= 937 ? 4 \
764 : (deadTime) <= 1875 ? 8 \
765 : 0)

◆ CHOOSE_TIM4_PRESCALER

#define CHOOSE_TIM4_PRESCALER ( tim4Freq)
Value:
((tim4Freq) < 15625 ? 4 : ((tim4Freq) < 31250 ? 2 : 1))

Macro to choose Timer4 pre-scaler.

Definition at line 743 of file config.h.

◆ CL_PIN

#define CL_PIN   PD6

PIN where low side gate PWM for phase C is connected.

Definition at line 615 of file config.h.

◆ DIRECTION_COMMAND_PIN

#define DIRECTION_COMMAND_PIN   PD2

Pin where direction command input is located.

Definition at line 690 of file config.h.

◆ DIRECTION_FORWARD

#define DIRECTION_FORWARD   0

Forward direction flag value.

Definition at line 636 of file config.h.

◆ DIRECTION_REVERSE

#define DIRECTION_REVERSE   1

Reverse direction flag value.

Definition at line 638 of file config.h.

◆ DIRECTION_UNKNOWN

#define DIRECTION_UNKNOWN   3

Unknown direction flag value.

Definition at line 640 of file config.h.

◆ ENABLE_PIN

#define ENABLE_PIN   PD0

Enable input pin.

Definition at line 692 of file config.h.

◆ F_HST

#define F_HST   64000000UL

High-speed system clock frequency.

Definition at line 601 of file config.h.

◆ FALSE

#define FALSE   0

FALSE constant value.

Definition at line 596 of file config.h.

◆ FAST_ACCESS

#define FAST_ACCESS ( register_address)
Value:
__attribute__((address(register_address)))
volatile motorflags_t motorFlags __attribute__((address(0x4A)))
Motor control flags placed in I/O space for fast access.

Assign a specific memory address to a variable for fast access.

This macro is used to specify the memory address of a register for fast access, directly instructing the compiler to place the variable at the given address. When parsed by IntelliSense in VSCode, the macro is defined as empty to avoid IntelliSense errors.

Definition at line 797 of file config.h.

◆ FAULT_PIN_1

#define FAULT_PIN_1   PD4

Fault Pin 1.

Definition at line 704 of file config.h.

◆ FAULT_PIN_2

#define FAULT_PIN_2   PB4

Fault Pin 2.

Definition at line 706 of file config.h.

◆ FAULT_PIN_3

#define FAULT_PIN_3   PB7

Fault Pin 3.

Definition at line 708 of file config.h.

◆ FORCE_INLINE

#define FORCE_INLINE   inline __attribute__((always_inline))

Macro for forcing inline expansion of functions.

This macro ensures that a function is always inlined by the compiler, overriding the compiler's own decision process. When parsed by IntelliSense in VSCode, it is defined as a simple inline to avoid IntelliSense errors. For actual compilation, it includes the GCC-specific always_inline attribute to enforce inlining.

Definition at line 781 of file config.h.

◆ H1_PIN

#define H1_PIN   PB1

Pin where H1 is connected.

Definition at line 646 of file config.h.

◆ H2_PIN

#define H2_PIN   PB2

Pin where H2 is connected.

Definition at line 648 of file config.h.

◆ H3_PIN

#define H3_PIN   PB3

Pin where H3 is connected.

Definition at line 650 of file config.h.

◆ HALL_PIN

#define HALL_PIN   PINB

PIN register for Hall sensor input.

Definition at line 644 of file config.h.

◆ OC_ENABLE_PORTB

#define OC_ENABLE_PORTB   ((1 << OC4OE3) | (1 << OC4OE2))

Bit pattern for Output Compare Enable Bits for PORTB (Phase A) placed on TCCR1E.

Definition at line 626 of file config.h.

◆ OC_ENABLE_PORTC

#define OC_ENABLE_PORTC   ((1 << OC4OE1) | (1 << OC4OE0))

Bit pattern for Output Compare Enable Bits for PORTC (Phase B) placed on TCCR1E.

Definition at line 629 of file config.h.

◆ OC_ENABLE_PORTD

#define OC_ENABLE_PORTD   ((1 << OC4OE5) | (1 << OC4OE4))

Bit pattern for Output Compare Enable Bits for PORTD (Phase C) placed on TCCR1E.

Definition at line 632 of file config.h.

◆ PWM_PATTERN_PORTB

#define PWM_PATTERN_PORTB   ((1 << AH_PIN) | (1 << AL_PIN))

Bit pattern of PWM pins placed on PORTB (Phase A).

Definition at line 619 of file config.h.

◆ PWM_PATTERN_PORTC

#define PWM_PATTERN_PORTC   ((1 << BH_PIN) | (1 << BL_PIN))

Bit pattern of PWM pins placed on PORTC (Phase B).

Definition at line 621 of file config.h.

◆ PWM_PATTERN_PORTD

#define PWM_PATTERN_PORTD   ((1 << CH_PIN) | (1 << CL_PIN))

Bit pattern of PWM pins placed on PORTD (Phase C).

Definition at line 623 of file config.h.

◆ REMOTE_PIN

#define REMOTE_PIN   PD3

Remote input pin.

Definition at line 694 of file config.h.

◆ SPEED_CONTROL_CLOSED_LOOP

#define SPEED_CONTROL_CLOSED_LOOP   1

Speed control selection for closed loop control.

Definition at line 726 of file config.h.

◆ SPEED_CONTROL_OPEN_LOOP

#define SPEED_CONTROL_OPEN_LOOP   0

Speed control selection for open loop control.

Definition at line 724 of file config.h.

◆ SPEED_CONTROLLER_MAX_INPUT

#define SPEED_CONTROLLER_MAX_INPUT   255

Maximum Speed Reference Input.

This macro specifies the maximum speed reference input value that the speed controller should consider which corresponds to the highest possible reading from the ADC This is by default 8 bits as only the top 8 bits of the 10 bit ADC is being used. This corresponds to a value of 255.

Note
This parameter is applicable when SPEED_CONTROL_METHOD is set to SPEED_CONTROL_CLOSED_LOOP. Only change this if changes to the code are made to alter the ADC bits used.

Definition at line 740 of file config.h.

◆ SPEED_INPUT_SOURCE_LOCAL

#define SPEED_INPUT_SOURCE_LOCAL   0

Speed input source - Local or speed input pin.

Definition at line 698 of file config.h.

◆ SPEED_INPUT_SOURCE_REMOTE

#define SPEED_INPUT_SOURCE_REMOTE   1

Speed input source - Remote input.

Definition at line 700 of file config.h.

◆ TRUE

#define TRUE   (!FALSE)

TRUE constant value, defined to be compatible with comparisons.

Definition at line 598 of file config.h.

◆ TURN_OFF_MODE_COAST

#define TURN_OFF_MODE_COAST   0

TURN_OFF_MODE value for coasting (disabled drivers).

Definition at line 718 of file config.h.

◆ TURN_OFF_MODE_RAMP

#define TURN_OFF_MODE_RAMP   1

TURN_OFF_MODE value for ramping down (drivers ramp to zero speed reference).

Definition at line 720 of file config.h.

◆ WAVEFORM_BLOCK_COMMUTATION

#define WAVEFORM_BLOCK_COMMUTATION   0

Waveform constant for block commutation.

Definition at line 712 of file config.h.

◆ WAVEFORM_UNDEFINED

#define WAVEFORM_UNDEFINED   3

Waveform status flag used for coasting.

Definition at line 714 of file config.h.

Typedef Documentation

◆ faultflags_t

typedef struct faultflags faultflags_t

Collection of all fault flags.

This struct contains all fault flags used in this implementation.

◆ motorconfigs_t

typedef struct motorconfigs motorconfigs_t

Collection of motor configurations.

This struct contains some of the motor configurations. This may support remote implementation.

◆ motorflags_t

typedef struct motorflags motorflags_t

Collection of all motor control flags.

This struct contains all motor control flags used in this implementation.

Enumeration Type Documentation

◆ fault_flag_t

Enumeration of fault flags.

Enumerator
FAULT_RESERVED 

Reserved flag, always false.

FAULT_REVERSE_DIRECTION 

Is motor spinning in an unexpected direction?

FAULT_MOTOR_STOPPED 

Is motor stopped?

FAULT_OVER_CURRENT 

Has it tripped the over current limit?

FAULT_NO_HALL_CONNECTIONS 

Is there no hall connections?

FAULT_USER_FLAG1 

Is user flag 1 set?

FAULT_USER_FLAG2 

Is user flag 2 set?

FAULT_USER_FLAG3 

Is user flag 3 set?

Definition at line 1090 of file config.h.

1091{
1108} fault_flag_t;
fault_flag_t
Enumeration of fault flags.
Definition config.h:1091
@ FAULT_OVER_CURRENT
Has it tripped the over current limit?
Definition config.h:1099
@ FAULT_USER_FLAG1
Is user flag 1 set?
Definition config.h:1103
@ FAULT_NO_HALL_CONNECTIONS
Is there no hall connections?
Definition config.h:1101
@ FAULT_USER_FLAG2
Is user flag 2 set?
Definition config.h:1105
@ FAULT_RESERVED
Reserved flag, always false.
Definition config.h:1093
@ FAULT_USER_FLAG3
Is user flag 3 set?
Definition config.h:1107
@ FAULT_REVERSE_DIRECTION
Is motor spinning in an unexpected direction?
Definition config.h:1095
@ FAULT_MOTOR_STOPPED
Is motor stopped?
Definition config.h:1097