Monday, January 6, 2014

Stepper Motor using a Pinguino Board

A stepper motor is an electromechanical device which converts electrical pulses into discrete mechanical movements. The shaft or spindle of a stepper motor rotates in discrete step increments when electrical command pulses are applied to it in the proper sequence. The motors rotation has several direct relationships to these applied input pulses. The sequence of the applied pulse is directly related to the direction of motor shafts rotation is directly related to the frequency of the input pulses and the length of rotation is directly related to the number of input pulses applied.

Stepper motors are ideally suited for precision positioning of an object or/and precision control of speed without using closed-loop feedback for any automation systems. It is also translate switched excitation changes into precisely defined increments of rotor position {'steps'}. Accurate positioning of the rotor is generally achieved by magnetic alignment of iron teeth on the stationary and rotating parts of the motor.

The basic function of stepper motor is that its output shaft rotates in a series of discrete angular intervals or steps, one step being taken each time a command pulse is received. When a definite number of pulses are supplied, the shaft turns through a definite known angle. The name stepper is used because this motor rotates through a fixed angular step in response to each input current pulse received bi its controller. These controllers can be computers, microprocessor and programmable controllers.

Principle of Operation

A stepping motor may be compared with a synchronous motor as far as operation is concerned: a rotating field, here generated by the control electronics, pulls a magnetic rotor along. Stepping motors are sub divided according to the manner in which the rotating field is generated, that is with unipolar or bipolar stator windings and the material from which the rotator has been constructed -- permanent magnetic material or soft iron.

Step angle: The angle through which the motor shaft rotates foer each command pulse is called the step angle φ = 360°/(No. of stator faze × No of rotor teeth).

The angle can be as small as 0.72° or as large as 90°, but the most common step angle 1.8°, 2.5°, 7.5°, 15°...

Stepper Motor Advantages and Disadvantages

Advantages

  • The rotation angle of the motor is proportional to the input pulse.
  • The motor has full torque at standstill (if the windings are energized)
  • Precise positioning and repeatability of movement since good stepper motors have an accuracy of 3--5% of a step and this error is non cumulative from one step to the next.
  • Excellent response to starting/stopping/reversing.
  • Very reliable since the are no contact brushes in the motor. Therefore the life of the motor is simply dependant on the life of the bearing.
  • The motors response to digital input pulses provides open-loop control, making the motor simpler and less costly to control.
  • It is possible to achieve very low speed synchronous rotation with a load that is directly coupled to the shaft.
  • A wide range of rotational speeds can be realized as the speed is proportional to the frequency of the input pulses.
Disadvantages
  • Resonances can occur if not properly controlled.
  • Not easy to operate at extremely high speeds.

Pinguino — Stepper Motors

Well, now we know about what a stepper motor is and how to work it, but the point of this topic is how to use this device with an embedded board or microcontrollers, and why not with a pinguino board. In this case I’m using a stepper motor with the next specification: TYPE 4H4018X1616, 1.8°, 5 V, 1.0 A. As we can see this motor needs 5 volts and 1 amper for its efficient operation, there are two ways to powering this motor, with my computer that only provide 500 mA and it can be dangerous for my USB port or using a external power source, for avoid any risk with my computer I will use a external power source, and chose this choice because I don't have material for a good driver or controller that provide enough current and security at the same time using my USB port.

I'm using the next material:

  • Resistors (10 KΩ and 33 Ω)
  • Dip switch (8 switchs)
  • ULN2003A
  • LCD 16x2
  • Pinguino Board (PIC18F4550)
  • Bipolar Stepper Motor

Schematic

Concrete

PIC C CCS COMPILER CODE

Fuses Code
#include <18F4550.h>
#device ADC=16

#fuses NOMCLR       //No Master Clear Reset. Used for I/O Instead 
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOVREGEN                 //USB voltage regulator disabled
#FUSES NOPBADEN                 //PORTB pins are configured as digital I/O on RESET
#FUSES NOLPT1OSC                //Timer1 configured for higher power operation
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

#use delay(CLOCK=20000000)

#include "flex_lcd.c"
Main Code
#include 

//Normal Full Step
unsigned char Motor[4] ={0x0a,0x06,0x05,0x0b};

void Stepper_Motor_ClockWise(unsigned char Steps){
unsigned int Index = 0;
unsigned int Count = 0;
    do {
        OUTPUT_D(Motor[Index]);
        Index ++;
        delay_ms(100);
            if(Index > sizeof(Motor)-1){
                Index = 0;
                Count ++;
            } 
            else if(Count == Steps){
                OUTPUT_D(0); 
                Count = 0;
                Index = 0;              
                lcd_putc("\f");
                break;
            }  
        lcd_gotoxy(1, 0);
        printf(lcd_putc,"Clockwise");                  
        lcd_gotoxy(1, 1);
        printf(lcd_putc,"Value: %u",Count);   
    } 
    while(Count <= Steps);
}    


void Stepper_Motor_AntiClockWise(unsigned char Steps){
int8 Index = 3;
unsigned int Count = 0;
    do {
        OUTPUT_D(Motor[Index]);
        Index --;
        delay_ms(100);
            if(Index == -1){
                Index = 3;
                Count ++;
            } 
            else if(Count == Steps){
                OUTPUT_D(0); 
                Count = 0;
                Index = 0;              
                lcd_putc("\f");
                break;
            }    
        lcd_gotoxy(1, 0);
        printf(lcd_putc,"AntiClockwise");        
        lcd_gotoxy(1, 1);
        printf(lcd_putc,"Value: %u",Count);   
    } 
    while(Count <= Steps);
}    

void Stepper_Motor(unsigned int Function){
    switch (Function){
        case 1: //ClockWise 
            lcd_putc("\f");     
            Stepper_Motor_ClockWise(10);    
        break;
        case 2: //AntiClockWise
            lcd_putc("\f");    
            Stepper_Motor_AntiClockWise(10);
        break;            
        default: 
            lcd_gotoxy(1, 0);
            printf(lcd_putc,"Waiting for...");        
            lcd_gotoxy(1, 1);
            printf(lcd_putc,"Command!");                        
        }
    }
    
void main()
{
lcd_init();

   while(TRUE)
   {
      //TODO: User Code
      Stepper_Motor(input_a());
   }

}

PINGUINO BOARD CODE

/*----------------------------------------------------- 
Author:  Jefferson GoVa--<>
Date: Fri Jan 03 23:14:02 2014
Description:
Stepper Motor using a Pinguino Board :D
-----------------------------------------------------*/

unsigned int Btn_State;


//Normal Full Step
unsigned char Motor[4] ={0x0a,0x06,0x05,0x0b};
    
void Stepper_Motor_ClockWise(unsigned char Steps){
unsigned int Index = 0;
unsigned int Count = 0;
    do {
        PORTD = Motor[Index];
        Index ++;
        delay(100);
            if(Index > sizeof(Motor)-1){
                Index = 0;
                Count ++;
            } 
            else if(Count == Steps){
                PORTD = 0; 
                Count = 0;
                Index = 0;              
                lcd.clear();
                break;
            }  
        lcd.setCursor(0, 0);
        lcd.printf("Clockwise");                  
        lcd.setCursor(0, 1);
        lcd.printf("Value: %u",Count);   
    } 
    while(Count <= Steps);
}    

void Stepper_Motor_AntiClockWise(unsigned char Steps){
int Index = 3;
unsigned int Count = 0;
    do {
        PORTD = Motor[Index];
        Index --;
        delay(100);
            if(Index < 0){
                Index = 3;
                Count ++;
            } 
            else if(Count == Steps){
                PORTD = 0; 
                Count = 0;
                Index = 0;              
                lcd.clear();
                break;
            }    
        lcd.setCursor(0, 0);
        lcd.printf("AntiClockwise");        
        lcd.setCursor(0, 1);
        lcd.printf("Value: %u",Count);   
    } 
    while(Count <= Steps);
}    

void Stepper_Motor(unsigned int Function){
    switch (Function){
        case 1: //ClockWise 
            lcd.clear();      
            Stepper_Motor_ClockWise(10);    
        break;
        case 2: //AntiClockWise
            lcd.clear();     
            Stepper_Motor_AntiClockWise(10);
        break;            
        default: 
            lcd.setCursor(0, 0);
            lcd.printf("Waiting for...");        
            lcd.setCursor(0, 1);
            lcd.printf("Command!");                        
        }
    }
    
void Check_Btns(){
    char State[3]; 
    int i; 
        for (i = 0 ;i < 3 ;i ++){
            State[i] = digitalRead(i+13);    
        }
    Btn_State = State[0] + State[1]*2 + State[2]*4;
    Stepper_Motor(Btn_State);
}    
    
void setup() {
    //run once:
    //DIP Switch States
    pinMode(13,INPUT);
    pinMode(14,INPUT);
    pinMode(15,INPUT);
    
    //Motor Stepper
    pinMode(21,OUTPUT);
    pinMode(22,OUTPUT);
    pinMode(23,OUTPUT);
    pinMode(24,OUTPUT);
    
    // initialize the library with the numbers of the interface pins
    //lcd.pins(RS, E, D4, D5, D6, D7, 0, 0, 0, 0); //4bits
    //lcd.pins(RS, E, D0, D1, D2, D3, D4, D5, D6, D7); //8bits
    lcd.pins(0, 1, 2, 3, 4, 5, 0, 0, 0, 0); // RS, E, D4 ~ D8 

    // set up the LCD's number of columns and rows: 
    lcd.begin(16, 2);   
    }

void loop() {
    //run repeatedly:
    Check_Btns();
    }
Concrete
If you like our work in Jeal's Blog just subscribe yourself. Get our posts in your RSS reader or by email.
Written by Jefferson GoVa

Ingeniero en electronica con aficiones a escribir y compartir todo aquello que le llama la atencion o que su curiosidad atrapa..

#Curioseando #Perdiendoeltiempo #sinnadamejorquehacer.

4 comments:

  1. Greetings!!., Here´s the thing, Im trying to do a progress bar with a 16x2 LCD display and pinguino, every tutorial I try fails because them are almost exclusive for Arduino. How do I do a progress bar usin Pinguino, thas my question. Thanks in advance.

    ReplyDelete
  2. Good job man! Have you a 4H4018X1616 datasheet?

    ReplyDelete
  3. Welcome Bonus | Casino Roll
    Looking for a bonus for your 라스벳 next 게임 사 spin? Casino Roll 솔레어 has all the details to bring you top casino 라이브채팅 promotions for your 홀덤 용어 slot game portfolio. No Deposit Bonuses

    ReplyDelete
  4. Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me. Honda outboard motors for sale

    ReplyDelete