Leisai Motion Control Card Programming: Limit Switch Configuration, Homing Modes, and Pulse Output Settings

  1. Limit Switch and Emergency Stop Configuration ================================================

1.1 Limit Switch Setup

The following code demonstrates how to configure limit switches using the dmc_set_el_mode function:

// Configure limit switches
// dmc_set_el_mode
ushort cardIndex = 0;
ushort axisIndex = 0;
ushort limitEnable = 1;  // Enable both positive and negative limits
ushort limitLogic = 0;  // Low-level effective for both limits
ushort stopMode = 0;    // Immediate stop for limit trigger
LTDMC.dmc_set_el_mode(cardIndex, axisIndex, limitEnable, limitLogic, stopMode);

1.2 Emergency Stop Configuration

// Emergency stop setup
LTDMC.dmc_set_emg_mode(cardIndex, axisIndex, limitEnable, limitLogic);

  1. Homing Configuration =======================

2.1 Homing Procedure

The homing motion involves the following main steps:

  1. Use dmc_set_home_pin_logic to set the active level of the home switch
  2. Use dmc_set_homemode to configure the homing method
  3. Set the velocity profile for homing motion
  4. Configure home offset, zero clearing after homing completion, and limit return behavior
  5. Execute homing motion using dmc_home_move function

2.2 Homing Modes

Mode 0: Single Pass Home Seeking

Suitable for short travel distances and high safety requirements. The motor moves at constant speed toward the home position. When the home switch is triggered, the motor stops immediately (Process 0). The stop position is set as the home position.

Mode 1: Single Pass Home with Return Search

This mode first performs Mode 0 motion, then reversely searches for the home switch edge position. When the home signal first becomes invalid, the motor stops immediately.

Mode 2: Dual Pass Home Seeking

This mode combines Mode 0 and Mode 1. First performs Mode 1 homing with reverse search, then performs Mode 0 single pass homing.

Mode 3: Home Seek with EZ Signal

During homing motion, after finding the home signal, the system waits for the axis EZ signal. Then the motor stops.

Mode 4: Single EZ Signal Homing

Mode 5: Home Seek with Reverse EZ Search

During homing motion, after finding the home signal, the motor decelerates to stop, then reversely searches for the EZ signal at reverse search speed. When EZ becomes active, the motor stops.

Mode 6: Home Latch

The motor returns to home at set speed. When the home switch edge is triggered, the current position is latched while the motor decelerates to stop. After stopping, the motor reversely returns to the latched position and stops.

Mode 7: Home Latch with Forward EZ Latch

This mode first executes Mode 6 home latch homing, then continues moving in the homing direction until an EZ signal is generated. When EZ signal occurs, the current position is latched and deceleration stop is executed. After the motor stops, it reversely searches for the EZ latched position and moves to that position, then stops.

Mode 8: Single EZ Latch

During homing, when a valid EZ edge is detected, the current position is latched and deceleration stop is executed. After the motor stops, it reversely searches for the EZ latched position and moves to that position, then stops.

Mode 9: Home Latch with Reverse EZ Latch

This mode first executes Mode 6 home latch homing, then moves in the opposite direction of the set homing direction until an EZ signal is generated. When EZ signal occurs, the current position is latched and deceleration stop is executed. After the motor stops, it reversely searches for the EZ latched position and moves to that position, then stops.

Mode 10: Single Limit Homing

This mode returns to home at set speed; suitable for short travel distances and high safety requirements. The motor moves at constant speed toward the limit position. When the limit switch is triggered, the motor stops immediately (Process 0). The stop position is set as the home position.

Mode 11: Single Limit Homing with Return Search

  1. Pulse Mode Configuration ===========================

3.1 Command Pulse Output Mode

3.2 Setting Pulse Output Mode for Specified Axis

3.3 Reading Pulse Output Mode for Specified Axis

  1. Function Testing ===================

4.1 Board Initialization

Closing Control Card

Control Card Hardware Reset Function

Getting Control Card Hardware ID

Getting Control Card Fimrware Version

Getting Control Card Hardware Version

Code Example

private void InitializeButton_Click(object sender, EventArgs e)
{
    short result;
    result = LTDMC.dmc_board_init();
    if (result <= 0 || result > 8)
    {
        Console.WriteLine("Initialization failed");
        return;
    }
    
    // Get all axis card IDs and firmware versions
    ushort cardCount = 0;
    uint[] cardTypeArray = new uint[8];
    ushort[] cardIdArray = new ushort[8];
    result = LTDMC.dmc_get_CardInfList(ref cardCount, cardTypeArray, cardIdArray);
    if (result == 0)
    {
        // Card number
        cardNumber = cardIdArray[0];
        // Version information
    }
    
    uint axisCount = 0;
    // Number of axes on the card
    short result2 = LTDMC.dmc_get_total_axes(cardIdArray[0], ref axisCount);
    if (result2 == 0)
    {
        axisListBox.Items.Clear();
        for (ushort i = 0; i < axisCount; i++)
        {
            axisArray[i] = i;
            axisListBox.Items.Add(axisArray[i]);
        }
        axisListBox.SelectedItem = 0;
        isInitialized = true;
    }
}

private void CloseButton_Click(object sender, EventArgs e)
{
    if (isInitialized)
    {
        LTDMC.dmc_board_close();
    }
}

4.2 Limit Switch Configuration

Setting EL Limit Signal

Setting Software Limits

Setting Arc Zone Limit Configuration

Querying Axis Status

Configuring Arc Limit Function Enable State

Code Example

public int ConfigureLimitSwitches()
{
    // Configure limit switches
    ushort cardIndex = 0;
    ushort axisIndex = 0;
    ushort limitEnable = 1;  // Enable both positive and negative limits
    ushort limitLogic = 0;  // Low-level effective for both limits
    ushort stopMode = 0;    // Immediate stop for limit trigger
    LTDMC.dmc_set_el_mode(cardIndex, axisIndex, limitEnable, limitLogic, stopMode);

    // Emergency stop setup
    LTDMC.dmc_set_emg_mode(cardIndex, axisIndex, limitEnable, limitLogic);

    // Set EL limit signal
    ushort elMode = 3;
    LTDMC.dmc_set_el_home(cardIndex, axisIndex, elMode);

    // Set whether to return when hitting limit during homing
    ushort enableReturn = 0;
    LTDMC.dmc_set_home_el_return(cardIndex, axisIndex, enableReturn);

    // Set homing offset and zero clearing mode
    LTDMC.dmc_set_home_position(cardIndex, axisIndex, enableReturn, -19);

    // Start homing in specified direction and speed mode
    LTDMC.dmc_home_move(cardIndex, axisIndex);

    // Read homing status
    ushort statusValue = 0;
    LTDMC.dmc_get_home_result(cardIndex, axisIndex, ref statusValue);

    // Set software limits
    ushort sourceSelect = 1;  // 0: Command position counter, 1: Encoder counter
    ushort limitAction = 1;   // Limit stop mode: 0: Deceleration stop, 1: Immediate stop
    ushort negativeLimit = 1000;  // Negative limit position in pulses
    ushort positiveLimit = 1000;  // Positive limit position in pulses
    LTDMC.dmc_set_softlimit(cardIndex, axisIndex, limitEnable, sourceSelect, limitAction, negativeLimit, positiveLimit);

    // Set arc zone limit configuration
    ushort[] axisList = new ushort[14];
    ushort axisNumber = 1;
    double[] centerPoint = new double[14];
    ushort radiusValue = 23;
    ushort counterSource = 1;  // Counter selection: 0: Command position, 1: Feedback position
    ushort haltMode = 1;       // Stop mode after limit trigger: 0: Deceleration stop, 1: Emergency stop
    LTDMC.dmc_set_arc_zone_limit_config(cardIndex, axisList, axisNumber, centerPoint, radiusValue, counterSource, haltMode);

    // Configure arc limit function enable state
    ushort arcEnable = 1;
    LTDMC.dmc_set_arc_zone_limit_enable(cardIndex, arcEnable);

    return 0;
}

4.3 Position Counter Control

Setting Command Pulse Position

Code Example

public int ManagePositionCounter()
{
    ushort cardIndex = 0;
    ushort axisIndex = 0;
    ushort limitEnable = 1;
    ushort limitLogic = 0;
    
    // Set command pulse position
    int targetPosition = 2222;
    LTDMC.dmc_set_position(cardIndex, axisIndex, targetPosition);

    // Read pulse position
    LTDMC.dmc_get_position(cardIndex, axisIndex);

    return 0;
}

4.4 Homing Operation

Setting ORG Home Signal

Reading ORG Home Signal

Setting Homing Mode (Important)

Important Notes:

  1. When homing mode = 4, the homing speed mode is fixed to low-speed homing
  2. DMC3C00 rear four axes only support 6 homing modes: 0, 1, 2, 10, 11, 12
  3. The last three homing modes are supported only by latest firmware (3XX201611 and later). Positive homing performs positive limit homing, negative homing performs negative limit homing; If starting homing while in limit signal, it first moves in the opposite direction of set homing direction, exits the limit signal range, then changes direction to find corresponding limit signal; Single limit homing emergency stops when encountering limit signal; Single limit homing with return search emergency stops when encountering limit signal during reverse search; Dual limit homing emergency stops when encountering limit signal for the second time

Reading Homing Mode

Limit Return During Homing

Setting Homing Offset and Zero Clearing Mode

Setting Limit Return Offset Distance

Homing Motion

Code Example

public int PerformHoming()
{
    // Set active level of home signal
    ushort cardIndex = 0;
    ushort axisIndex = 0;
    ushort homeLogic = 0;  // Home signal low-level active
    double filterParam = 0.4;  // Reserved parameter
    
    LTDMC.dmc_set_home_pin_logic(cardIndex, axisIndex, homeLogic, filterParam);

    // Select homing mode
    ushort homeDirection = 0;  // Negative direction homing
    double homeVelocity = 0;   // Low-speed homing mode
    ushort homingMode = 1;     // Mode 1: single pass homing
    ushort ezCountParam = 0;   // Reserved parameter
    LTDMC.dmc_set_homemode(cardIndex, axisIndex, homeDirection, homeVelocity, homingMode, ezCountParam);

    // Set whether to return when hitting limit during homing
    ushort enableReturn = 0;
    LTDMC.dmc_set_home_el_return(cardIndex, axisIndex, enableReturn);

    // Set homing offset and zero clearing mode
    ushort zeroClearMode = 0;  // 0: Don't clear, 1: Clear after homing then offset, 2: Clear after homing and offset complete
    LTDMC.dmc_set_home_position(cardIndex, axisIndex, zeroClearMode, 2900);

    // Set limit return offset distance
    double offsetDistance = 20;
    LTDMC.dmc_set_el_ret_deviation(cardIndex, axisIndex, enableReturn, offsetDistance);

    // Execute homing motion
    LTDMC.dmc_home_move(cardIndex, axisIndex);

    return 0;
}

4.5 Origin Latch

Setting Origin Latch Mode

Clearing Origin Latch Flag

Code Example

public int OriginLatching()
{
    ushort cardIndex = 0;
    ushort axisIndex = 0;
    ushort latchEnable = 0;  // Origin latch mode: 0: Disable, 1: Enable
    ushort triggerLogic = 0; // Trigger method: 0: Falling edge, 1: Rising edge
    ushort counterSource = 1;  // 0: Command position counter, 1: Encoder counter
    
    // Set origin latch mode
    LTDMC.dmc_set_homelatch_mode(cardIndex, axisIndex, latchEnable, triggerLogic, counterSource);

    // Clear origin latch flag
    LTDMC.dmc_reset_homelatch_flag(cardIndex, axisIndex);

    return 0;
}

4.6 Motion Status Detection and Control

Reading Stop Reason for Specified Axis

Clearing Stop Reason for Specified Axis

Reading Current Speed Value

Checking Communication Status Between Main Card and Terminal Box

Setting All Output Level States

Checking Specified Axis Motion Status

Checking Coordinate System Motion Status

Reading Motion Signal Status for Specified Axis

Stopping Specified Axis Motion

Stopping All Axes in Coordinate System

Emergency Stop All Axes

Reading Target Position of Moving Axis

Code Example

public int MonitorAndControlMotion()
{
    // Read stop reason for specified axis
    ushort cardIndex = 0;
    ushort axisIndex = 0;
    ushort outputMode = 4;
    int stopReason = -1;
    LTDMC.dmc_get_stop_reason(cardIndex, axisIndex, ref stopReason);

    // Clear stop reason for specified axis
    LTDMC.dmc_clear_stop_reason(cardIndex, axisIndex);

    // Read current axis speed
    double currentSpeed = LTDMC.dmc_read_current_speed(cardIndex, axisIndex);

    // Check communication status between main card and terminal box
    ushort connectionState = 1;  // Connection state: 0: Connected, 1: Disconnected
    LTDMC.dmc_LinkState(cardIndex, ref connectionState);

    // Set all output level states
    ushort outputState = 1;
    LTDMC.dmc_set_output_status_repower(cardIndex, outputState);

    // Check specified axis motion status
    short axisState = LTDMC.dmc_check_done(cardIndex, outputState);  // 1: Axis stopped, 0: Running normally

    // Check coordinate system motion status
    short coordState = LTDMC.dmc_check_done_multicoor(cardIndex, outputState);  // 0: In use, 1: Running normally

    // Read motion signal status for specified axis
    LTDMC.dmc_axis_io_status(cardIndex, axisIndex);

    // Stop specified axis
    ushort stopModeValue = 21;
    LTDMC.dmc_stop(cardIndex, axisIndex, stopModeValue);

    // Stop all axes in coordinate system
    LTDMC.dmc_stop_multicoor(cardIndex, axisIndex, stopModeValue);

    // Emergency stop all axes
    LTDMC.dmc_emg_stop(cardIndex);

    // Read target position of moving axis
    LTDMC.dmc_get_target_position(cardIndex, axisIndex);
    
    return 0;
}

Tags: Leisai motion control limit switch homing home seeking

Posted on Sun, 21 Jun 2026 16:22:41 +0000 by popcornplya