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.

Step Motor Driving Problem

Status
Not open for further replies.

rezaf

Advanced Member level 4
Joined
Apr 11, 2009
Messages
106
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Location
Montagram
Activity points
2,147
Hi friends,
I have a stepper motor driving project but have problem with steps. please see my circuit and code and say to me if you see problems.
Very Thanks. (source code written with mikroc)

char uart_rd[5];
char uart_rd2[5];
int i;
char FullStepForward [4]={0x01, 0x02, 0x04, 0x08};
char FullStepBackward[4]={0x09, 0x0C, 0x06, 0x03};


void MotorCW()
{

if(i<4){
PORTC = FullStepForward ;
delay_ms(100);
}
else if(i>4) i=0;
i++;
}

void MotorCCW()
{
if(i<4){
PORTC=FullStepBackward;
delay_ms(100);
}
else if(i>4) i=0;
i--;
}

void main() {
ADCON1 = 0b00000111;
CCP1CON = 0x00;
TRISB1_bit = 0x00; //output
TRISB2_bit = 0x00;
TRISB3_bit = 0x00;
TRISB4_bit = 0x00;
TRISB5_bit = 0x00;
PORTB = 0;
TRISC0_bit = 0x00; //output
TRISC1_bit = 0x00;
TRISC2_bit = 0x00;
TRISC3_bit = 0x00;
PORTC = 0;
i=0;
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize

while (1) {

if (UART1_Data_Ready() == 1) { // if data is received
uart_rd[1] = UART1_Read(); // reads text until command is found
}


switch(uart_rd[1]){
case 0x50: //Motor-CW(P)
MotorCW();
break;
case 0x48: //Motor-CCW(H)
MotorCCW();
break;
}
uart_rd[1] = 0;
}
}
 

Attachments

  • 1.jpg
    1.jpg
    81.2 KB · Views: 66

Firstly, UART_rd[1] = 0 would not allow the control to go through the switch case. So it would go to the switch case only once, move one step and wait for the input to arrive.

secondly, (very minor) your motor wont do anything for i==4.
 

Thanks, I corrected the problems that you said but don't know why the motor rotate 2.7 degree in CW and 2.7 degree in CCW and with more commands return, (I want the motor rotate 1.8 degree with every command until a 360 degree revolution completes, can you help me?
 

if(i<4){
PORTC = FullStepForward ;
delay_ms(100);
}
else if(i>4) i=0;
i++;

In this case, i=0 is never reached. As soon as i=5, i=0 and then i++ makes it i=1. correct this and I think it would all work fine.

If you still have problems, post your new modified code.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top