|
|
View previous topic :: View next topic |
Author |
Message |
imET
Joined: 05 Jul 2005 Posts: 4 Location: Canada
|
step and direction output for stepper controller. |
Posted: Wed Mar 22, 2006 6:55 pm |
|
|
Hi,
I'm trying to build an XY pen plotter and
I'm wondering what is a better way of
sending step pulse to a stepper controller,
I basically just sending steps to a stepper
controller by turning a pin Hi or Lo as you could
see below:
Code: |
void point2d(SINT32 x, SINT32 y, SINT32 x2, SINT32 y2)
{
/* output the point */
setDirection();
delay_ms(PulseWidth);//delay between steps
if(sx != 0)output_high(STEP_X);
if(sy != 0)output_high(STEP_Y);
delay_ms(PulseWidth);//delay between steps
output_low(STEP_Y);
output_low(STEP_X);
//printf(lcd_putc, "\f%ld %ld", x,y);
//printf(lcd_putc,"\n%d", PulseWidth);
// Pseudo Acceleration/Deceleration,
if ((x - x2) >= MinStep | (y - y2) >= MinStep)
PulseWidth -= 1;
else
PulseWidth += 1;
if(PulseWidth <= MaxPulseWidth) PulseWidth = MaxPulseWidth;
if(PulseWidth >= 50) PulseWidth = 50;
//printf(lcd_putc,"\f%ld", count);
}//end point2d
|
|
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
|
Posted: Wed Mar 22, 2006 9:33 pm |
|
|
If you haven't done it already, take a look at the CCS' example EX_STEP.C . |
|
|
imET
Joined: 05 Jul 2005 Posts: 4 Location: Canada
|
|
Posted: Thu Mar 23, 2006 3:27 pm |
|
|
Thanks, but I'm not trying to make a stepper controller,
I already have a stepper controller base on Allegro 3977SED.
I'm basically just sending steps and direction to the controller,
and I think there's a better way, than what was done in the previous posted code is doing.
here's some more of the code if it would helps.
It's part of the code I found online, so I'm not putting a claim to it.,
the original code is designed to do 3 axis, but I only need the two.
Code: |
void line2D(SINT32 x1, SINT32 y1, SINT32 x2, SINT32 y2)
{
//SINT32 x, y;
SINT32 ax, ay;
SINT32 xd, yd;
SINT32 dx, dy;
//Difference between start and endpoint
dx = x2 - x1;
dy = y2 - y1;
/* TrueDistance:= SQRT(SQR(Xdest - X) + SQR(Ydest - Y));
Pythagorean theroem*/
/*
// absolute value of a
//#define ABS(a) (((a) < 0)? -(a):(a))
ax = ABS(dx) << 1;
ay = ABS(dy) << 1;
//xInc = dx / stepDiv;
//yInc = dy / stepDiv;
//ax = ABS((dx) / stepDiv);// determine how far each axis should move
//ay = ABS((dy) / stepDiv);
// take sign of a, either -1, 0, or 1
//#define ZSGN(a) (((a) < 0)? -1 : (a) >0 ? 1 : 0)
sx = ZSGN(dx);//is dx 1, 0, or -1
sy = ZSGN(dy);//is dy 1, 0, or -1 / 1=CW : 0 or -1 =CCW
x = x1;
y = y1;
//X axis dominant ?
if (ax >= ay )
{
yd = ay - (ax >> 1);
for (;;)
{
point2d(x,y,x2,y2); //X is the driving axis hence dominant
if (x == x2)
{
return; //current move completed
}
if (yd >= 0)
{
y += sy;
yd -= ax;
}
x += sx;
yd += ay;
}//end for
}
//Y axis dominant ?
else if (ay >= ax)
{
xd = ax - (ay >> 1);
for (;;)
{
point2d(x, y,x2,y2);
if (y == y2)
{
return;
}
if (xd >= 0)
{
x += sx;
xd -= ay;
}
y += sy;
xd += ax;
}//end for
}//end elseif
} //end line2d
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|