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
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_CURRENT   ADC_MUX_L_ADC7
 Lower analog channel selection bits (MUX4:0) for motor current measurement.
 
#define ADC_MUX_H_CURRENT   ADC_MUX_H_ADC7
 High analog channel selection bit (MUX5) for for motor current measurement.
 
#define ADC_MUX_L_GATEVREF   ADC_MUX_L_ADC6
 Lower analog channel selection bits (MUX4:0) for motor gateVref measurement.
 
#define ADC_MUX_H_GATEVREF   ADC_MUX_H_ADC6
 High analog channel selection bit (MUX5) for for motor gateVref measurement.
 
#define ADC_MUX_L_BREF   ADC_MUX_L_ADC0
 Lower analog channel selection bits (MUX4:0) for motor bref measurement.
 
#define ADC_MUX_H_BREF   ADC_MUX_H_ADC0
 High analog channel selection bit (MUX5) for for motor bref measurement.
 
#define ADC_PRESCALER   ADC_PRESCALER_DIV_8
 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_BRAKING   1
 Waveform status flag for braking.
 
#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_BRAKE   1
 
#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)   ((tim4Freq) < 15625 ? 4 : ((tim4Freq) < 31250 ? 2 : 1))
 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)   __attribute__((address(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.
 

Detailed Description

These defines should not be modified by the user.

Macro Definition Documentation

◆ ADC_MUX_H_BREF

#define ADC_MUX_H_BREF   ADC_MUX_H_ADC0

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

Definition at line 609 of file main.h.

◆ ADC_MUX_H_CURRENT

#define ADC_MUX_H_CURRENT   ADC_MUX_H_ADC7

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

Definition at line 601 of file main.h.

◆ ADC_MUX_H_GATEVREF

#define ADC_MUX_H_GATEVREF   ADC_MUX_H_ADC6

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

Definition at line 605 of file main.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 597 of file main.h.

◆ ADC_MUX_L_BREF

#define ADC_MUX_L_BREF   ADC_MUX_L_ADC0

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

Definition at line 607 of file main.h.

◆ ADC_MUX_L_CURRENT

#define ADC_MUX_L_CURRENT   ADC_MUX_L_ADC7

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

Definition at line 599 of file main.h.

◆ ADC_MUX_L_GATEVREF

#define ADC_MUX_L_GATEVREF   ADC_MUX_L_ADC6

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

Definition at line 603 of file main.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 594 of file main.h.

◆ ADC_PRESCALER

#define ADC_PRESCALER   ADC_PRESCALER_DIV_8

ADC clock pre-scaler used in this application.

Definition at line 613 of file main.h.

◆ ADC_REFERENCE_VOLTAGE

#define ADC_REFERENCE_VOLTAGE   ADC_REFERENCE_VOLTAGE_VCC

ADC voltage reference used in this application.

Definition at line 615 of file main.h.

◆ ADC_TRIGGER

#define ADC_TRIGGER   ADC_TRIGGER_TIMER0_OVF

ADC trigger used in this application.

Definition at line 617 of file main.h.

◆ AH_PIN

#define AH_PIN   PB6

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

Definition at line 544 of file main.h.

◆ AL_PIN

#define AL_PIN   PB5

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

Definition at line 550 of file main.h.

◆ BH_PIN

#define BH_PIN   PC7

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

Definition at line 546 of file main.h.

◆ BL_PIN

#define BL_PIN   PC6

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

Definition at line 552 of file main.h.

◆ CH_PIN

#define CH_PIN   PD7

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

Definition at line 548 of file main.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 695 of file main.h.

695#define CHOOSE_DT_PRESCALER(deadTime) \
696 ((deadTime) <= 234 ? 1 : (deadTime) <= 468 ? 2 \
697 : (deadTime) <= 937 ? 4 \
698 : (deadTime) <= 1875 ? 8 \
699 : 0)

◆ CHOOSE_TIM4_PRESCALER

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

Macro to choose Timer4 pre-scaler.

Definition at line 677 of file main.h.

◆ CL_PIN

#define CL_PIN   PD6

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

Definition at line 554 of file main.h.

◆ DIRECTION_COMMAND_PIN

#define DIRECTION_COMMAND_PIN   PD2

Pin where direction command input is located.

Definition at line 621 of file main.h.

◆ DIRECTION_FORWARD

#define DIRECTION_FORWARD   0

Forward direction flag value.

Definition at line 575 of file main.h.

◆ DIRECTION_REVERSE

#define DIRECTION_REVERSE   1

Reverse direction flag value.

Definition at line 577 of file main.h.

◆ DIRECTION_UNKNOWN

#define DIRECTION_UNKNOWN   3

Unknown direction flag value.

Definition at line 579 of file main.h.

◆ ENABLE_PIN

#define ENABLE_PIN   PD0

Enable input pin.

Definition at line 623 of file main.h.

◆ F_HST

#define F_HST   64000000UL

High-speed system clock frequency.

Definition at line 540 of file main.h.

◆ FALSE

#define FALSE   0

FALSE constant value.

Definition at line 535 of file main.h.

◆ FAST_ACCESS

#define FAST_ACCESS ( register_address)    __attribute__((address(register_address)))

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 731 of file main.h.

◆ FAULT_PIN_1

#define FAULT_PIN_1   PD4

Fault Pin 1.

Definition at line 635 of file main.h.

◆ FAULT_PIN_2

#define FAULT_PIN_2   PB4

Fault Pin 2.

Definition at line 637 of file main.h.

◆ FAULT_PIN_3

#define FAULT_PIN_3   PB7

Fault Pin 3.

Definition at line 639 of file main.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 715 of file main.h.

◆ H1_PIN

#define H1_PIN   PB1

Pin where H1 is connected.

Definition at line 585 of file main.h.

◆ H2_PIN

#define H2_PIN   PB2

Pin where H2 is connected.

Definition at line 587 of file main.h.

◆ H3_PIN

#define H3_PIN   PB3

Pin where H3 is connected.

Definition at line 589 of file main.h.

◆ HALL_PIN

#define HALL_PIN   PINB

PIN register for Hall sensor input.

Definition at line 583 of file main.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 565 of file main.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 568 of file main.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 571 of file main.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 558 of file main.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 560 of file main.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 562 of file main.h.

◆ REMOTE_PIN

#define REMOTE_PIN   PD3

Remote input pin.

Definition at line 625 of file main.h.

◆ SPEED_CONTROL_CLOSED_LOOP

#define SPEED_CONTROL_CLOSED_LOOP   1

Speed control selection for closed loop control.

Definition at line 660 of file main.h.

◆ SPEED_CONTROL_OPEN_LOOP

#define SPEED_CONTROL_OPEN_LOOP   0

Speed control selection for open loop control.

Definition at line 658 of file main.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 674 of file main.h.

◆ SPEED_INPUT_SOURCE_LOCAL

#define SPEED_INPUT_SOURCE_LOCAL   0

Speed input source - Local or speed input pin.

Definition at line 629 of file main.h.

◆ SPEED_INPUT_SOURCE_REMOTE

#define SPEED_INPUT_SOURCE_REMOTE   1

Speed input source - Remote input.

Definition at line 631 of file main.h.

◆ TRUE

#define TRUE   (!FALSE)

TRUE constant value, defined to be compatible with comparisons.

Definition at line 537 of file main.h.

◆ TURN_OFF_MODE_BRAKE

#define TURN_OFF_MODE_BRAKE   1

TURN_OFF_MODE value for braking (drivers pulsed at 50% to dissipate energy to VIN and GND).

Definition at line 654 of file main.h.

◆ TURN_OFF_MODE_COAST

#define TURN_OFF_MODE_COAST   0

TURN_OFF_MODE value for coasting (disabled drivers).

Definition at line 651 of file main.h.

◆ WAVEFORM_BLOCK_COMMUTATION

#define WAVEFORM_BLOCK_COMMUTATION   0

Waveform constant for block commutation.

Definition at line 643 of file main.h.

◆ WAVEFORM_BRAKING

#define WAVEFORM_BRAKING   1

Waveform status flag for braking.

Definition at line 645 of file main.h.

◆ WAVEFORM_UNDEFINED

#define WAVEFORM_UNDEFINED   3

Waveform status flag used for coasting.

Definition at line 647 of file main.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.