![]() |
Bipolar stepper motor (Model 42BYGH34-0400A) with 1.8 degree step angle. |
It is made of two distinct coils, but each coil is separated a much as possible around the rotor, to make stepping angle much smaller.
![]() |
Diagram of common bipolar stepper motor. This motor come from the Chinese company as shown in the picture above. |
To make it step look at the time diagram below:
![]() |
Timing Diagram for stepping clock wise and counter clock wise |
Difference bipolar stepper motor has difference stepping angle. We can check its spec before use.
The example below just like the previous example. I use a switch connects to PD7 to control the stepping direction of the bipolar stepper motor.
![]() |
A bipolar stepper motor connects to PORTC. PD7 is used for controlling the direction. |
Source code:
#include <avr/io.h>
#define F_CPU 16000000UL
#include "util/delay.h"
#define stepTime 100
//clock wise stepping
void stepCW(){
PORTC=0b00001100;
_delay_ms(stepTime);
PORTC=0b00000110;
_delay_ms(stepTime);
PORTC=0b00000011;
_delay_ms(stepTime);
PORTC=0b00001001;
_delay_ms(stepTime);
}
//counter clock wise stepping
void stepCCW(){
PORTC=0b00001001;
_delay_ms(stepTime);
PORTC=0b00000011;
_delay_ms(stepTime);
PORTC=0b00000110;
_delay_ms(stepTime);
PORTC=0b00001100;
_delay_ms(stepTime);
}
int main(void)
{
DDRC=0xFF;
DDRD=0x7F;
PORTD=0x80;
while (1)
{
if((PIND&0xFE)==0) stepCW();
else stepCCW();
}
}