Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help!!! PIC 16F690 AND L297 stepper motor control C Code

Status
Not open for further replies.

Eng_MC

Member level 1
Joined
Nov 16, 2010
Messages
39
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,865
hi there i am working on a project to control two stepper motors from a pic16f690 using L297 stepper motor controllers adn uln2075b quad darlington transitor ic. i having difficulty with the c code to control the motors from the pic can anyone help me with C code to control the motors??? PLEase:-D:-D
 

Post your code, and the problems that you are facing with the code and hardware.

Guys here will be more than helpful.
 


Code C - [expand]
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
//////**********Chamwasu Musa Gali******Stepper Motor Control Codes*******Final Year Project Codes/////////////////
#include <htc.h>
#include <pic.h>
#define stepcnt 100 //max number of steps
#define _XTAL_FREQ 4000000
 
void Run_Motor1_cw(void);
void Run_Motor2_cw(void);
void Accel_Motor1_cw(void);
void Deccel_Motor1_cw(void);
void Accel_Motor2_cw(void);
void Deccel_Motor2_cw(void);
void Run_Motor1_ccw(void);
void Run_Motor2_ccw(void);
void Accel_Motor1_ccw(void);
void Deccel_Motor1_ccw(void);
void Accel_Motor2_ccw(void);
void Deccel_Motor2_ccw(void);
 
 
void main(void)
{
TRISA = 0xFF; //SET PORT A AS INPUT
PORTA = 0; //INITIALISE PORTA AS 0
 
TRISB = 0xFF; //SET PORT B AS INPUT PORT
PORTB = 0; //INITIALISE PORT B AS 0
 
TRISC = 0x00; //SET PORT C AS AN OUTPUT PORT
 
Run_Motor1_cw();
 
 
}
 
void Run_Motor1_cw(void) //function to run motor 1 at constant speed
{
    int b;
    PORTC = 0x32; //reset motor phases to initial position 0101 and light up led to indicate motor 1 is active and wait for the step signal
    __delay_us(150);
    
    for(b=0;b<=stepcnt;b++) //loop to step 100 times running motor1
    {
        PORTC = 0xB2;
        __delay_us(150);
        PORTC= 0xB3;
        __delay_us(50);
    }
}
 
void Run_Motor2_cw(void) //function to run motor 2 at constant speed
{
    int d;
    PORTC = 0x52; //turn on led to indicate motor 2 is about to start running and wait for the step signal
    __delay_us(15);
 
    for(d=0;d<=stepcnt;d++) //loop to run motor 2 for 100 steps
    {
        PORTC = 0xD2;
        __delay_us(15);
        PORTC = 0xD6;
        __delay_us(5);
    }
}
 
void Accel_Motor1_cw(void) //function to accelerate motor 1
{
    int x;
    PORTC= 0xB2; //delay tables to accelerate motor 1
    __delay_us(25);
    PORTC = 0xB3;
    __delay_us(5);
    PORTC = 0xB2;
    __delay_us(20);
    PORTC = 0xB3;
    __delay_us(5);
    PORTC = 0xB2;
    __delay_us(15);
    PORTC = 0xB3;
    __delay_us(5);
    PORTC = 0xB2;
    __delay_us(10);
    PORTC = 0xB3;
    __delay_us(5);
    PORTC = 0xB2;
    __delay_us(5);
    PORTC = 0xB3;
 
    for(x=0;x<=stepcnt;x++) //loop to maintain final speeed after delay table implementation for 100 steps
    {
        PORTC = 0xB2;
        __delay_us(5);
        PORTC = 0xB3;
        __delay_us(5);
    }
}
 
void Deccel_Motor1_cw(void) //function to decelerate motor 1
{
    int y;
    PORTC = 0xB2; //delay tables to decelerate motor 1
    __delay_us(5);
    PORTC = 0xB3;
    __delay_us(5);
    PORTC = 0xB2;
    __delay_us(10);
    PORTC = 0xB3;
    __delay_us(5);
    PORTC= 0xB2;
    __delay_us(15);
    PORTC = 0xB3;
    __delay_us(5);
    PORTC= 0xB2;
    __delay_us(20);
    PORTC= 0xB3;
    __delay_us(5);
    PORTC= 0xB2;
    __delay_us(25);
    PORTC = 0xB3;
 
    for(y=0;y<=stepcnt;y++) //loop to maintain final speed after deceleration table implentation
    {
        PORTC = 0xB2;
        __delay_us(25);
        PORTC = 0xB3;
        __delay_us(25);
    }
}
 
void Accel_Motor2_cw(void) //function to accelerate motor 2
{
    int m;
    PORTC= 0xD2; //delay tables to accelerate motor two
    __delay_us(25);
    PORTC = 0xD6;
    __delay_us(5);
    PORTC = 0xD2;
    __delay_us(20);
    PORTC = 0xD6;
    __delay_us(5);
    PORTC = 0xD2;
    __delay_us(15);
    PORTC = 0xD6;
    __delay_us(5);
    PORTC = 0xD2;
    __delay_us(10);
    PORTC = 0xD6;
    __delay_us(5);
    PORTC = 0xD2;
 
    for(m=0;m<=stepcnt;m++) //loop to maintain final speeed after delay table implementation for 100 steps
    {
        PORTC = 0xD2;
        __delay_us(5);
        PORTC = 0xD6;
        __delay_us(5);
    }   
}
 
void Deccel_Motor2_cw(void)
{
    int n;
    PORTC = 0xD2; //delay tables to decelerate motor 2
    __delay_us(5);
    PORTC = 0xD6;
    __delay_us(5);
    PORTC = 0xD2;
    __delay_us(10);
    PORTC = 0xD6;
    __delay_us(5);
    PORTC= 0xD2;
    __delay_us(15);
    PORTC = 0xD6;
    __delay_us(5);
    PORTC= 0xD2;
    __delay_us(20);
    PORTC= 0xD6;
    __delay_us(5);
    PORTC= 0xD2;
    __delay_us(25);
    PORTC = 0xD6;
 
    for(n=0;n<=stepcnt;n++) //loop to maintain final speed after deceleration table implentation
    {
        PORTC = 0xD2;
        __delay_us(25);
        PORTC = 0xD6;
        __delay_us(25);
    }
}
 
void Run_Motor1_ccw(void)       //function to run motor 1 counter clockwise
{
    int n;
    PORTC = 0x30;           //initialise motor 1 and turn on led for motor 1
    __delay_us(150);
    for(n=0;n<=stepcnt;n++) // loop to run motor one at contstan speed counter clockwise
    {
        PORTC = 0xB0;
        __delay_us(150);
        PORTC = 0xB1;
        __delay_us(50);
    }
}
 
void Run_Motor2_ccw(void)
{
    int n;
    PORTC = 0x50;
    __delay_us(150);
    for(n=0;n<=stepcnt;n++)
    {
        PORTC = 0xD0;
        __delay_us(150);
        PORTC = 0xD4;
        __delay_us(50);
    }
}
 
void Accel_Motor1_ccw(void)
{
    int x;
    PORTC= 0xB0; //delay tables to accelerate motor 1
    __delay_us(25);
    PORTC = 0xB1;
    __delay_us(5);
    PORTC = 0xB0;
    __delay_us(20);
    PORTC = 0xB1;
    __delay_us(5);
    PORTC = 0xB0;
    __delay_us(15);
    PORTC = 0xB1;
    __delay_us(5);
    PORTC = 0xB0;
    __delay_us(10);
    PORTC = 0xB1;
    __delay_us(5);
    PORTC = 0xB0;
    __delay_us(5);
    PORTC = 0xB1;
 
    for(x=0;x<=stepcnt;x++) //loop to maintain final speeed after delay table implementation for 100 steps
    {
        PORTC = 0xB0;
        __delay_us(5);
        PORTC = 0xB1;
        __delay_us(5);
    } 
}
 
void Deccel_Motor2__ccw(void)
{
    int n;
    PORTC = 0xD0; //delay tables to decelerate motor 2
    __delay_us(5);
    PORTC = 0xD4;
    __delay_us(5);
    PORTC = 0xD0;
    __delay_us(10);
    PORTC = 0xD4;
    __delay_us(5);
    PORTC= 0xD0;
    __delay_us(15);
    PORTC = 0xD4;
    __delay_us(5);
    PORTC= 0xD0;
    __delay_us(20);
    PORTC= 0xD4;
    __delay_us(5);
    PORTC= 0xD0;
    __delay_us(25);
    PORTC = 0xD4;
 
    for(n=0;n<=stepcnt;n++) //loop to maintain final speed after deceleration table implentation
    {
        PORTC = 0xD0;
        __delay_us(25);
        PORTC = 0xD4;
        __delay_us(25);
    }


}

---------- Post added at 00:21 ---------- Previous post was at 00:17 ----------

HI guys this is the code to run two motors from one pic 16f690 using L297 stepper motor controllers and an ULN2075B quad darlington arrays to step the motors i have been running the code but the motors are not responding i am thinking wether the delays i have used are too small or what is the problem i don't know. i am using unipolar steeper motor with 28mA per phase and 7.5W power please can somenone give me some help here cheers
 
Last edited by a moderator:

how the code for pic16f677a with L298 to control the stepper motor
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top