-
Notifications
You must be signed in to change notification settings - Fork 5
/
my_motor.c
113 lines (94 loc) · 2.16 KB
/
my_motor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* my_motor.c
*
* Created on: May 29, 2019
* Author: jms29
*/
#include "DSP28x_Project.h"
#define IN1 GPIO32
#define IN2 GPIO33
#define TRUE 1
#define FALSE 0
void InitMotor(void)
{
EALLOW;
// init gpio, and stop state
GpioCtrlRegs.GPBPUD.bit.IN1 = 0;
GpioDataRegs.GPBCLEAR.bit.IN1 = 1;
GpioCtrlRegs.GPBMUX1.bit.IN1 = 0;
GpioCtrlRegs.GPBDIR.bit.IN1 = 1;
GpioCtrlRegs.GPBPUD.bit.IN2 = 0;
GpioDataRegs.GPBCLEAR.bit.IN2 = 1;
GpioCtrlRegs.GPBMUX1.bit.IN2 = 0;
GpioCtrlRegs.GPBDIR.bit.IN2 = 1;
EDIS;
}
void MotorForward(void)
{
GpioDataRegs.GPBCLEAR.bit.IN1 = 1;
GpioDataRegs.GPBSET.bit.IN2 = 1;
}
void MotorStart(void)
{
MotorForward();
}
void MotorStop(void)
{
GpioDataRegs.GPBCLEAR.bit.IN1 = 1;
GpioDataRegs.GPBCLEAR.bit.IN2 = 1;
}
void MotorReverse(void)
{
GpioDataRegs.GPBSET.bit.IN1 = 1;
GpioDataRegs.GPBCLEAR.bit.IN2 = 1;
}
int IsMotorRunning(void)
{
if((GpioDataRegs.GPBDAT.bit.IN1 == 1 && GpioDataRegs.GPBDAT.bit.IN2 == 0)
|| (GpioDataRegs.GPBDAT.bit.IN1 == 0 && GpioDataRegs.GPBDAT.bit.IN2 == 1))
{
return TRUE;
}
if((GpioDataRegs.GPBDAT.bit.IN1 == 0 && GpioDataRegs.GPBDAT.bit.IN2 == 0)
|| (GpioDataRegs.GPBDAT.bit.IN1 == 1 && GpioDataRegs.GPBDAT.bit.IN2 == 1))
{
return FALSE;
}
return FALSE;
}
int IsMotorForward(void)
{
if(GpioDataRegs.GPBDAT.bit.IN1 == 0 && GpioDataRegs.GPBDAT.bit.IN2 == 1){
return TRUE;
}else{
return FALSE;
}
}
int IsMotorReverse(void)
{
if(GpioDataRegs.GPBDAT.bit.IN1 == 1 && GpioDataRegs.GPBDAT.bit.IN2 == 0){
return TRUE;
}else{
return FALSE;
}
}
void EnableMotorStart(void)
{
// enable xint3
PieCtrlRegs.PIEIER12.bit.INTx1 = 1;
}
void DisableMotorStart(void)
{
// disable xint3
PieCtrlRegs.PIEIER12.bit.INTx1 = 0;
}
void EnablePwmChange(void)
{
PieCtrlRegs.PIEIER12.bit.INTx2 = 1; // Enable XINT3
PieCtrlRegs.PIEIER12.bit.INTx3 = 1; // XINT4
}
void DisablePwmChange(void)
{
PieCtrlRegs.PIEIER12.bit.INTx2 = 0; // Enable XINT3
PieCtrlRegs.PIEIER12.bit.INTx3 = 0; // XINT4
}