Using tone to control a stepper motor

I need to control a 4 amp stepper motor connected to the uno via a dedicated driver unit.
I will need to control the speeed very accurately, using mils with alternate high and low on an output pin will not give the sensitivity I need.
The step pulse Frequency will vary from about 1k Hz to about 20kHz, but will in most cases need decimal frequency numbers eg one I will need is 1642.Hz.

The question is, will I be able to use a square wave derived to the tone function , perhaps with some other form of buffering??? And connect this to the driver.

or is there another way this could be achieved? Pam seems to use the high mils delay and low as well.
I don’t want to spend the cash needed to buy the stepper, drive and PSU useless I can resolve this problem before continuing with the project.

You could try it.

The pulses to control a stepper motor are usually very short - maybe 10µsecs - with the interval between pulses being used to control the speed. You need to study the datasheet for your stepper driver to find out what width of pulse it requires.

For high step rates the best thing is probably to use one of hardware Timers to generate a pulse or an interrupt at the appropriate intervals.

…R
Stepper Motor Basics
Simple Stepper Code

I have used the Tone library (not to be confused with the tone() function) to play music using steppers for fun. I can't say how accurate the frequencies are, though. But, like Robin says, the tones are at 50% duty cycle. Doen't bother my DRV8825 drivers.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

What is the stepper driver module? Link to spec/data please.

Thanks... Tom.. :slight_smile:

Thanks for the replies —- More info
The project will be an electronic lead-screw for my Myford lathe.
This will develop in several distinct stages

  1. Rev counter and display. 60 tooth rotor and optical sensor on spindle using a mega for higher number of control button interrupts and digital pins using a mega
  2. Variable speed Leadscrew driver steppper driver to give a set speed for fine feed ( simple pulse calculation) using a uno
  3. Varying the speed of Leadscrew to be auto variable relative to the speed of spindle rotation thus staying constant per rev Using pulses from the spindle rotor and integrating this in the uno being used as the stepper pulse generator, fed with data from the mega
  4. Develop both input controls and display to give pitches for screwcutting and needing an accurate start pulse from an additional single spindle optical for consistent tool positioning for each cut

It is the screw cutting which needs the highly accurate pulsing The early development for a fine feed (typically 2 to 10 thou per spindle rev) will not need such a critical control, but Attaining this will be a crucial development task.
However, This is where the accurate pulse rate will be required, the 1642.6 Hz equates to cutting a pitch of 26 tip at 200 rpm, 3.33 Rev’s per second, with an 8 tip Leadscrew and a 200 stepper with 8 micro-steps. I.e the drive system will need 12.8 steps on the Leadscrew to move 1 thousandth of an inch, 26 tip equates to a pitch of 38.5 thou therefore needing 492.8 pulse steps per spindle rev to deliver

I have found many references to this type of system, but no real meat details
Tachometer and lcd driver circuits and sketches are common
At the moment, it is a question of overall strategy rather than circuits and sketches. No drivers or steppers have yet been researched except those I used for a CNC miller conversion These stages as outlined above and can be classed as sub-systems which will function in their own then integrated to work as a complete unit but the core is all about delivering accurate frequency of pulsing for the driver, resulting in the request about the possibility of using a tone for the pulse output

zan2:
It is the screw cutting which needs the highly accurate pulsing The early development for a fine feed (typically 2 to 10 thou per spindle rev) will not need such a critical control, but Attaining this will be a crucial development task.
However, This is where the accurate pulse rate will be required, the 1642.6 Hz equates to cutting a pitch of 26 tip at 200 rpm, 3.33 Rev’s per second, with an 8 tip Leadscrew and a 200 stepper with 8 micro-steps. I.e the drive system will need 12.8 steps on the Leadscrew to move 1 thousandth of an inch, 26 tip equates to a pitch of 38.5 thou therefore needing 492.8 pulse steps per spindle rev to deliver

My guess is that you need a cumulative accuracy so that the forward motion of the cutting tip keeps the correct position relative to the material in which the thread is being cut. But I suspect you do not need strictly precise timing for every motor step. If one step is behind by a few microsecs it can be made up on the next step.

The other thing that is essential is the correct phasing between the cutting head and the material so that the tool moves in the same groove each time. That requires synchronisation between the spindle and the progress of the tool.

My feeling is that leaving all that to the tone library would be very risky.

…R

Ok thanks. I have ordered the stepper n driver system and will set it up with a Lego lashup to trial it all it’s going to need a lot of head scratching, but will be fun!
I do understand the need to start in the correct place, both spindle and tool. It will be needing a optical sensor on the saddle at the end of the movement. At the start of the thread position a similar action is needed, and when the return button is hit it will have another optical, a blade, and it will go past this after triggering then go forward until the blade is just deactivated thus setting a precise start position and elimating any slack(backlash) in the machine. After a adding cut manually after hitting cycle start a small delay, will cause a wait fir stability and start with a pulse from the spindle before starting the next cut.

Spent another hour or two today chasing circular references between links on the subject still uncertain
So you don’t think the tone will be consistent in its accuracy in both frequency and amplitude?

zan2:
So you don’t think the tone will be consistent in its accuracy in both frequency and amplitude?

I just don't know.

...R