Stepper motor controller SNAP protocol

From RepRap
Revision as of 14:03, 23 July 2015 by Glenn (talk | contribs) (catchg)
Jump to: navigation, search

This page documents the SNAP Protocol stepper motor controller used in the Generation 1 Electronics and Generation 2 Electronics. For more recent G-code protocol stepper motor controllers, see stepper motor driver and list of electronics.

Stepper Motor Controller SNAP Protocol Version 0

This is the first version of the stepper driver command protocol, version 0. It communicates using the SNAP communication protocol, and accepts various commands for controlling both a single stepper controller, as well as doing coordinated movement with multiple stepper motors.

API

The following commands are in addition to the globally required commands on the main modules page.

[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

Parameters:

  • Nothing

Returns:

  • 1 byte: low order byte of 16 bit position counter
  • 1 byte: high order byte of 16 bit 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

Tells the stepper board to notify the host when it has reached the target for its mode (position, home, etc.)

Parameters:

  • 1 byte: address to notify (generally host)

Returns:

  • Nothing

Upon notification, the board will send a SNAP packet to the notification address that contains different data, depending on the type of notification.

Completion of rome/reset

  • 1 byte: 16 (home/reset command value)

Completion of calibration:

  • 1 byte: 9 (calibration command value)
  • 1 byte: low order byte of 16 bit maximum position counter
  • 1 byte: high order byte of 16 bit maximum position counter

Completion of seek:

  • 1 byte: 5 (seek command value)
  • 1 byte: low order byte of 16 bit current position counter
  • 1 byte: high order byte of 16 bit current position counter

Completion of DDA:

  • 1 byte: 11 (DDA command value)
  • 1 byte: low order byte of 16 bit current position counter
  • 1 byte: high order byte of 16 bit current position counter

[8] Prepare for synchronised movement

Parameters:

  • 1 byte: sync mode for the stepper motor. based on the table below:

Returns:

  • Nothing
Value Meaning
0 no sync (ignore sync pulses)
1 synchronized seeking (not sure if this is used)
2 incremental sync. move stepper forward 1 step each sync pulse
3 decremental sync. move stepper backward 1 step each sync pulse

[9] Calibrate

Initiates the calibration routine. This consists of seeking to home/minimum sensor, setting position to 0, then seeking to maximum sensor and recording the maximum position.

Parameters:

  • 1 byte: Speed to move (1 to 255)

Returns:

  • Nothing

[10] Get motion range

Parameters:

  • 1 byte: 10 (get range command value)
  • 1 byte: low order byte of 16 bit maximum position counter
  • 1 byte: high order byte of 16 bit maximum position counter

Returns:

  • Nothing

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

Starts a DDA movement where the X/Y axis move in a coordinated fashion to draw a straight line where they both start and stop at the same time.

Parameters:

  • 1 byte: Speed to move (1 to 255)
  • 1 byte: low order byte of 16 bit master's target
  • 1 byte: high order byte of 16 bit master's target
  • 1 byte: low order byte of 16 bit slave's delta (which is abs(slave.current_position - slave.target_position))
  • 1 byte: high order byte of 16 bit slave's delta (which is abs(slave.current_position - slave.target_position))

Returns:

  • Nothing

[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

There are two different versions of firmware: older, stable firmware designed for the PIC16F648 and newer firmware designed for the Arduino. They both function identically, and accept the same commands.

PIC Based Firmware

The PIC based firmware is based upon each individual stepper controller board having its own individual PIC chip. Each board gets programmed with its own unique firmware. The three firmwares provide controllers on network addresses 2, 3 and 4.

PIC16F628 code images and source are available from SourceForge.

More information on the electronics required to process the commands is located at Generation 1 Electronics.

Arduino Based Firmware

The Arduino is a much more powerful microcontroller board based on the ATmega168, and we provide a firmware for it that emulates 3 individual stepper motor boards. From the perspective of the host software, it operates completely identical. The emulated controllers are on network addresses 2, 3, and 4.

Arduino firmware is available from SourceForge.

More information on the electronics required to process the commands is located at Generation 2 Electronics.