| Online Development Notebook > Index > ODN > USBm DLL Programming > Device Commands > Stepper |
Stepper
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 transfered 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
| 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).
| Hardware: U401 USB Interface U421 USB Interface |
| Programming: USBm DLL Programming Download Files |
| Application Notes: U4x1 Application Notes Misc Applications and Information FAQ |