Stepper motor controller SNAP protocol

From RepRap
Revision as of 02:07, 3 April 2006 by SimonMcAuliffe (talk) (version migrated from twiki)
Jump to: navigation, search

Stepper Motor Controller

Pinouts

When programmed into a PIC16F628 (default), the pinouts are:

Device pinouts

  1. RA2/AN2/Vref ...... Sync bus connection (A)
  2. RA3/AN3/Cmp1 ...... Sync bus connection (B)
  3. RA4/T0CK1/Cmp2 .... Not used
  4. RA5/MCLR/Vpp ...... Maximum optointerrupter input
  5. Vss ............... Ground
  6. RB0/INT ........... Minimum optointerrupter input
  7. RB1/RX/DT ......... RX
  8. RB2/TX/CK ......... TX
  9. RB3/CCP1........... Stepper enable/PWM output
  10. RB4/PGM ........... Stepper output 1
  11. RB5 ............... Stepper output 2
  12. RB6/T1OSO/T1CK1/PGC Stepper output 3
  13. RB7/T1OS1/PGD ..... Stepper output 4
  14. Vdd ............... +5V
  15. RA6/OSC2/CLKOUT ... Not used
  16. RA7/OSC1/CLKIN .... Not used
  17. RA0/AN0 ........... Not used
  18. RA1/AN1 ........... Not used

API

[0] Get Version

Returns the version of the module. This message is the only message universally supported by all devices and is therefore useful as a test.

Parameters:

  • None

Returns:

  • 1 byte: Response type (0)
  • 1 byte: minor version number
  • 1 byte: major version number

[1] Set forward motion

Starts the motor turning indefinitely in a forward direction. If the motor reaches the maximum position sensor (as defined by the maximum optointerrupter input), motion will stop.

Parameters:

  • 1 byte: Speed to turn (0 to 255)

Returns:

  • Nothing

Notes: A speed of 0 will hold the current motor position. Use command [6] to power down the motor and let it turn freely.

[2] Set reverse motion

Starts the motor turning indefinitely in a reverse direction. If the motor reaches the minimum position sensor (as defined by the minimum optointerrupter input), motion will stop.

Parameters:

  • 1 byte: Speed to turn (0 to 255)

Returns:

  • Nothing

Notes: A speed of 0 will hold the current motor position. Use command [6] to power down the motor and let it turn freely.

[3] Set position counter

Parameters:

  • 1 byte: low order byte of 16 bit position counter
  • 1 byte: high order byte of 16 bit position counter

Returns:

  • Nothing

[4] Get position counter

[5] Seek to position

Parameters:

  • 1 byte: Speed to move (1 to 255)
  • 1 byte: low order byte of 16 bit position counter
  • 1 byte: high order byte of 16 bit position counter

[6] Power down motor (torque off)

Powers the stepper motor down so that it can freely turn. This is accomplished by dropping the enable line and the four stepper outputs.

Parameters:

  • None

Returns:

  • Nothing

[7] Enable asynchronous notifications

[8] Prepare for synchronised movement

[9] Calibrate

[10] Get motion range

[11] DDA; follow a co-ordinated line of motion

[12] Forward a single step

Parameters:

  • None

Returns:

  • Nothing

[13] Reverse a single step

Parameters:

  • None

Returns:

  • Nothing

[14] Set motor power

Set the power output to the stepper motor. This is useful where output power must be limited to prevent damage to a motor. By default, for safety reasons, the driver starts in a low current mode. To enable full power output this function must be called first.

Note: This function has no effect if RB3 is not connected to the motor driver enable line (eg if it is held permanently on).

[15] Get raw sensor inputs

Primarily for debugging and diagnostic purposes, but possibly also useful for reporting.

Parameters:

  • None

Returns:

  • 1 byte: Response type (15)
  • 1 byte: PORTA inputs
  • 1 byte: PORTB inputs

Firmware

The driver firmware works with either a unipolar or bipolar motor.

PIC16F628 code images are included below. The three images are put one on each axis and provide controllers on network addresses 2, 3 and 4.

See Also

See Building A Stripboard Stepper Controller for construction details of a stripboard version for use with a unipolar stepper motor. See Building a bipolar stripboard stepper controller for a version that works with a bipolar motor.

-- Main.SimonMcAuliffe - 30 Dec 2005