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 with stepper motor interfacing with pic16f877a

Status
Not open for further replies.

RishabhG

Member level 3
Joined
Aug 10, 2012
Messages
65
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,815
Hi I am trying to interface a stepper motor using pic16f877a. I am using HiTech C Compiler

Here is the code


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
#include<htc.h>
 
__CONFIG(0x2F0A);
 
 
 
 
void delay(unsigned int time)
{
    unsigned char pause;
    while(time>0)
    {
        pause=255;
        while(pause--);
        time--;
    }
}
 
void main()
{
    TRISC=0x00;
 
    while(1)
    {
        
            
            
            PORTC=0x09;
            delay(500);
            PORTC=0X08; 
               delay(500);
    
            PORTC=0X0C;
            delay(500);
            PORTC=0X04; 
            delay(500);
 
            PORTC=0X06;
            delay(500);
            PORTC=0X02; 
            delay(500);
    
            PORTC=0X03;
            delay(500);
            PORTC=0X01;
            delay(500);
        
     }
}



The motor does not rotate continuously;it rotates a few steps forward and then backward.
I am using ULN2803 as the driver. Can anyone please give me the circuit diagram of this IC with PIC?
 

The link you have posted is for MikroC compiler(not for HiTech C). Also I want to know the mistakes in my code.
 
Last edited:

The motor does not rotate continuously;it rotates a few steps forward and then backward.

Try to see how many steps the motor take to one direction before go to the other direction (make delays bigger in your code). Is it lets say 3 steps CW, 1 CCW. Maybe 1 of the windings is not connected correctly (you are using a unipolar motor, right?).

See these too:

https://www.piccircuit.com/shop/doc/Tut8_StepperMotorDemoSch.pdf
**broken link removed**
 

I have seen a lot of tutorials with ULN2008 but I am trying to interface using ULN2803 . Yes its a unipolar motor.
 

You can use that mikroC code. All you have to do is replace the delay_ms() functions with your delay function. delay will decide the speed of rotation
 

it doesn't matter whether u use ULN2008 or ULN2803

try this sequence. before that check ur stepper motor is healthy and coils are in good condition by giving the voltage to each coil one by one sequentially and it has to rotate in same direction. if any one of the coil energizing reflects the change in direction change the coil sequence. mostly it'll fix ur prob. otherwise try this code.

Code:
while(1)
  {

           delay(1000);  // this delay will help u to know the starting pulse 
           delay(1000);  // this will help u for debugg ur prob (debugging purpose only) 
           delay(1000);  // after this delay u start track and find which coil going reverse then change the sequence

            PORTC=0X08; 
            delay(1000);
    
            PORTC=0X04; 
            delay(1000);
 
            PORTC=0X02; 
            delay(1000);
    
            PORTC=0X01;
            delay(1000);
        
}
 
Last edited:

I am trying to run the following modified code. The strange thing is that the code ran the motor 2-3 times in 40-50 attempts. The same code on burning and running again does not run the motor. Also I wrote the code to turn the motor 90 degrees but even when the motor ran, it ran continuously;not 90 degrees.

Code:
#include <htc.h>
#include"ms_delay.h"

__CONFIG(0x2F0A);


void main()
{
   		
    TRISC=0x00;	

	for(int i=0; i<50 ; i++)
	{
		PORTC=0x01;		
    	        msDelay();
    	        PORTC =0x03;
    	        msDelay();
		PORTC=0x02;
   		msDelay();
    	        PORTC=0x06;
    	        msDelay();
	        PORTC=0x04;
    	        msDelay();
    	        PORTC=0x0C;
    	        msDelay();	
    	        PORTC=0x08;
  	        msDelay();
	        PORTC=0x09;
    	        msDelay();
		
	}
 
}

Please help me out.

- - - Updated - - -

void delay_ms();


void delay_ms()
{
long int i=1000;
while(i)
i--;
}
 

That is what I want. I don't want it run continuously. Anyhow I found out that I had written 1<50 instead of i<50,which is why it was running continuously. Now the problem is that it doesn't run at all;it just vibrates. I have checked all the connections.

On what basis is the delay between two sequence values decided? I know greater the delay, slower will be the motor, but is there some range or criteria to calculate delay?
 

Which 4 ways are you talking about?

I am using half stepping.

- - - Updated - - -

Which 4 ways are you talking about?

I am using half stepping.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top