Sunday, February 17, 2013

Step counter for Unipolar stepper motor

In previous post.I told you that I was able to drive an old scavenged unipolar stepper motor from my old printer.As I couldn’t find any datasheet it was not possible to fine how many steps needed for a full turn.I plugged in my 16*2 LCD to the my board and coded a bit to get that measurement.

The circuit and configuration bits are exactly same as the unipolar stepper driver post. The only difference is  plugged the LCD to the connector.

This is the completed circuit.

DSCF5600_800x600

I marked a small point at the staring point the given time using a marker pen. Using it I can count how many turns it rotated.

DSCF5603_800x600

Here is the code Winking smileThe bolded lines are used to calculate and show the number of steps Open-mouthed smile

sbit LCD_RS at RB5_bit;
sbit LCD_EN at RB4_bit;
sbit LCD_D4 at RB3_bit;
sbit LCD_D5 at RB2_bit;
sbit LCD_D6 at RB1_bit;
sbit LCD_D7 at RB0_bit;

sbit LCD_RS_Direction at TRISB5_bit;
sbit LCD_EN_Direction at TRISB4_bit;
sbit LCD_D4_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB2_bit;
sbit LCD_D6_Direction at TRISB1_bit;
sbit LCD_D7_Direction at TRISB0_bit;

void main() {

int count=0;
char CountStr[7];
    osccon = 0x70;
    ansel  = 0;
    anselh  = 0;
    trisa = 0;
    trisb = 0;
    trisc = 0;
    trisd = 0;
    Lcd_Init();

  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Cmd(_LCD_CURSOR_OFF);
  Lcd_Out(1,1,"Step Count:");

  for(;;){
  portd.f4=1;
 
  porta.f7=1;
  porta.f6=0;
  portc.f0=0;
  portc.f1=0;

  delay_ms(10);

  porta.f7=0;
  porta.f6=1;
  portc.f0=0;
  portc.f1=0;
 
  delay_ms(10);
 
  porta.f7=0;
  porta.f6=0;
  portc.f0=1;
  portc.f1=0;

  delay_ms(10);
 
  porta.f7=0;
  porta.f6=0;
  portc.f0=0;
  portc.f1=1;

  portd.f4=0;
  delay_ms(10);
 
  count=count+1;
  IntToStrWithZeros(count, CountStr);
  Lcd_Out(2,1,CountStr);

  delay_ms(2000)   ;
  }
   
}

Capture

I found out that it takes 120 steps to rotate a 360 degree full turn. That is simply 3degrees for a step. Impressive isn’t it ? Winking smile

DSCF5605_800x600

1 comment: