Converting 4 phase stepper signal to STEP/DIR standard

Hi everybody!

I'm quite new to Arduino and I would like to ask you for help.
I have an advanced controller for stepper motor that originally sends out 4 phase power signal (A-A' and B-B' coils) directly to motor.
But for a few reasons I want to change the stepper motor into a different one which has built in controller that requires STEP/DIR signal.
I couldn't find any ready converters like that so I decided to make my own with Arduino nano. It is very simple from the electronics side, but I have no idea how to write the sketch :slight_smile:
So could anyone help me with developing the idea method of software interpreting signals from four inputs so that on two outputs I get STEP and DIR signal?
I suppose it is very easy but for the newbie like me it seems like black magic :slight_smile:
I would be grateful for any tips.

Thanks in advance
Chris

I don't understand why you want to get away from a specialized stepper driver that takes step and direction signals. They are much more suitable for controlling stepper motors than any other DIY alternative.

...R
Stepper Motor Basics
Simple Stepper Code

Hi Robin and thanks for fast response.

To make a long story short: this device I have is just a 4 phase switch without any current driver, chopper or anything. It was designed for little, low power motors (12 V, 0,5 A max.) and I need to drive something more powerful. But I need to remain all the features of the original controller (it’s USB controlled with ASCOM compatibility and many usefull options I couldn’t find in any other gear). So the only reasonable way for me is to make a converter, which shouldn’t be complicated if I only know how to write the sketch :slight_smile:
I’m even willing to pay for the code if anyone would be kind enough to spend some time and write it for me.

C.

It seems to me that you need to select a suitable stepper motor driver that can comfortably deliver the current required by your motor and use an Arduino to control the stepper driver. As you have not provided details of the motor I can't suggest a driver.

If you just want someone to write a program for you please ask in the Gigs and Collaborations section of the Forum and be prepared to pay. However you will need to be able to tell them precisely what hardware you are using and you will have to do all the testing unless the programmer has identical hardware.

If you want the Arduino program to behave like some other device you will need to be able to provide full details of the other device. And testing for compatibility, especially for edge cases, could be time consuming.

...R

The problem is that I need to use the original USB Focuser 2 device which is controlled via ASCOM platform. But this is just a simple switch with no current limiting and capable of max. 1 A.
The stepper I want to use is: 43H4P-2.33-807 and it's current is 1.5 A.
After I connect those two directly it works but the chip in Focuser heats up very fast and turns off due to thermal protection. Another thing is that this USB Focuser has only half-step control, so it tugs stepper a bit and I want a smooth movement. So I added A4988 driver to the stepper and I need to find the way to control it's DIR/STEP inputs with 4 phase outputs of the switch.

entik:
The problem is that I need to use the original USB Focuser 2 device which is controlled via ASCOM platform.

You have not provided nearly enough information about that for me to have a clue what it is or how it works.

A DRV8825 stepper driver will be suitable for your 1.5 amp motor. You can read all about them on the Pololu website. They are widely available.

...R

All details about USB Focuser 2 you can findHERE. Oryginaly it is in French but you can switch to English. As I wrote before it is just a simple switch with four outputs but it cooperates with ASCOM software for telescopes that I need to use. That is why I can't control stepper from Arduino and I need this USB Focuser device.

DRV8825 is nearly exactly the same as A4988 driver that I use. But both of them require STEP/DIR signal that USB Focuser does not provide.

entik:
DRV8825 is nearly exactly the same as A4988 driver that I use. But both of them require STEP/DIR signal that USB Focuser does not provide.

I'm lazy. It would take me too long to make sense of your link.

You say the USB Focuser does not provide step and direction signals - what does it provide?

I suspect you could use an Arduino to interpret the output from the Focuser and produce appropriate signals for the A4988.

Another VERY IMPORTANT issue is the voltage of the output from the Focuser. Anything outside 0v to 5v will damage an Arduino.

...R

Robin2:
You say the USB Focuser does not provide step and direction signals - what does it provide?

I wrote it in the very first post :slight_smile:
"I have an advanced controller for stepper motor that originally sends out 4 phase power signal (A-A' and B-B' coils) directly to motor." It has simple 4 outputs which switch voltage in correct order to drive a stepper motor with two coils (4 wires).

Robin2:
I suspect you could use an Arduino to interpret the output from the Focuser and produce appropriate signals for the A4988.

Robin, that is exactly what I was asking for in the firs post :slight_smile: How to write a sketch for Arduino to convert 4 wires direct signal for stepper into STEP/DIR signals for A4988? I don't know how to put it simpler :slight_smile:

entik:
I don't know how to put it simpler :slight_smile:

What is clear now was not so clear from your Original Post on its own.

You have not said what voltage the Focuser produces - and if it is not clear from its documentation you may need an oscilloscope to measure it because the pulses may be too short to measure with a multimeter.

I believe that to drive a stepper motor the A and A' connections are sometimes 0v and Xv and other times Xv and 0v. I don't think you can detect those directly with an Arduino (because the GND swaps from one to the other) unless you can get a separate connection between the Focuser GND and the Arduino GND. If you can get a connection to the Focuser GND then you should be able to connect the 4 lines to Arduino I/O pins and detect whether each one is HIGH or LOW. There is a well defined pattern for the succession of pulses.

This is the step sequence from a program I have written for a 28BYJ-48 stepper motor. I think it is the same for other types of motor. The order in which the sequence operates determines the direction

switch(stepSequence){
    case 0:
         digitalWriteFast(stepperPin1, HIGH);
         digitalWriteFast(stepperPin2, HIGH);
         digitalWriteFast(stepperPin3, LOW);
         digitalWriteFast(stepperPin4, LOW);
        break;
    case 1:
         digitalWriteFast(stepperPin1, LOW);
         digitalWriteFast(stepperPin2, HIGH);
         digitalWriteFast(stepperPin3, HIGH);
         digitalWriteFast(stepperPin4, LOW);
        break;
    case 2:
         digitalWriteFast(stepperPin1, LOW);
         digitalWriteFast(stepperPin2, LOW);
         digitalWriteFast(stepperPin3, HIGH);
         digitalWriteFast(stepperPin4, HIGH);
        break;
    case 3:
         digitalWriteFast(stepperPin1, HIGH);
         digitalWriteFast(stepperPin2, LOW);
         digitalWriteFast(stepperPin3, LOW);
         digitalWriteFast(stepperPin4, HIGH);
        break;
}

If you can't get a separate GND for the Focuser then I reckon I am out of my depth. Hopefully someone else will come along who is better at electronic circuits.

...R

Internal electronics of Focuser is powered from 5V from USB. But as I wrote before the outputs are just a simple Mosfet switches not connected with internal power and they require external voltage to be connected. So I can decide how high it is. Therefore I can have a common ground with Arduino. I can also use optocoupler for safety. But I don't worry about electronics. It is simple for me as I am electronics engineer.
The ONLY concern I have is how to write a sketch that will detect a step sequence from Focuser outputs (just the sequence of High and Low states) and convert them to apropiate step and dir signals on other two outputs. As I see it there definitely has to be some function that will check in what order states of all 4 inputs are changing and convert it to correct state of DIR output. Then another function should check if states on 4 inputs are changing and if yes it generates STEP pulses on STEP output. That is theory :slight_smile: But how to code it in practice? No idea :slight_smile:

entik:
To make a long story short: this device I have is just a 4 phase switch without any current driver, chopper or anything. It was designed for little, low power motors (12 V, 0,5 A max.) and I need to drive something more powerful.

If you were to put a bi-color led and a suitable resistor on a+,a- and a addition setup on b+,b-. Then send commands to “move” through your software. You should be able to document each step and figure out the truth table used.

Going to the Arduino could be as simple as using two “color” sensors to watch those LEDs.

Slumpert:
If you were to put a bi-color led and a suitable resistor on a+,a- and a addition setup on b+,b-. Then send commands to “move” through your software. You should be able to document each step and figure out the truth table used.

That’s a very good idea. But rather than using different colours just use all white LEDs wired in reverse for each pair of wires so one is on when the other is off. Then use 4 photo-transistors to detect when an LED is ON.

I would expect the truth table to be very like (if not identical to) what I posted in Reply #9.

If you treat the 4 states as 4 binary values then they will be 1100 (12 decimal) 0110 (6) 0011 (3) and 1001 (9). If you connect the photo transistors to 4 pins on the same port you can get those number with a simple Port read. Each change will constitute a step. The order the numbers appear will determine the direction.

…R

If controller always has a default start position “which it likely would”.

He would not even need to store all the positions. Just the first forward port read value and the first backward port read value.

Once you know what direction your first movement was in, you just need to remember the prior value to determine direction for the step. If the new value = previous value your going backwards, if the new value = something else you must be going forward.

Slumpert:
If controller always has a default start position “which it likely would”.

He would not even need to store all the positions. Just the first forward port read value and the first backward port read value.

Once you know what direction your first movement was in, you just need to remember the prior value to determine direction for the step. If the new value = previous value your going backwards, if the new value = something else you must be going forward.

Can you explain your thinking in more detail. I can't make this fit my mental image of how the thing works.

I suspect there is no start position and it just works on the basis of morve-clockwise or move-anticlockwise and the human operator provides the limits.

...R

I am going to refer to the voltage state of the 4 wires from the controller as “input”.

At first I was thinking he would need to have a lookup table for each input in step order and then compare positions in the table to the previous position in the table to determine the step direction.

But then I was thinking his controller likely has a default output on power up that it always goes too. (Indeed I know high end controllers can store last state in fram or similar but this is not a high end controller)

So we can code for the initial power up of the controller and await for the “default” input before enabling the stepper driver.

Now we just need to know the very first value we will see as input when the controller outputs either a forward or backward step. So when the input changes, if it matched forward step we know to set direction pin high then step, else we know to set direction pin low then step.

Now the code just needs to compare the current input too two variables. “Last input value” to see if there is a change. If there is a change compare current input to “Previous input value” to see if we reversed direction. If we didn’t reverse then current input must be signal to take new step in current direction

Now we update “Previous input value” to equal “Last input value” and then “Last input value” to equal current input, and we are ready to compare input against those two variables for the loop.

In short, we know where we have been, so we know which direction to send the next step without having to lookup all possible input options.

Slumpert:
In short, we know where we have been, so we know which direction to send the next step without having to lookup all possible input options.

I don’t think that is significantly different from what I had in mind - you have just expressed it in more detail.

If the change from one input number to the next signifies the direction then I don’t think there is any need to make special provision for the starting direction. Just do nothing until the second input is detected. That way it makes no difference whether the Arduino is started before the Focuser or vice versa.

…R

Hmmm... I get your way of thinking but I have no idea about truth tabels or switch strings, so I have to learn more before I'll uderstand how to write a sketch out of your tips :slight_smile: Anyway thanks for help and please continue :slight_smile:
And just one more thing. I don't need to use LEDs or phototransistors as I can directly connect focuser outputs when powered from 5 V.

entik:
And just one more thing. I don’t need to use LEDs or phototransistors as I can directly connect focuser outputs when powered from 5 V.

That will work if you also have GND connection from the focuser’s stepper control system. Then you can connect the GND to the Arduino GND and the 4 outputs to 4 Arduino input pins.

However if you don’t have a GND connection from the focuser then the LED solution will work without it. Of course it does require more hardware on the Arduino side.

As a separate comment, while thinking about how to solve the problem is very important I reckon it is equally important to do some tests to learn how little parts of the system work. The knowledge from the tests can then feed into the overall design.

…R

I looked at the USB Focuser 2 sales specs and it is listed as supporting 5 wire unipolar steppers.

You could use that configuration to go directly to the Arduino pins from the USB Focuser 2.

If you connect them to pin 4,5,6,7 and ground, you could read them with a PortD call.