R2R
Functions
Motor.c File Reference

The motor source code. More...

#include "r2r.h"
#include "Motor.h"
#include "Utilities.h"

Functions

void motorInit ()
 Initializes the GPIO pins for the motor. More...
 
void M1HIntHandler (void)
 Hall sensor interrupt for motor 1. More...
 
void M2HIntHandler (void)
 Hall sensor interrupt for 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 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...
 
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 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...
 

Detailed Description

The motor source code.

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