Thu. Jan 30th, 2025

Introduction

In this post, we will control the speed of a 57HSE2N-D25 servo motor. For this, we will also need a controller, the HSS57 Hybrid Servo Driver, which will connect to our Arduino-based PLC for speed control automation. For the software, we implement the pulses.h library (the software without using the pulses.h library is also connected).

Connections
Servo Motor – Driver Connections:

  • Red     ->       A+
  • Green   ->       A-
  • Yellow  ->       B+
  • Blue    ->       B-

Ethernet PLC – Driver Connections:

  • PIN 3   ->  PUL+ (pulses)
  • PIN 2   ->  DIR+ (rotational direction)
  • PIN 50 (MISO) ->  ENA+ (enable)
  • GND     ->  PUL-, DIR-, ENA-
  • Signals = 5Vdc
  • Remember to power the PLC with 12 to 24V.
  • In this case, we are using a 5V signal, so no resistors are required between PUL+, ENA+, DIR+, and PIN2, PIN3, PIN50.
  • The controller used is the M-Duino 21+.
  • The encoder is not used in this post.

 

Software

With this code, you can control the stepper motor’s speed, direction, and the number of revolutions.

  • Change PIN2 to control the direction.
  • Change NUM_REVOLUTIONS to set the desired number of revolutions.
  • Change FREQ to adjust the frequency (rotation speed).

Below is the code:

/*
Copyright (c) 2018 Boot&Work Corp., S.L. All rights reserved

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <Pulses.h>

#define PIN_STEPPER_PUL 3
#define PIN_STEPPER_DIR 2
#define PIN_STEPPER_ENA 50
#define STEPPER_PULSES_PER_REV 1600UL
#define FREQ (2000UL) // Hz
#define NUM_REVOLUTIONS 10
#define STEPPER_STEPS ((NUM_REVOLUTIONS) * (STEPPER_PULSES_PER_REV))

volatile uint32_t stepsCnt = STEPPER_STEPS;

ISR(TIMER3_COMPA_vect) {
if (stepsCnt) {
–stepsCnt;
if (stepsCnt == 0UL) {
stopPulses(PIN_STEPPER_PUL);
}
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
pinMode(PIN_STEPPER_DIR, OUTPUT);
pinMode(PIN_STEPPER_PUL, OUTPUT);
pinMode(PIN_STEPPER_ENA, OUTPUT);
digitalWrite(PIN_STEPPER_DIR, HIGH);
digitalWrite(PIN_STEPPER_ENA, HIGH);
// It depends on the PIN_STEPPER_PUL
TIMSK3 |= 1 << OCIE3A;
startPulses(PIN_STEPPER_PUL, FREQ, 3);
}

////////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
}

                               

sales@logicbus.com   |  support@logicbus.com   |  +1 619 616 7350    |   Start conversation

Leave a Reply

Your email address will not be published. Required fields are marked *