Stepper Motor

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
Frank G.
Posts: 7
Joined: Thu Jan 05, 2006 2:12 am
Contact:

Stepper Motor

Post by Frank G. »

Hi! John

My Led outputs are as follows:

Port B
Bits 3 2 1 0
start 0 0 0

1 0
0
1
------------- 1010

1
1
0
0
------------- 0011

1
0
1
0
------------ 0101

0
0
1
1
------------ 1100

johnwilliamdobson
Posts: 1
Joined: Mon Feb 06, 2006 3:50 pm
Contact:

stepper

Post by johnwilliamdobson »

You can't do that. You need to write all the bits simultaneously. If you write one bit at a time then it will move in an unpredictabel manner.

regards

John

Frank G.
Posts: 7
Joined: Thu Jan 05, 2006 2:12 am
Contact:

Post by Frank G. »

Hi! John


This what I have.



void main()
{
Setup_Hardware();
PORTB=0;
while(1)
{
/* Check SW_RB0 */
if(input_pin_port_a(0))
{
/* step 1 - 0A */
output_low_port_b(0);
output_high_port_b(1);
delay_ms(100000);

output_low_port_b(2);
output_high_port_b(3);
delay_ms(10000000);

/* step 2 - 03 */
output_high_port_b(0);
output_high_port_b(1);
delay_ms(100000);

output_low_port_b(2);
output_low_port_b(3);
delay_ms(10000000);

/* step 3 - 05 */
output_high_port_b(0);
output_low_port_b(1);
delay_ms(10000000);

output_high_port_b(2);
output_low_port_b(3);
delay_ms(10000000);

/* step 4 - 0C */
output_low_port_b(0);
output_low_port_b(1);
delay_ms(100000);

output_high_port_b(2);
output_high_port_b(3);
delay_ms(10000000);



}
}
}

User avatar
Steve
Matrix Staff
Posts: 3418
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Post by Steve »

Hi Frank,

As John says, the whole 4-bit sequence needs to change at the same time to ensure the motor turns appropriately.

I also note that your delays seem excessively large. Here's what I would suggest:

Code: Select all

char mydelay = 10;  //the delay here will represent speed

Setup_Hardware(); 

while(1) 
{ 

  //step 1
  portb = (portb & 0xF0) | 0x0A;
  delay_ms(mydelay);

  //step 2
  portb = (portb & 0xF0) | 0x03;
  delay_ms(mydelay);

  //step 3
  portb = (portb & 0xF0) | 0x05;
  delay_ms(mydelay);

  //step 4
  portb = (portb & 0xF0) | 0x0C;
  delay_ms(mydelay);
}

Frank G.
Posts: 7
Joined: Thu Jan 05, 2006 2:12 am
Contact:

Post by Frank G. »

Hi! John and Steve
:lol:

Sorry I am so late responding but I really appreciate your help. I tried it and it works but there is still little bugs that I need to work on to get it to work in single steps. I am working on it.

Thanks,

Frank G.

Post Reply