R2R
Motor.h
Go to the documentation of this file.
1 
13 #ifndef MOTOR_H_
14 #define MOTOR_H_
15 
16 #define PWMPERIOD 4000
17 
18 // MOTOR 1 HALL SENSOR PINS
19 #define M1H_PERIPH SYSCTL_PERIPH_GPIOM
20 #define M1H_PORT GPIO_PORTM_BASE // IF YOU CHANGE THIS PORT YOU MUST CHANGE THE INT HANDLER IN tm4c1294ncpdt_startup_css.c
21 #define M1H_PORT_INT INT_GPIOM
22 #define M1H_PIN_A GPIO_PIN_0
23 #define M1H_PIN_B GPIO_PIN_1
24 #define M1H_PIN_C GPIO_PIN_2
25 #define M1H_PINS (M1H_PIN_A | M1H_PIN_B | M1H_PIN_C)
26 
27 // MOTOR 1 COMMUTATION DATA
28 #define M1_HALLSTATE_0 (M1H_PIN_A | M1H_PIN_B)
29 #define M1_HALLSTATE_1 M1H_PIN_A
30 #define M1_HALLSTATE_2 (M1H_PIN_A | M1H_PIN_C)
31 #define M1_HALLSTATE_3 M1H_PIN_C
32 #define M1_HALLSTATE_4 (M1H_PIN_B | M1H_PIN_C)
33 #define M1_HALLSTATE_5 M1H_PIN_B
34 
35 // MOTOR 1 CONTROL PINS
36 #define M1_INL_PERIPH_A SYSCTL_PERIPH_GPIOP
37 #define M1_INL_PORT_A GPIO_PORTP_BASE
38 #define M1_INL_PIN_A GPIO_PIN_0
39 #define M1_INL_PERIPH_B SYSCTL_PERIPH_GPIOP
40 #define M1_INL_PORT_B GPIO_PORTP_BASE
41 #define M1_INL_PIN_B GPIO_PIN_1
42 #define M1_INL_PERIPH_C SYSCTL_PERIPH_GPIOP
43 #define M1_INL_PORT_C GPIO_PORTP_BASE
44 #define M1_INL_PIN_C GPIO_PIN_2
45 
46 // MOTOR 2 HALL SENSOR PINS
47 #define M2H_PERIPH SYSCTL_PERIPH_GPION
48 #define M2H_PORT GPIO_PORTN_BASE // IF YOU CHANGE THIS PORT YOU MUST CHANGE THE INT HANDLER IN tm4c1294ncpdt_startup_css.c
49 #define M2H_PORT_INT INT_GPION
50 #define M2H_PIN_A GPIO_PIN_0
51 #define M2H_PIN_B GPIO_PIN_1
52 #define M2H_PIN_C GPIO_PIN_2
53 #define M2H_PINS (M2H_PIN_A | M2H_PIN_B | M2H_PIN_C)
54 
55 // MOTOR 2 CONTROL PINS
56 #define M2_INL_PERIPH_A SYSCTL_PERIPH_GPIOM
57 #define M2_INL_PORT_A GPIO_PORTM_BASE
58 #define M2_INL_PIN_A GPIO_PIN_5
59 #define M2_INL_PERIPH_B SYSCTL_PERIPH_GPIOM
60 #define M2_INL_PORT_B GPIO_PORTM_BASE
61 #define M2_INL_PIN_B GPIO_PIN_6
62 #define M2_INL_PERIPH_C SYSCTL_PERIPH_GPIOM
63 #define M2_INL_PORT_C GPIO_PORTM_BASE
64 #define M2_INL_PIN_C GPIO_PIN_7
65 
66 // MOTOR 2 COMMUTATION DATA
67 #define M2_HALLSTATE_0 (M2H_PIN_A | M2H_PIN_B)
68 #define M2_HALLSTATE_1 M2H_PIN_A
69 #define M2_HALLSTATE_2 (M2H_PIN_A | M2H_PIN_C)
70 #define M2_HALLSTATE_3 M2H_PIN_C
71 #define M2_HALLSTATE_4 (M2H_PIN_B | M2H_PIN_C)
72 #define M2_HALLSTATE_5 M2H_PIN_B
73 
74 
84 extern void M1HIntHandler(void);
85 
86 
96 extern void M2HIntHandler(void);
97 
109 void motor1Commutate(int State, int control);
110 
121 void motor2Commutate(int State, int control);
122 
123 
133 extern void motor1PWM(int pwm1, int pwm2, int pwm3);
134 
144 extern void motor2PWM(int pwm1, int pwm2, int pwm3);
145 
146 
161 extern void motor1ControlPWM(int control);
162 
178 extern void motor2ControlPWM(int control);
179 
180 
181 
190 extern void motorInit(void);
191 
192 
204 void M1_INL_WRITE(int a, int b, int c);
205 
217 void M2_INL_WRITE(int a, int b, int c);
218 
219 
226 int getmotor1PWM(void);
227 
228 
235 int getmotor2PWM(void);
236 
246 int32_t getmotor1HALLS(void);
247 
248 
258 int32_t getmotor2HALLS(void);
259 
260 
269 extern void MotorSPIinit(void);
270 
271 
272 
278 extern void motorDriverInit(void);
279 
280 
290 extern void pwmInit(void);
291 
292 #endif /* MOTOR_H_ */
void pwmInit(void)
Initializes PWM.
void motorDriverInit(void)
Initializes the SPI commands to set the motor's configuration for 1x PWM mode.
Definition: Motor.c:385
int getmotor1PWM(void)
Returns the current PWM of motor 1.
Definition: Motor.c:323
void motor2Commutate(int State, int control)
Commutate motor 2 with a given pwm.
Definition: Motor.c:277
void MotorSPIinit(void)
Initializes the SPI channels for the motor drivers.
Definition: Motor.c:346
void motor1PWM(int pwm1, int pwm2, int pwm3)
Sets the PWM value to motor 1.
Definition: Motor.c:309
void motor2ControlPWM(int control)
Sets the PWM value and direction to motor 2.
Definition: Motor.c:180
void motor1Commutate(int State, int control)
Commutate motor 1 with a given pwm.
Definition: Motor.c:245
int getmotor2PWM(void)
Returns the current PWM of motor 2.
Definition: Motor.c:328
int32_t getmotor2HALLS(void)
Returns the current state of the halls for motor 2.
Definition: Motor.c:338
int32_t getmotor1HALLS(void)
Returns the current state of the halls for motor 1.
Definition: Motor.c:333
void motorInit(void)
Initializes the GPIO pins for the motor.
Definition: Motor.c:21
void M2_INL_WRITE(int a, int b, int c)
Commutation table for motor 2.
Definition: Motor.c:453
void M1_INL_WRITE(int a, int b, int c)
Commutation table for motor 1.
Definition: Motor.c:423
void motor1ControlPWM(int control)
Sets the PWM value and direction to motor 1.
Definition: Motor.c:116
void motor2PWM(int pwm1, int pwm2, int pwm3)
Sets the PWM value to motor 2.
Definition: Motor.c:316
void M2HIntHandler(void)
Hall sensor interrupt for motor 2.
Definition: Motor.c:107
void M1HIntHandler(void)
Hall sensor interrupt for motor 1.
Definition: Motor.c:98