R2R
Macros | Functions
Motor.h File Reference

utilities header More...

Go to the source code of this file.

Macros

#define PWMPERIOD   4000
 
#define M1H_PERIPH   SYSCTL_PERIPH_GPIOM
 
#define M1H_PORT   GPIO_PORTM_BASE
 
#define M1H_PORT_INT   INT_GPIOM
 
#define M1H_PIN_A   GPIO_PIN_0
 
#define M1H_PIN_B   GPIO_PIN_1
 
#define M1H_PIN_C   GPIO_PIN_2
 
#define M1H_PINS   (M1H_PIN_A | M1H_PIN_B | M1H_PIN_C)
 
#define M1_HALLSTATE_0   (M1H_PIN_A | M1H_PIN_B)
 
#define M1_HALLSTATE_1   M1H_PIN_A
 
#define M1_HALLSTATE_2   (M1H_PIN_A | M1H_PIN_C)
 
#define M1_HALLSTATE_3   M1H_PIN_C
 
#define M1_HALLSTATE_4   (M1H_PIN_B | M1H_PIN_C)
 
#define M1_HALLSTATE_5   M1H_PIN_B
 
#define M1_INL_PERIPH_A   SYSCTL_PERIPH_GPIOP
 
#define M1_INL_PORT_A   GPIO_PORTP_BASE
 
#define M1_INL_PIN_A   GPIO_PIN_0
 
#define M1_INL_PERIPH_B   SYSCTL_PERIPH_GPIOP
 
#define M1_INL_PORT_B   GPIO_PORTP_BASE
 
#define M1_INL_PIN_B   GPIO_PIN_1
 
#define M1_INL_PERIPH_C   SYSCTL_PERIPH_GPIOP
 
#define M1_INL_PORT_C   GPIO_PORTP_BASE
 
#define M1_INL_PIN_C   GPIO_PIN_2
 
#define M2H_PERIPH   SYSCTL_PERIPH_GPION
 
#define M2H_PORT   GPIO_PORTN_BASE
 
#define M2H_PORT_INT   INT_GPION
 
#define M2H_PIN_A   GPIO_PIN_0
 
#define M2H_PIN_B   GPIO_PIN_1
 
#define M2H_PIN_C   GPIO_PIN_2
 
#define M2H_PINS   (M2H_PIN_A | M2H_PIN_B | M2H_PIN_C)
 
#define M2_INL_PERIPH_A   SYSCTL_PERIPH_GPIOM
 
#define M2_INL_PORT_A   GPIO_PORTM_BASE
 
#define M2_INL_PIN_A   GPIO_PIN_5
 
#define M2_INL_PERIPH_B   SYSCTL_PERIPH_GPIOM
 
#define M2_INL_PORT_B   GPIO_PORTM_BASE
 
#define M2_INL_PIN_B   GPIO_PIN_6
 
#define M2_INL_PERIPH_C   SYSCTL_PERIPH_GPIOM
 
#define M2_INL_PORT_C   GPIO_PORTM_BASE
 
#define M2_INL_PIN_C   GPIO_PIN_7
 
#define M2_HALLSTATE_0   (M2H_PIN_A | M2H_PIN_B)
 
#define M2_HALLSTATE_1   M2H_PIN_A
 
#define M2_HALLSTATE_2   (M2H_PIN_A | M2H_PIN_C)
 
#define M2_HALLSTATE_3   M2H_PIN_C
 
#define M2_HALLSTATE_4   (M2H_PIN_B | M2H_PIN_C)
 
#define M2_HALLSTATE_5   M2H_PIN_B
 

Functions

void M1HIntHandler (void)
 Hall sensor interrupt for motor 1. More...
 
void M2HIntHandler (void)
 Hall sensor interrupt for motor 2. More...
 
void motor1Commutate (int State, int control)
 Commutate motor 1 with a given pwm. More...
 
void motor2Commutate (int State, int control)
 Commutate motor 2 with a given pwm. More...
 
void motor1PWM (int pwm1, int pwm2, int pwm3)
 Sets the PWM value to motor 1. More...
 
void motor2PWM (int pwm1, int pwm2, int pwm3)
 Sets the PWM value to motor 2. More...
 
void motor1ControlPWM (int control)
 Sets the PWM value and direction to motor 1. More...
 
void motor2ControlPWM (int control)
 Sets the PWM value and direction to motor 2. More...
 
void motorInit (void)
 Initializes the GPIO pins for the motor. More...
 
void M1_INL_WRITE (int a, int b, int c)
 Commutation table for motor 1. More...
 
void M2_INL_WRITE (int a, int b, int c)
 Commutation table for motor 2. More...
 
int getmotor1PWM (void)
 Returns the current PWM of motor 1. More...
 
int getmotor2PWM (void)
 Returns the current PWM of motor 2. More...
 
int32_t getmotor1HALLS (void)
 Returns the current state of the halls for motor 1. More...
 
int32_t getmotor2HALLS (void)
 Returns the current state of the halls for motor 2. More...
 
void MotorSPIinit (void)
 Initializes the SPI channels for the motor drivers. More...
 
void motorDriverInit (void)
 Initializes the SPI commands to set the motor's configuration for 1x PWM mode. More...
 
void pwmInit (void)
 Initializes PWM. More...
 

Detailed Description

utilities header

This file contains the motor functions

Author
Benjamen Lim
Huan Weng
Blake Strebel

Function Documentation

◆ getmotor1HALLS()

int32_t getmotor1HALLS ( void  )

Returns the current state of the halls for motor 1.

It returns 32 bit number representing the state of the motor as a bit array It is compared to the HALLSTATE definitions to determine the current state.

Parameters
Void
Returns
int32_t the state of the motor in a bit array

◆ getmotor1PWM()

int getmotor1PWM ( void  )

Returns the current PWM of motor 1.

Parameters
Void
Returns
int pwm of motor

◆ getmotor2HALLS()

int32_t getmotor2HALLS ( void  )

Returns the current state of the halls for motor 2.

It returns 32 bit number representing the state of the motor as a bit array It is compared to the HALLSTATE definitions to determine the current state.

Parameters
Void
Returns
int32_t the state of the motor in a bit array

◆ getmotor2PWM()

int getmotor2PWM ( void  )

Returns the current PWM of motor 2.

Parameters
Void
Returns
int pwm of motor

◆ M1_INL_WRITE()

void M1_INL_WRITE ( int  a,
int  b,
int  c 
)

Commutation table for motor 1.

This function contains the commutation table for motor 1 and sets the control pins for each phase accordingly.

Parameters
inta phase A
intb phase B
intc phase C
Returns
Void

◆ M1HIntHandler()

void M1HIntHandler ( void  )

Hall sensor interrupt for motor 1.

This function is used to determine the commutation on motor 1

Parameters
Void
Returns
Void

◆ M2_INL_WRITE()

void M2_INL_WRITE ( int  a,
int  b,
int  c 
)

Commutation table for motor 2.

This function contains the commutation table for motor 2 and sets the control pins for each phase accordingly.

Parameters
inta phase A
intb phase B
intc phase C
Returns
Void

◆ M2HIntHandler()

void M2HIntHandler ( void  )

Hall sensor interrupt for motor 2.

This function is used to determine the commutation on motor 2

Parameters
Void
Returns
Void

◆ motor1Commutate()

void motor1Commutate ( int  State,
int  control 
)

Commutate motor 1 with a given pwm.

The state of the commutation is determined by the hall sensing

Parameters
Stateof 1 to 6
controlthe pwm for the motor
Returns
Void

◆ motor1ControlPWM()

void motor1ControlPWM ( int  control)

Sets the PWM value and direction to motor 1.

This function handles all the commutation for motor 1. This is done via hall sensing to determine the position the BLDC motor is in.

Example: motor2ControlPWM(200); // sets the motor speed to 5% of default, clockwise delayMS(100); //delay for 100 ms motor2ControlPWM(-200); // sets motor speed to 5% of default, counter clockwise.

Parameters
controlThe pwmValue ranges from -maximum pwm period to the positive period. The default pwm period is 4000, 30kHz.
Returns
Void

◆ motor1PWM()

void motor1PWM ( int  pwm1,
int  pwm2,
int  pwm3 
)

Sets the PWM value to motor 1.

Parameters
pwm1the pwm output on phase A
pwm2the pwm output on phase B
pwm3the pwm output on phase C
Returns
Void

◆ motor2Commutate()

void motor2Commutate ( int  State,
int  control 
)

Commutate motor 2 with a given pwm.

The state of the commutation is determined by the hall sensing

Parameters
Stateof 1 to 6
controlthe pwm for the motor
Returns
Void

◆ motor2ControlPWM()

void motor2ControlPWM ( int  control)

Sets the PWM value and direction to motor 2.

This function handles all the commutation for motor 2. This is done via hall sensing to determine the position the BLDC motor is in.

Example: motor2ControlPWM(200); // sets the motor speed to 5% of default, clockwise delayMS(100); //delay for 100 ms motor2ControlPWM(-200); // sets motor speed to 5% of default, counter clockwise.

Parameters
controlThe pwmValue ranges from -maximum pwm period to the positive period. The default pwm period is 4000, 30kHz.
Returns
Void

◆ motor2PWM()

void motor2PWM ( int  pwm1,
int  pwm2,
int  pwm3 
)

Sets the PWM value to motor 2.

Parameters
pwm1the pwm output on phase A
pwm2the pwm output on phase B
pwm3the pwm output on phase C
Returns
Void

◆ motorDriverInit()

void motorDriverInit ( void  )

Initializes the SPI commands to set the motor's configuration for 1x PWM mode.

Parameters
Void
Returns
Void

◆ motorInit()

void motorInit ( void  )

Initializes the GPIO pins for the motor.

Initializes the direction, brake, and halt pins for the motor in 1x PWM mode

Parameters
Void
Returns
Void

◆ MotorSPIinit()

void MotorSPIinit ( void  )

Initializes the SPI channels for the motor drivers.

Initializes SSI1 ~ 4 and their corresponding GPIO pins

Parameters
Void
Returns
Void

◆ pwmInit()

void pwmInit ( void  )

Initializes PWM.

Initialize PWM on PF0 (motor 1) and PG0 (motor 2), and the default period if 320 SysClk cycles.

Parameters
Void
Returns
Void