rezaf
Advanced Member level 4
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;
}
}
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;
}
}