Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/21/07 22:39
Read: times


 
Msg Score: +1
 +1 Informative
#131197 - Maybe this will help
Responding to: ???'s previous message
Following is some code that might help. It's incomplete and somewhat hardware-dependent, but it might give you some ideas.

-- Russ
 
/* ////////////////////////////////////////////////////////////////////////////
                                 Handy Macros
//////////////////////////////////////////////////////////////////////////// */

#define set_motor(X) P1 = (P1 & 0xC0) | X       /* Set the motor control lines
                                                   without messing up the other
                                                   two bits of Port 1 */

/* ////////////////////////////////////////////////////////////////////////////
                           Local Function Prototypes
//////////////////////////////////////////////////////////////////////////// */

void step_the_motor(signed char);

/* ////////////////////////////////////////////////////////////////////////////
                               Module Variables
//////////////////////////////////////////////////////////////////////////// */

/*  These macros correlate the L6219 signal names with their positions within
    Port 1.  Note that here we call the two windings 'A' and 'B' instead of '1'
    and '2' like the data sheet does.  */

#define A_I0    0x01                            /* Hardware dependent */
#define A_I1    0x02                            /* Hardware dependent */
#define A_Ph    0x04                            /* Hardware dependent */
#define B_I0    0x20                            /* Hardware dependent */
#define B_I1    0x10                            /* Hardware dependent */
#define B_Ph    0x08                            /* Hardware dependent */

/*  These macros give names to the various possible settings of the current
    control signals.  The numbers in the names indicate percent of full
    current.  */

#define A_0     (A_I0 | A_I1)
#define A_33    A_I1
#define A_67    A_I0
#define A_100   0

#define B_0     (B_I0 | B_I1)
#define B_33    B_I1
#define B_67    B_I0
#define B_100   0

/*  These macros give names to the directions of current flow in the two
    windings.  */

#define A_PLUS  A_Ph
#define A_MINUS 0

#define B_PLUS  B_Ph
#define B_MINUS 0

/*  This table specifies the sequencing of the I/O lines needed to make the
    motor move.  See the data sheet for the L6219 motor driver for details.  */

#if STEP_FULL                           /* Full stepping with 100% current */
static code char sequence[] = {
    A_MINUS | A_100  | B_MINUS | B_100,
    A_PLUS  | A_100  | B_MINUS | B_100,
    A_PLUS  | A_100  | B_PLUS  | B_100,
    A_MINUS | A_100  | B_PLUS  | B_100
    };
#endif

#if STEP_HALF                           /* Half stepping with 67% current */
static code char sequence[] = {
    A_MINUS | A_0    | B_PLUS  | B_67,
    A_PLUS  | A_67   | B_PLUS  | B_67,
    A_PLUS  | A_67   | B_PLUS  | B_0,
    A_PLUS  | A_67   | B_MINUS | B_67,
    A_PLUS  | A_0    | B_MINUS | B_67,
    A_MINUS | A_67   | B_MINUS | B_67,
    A_MINUS | A_67   | B_MINUS | B_0,
    A_MINUS | A_67   | B_PLUS  | B_67
    };
#endif

#if STEP_QUARTER                        /* Quarter stepping with 67% current */
static code char sequence[] = {
    A_MINUS | A_0    | B_PLUS  | B_67,
    A_PLUS  | A_33   | B_PLUS  | B_67,
    A_PLUS  | A_67   | B_PLUS  | B_67,
    A_PLUS  | A_67   | B_PLUS  | B_33,
    A_PLUS  | A_67   | B_PLUS  | B_0,
    A_PLUS  | A_67   | B_MINUS | B_33,
    A_PLUS  | A_67   | B_MINUS | B_67,
    A_PLUS  | A_33   | B_MINUS | B_67,
    A_PLUS  | A_0    | B_MINUS | B_67,
    A_MINUS | A_33   | B_MINUS | B_67,
    A_MINUS | A_67   | B_MINUS | B_67,
    A_MINUS | A_67   | B_MINUS | B_33,
    A_MINUS | A_67   | B_MINUS | B_0,
    A_MINUS | A_67   | B_PLUS  | B_33,
    A_MINUS | A_67   | B_PLUS  | B_67,
    A_MINUS | A_33   | B_PLUS  | B_67
    };
#endif

#if STEP_SIXTH                          /* Sixth stepping with 100% current */
static code char sequence[] = {
    A_MINUS | A_0    | B_PLUS  | B_100,
    A_PLUS  | A_33   | B_PLUS  | B_100,
    A_PLUS  | A_67   | B_PLUS  | B_100,
    A_PLUS  | A_100  | B_PLUS  | B_100,
    A_PLUS  | A_100  | B_PLUS  | B_67,
    A_PLUS  | A_100  | B_PLUS  | B_33,
    A_PLUS  | A_100  | B_PLUS  | B_0,
    A_PLUS  | A_100  | B_MINUS | B_33,
    A_PLUS  | A_100  | B_MINUS | B_67,
    A_PLUS  | A_100  | B_MINUS | B_100,
    A_PLUS  | A_67   | B_MINUS | B_100,
    A_PLUS  | A_33   | B_MINUS | B_100,
    A_PLUS  | A_0    | B_MINUS | B_100,
    A_MINUS | A_33   | B_MINUS | B_100,
    A_MINUS | A_67   | B_MINUS | B_100,
    A_MINUS | A_100  | B_MINUS | B_100,
    A_MINUS | A_100  | B_MINUS | B_67,
    A_MINUS | A_100  | B_MINUS | B_33,
    A_MINUS | A_100  | B_MINUS | B_0,
    A_MINUS | A_100  | B_PLUS  | B_33,
    A_MINUS | A_100  | B_PLUS  | B_67,
    A_MINUS | A_100  | B_PLUS  | B_100,
    A_MINUS | A_33   | B_PLUS  | B_100,
    A_MINUS | A_67   | B_PLUS  | B_100
    };
#endif

/* ////////////////////////////////////////////////////////////////////////////
                               step_the_motor()
///////////////////////////////////////////////////////////////////////////////
DESCRIPTION:    This function moves the motor by one step in the specified
                direction.

NOTE:           A "step" is a full motor step (1.8°) if STEP_FULL is 1, or a
                half step (0.9°) if STEP_HALF is 1, or a quarter step (0.45°)
                if STEP_QUARTER is 1.

REVISIONS:      31 Jul 06 - RAC - Genesis
//////////////////////////////////////////////////////////////////////////// */

void step_the_motor(signed char inc) {

    static signed char  index;                  /* Sequence table index */

    index += inc;                               /* Bump sequence table index */

#if STEP_FULL
    index &= 0x03;                              /* Wrap at end of table */
#endif
#if STEP_HALF
    index &= 0x07;                              /* Wrap at end of table */
#endif
#if STEP_QUARTER
    index &= 0x0F;                              /* Wrap at end of table */
#endif
#if STEP_SIXTH
    if (index > 23) index = 0;                  /* Wrap at end of table */
    if (index < 0)  index = 23;                 /* Wrap at end of table */
#endif

    set_motor(sequence[index]);                 /* Apply new pattern */
    }                                           /* End step_the_motor() */

 



List of 22 messages in thread
TopicAuthorDate
8051 & L6219 (Stepper Motor Driver)            01/01/70 00:00      
   CNCZone            01/01/70 00:00      
   Maybe this will help            01/01/70 00:00      
      this helps a lot            01/01/70 00:00      
         Think Search and Replace            01/01/70 00:00      
            static            01/01/70 00:00      
               static about 'static' and 'code'            01/01/70 00:00      
                  That's modularity for you!            01/01/70 00:00      
                  Different Reason            01/01/70 00:00      
         Concepts            01/01/70 00:00      
      Imprecise comment            01/01/70 00:00      
         Another imprecise comment            01/01/70 00:00      
            Ah... That is the catch :)            01/01/70 00:00      
            Better            01/01/70 00:00      
               Yup            01/01/70 00:00      
                  Works Beautifully            01/01/70 00:00      
                     Another happy ending            01/01/70 00:00      
                        One more problem - Direction            01/01/70 00:00      
                           Extra Table Shouldn't Be Necessary            01/01/70 00:00      
                              thats what i thought too            01/01/70 00:00      
      nevermind i screwed up...            01/01/70 00:00      
   Visit Jones on Stepping Motors            01/01/70 00:00      

Back to Subject List