CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

step and direction output for stepper controller.

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
imET



Joined: 05 Jul 2005
Posts: 4
Location: Canada

View user's profile Send private message

step and direction output for stepper controller.
PostPosted: Wed Mar 22, 2006 6:55 pm     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Wed Mar 22, 2006 9:33 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Mar 23, 2006 3:27 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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