20081113 Slider Stepper Control

Position a stepper by a slider control on a web page

Slider on a web page returns a get with a range of 0-512 (reflects the actual step range of the target stepper module 

For this we will have to use a elapsed time check using the tick functions as the time between steps for a Sony DVD head position stepper device is 2-3ms (empirically tested) any faster and it slips due to the acceleration.  We will make the delay able to be variable later (whole ms increments).  It seems 1ms is fine when half steps, but 3ms is required when full stepping for this particular stepper arrangement.  Interestingly this means we can actually move faster with halfsteps..

Also, a rapid direction change requires a larger delay or we will slip a step or 3..

Additionally, we will have togglable options:

- full steps only

- half steps only

- mixed.  In this full steps are used for faster/coarser movement with a final half step when required.

Also noticed that starting in full steps misses a few sometimes depending on the start point..


TCPIP Site changes:

Added ~slider2~ to sliders.cgi

Added another page 'step1.htm' with YUI slider.

 


MPLAB C18 changes..


hardwareprofile.h in my board section:

 //Stepper Controller
 #define STEPPER_TRIS  (TRISD)
 #define STEPPER_LAT   (LATD)
 #define STEPPER_USEHIGHNIBBLE


I need a GLOBAL variable and after a lot of hair pulling this works:

Add new files fnf.h & fnf.c and add them to the project:

// fnf.h

/////////////////////
// My Custom stuff //
/////////////////////

//Globals
/////////////////////

// Stepper

extern WORD stepperrequiredposition;

 

// fnf.c

#include "TCPIP Stack/TCPIP.h"

/////////////////////
// My Custom stuff //
/////////////////////

//Globals
/////////////////////

// Stepper

WORD stepperrequiredposition = 0;

ADD to tcpip.h:

// My Custom
#include "fnf.h"

 


maindemo.c changes - declares:

  /****************************************************************************
 My Custom Stuff
   ***************************************************************************/
 
 // Stepper Motor Control Sequences
 const BYTE stepperhalfstep[8] = {1, 5, 4, 6, 2, 10, 8, 9}; // goes full step, half step, full step....
 
 // Movement range (at half steps)

 static signed char stepperdirection = 0;
 static BYTE stepperstepsize = 1;// 1 = half only, 2 = full only
 static BOOL stepperallowmixedsteps = TRUE;
 static BYTE steppermstowait = 3;
 static BYTE steppersteppingmstowait = 3;
 static BYTE stepperdirectionchangemstowait = 25;

 WORD stepperminposition = 0;
 WORD steppermaxposition = 512;
 static WORD stepperposition = 512 + 8;    // in case is out of position
 
 // trap tick when last actioned
 static TICK steppertime;
 
 #define TICKS_PER_MS ((LONG)TICKS_PER_SECOND)/1000)

 BYTE LCDTemp[8+1];

 ////////////////////////////////////////////////////////////////////////////////


maindemo.c added to section '// Initialize application specific hardware' section:

  //StepperPins to Output
 #if defined(STEPPER_USE_HIGH_NIBBLE)
  STEPPER_TRIS = (0b00001111&STEPPER_TRIS);
 #else
  STEPPER_TRIS = (0b11110000&STEPPER_TRIS);
    #endif

 steppertime = TickGet();


maindemo.c at very bottom of main loop

  // Stepper Movement
  if((LONG)(TickGet() - steppertime) >= (TICKS_PER_MS * steppermstowait)
  {
   steppertime = TickGet();
   steppermstowait = steppersteppingmstowait; // in case we just had a direction change
   if(stepperposition != stepperrequiredposition)
   {
    if (stepperrequiredposition > stepperposition)
    {
     stepperdirection = 1;
    }
    else
    {
     stepperdirection = -1;
    }

    stepperposition += stepperdirection; // move a half step first
    // can we move a full step? (needs to be an even step to even step)
    // we will check:
    // - have we just moved to an odd step? so an extra step will put us back on an even step,
    // - are we still not at our desired position?
    // - are we allowed to use fullsteps(step size 2 or mixed steps is allowed..
    if (((stepperposition&0b00000001)==1) && (stepperrequiredposition != stepperposition) && ((stepperstepsize == 2) || (stepperallowmixedsteps == TRUE)))
    {
     stepperposition += stepperdirection;
    }

    #if defined(STEPPER_USE_HIGH_NIBBLE)
     // divide position by 8 to get step index.. right shift 4 if high nibble, then overlay with TRIS for required pins only
     STEPPER_LAT = (((stepperhalfstep[stepperposition&0b00000111])<<4)+(STEPPER_LAT&0b00001111));
    #else
     // divide position by 8 to get step index, then overlay with TRIS for required pins only
     STEPPER_LAT = (((stepperhalfstep[stepperposition&0b00000111]))+(STEPPER_LAT&0b11110000));
       #endif
  }

 


Note that from a previous exercise we already knew the increments required to drive our stepper:

   L293DMotorFullStep[0] = 0b00000001;
   L293DMotorFullStep[1] = 0b00000100;
   L293DMotorFullStep[2] = 0b00000010;
   L293DMotorFullStep[3] = 0b00001000;
  
   L293DMotorHalfStep[0] = 0b00001000; // 8
   L293DMotorHalfStep[1] = 0b00001001;
   L293DMotorHalfStep[2] = 0b00000001; // 1
   L293DMotorHalfStep[3] = 0b00000101;
   L293DMotorHalfStep[4] = 0b00000100; // 4
   L293DMotorHalfStep[5] = 0b00000110;
   L293DMotorHalfStep[6] = 0b00000010; // 2
   L293DMotorHalfStep[7] = 0b00001010; 2