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
Stepper Motor
-
- Posts: 1
- Joined: Mon Feb 06, 2006 3:50 pm
- Contact:
stepper
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
regards
John
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);
}
}
}
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);
}
}
}
- Steve
- Matrix Staff
- Posts: 3418
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
- Contact:
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:
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);
}