Introduction
In this post, we will control the speed of a servo motor 57HSE2N-D25. For this we will also need a driver, HSS57 Hybrid Servo Driver, for the servo motor that will be connected to our Arduino based PLC for the automation of the speed control. For the software, a pulses.h library is implemented ( software without using pulses.h library is also attached).
Requirements
- Ethernet PLC:Â Â Ethernet PLC >>>Â Â Â Â
- HSS57 Hybrid Servo Driver:Â Â HSS57 Hybrid Servo Driver >>>
- 57HSE2N-D25 Servo motor:Â Â 57HSE2N-D25 >>>
- Pulses.h: Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Pulses Library - Github Repository >>>
- Industrial Shields boards:Â Â How to use the mapping pins of Industrial Shields boards >>>
Connections
Servo Motor - Driver connections:
Red   ->    A+
Green   ->    A-
Yellow  ->      B+
Blue  ->    B-
Ethernet PLC - Driver connections:Â
PIN 3Â Â ->Â PUL - (pulses)Â Â Â Â
PIN2Â Â ->Â DIR- (rotational direction)
PIN 50 (MISO)Â ->Â ENA- (enable)Â Â Â Â Â Â Â Â Â Â Â
GNDÂ Â -> PUL- , DIR - , ENA -
* Signals = 5Vdc
*Remember to power supply the PLC between 12 and 24V.
*In this case we are using 5V signal, so, no resistors are needed between PUL+,ENA+, DIR+Â and PIN2, PIN3, PIN50.
*Controller is M-Duino 21+
*Encoder is not used in this post
Software
Using this sketch you are able to control the speed of the stepper, direction and number of revolutions.
Change PIN2 to control the direction, change NUM_REVOLUTIONS to decide how many revolutions do you require and change FREQ to change 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() {
}
Â
Â
Servo Motor with Arduino based PLC