Set up dir and pulse pins

Hi guys, my mission is to set up an external 240v servo driver, just need forward, reverse, and speed control,
I have had it running via mach3 but don't want to have a full pc setup, I know this has been asked before but I just can't find the right setup for what I need, basically just want speed control via a pot, and directional control with 3 way switch, I finally got it working thru Arduino but only one direction and very(very) slow with borrowed code from Arduino for dummies, lol, any help would be great,
The servo drive takes pp+ pp- ( pulse)pd+ pd- (direction)up to 12v p- is common, I'm thinking I just don't have the right wave frequency going in?

Since you've provided absolutely information about the "external 240v servo driver" it's difficult to know how to help. A link to a datasheet might be useful. Also please post the code you are currently using that almost works.

Steve

Hi Steve

The driver is Chinese model as are the instructions, sort of half english, it's a 2.3kw driver, from fasttobuy.com, to large to post, will get info from it in morning
The code I can't locate anymore but it doesn't seem to work anymore after restart so I think it was just luck it worked at all

This is what I need code for, if it exists

Found this

Will it work?

Thanks for any input, starting to lose sleep, lol

Arduino-Stepper-Hookup.jpg

Image from Reply #3 so we don't have to download it. See this Simple Image Guide

Arduino-Stepper-Hookup.jpg

...R

In your Original Post you say that you want to control "an external 240v servo driver"

Your link and your picture both refer to stepper motors - which is it?

I understand that there may be some similarities between the control of your servo and the control of a stepper motor but I presume the reason you are asking for help is because the differences are causing you a problem. Without details of the actual motor and driver that you have, how can we help?

...R

Hi Robin2

Yeah I've had it running set up exactly as pictured, swap the stepper driver for the servo driver, running it from a mach3 breakout board,
The drive unit is just a signal amp, jumping the 5v input up to 240v output,
There must be a way to replicate the output of the mach3 board, yeah?

I am not familiar with Mach3 or your Mach3 breakout board. Can you post a link to the datasheet for the breakout board?

If your servo driver is interchangeable with a stepper driver then I would expect this Simple Stepper Code to be suitable for testing. If there is an enable pin you may also need to set that correctly.

It may help with your diagnostics if you have a stepper motor and stepper motor driver that you can get working first with my code. Then you can substitute your servo driver (and servo motor) in the knowledge that the code works.

...R

Hi Robin

This is the code I had working very slow

/*
Stepper Motor Control - speed control

This program drives a unipolar or bipolar stepper motor.
The motor is attached to digital pins 8 - 11 of the Arduino.
A potentiometer is connected to analog input 0.

The motor will rotate in a clockwise direction. The higher the potentiometer value,
the faster the motor speed. Because setSpeed() sets the delay between steps,
you may notice the motor is less responsive to changes in the sensor value at
low speeds.

Created 30 Nov. 2009
Modified 28 Oct 2010
by Tom Igoe

*/

#include <Stepper.h>

const int stepsPerRevolution = 1500; // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 3, 6, 4, 5);

int stepCount = 0; // number of steps the motor has taken

void setup() {
// nothing to do inside the setup
}

void loop() {
// read the sensor value:
int sensorReading = analogRead(A0);
// map it to a range from 0 to 100:
int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
// set the motor speed:
if (motorSpeed > 0) {
myStepper.setSpeed(motorSpeed);
// step 1/100 of a revolution:
myStepper.step(stepsPerRevolution / 100);
}
}

There is something seriously wrong with this

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 3, 6, 4, 5);

In any case the regular Stepper library is not suitable for a stepper driver that takes step and direction signals. Either use the code I gave you a link for, or use the AccelStepper library.

...R

I changed the pin numbers to suit the input pins on drive,
Will try your code, after work,
Thanks man, will let you know

Got home, plugged in the board, lights up but nothing happening, Windows won't connect, no com3, google researched, full uninstall reinstall, still no go, can jump 2 pins to force usb to run but won't install drivers,
Stuffed?

I have another board, uno with wifi, runs but won't load sketch, sdk500 sync error, tryed other board settings, no luck,

I am not familiar with Windows but I suspect you will need to provide a lot more detail before people can understand exactly what you are having a problem with.

I suggest you disconnect everything from your Uno and just try to upload the BLINK demo. If that works change the blink period and try to upload the revised program.

...R

Hi guys, so got new board,
Running this code :

/*

Stepper Motor Test

stepper-test01.ino

Uses MA860H or similar Stepper Driver Unit

Has speed control & reverse switch

DroneBot Workshop 2019

*/

// Defin pins

int reverseSwitch = 2; // Push button for reverse

int driverPUL = 7; // PUL- pin

int driverDIR = 6; // DIR- pin

int spd = A0; // Potentiometer

// Variables

int pd = 500; // Pulse Delay period

boolean setdir = LOW; // Set Direction

// Interrupt Handler

void revmotor (){

setdir = !setdir;

}

void setup() {

pinMode (driverPUL, OUTPUT);

pinMode (driverDIR, OUTPUT);

attachInterrupt(digitalPinToInterrupt(reverseSwitch),revmotor, FALLING);

}

void loop() {

pd = map((analogRead(spd)),0,1023,2000,50);

digitalWrite(driverDIR,setdir);

digitalWrite(driverPUL,HIGH);

delayMicroseconds(pd);

digitalWrite(driverPUL,LOW);

delayMicroseconds(pd);

}

Everything works, just the speed is an issue,
As is I get 1 up to 19 rpm
I changed pd = map from 2000 up to 5000 and got 1 up to 36 rpm but if I increase it any higher it stays at 36 rpm but won't go back to 1
I have a 50k pot and noticed most people use 10k ?
9v 1.6amp psi, maybe need a 12v?

I'm happy it's working but need speed range 1 up to 1400 rpm

As always any help would be awesome

Trajan17:
As always any help would be awesome

Good to hear you are making progress, but please post your code properly and make sure to omit unnecessary blank lines.

When posting code please use the code button </>
codeButton.png

so your code 
looks like this

and is easy to copy to a text editor See How to use the Forum

Also please use the AutoFormat tool to indent your code for easier reading.

...R

/*

  Stepper Motor Test

  stepper-test01.ino

  Uses MA860H or similar Stepper Driver Unit

  Has speed control & reverse switch

  

  DroneBot Workshop 2019

  https://dronebotworkshop.com

*/

 

// Defin pins

 

int reverseSwitch = 2;  // Push button for reverse

int driverPUL = 7;    // PUL- pin

int driverDIR = 6;    // DIR- pin

int spd = A0;     // Potentiometer

 

// Variables

 

int pd = 500;       // Pulse Delay period

boolean setdir = LOW; // Set Direction

 

// Interrupt Handler

 

void revmotor (){

 

  setdir = !setdir;

  

}

 

 

void setup() {

 

  pinMode (driverPUL, OUTPUT);

  pinMode (driverDIR, OUTPUT);

  attachInterrupt(digitalPinToInterrupt(reverseSwitch),revmotor, FALLING);

  

}

 

void loop() {

  

    pd = map((analogRead(spd)),0,1023,2000,50);

    digitalWrite(driverDIR,setdir);

    digitalWrite(driverPUL,HIGH);

    delayMicroseconds(pd);

    digitalWrite(driverPUL,LOW);

    delayMicroseconds(pd);

}

You have not removed all the unnecessary blank line in your code - they make it very hard to read quickly.

With a microsecs range from 2000 to 50 (which is doubled to 4000 to 100 because your code uses it twice) you have step rates varying from 250 per sec to 10,000. If you are not using microstepping then 10,000 per second is fast.

Stepper motors need a high supply voltage if they are to work at higher speeds - just be careful to respect the max for the stepper driver and ensure that the current limit on the driver is set at the appropriate limit for the motor.

...R