-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
143 lines (136 loc) · 2.95 KB
/
main.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*!
* \file main.c
* \author Max Gröning (mail@max-g.net)
* \date April, 2013
* \brief Demonstration of the Stepper Booster Library
*/
#include <msp430.h>
#include "stepper/stepper.h"
int main(void) {
/* Initialize */
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR = 0x0; // Configure all I/Os as inputs
P2DIR = 0x0; //
P1OUT = 0x0;
P2OUT = 0x0;
stepper_init(); // Initialize stepper booster
stepper_full_step();
// stepper_half_step();
// stepper_quarter_step();
// stepper_8_microstep();
// stepper_16_microstep();
// stepper_32_microstep();
stepper_no_sleep();
stepper_enable();
unsigned i = 0;
while(1) {
/* Different step sizes */
stepper_full_step();
for (i = 1000; i > 0; --i) {
stepper_step();
__delay_cycles(10000);
}
stepper_half_step();
for (i = 1000; i > 0; --i) {
stepper_step();
__delay_cycles(10000);
}
stepper_quarter_step();
for (i = 1000; i > 0; --i) {
stepper_step();
__delay_cycles(10000);
}
stepper_8_microstep();
for (i = 1000; i > 0; --i) {
stepper_step();
__delay_cycles(10000);
}
stepper_16_microstep();
for (i = 1000; i > 0; --i) {
stepper_step();
__delay_cycles(10000);
}
stepper_32_microstep();
for (i = 1000; i > 0; --i) {
stepper_step();
__delay_cycles(10000);
}
/* Different speeds and directions */
stepper_full_step();
for (i = 500; i > 0; --i) {
stepper_step();
__delay_cycles(5000);
}
stepper_dir_x();
for (i = 500; i > 0; --i) {
stepper_step();
__delay_cycles(4000);
}
stepper_dir_x();
for (i = 500; i > 0; --i) {
stepper_step();
__delay_cycles(3000);
}
stepper_dir_x();
for (i = 500; i > 0; --i) {
stepper_step();
__delay_cycles(2000);
}
/* Turning with delays */
stepper_full_step();
stepper_dir_0();
__delay_cycles(1000000);
for (i = 100; i > 0; --i) {
stepper_step();
__delay_cycles(2500);
}
__delay_cycles(1000000);
stepper_dir_1();
for (i = 25; i > 0; --i) {
stepper_step();
__delay_cycles(2500);
}
__delay_cycles(1000000);
stepper_dir_0();
for (i = 50; i > 0; --i) {
stepper_step();
__delay_cycles(2500);
}
__delay_cycles(1000000);
stepper_dir_1();
for (i = 25; i > 0; --i) {
stepper_step();
__delay_cycles(2500);
}
__delay_cycles(1000000);
/* Turning without delays */
stepper_full_step();
stepper_dir_0();
for (i = 100; i > 0; --i) {
stepper_step();
__delay_cycles(2500);
}
stepper_dir_1();
for (i = 25; i > 0; --i) {
stepper_step();
__delay_cycles(2500);
}
stepper_dir_0();
for (i = 50; i > 0; --i) {
stepper_step();
__delay_cycles(2500);
}
stepper_dir_1();
for (i = 25; i > 0; --i) {
stepper_step();
__delay_cycles(2500);
}
}
}
#pragma vector = ADC10_VECTOR, COMPARATORA_VECTOR, NMI_VECTOR, \
PORT1_VECTOR, PORT2_VECTOR, TIMER0_A0_VECTOR, TIMER0_A1_VECTOR, \
USI_VECTOR, WDT_VECTOR
__interrupt void ISR_trap(void) {
// Causing an access violation which will result in a PUC reset
WDTCTL = 0;
}