Adjustable speed pulse trains

Hi I have 2 stepper motors Each needs a string of pulses and iether a high or low signal to select forwards or reverse

I want to use a joystick that has 4 switches on it to control the two steppers X Left/Right and Y Up/Down and a slider pot to control speed I dont need to count pulses to move a set distance , They will move till I release the joystick

I know I can use something like

To move left If input left is high then send pulses out to the left/right motor and make its direction pin high

or to move right if input right is high then send pulses out to the left/right motor and make its direction pin low

and the same for up./down

I know I can change the speed by reading the pot value on an analogue pin

I believe using delay for making the pulse train will be a non starter and I must use millis or maybe an ISR but I dont know how to do that

How can I ( using millis or an ISR ) make a pulse train start at the speed I selected when it detects that a joystick has been activated ?

Hope someone can help

Don

Each needs a string of pulses and iether a high or low signal to select forwards or reverse

What kind of steppers? What kind of driver? Most stepper drivers need the direction pin set HIGH to rotate one way and LOW to rotate the other way. I've never heard of one that takes a string to control direction. Or even one that needs more than one change of level.

Start by having a look at these links Stepper Motor Basics Simple Stepper Code especially the second code example that uses millis()

Also have a look at the AccelStepper library. It is not necessary to use the library but you may find it useful.

You should also post a link to the datasheet for your stepper motor and tell us what stepper motor driver you are using.

...R

Hi Paul

PaulS: Most stepper drivers need the direction pin set HIGH to rotate one way and LOW to rotate the other way. I've never heard of one that takes a string to control direction. Or even one that needs more than one change of level.

No , Im not suggesting to send a series of pulses to the direction pin

lets see if I can explain it better with a pseudo program

The joystick left switch is connected to arduino pin 3 the joystick right switch is connected to arduino pin 4 the stepper driver direction input connects to arduino pin 5 the stepper motor pulse ( step) input connects to arduino pin 6

Now for the X axis stepper

If pin 3 is high // joystick is pushed right set pin 5 High // set direction to CW start sending pulses to pin 6 // Move the stepper continue sending pulses till joystick is released

if Pin 3 is low // Joystick is pushed left set pin 5 Low // set direction to CCW start sending pulses to pin 6 // stepper continue sending pulses till joystick is released

and then of course I need to do the same for the y axis motors

setting the direction and making it move is not the problem I did that when I built my cnc mill but with that I always send the pulses out at a fixed speed . Now I want to be able to vary the speed of the pulses by reading the value of a pot on an analogue input, and preferably 2 different speeds one from a pot on each axis

I know I cant use delay to do it as that ties the arduino up all the time its in a delay loop. I assumed that millis or an ISR would be the way to go but have no experience using those

Regards Don

Robin2: You should also post a link to the datasheet for your stepper motor and tell us what stepper motor driver you are using.

...R

Hi Robin

I didnt see how what kind of stepper or driver would alter the info I was after as I already know how to drive them it was how to make a variable speed pulse train using millis or an ISR that I needed but if it helps the driver is an MSD415 http://www.motioncontrolproducts.com/drives/msd415-microstepping-drive.php?cat=2

your links that you gave me look promissing and I will go read them now

Thank you

Don

Hi Robin

You were right the second example looks perfect if I map the analogue input to the millisbetweenSteps variable it will change the speed

Thats great thanks

Don

Glad to hear you are making progress

DonRecardo: I didnt see how what kind of stepper or driver would alter the info I was after as I already know how to drive them

When trying to help it is impossible to know how much the questioner knows or does not know and I have seen Threads run to 30 or 40 Replies before some critical piece of data emerges. So my policy is to try to get all the facts up front :)

...R