Issue with stepper motor (MISTSUMI unipolar 4.7 degree,10Ω )

Status
Not open for further replies.

magvitron

Active Member
Hi,
i was doing a project on automatic sealing machine and I'm changing a printer to suit my needs., a lexmark printer. it has got a MISTSUMI unipolar 4.7 degree,10Ω. the problem is that the maximum RPM is very low when I m using an L293D h bridge driver. Im posting my code.. and every file I have.

View attachment stamper.zip

Code:
/*****************************
		Stamper 
******************************
Program by   : Manu krishnan
version      : 1.0.0.0 (beta)
Assembled in : winavr
core         : mega 8 (8k)
fuse         : 8Mhz internal rc
			   rst disabled
AVR Studio	 :	4.15.623  
GUI Version	 :	4, 15, 0, 623
AVR Simulator:  1, 0, 2, 1
ATMEGA16		247
date 		 : 12 feb 2013 20.44
*******************************/
/*******************************
Preprovcessor Directive
*******************************/

#define F_CPU 1000000UL
//#include <avr/pgmspace.h>
#include<avr/io.h>
#include<util/delay.h>
//#include<avr/interrupt.h>
#include<avr/eeprom.h>
/******************************/
//MACROS
#define output_low(port,pin) port &= ~(1<<pin)
#define output_high(port,pin) port |= (1<<pin)
#define set_input(portdir,pin) portdir &= ~(1<<pin)
#define set_output(portdir,pin) portdir |= (1<<pin)
/*******************************
LCD definitions
*******************************/
#define ctrl PORTD
#define en PD3		//enable signal
#define rs PD2		//resister select signal

/*******************************
uart definitions
*******************************/
#define motor PORTB
#define servo PB6
#define mot1 PB2
#define mot2 PB3

void init();
void backward(int delayx);
void forward(int delayx);
void servo_to(char degree);void calibrate();
void lcddata(char dataout); 
void lcdcmd(char cmdout);
void dis_data(char data_value);
void to_line(char line,char pos);
void dis_cmd(char cmd_value);
void lcd_init();	// fuction for intialize 
void run(unsigned char X);
void stamp();
 unsigned int degree_value,time,number_of_steps;
unsigned char temp,del,k,serial,pre;
unsigned int max_ser,min_ser,addr,delay,r;
void lcd_write_string(char *str);

int main()
{

max_ser=180;
min_ser=0;
temp=100;
init();
to_line(1,0);
lcd_write_string("AutomaticStamper");
to_line(2,0);
lcd_write_string("----------------");
int i,j;
//_delay_ms(1000);
	while(1)
	 {
	 for(j=0;j<=4;j++)
	 {
       for(i=0;i<100;i++)
	  {
       	run('F');
	   }
	   	 	stamp();
     }
     
	  //_delay_ms(1000);
	  run('U');
	 _delay_ms(500);
	 stamp();	
	run('D');
	_delay_ms(500);
	}
	

}
void refil()
{
	run('U');
		_delay_ms(1000);
	 	stamp();	
		run('D');


}
void init()
{
DDRB=0xff;DDRD=0xFC;
 lcd_init();
 ICR1=20000;
 TCCR1A  = (0<<COM1A0)|(1<<COM1A1)|(0<<COM1B0)|(0<<COM1B1)|(0<<FOC1A)|(0<<FOC1B)|(1<<WGM11)|(0<<WGM10);
	TCCR1B =  (0<<ICNC1)|(0<<ICES1)|(1<<WGM13)|(1<<WGM12)|(0<<CS12)|(0<<CS11)|(1<<CS10);
}


void run(unsigned char X)
{
	switch (X)
	{
		case 'F':
			forward(1);
			to_line(2,0);
	    	lcd_write_string(" Stepper Forward");
		
			pre='F';
		break;
		case 'B':
			backward(26);
			to_line(2,0);
			lcd_write_string(" Stepper Backward");
			pre='B';
		break;
		case 'S':
			to_line(2,0);
			lcd_write_string(" Stamping...     ");
			stamp();	
		break;
		case 'U':
		to_line(1,0);
			lcd_write_string("Motor UP        ");
			output_high(motor,mot1) ;
			output_low(motor,mot2);
		break;
		case 'D':
		to_line(1,0);
			lcd_write_string("Motor DOWN      ");
			output_high(motor,mot2);
			output_low(motor,mot1);
		break;
	}
}


void stamp()
{
to_line(2,0);
lcd_write_string("Stamping...");
// unsigned int a;
    OCR1A=2000;
	_delay_ms(1000);
	/////////////////
	OCR1A=1000;
	_delay_ms(1000);
//	OCR1A=1000;
	

}



void forward(int delayx)
{

	PORTB = 0b10101111;
	_delay_ms(3);
	PORTB = 0b01101111;//-45*/
	_delay_ms(3);
	PORTB = 0b01011111;//-45*/
	_delay_ms(3);
	PORTB = 0b10011111;//-45*/
	_delay_ms(3);

	PORTB = 0b00000000;//-45*/
}

void backward(int delayx)
{

	PORTB = 0b1001;//-45
	_delay_ms(delayx);
	PORTB = 0b0101;//-135
	_delay_ms(delayx);
	PORTB = 0b0110; //+135
	_delay_ms(delayx);
	PORTB = 0b1010;//+45
	_delay_ms(delayx);
	PORTB = 0b0000;//-45
}



/*******************************
Class LCD 4 bit for 4 bit lcd
interface 
*******************************/

void lcd_init()	// fuction for intialize 
{
	dis_cmd(0x02);		// to initialize LCD in 4-bit mode.
	dis_cmd(0x28);		//to initialize LCD in 2 lines, 5X7 dots and 4bit mode.
	dis_cmd(0x0C);
	dis_cmd(0x06);
	dis_cmd(0x80);
	_delay_ms(100);
}

void dis_cmd(char cmd_value)
{
	char cmd_value1;
	cmd_value1 = cmd_value & 0xF0;		//mask lower nibble because PA4-PA7 pins are used. 
	lcdcmd(cmd_value1);			// send to LCD
 	cmd_value1 = ((cmd_value<<4) & 0xF0);	//shift 4-bit and mask
	lcdcmd(cmd_value1);			// send to LCD
}						
 
void to_line(char line,char pos)
{
if(line ==1)
{
 	dis_cmd(0x80 + pos);
}
else
{
 	dis_cmd(0xC0+pos);
}
}
void clear()
{
    to_line(1,0); 
    lcd_write_string("                ");
}

void dis_data(char data_value)
{

	char data_value1;
	
	data_value1=data_value&0xF0;
	lcddata(data_value1);
 
	data_value1=((data_value<<4)&0xF0);
	lcddata(data_value1);
}
 
void lcdcmd(char cmdout)
{
	ctrl=cmdout;
	ctrl&=~(1<<rs);
	ctrl|=(1<<en);
	_delay_ms(1);
	ctrl&=~(1<<en);
}

void lcddata(char dataout)
{
	ctrl=dataout;
	ctrl|=(1<<rs);
	ctrl|=(1<<en);
	_delay_ms(1);
	ctrl&=~(1<<en);
}
 
void lcd_write_string(char *str)	//take address vaue of the string in pionter *str
{
	int i=0;
	while(str[i]!='\0')				// loop will go on till the NULL charaters is soon in string 
	{
		dis_data(str[i]);				// sending data on CD byte by byte
		i++;
	}

}

this is the piece of code that controls the stepper
void forward(int delayx)
{

PORTB = 0b10101111;
_delay_ms(3);
PORTB = 0b01101111;//-45*/
_delay_ms(3);
PORTB = 0b01011111;//-45*/
_delay_ms(3);
PORTB = 0b10011111;//-45*/
_delay_ms(3);

PORTB = 0b00000000;//-45*/
}
 
Why is the RPM low? Can't you just change the 3mS delay to a smaller delay to make it faster?

If it is stalling when you try to run faster, you can try these things;
1. use more voltage
2. use more current
3. add damping ot the stepper (flywheel etc)
4. ramp the speed up, ie accelerate up to full speed.
 
hey.. i got over the problem. i have made a small change in code, enabled the interrupt and inserted the following ISR

Code:
ISR(TIMER0_OVF_vect)
{

	if(dir==1)
	{
	 

		switch (i)
		{

			case 0:
			PORTB = 0b10101111;
			break;
			case 1:
			PORTB = 0b01101111;//-45
			break;
			case 2 :
			PORTB = 0b01011111;//-45
			break;
			case 3:
			PORTB = 0b10011111;//-45
			break;

		}

    }
	else
	{
	switch (i)
		{
	
			case 0:
			PORTB = 0b10011111;
			break;
			case 1:
			PORTB = 0b01011111;//-45
			break;
			case 2 :
			PORTB = 0b01101111;//-45
			break;
			case 3:
			PORTB = 0b10101111;//-45
			break;
		}
	}
i=i+1;
if(i==4)
 i=0;
//	PORTB = 0b00000000;//-45*/
}
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…