Set up ⁄ control a stepper motor
VERSION 1.20+ of the firmware
Description:
This is a USBm.dll function that controls the two channels of stepper motor digital signals.
Please note: The stepper motor capabilities of the U401⁄U421 provide the digital level control signals for stepper motor driver interfacing. Driver circuitry is required between the U4x1 and the stepper motor – the U4x1 device can not provide the current⁄voltage required to directly drive a stepper motor. Please see the application notes for more information.
Command Syntax: (USBm.dll)
USBm_Stepper( device, channel, enable, direction, type, initial, rate )
The USBm_Stepper function syntax has these parts:
Part | Description |
device | A zero-based index to address the appropriate USB device. |
channel | Stepper channel that this command controls. The U4x1 has two stepper channels, this value can only be 01h or 02h. |
enable | Enables the pattern output on the pins associated with the channel. 1h would enable that channel to cycle through the stepper sequence, 0h would stop the sequence. The initial value for the sequence is accepted only when this byte is 0h. |
direction | Direction of the step sequence, and thus the direction of the motor travel. The actual direction depends on motor wiring. Valid values are 0h and 1h. |
type | Step type. Should be set to 1h for wave stepping and full stepping, and set to 0h for half stepping. |
initial | Initial state of the stepper pattern. This should only be set to 3h, for Full and Half stepping, and to 1h for wave stepping. The initial value is only transferred when enable is 0 (disabled). |
rate | Step rate (time between stepper pattern changes). The actual rate is this value times 128 microseconds. |
steps | Number of steps. FFh is continuous, 00h is off. VERSION 1.50+ of the firmware, VERSION 60+ of the DLL |
Remarks:
This command does not set the port direction pins. Therefore a DirectionA would be required to set the correct port pins to be outputs.
Stepper Channel 1 controls the lower nibble of port A. Port A.0, A.1, A.2, A.3.
Stepper Channel 2 controls the upper nibble of port A. Port A.4, A.5, A.6, A.7.
The enable, direction, type, initial value, and rate apply to each channel, such that two steppers can run in different directions and at different rates.
VB Declaration
Public Declare Function USBm_Stepper _ Lib “USBm.dll” _ (ByVal device As Byte, _ ByVal channel As Byte, _ ByVal enable As Byte, _ ByVal direction As Byte, _ ByVal steptype As Byte, _ ByVal initial As Byte, _ ByVal steprate As Byte) _ As Integer |
VB Example
USBm_Stepper 3, 1, 0, 0, 1, 3, 50 |
This code fragment addresses device #3 and disables stepper channel 1. It sets the direction (0), step type (1), initial value (3) and step rate (to 50).
C Prototype
int USBm_Stepper( unsigned char device, unsigned char channel, unsigned char enable, unsigned char direction, unsigned char type, unsigned char initial, unsigned char rate ); |
C Example
⁄⁄ Run the stepper motor USBm_Stepper( 3, 1, 0, 0, 1, 3, 50 ); |
This code fragment addresses device #3 and disables stepper channel 1. It sets the direction (0), step type (1), initial value (3) and step rate (to 50).
RobotBASIC
usbm_Stepper(ne_DeviceNumber,se_DataSpecs)
Returns true if successful, false otherwise. The byte data string specifies the channel and so forth.
Raw Command Format:
Byte Number | Description |
0 | 1Ch: StepperCmd |
1 | Channel – Stepper channel number. There are two available channels. |
2 | Control – Stepper channel control byte. |
3 | Rate – Stepper channel step rate. |
4 | Steps – number of steps VERSION 1.50+ of the firmware, VERSION 60+ of the DLL |
5 | <not used> |
6 | <not used> |
7 | <not used> |
Raw Command Format Details:
Byte 0 contains the command. Byte 1 contains the channel that this command controls. The U4x1 has two stepper channels, this value can only be 01h or 02h.
Byte 2 is the stepper control byte. The format of this byte is divided into bit fields.
Bits 3, 2, 1, and 0 are the initial state of the stepper pattern. These bits should only be set to 3h, for Full and Half stepping, and to 1h for wave stepping. The initial value is only transferred when Bit 7 is 0 (disabled).
Bit 4 sets the step type and should be set to 1h for wave stepping and full stepping, and set to 0h for half stepping.
Bit 6 sets the direction of the step sequence, and thus the direction of the motor travel. The actual direction depends on motor wiring. Valid values for this bit are 0h and 1h, naturally.
Bit 7 enables the pattern output on the pins associated with the channel. 1h would enable that channel to cycle through the stepper sequence, 0h would stop the sequence. The initial value for the sequence is accepted only when Bit 7 is 0h.
Byte 3 contains the step rate (time between stepper pattern changes). The actual rate is this value times 128 microseconds.
Byte 4 contains the number of steps to execute, from 1 to 254. 00h is stop, FFh is continuous.
This command does not set the port direction pins. Therefore a DirectionACmd would be required to set the correct port pins to be outputs.
Stepper Channel 1 controls the lower nibble of port A. Port A.0, A.1, A.2, A.3.
Stepper Channel 2 controls the upper nibble of port A. Port A.4, A.5, A.6, A.7.
The enable, direction, type, initial value, and rate apply to each channel, such that two steppers can run in different directions and at different rates.
Raw Command Response Format:
Byte Number | Description |
0 | 1Ch: StepperCmd |
1 | <not used> |
2 | <not used> |
3 | <not used> |
4 | <not used> |
5 | <not used> |
6 | <not used> |
7 | <not used> |
Raw Command Response Format Details:
Byte 0 contains the command. Byte 1 through byte 7 are unused.