Tuesday, April 28, 2020

Controlling the uni-polar stepper motor with ATMega32

Uni-polar stepper motor is kind of brush-less DC motor that convert electrical pulse to mechanical movement. Comparing to bipolar stepper motor, it's easy to control but with lower torque. Stepper motor give a higher precision stepping than simple brushed DC motor. It's commonly use in photocopier machine, numerical control etc.

Different size of Uni-polar Stepper Motor 

It is made of two distinct coils. Each coil divided into two pieces by a common centered tap.


Unipolar Stepper Motor internal diagram.
Two distinct coil make four coil, A1, A2, B1, B2.
 We can rotate by two method, half stepping and full stepping.

Half Stepping

Half stepping is very easy to implement. Since the motor made of four coil, we just active each coil one by one. For Example, we activate A1 Coil for a given millisecond and then turn A1 off. After that we do this to the next A2 coil.

This stepping method could be easily implemented using a synchronous digital circuit.

The timing diagram below used for stepping counter clock wise:
Timing Diagram For Counter Clock Wise Half Stepping

The time diagram below used for stepping clock wise:

Timing Diagram For Clock Wise Stepping

The example below I use a switch to set the direction of half stepping.

ATMega32 controlling the direction of unipolar stepper motor

Source Code of this half stepping example could be download here:

#include <avr/io.h>
#define F_CPU 16000000UL
#include "util/delay.h"
#define stepTime 50

 void stepBackward(){
 PORTC=0x01;
 _delay_ms(stepTime);
 PORTC=0x02;
 _delay_ms(stepTime);
 PORTC=0x04;
 _delay_ms(stepTime);
 PORTC=0x08;
 _delay_ms(stepTime);
 }
 void stepForward(){
 PORTC=0x08;
 _delay_ms(stepTime);
 PORTC=0x04;
 _delay_ms(stepTime);
 PORTC=0x02;
 _delay_ms(stepTime);
 PORTC=0x01;
 _delay_ms(stepTime);
 }
 int main(void)
 {
     DDRC=0x0F; //PC0.3 ARE OUTPUT
 PORTC=0x00; //Clear PortC
 DDRD=0x7F;  //PD7 IS INPUT
 PORTD=0x80; //PULLUP PD7 HIGH
     while (1) 
     {
 if(PIND&0x80) stepBackward();
 else stepForward();
     }
 }

Full Stepping

Full stepping give the motor to maximize its output torque. For this stepping, we must active two coil at the same time to make one step.

The timing diagram below gives the full step clock wise rotation:

Full step clock wise rotation timing diagram

The timing diagram below gives the full step counter clock wise rotation:

Full step counter clock wise rotation timing diagram

I repeat the above example, but with full stepping. The schematic remain the same, but I modify the source code for full stepping.

Source Code for full stepping could be downloaded here:

#include <avr/io.h> 

#define F_CPU 16000000UL 
#include "util/delay.h" 
#define stepTime 50 
 void stepForward(){ 
 PORTC=0b1001; 
 _delay_ms(stepTime); 
 PORTC=0x0011; 
 _delay_ms(stepTime); 
 PORTC=0b0110; 
 _delay_ms(stepTime); 
 PORTC=0b1100; 
 _delay_ms(stepTime); 
 } 
 void stepBackward(){ 
 PORTC=0b1100; 
 _delay_ms(stepTime); 
 PORTC=0b0110; 
 _delay_ms(stepTime); 
 PORTC=0b0011; 
 _delay_ms(stepTime); 
 PORTC=0b1001; 
 _delay_ms(stepTime); 
 } 
 int main(void) 
 { 
 DDRC=0x0F; //PC0.3 ARE OUTPUT 
 PORTC=0x00; //Clear PortC 
 DDRD=0x7F;  //PD7 IS INPUT 
 PORTD=0x80; //PULLUP PD7 HIGH 
 while (1) 
 { 
 if(PIND&0x80) stepBackward(); 
 else stepForward(); 
 } 
 } 
Back to main tutorial page ATMega32 tutorials in C with Atmel Studio 7.

No comments:

Post a Comment

Search This Blog

Labels

25AA010A (1) 8051 (7) 93AA46B (1) ADC (30) Analog Comparator (1) Arduino (15) ARM (6) AT89C52 (7) ATMega32 (56) AVR (57) CCS PICC (28) DAC (1) DHT11 (2) Display (105) Distance Sensor (3) DS18B20 (3) dsPIC (2) dsPIC30F1010 (2) EEPROM (5) Environment Sensor (4) esp8266 (1) I2C (29) Input/Output (67) Interrupt (19) Keil (5) Keypad (10) LCD (47) Master/Slave (1) MAX7221 (1) MCP23017 (5) MCP23S17 (4) Meter (3) MikroC (2) Motor (15) MPLABX (71) Nokia 5110 LCD (3) OLED (2) One-Wire (6) Oscillator (8) PCB (6) PCD8544 (3) PCF8574 (5) PIC (107) PIC12F (2) PIC16F628A (2) PIC16F630 (1) PIC16F716 (3) PIC16F818 (10) PIC16F818/819 (2) PIC16F84A (15) PIC16F876A (1) PIC16F877A (9) PIC16F88 (1) PIC16F887 (60) PIC18 (19) PIC18F1220 (4) PIC18F2550 (3) PIC18F4550 (12) PWM (11) RTC (8) Sensor (10) SH1106 (1) Shift Register (11) Shift Registers (3) SPI (24) STM32 (6) STM32 Blue Pill (6) STM32CubeIDE (6) STM32F103C8T6 (6) SysTick (3) temperature sensor (11) Thermometer (21) Timer/Counter (31) TM1637 (2) UART (7) Ultrasonic (4) Voltmeter (7) WDT (1) XC16 (2) XC8 (94)