# I need programming help

I need help programming.
I want to control a stepper motor with microstep.
I have the motor and the driver.
The driver is a box that fixes everything with phases, current etc,
The driver has only 2 inputs, step puls and direction, both 0-5 volt. (= equals directly connectable to Audrino)
The motor has 200 steps per revolution, the driver needs 128 microstep pulses to make the motor move one full step.
This means that a total of 200 * 128 = 25600 pulses are needed for one motor revolution.
I want the motor to be able to run rather fast, the maximum number of pulses the driver accepts is
200 000 pulses per second, meaning the max possible speed of the motor would be almost 8 revs per second. This is acceptable for me.
The reason for microstepping is the very quiet motor performance, and also very smooth drive.
I want to control the motor at this stage from a joystick.
The analogue input on the Arduino is acceptable with the 1024 resolution.
I also want to know where the motor is, so a 32 bit positioning is desireable.
Also, I would need a "homing" routine at cold start.
The Project is to control a camera along a track.
I have all the needed hardware, such as gears, pulley, wheels, track etc, including the swithch at one end producing the homing pulse.

Yours

This demo has some simple code to drive a motor with a driver that requires step and direction signals. When you get it working you can adjust the variables to experiment with speeds.

Usually if high speeds are required micro-stepping is not used.
200,000 pulses per second is 1 pulse every 5 microseconds. You may get a 16MHz Arduino to do that, but it won't be able to do anything else.

...R

Yes, excactly, one puls every 5 microseconds.
Is if possible to write a effective Arduino code that will perform that?
Including updating a 32 bit position register? (The track is several meters long)
Including A/D from the joystick?
Is this at all possible with Arduino?
Can anyone help me with writing such an effective code?

Yours

Yes, excactly, one puls every 5 microseconds.
Is if possible to write a effective Arduino code that will perform that?
Including updating a 32 bit position register? (The track is several meters long)
Including A/D from the joystick?
Is this at all possible with Arduino?

Try some "back-of-an-envelope" maths

The Arduino does 16 instructions per microsec - less if there are branching instructions that need 2 clock cycles.

How many Arduino cycles are needed to make a pulse pin go high, wait for (say) 1 microsec (what is the minimum pulse length required by your stepper driver?) and then make the pulse pin go low

How many cycles are needed to update 4 bytes (for a 32 bit value)

How many cycles are needed to read an analog value?

How many cycles are needed to figure out when it is time to read the analog value?

Are all these cycles likely to add up to less than 80?

I don't think so.

...R

I Think you might be quite correct.
I now understand that I am on thin ice.
Do you think it would still be out of reach if we used the Arduino Due, with 80 MHz and 32 bus?

Yours