-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotor.c
91 lines (87 loc) · 1.91 KB
/
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
#include "dev_mem_map.h"
#define ABROAD
#include "driver.h"
#undef ABROAD
//------------------------------------------------------------------------
/* Pins 7 and 8 should only be manipulated in motor_run and motor_stop
Sets direction of the motor
*/
void motor_run(int direction)
{
if (control_dir == direction)
return;
if (1 == direction)
{
control_dir = 1;
PIN_CLR(7);
PIN_SET(8);
}
else if (-1 == direction)
{
control_dir = -1;
PIN_CLR(8);
PIN_SET(7);
}
}
//------------------------------------------------------------------------
void motor_stop()
{
PIN_SET(7);
PIN_SET(8);
control_dir = 0;
}
void motor_stop1()
{
PIN_CLR(7);
PIN_CLR(8);
control_dir = 0;
}
//------------------------------------------------------------------------
void move_to_limit(int direction)
{
unsigned start_tick;
start_tick = last_tick;
set_motor_voltage(75);
motor_run(direction);
while(start_tick == last_tick)
;
while(((NOW_TIME() - last_tick) < STALL_TIMEOUT) || ((NOW_TIME() - last_tick) < STALL_TIMEOUT))
;
motor_stop();
hexstring(x);
//hexstring(t[t_head]);
//hexstring(NOW_TIME());
}
//------------------------------------------------------------------------
void move(int direction, int ticks)
{
int i,j;
//puts("move\n\r");
i = x + direction*ticks;
j = 0;
motor_run(direction);
while((direction*(x-i))<0) {
//TODO: Figure out why the stall check fails closed like a valve
/*if(!(((NOW_TIME() - t[t_head]) < STALL_TIMEOUT) || ((NOW_TIME() - t[t_head]) < STALL_TIMEOUT)))
{
puts("stalled\n\r");
break;
}
*/
j++;
usleep(1);
//if (j>ticks) break;
}
motor_stop();
//puts("done\n\r");
//hexstring(i);
//hexstring(x);
}
//------------------------------------------------------------------------
void move_to(int position)
{
if (x>position)
move(-1, x-position);
else
move(1, position-x);
}