stepper.h File Reference

Driver to control stepper motor. More...

#include <cfg/compiler.h>
#include <algo/ramp.h>

Go to the source code of this file.


Data Structures

struct  StepperConfig
 Stepper configuration. More...
struct  Stepper
 Motor context structure. More...

Defines

#define STEPS_INFINITE_POSITIVE   ((int16_t)0xFFFF)
 Special value for steps to move the motor continuously.
#define STEPS_INFINITE_NEGATIVE   ((int16_t)0x8FFF)
 Maximum value for stepper steps.
#define MAX_STEPS   0x7FFF
 Default value -> no level sensor associated to the motor.
#define MOTOR_NO_LEVEL_SENSOR   0xFFFF
 Default value -> no home sensor associated to the motor.
#define MOTOR_NO_HOME_SENSOR   0xFFFF
 Default value for deafsteps in normal movement (no level sensor).
#define DEAFSTEPS_DEFAULT   MAX_STEPS
 Out-of-band values for speed.
#define SPEED_STOPPED   0xFFFF
 motor is stopped
#define SPEED_HOMING   0xFFFE
 motor is homing

Typedefs

typedef void(* stepper_isr_t )(struct Stepper *)
 Time for steppers motor.

Enumerations

enum  MotorDirection { DIR_POSITIVE = 1, DIR_NONE = 0, DIR_NEGATIVE = -1 }
 Motor direction. More...
enum  StepperState {
  MSTS_UNINIT, MSTS_RUN, MSTS_IDLE, MSTS_PREIDLE,
  MSTS_PRERUN, MSTS_PREINIT, MSTS_INIT, MSTS_ENTERING,
  MSTS_LEAVING, MSTS_OUTHOME, MSTS_ERROR
}
 Stepper state-machine conditions. More...

Functions

void stepper_init (void)
 Initialize the stepper module.
struct Stepperstepper_setup (int index, struct StepperConfig *cfg)
 Apply a setup config to motor structure context.
void stepper_disable (void)
 Set the enable for all the motors to 0 before switching on the power.
void stepper_reset (struct Stepper *motor)
 Reset the motor.
void stepper_home (struct Stepper *motor)
 Find the home of a motor assuming no current knowledge about its position.
int16_t stepper_move (struct Stepper *motor, int16_t step, uint16_t speed, int16_t deafstep)
 Move motor to absolute position at specified speed.
void stepper_stop (struct Stepper *motor)
 Stop motor gracefully.
void stepper_break (struct Stepper *motor, enum StepperState state)
 Stop motor immediately, changing the status.
bool stepper_idle (struct Stepper *motor)
 Returns true if the stepper is in error mode.
bool stepper_error (struct Stepper *motor)
 check the home sensor in zero position

Variables

enum StepperState(* fsm_state )(struct Stepper *)
 Pointer to a isr stepper function.

Detailed Description

Driver to control stepper motor.

Version:
Id
stepper.h 1243 2008-05-02 11:51:11Z asterix

Author:
Francesco Michelini <francesco.michelini@seacfi.com>

Giovanni Bajo <rasky@develer.com>

Bernardo Innocenti <bernie@develer.com>

Simone Zinanni <s.zinanni@develer.com>

Daniele Basile <asterix@develer.com>

Definition in file stepper.h.


Enumeration Type Documentation

Motor direction.

Enumerator:
DIR_POSITIVE  moving away from zero (which is the home)
DIR_NONE  no movement
DIR_NEGATIVE  moving towards towards zero (which is the home)

Definition at line 75 of file stepper.h.

Stepper state-machine conditions.

Enumerator:
MSTS_UNINIT  stepper_init() not yet called
MSTS_RUN  running
MSTS_IDLE  waiting for a command
MSTS_PREIDLE  waiting before going low-current
MSTS_PRERUN  waiting after high-current
MSTS_PREINIT  preparing to initialize ;-)
MSTS_INIT  initializing home procedure
MSTS_ENTERING  entering home sensor
MSTS_LEAVING  moving away from home (inside the sensor)
MSTS_OUTHOME  moving away from home (outside the sensor)
MSTS_ERROR  error status

Dummy entry to guarantee the right underlying size for the enum

Definition at line 88 of file stepper.h.


Function Documentation

void stepper_break ( struct Stepper motor,
enum StepperState  state 
)

Stop motor immediately, changing the status.

Returns true if the stepper is in idle at the final position or in error:

Definition at line 920 of file stepper.c.

void stepper_home ( struct Stepper motor  ) 

Find the home of a motor assuming no current knowledge about its position.

This must be done when the motor is desynchronized with the firmware and we do not know anymore where it is.

In normal operation mode, to go back to the home, it is sufficient to use move to step #0 with stepper_move, since the home is always at step #0.

Definition at line 739 of file stepper.c.

int16_t stepper_move ( struct Stepper motor,
int16_t  steps,
uint16_t  speed,
int16_t  deafstep 
)

Move motor to absolute position at specified speed.

  • steps position to reach in steps
  • speed speed in timer ticks (use TIME2CLOCKS() to convert)

Definition at line 861 of file stepper.c.