Motor Information

Stepper/Servo motors are used extensively in automation these days, some of the popular ones being CNC machine, 3D Printers and various Robotic applications.

Do not get Stepper/Servo motors confused with DC brushed motors as they are controlled very differently.

Stepper/Servo motors are controlled by sending pulses and changing the speed (frequency) to that pulse train to increase or decrease the speed. With DC motors you send a pulse that is usually at a fixed frequency and then you alter the width of the pulse to speed it up or shorten the pulse to slow it down.

The PTHAT is designed to control Stepper/Servo motors by sending very accurate and smooth pulse trains and is not designed for controlling DC motors.

Rather than repeat too much of what is already out their on the web, please check out this link https://en.wikipedia.org/wiki/Stepper_motor for detailed workings of the inside of a Stepper motor.

Stepper Drivers

Stepper Motor Pulses

Most of the popular Stepper motors used are known as 1.8 degree, which is the resolution of 360 degrees divided by the steps of the motor for one revolution, or worked backwards 360/1.8=200.
So we have to send 200 pulses to get the motor to turn one whole revolution. If we sent 100 pulses then the motor would do half a revolution, which is 180 degrees.

Now even though 1.8 degree sounds a good resolution for simple projects, it becomes a bit restrictive when needing high resolution movements.
But this is not a problem as modern Stepper drivers are known as Micro Step drivers and can increase the resolution from 200 pulses to ten’s of thousands of pulses by some clever electronics.

Controlling a Stepper Motor with a Driver

Not only does the Stepper driver increase the pulses that are needed to do one revolution, but also make control of the motor very simple by offering a Pulse input pin and Direction pin as the interface. You simply send a pulse on the Pulse input to make the motor step the degree resolution you have set on the driver. Then by either supplying 5 volts or 0 volts to the Direction pin will determine if the motor rotates forward or backwards.

Another thing the Stepper driver does is isolate the higher voltage that is needed to run the motor, away from the inputs that are usually TTL logic levels.

Ease of use

Finally the Stepper driver restricts the current that is supplied to the motors, which is usually set using a simple set of switches on the driver.

As you can see, once you have your motors wired up to the drivers and they are all configured, then the next stage is working out how you are going to send and control the pulses to get your motors moving. This is where the PTHAT comes into play as it takes a lot of the complicated stuff away from the developer.

Resolution/Travel Distance

Using Ballscrews

Lets go back to the resolution for the moment and see how that works out when introducing different mechanical elements.

One of the most popular components used in CNC machines is the ballscrew that you connect to the motor.

As we are talking about resolution here, the main thing we are interested in, is the pitch of the ballscrew. You can get many different pitches and popular ones are 4mm and 5mm. The pitch determines how far the ball nut will travel when turned one revolution. So if the pitch is 5mm, then when the ballscrew is rotated one full revolution the ball nut will travel 5mm.

So based on this, we can now work out our best resolution of travel that is possible when combined with our Stepper driver.

If we have our stepper driver set to Full Step (200 Pulses Per Rev) then we know that sending 200 pulses will turn the ballscrew one revolution and move the ball nut 5mm. By dividing the pitch down by the pulses, we can calculate that 5.0/200 = 0.025mm resolution. If we send one pulse to the Motor driver then the ball nut will move 0.025mm. Now we increase the Stepper driver to 1/8 Step (1600 Pulses Per Rev) and we get a much better resolution 5.0/1600 = 0.003125mm.

Controlling a Stepper Motor with a Driver

Some drivers will let you go way much higher than the steps shown above in the example, but there does come a point where increasing the Pulses Per Rev is not really going to make a difference and most applications will not use above 1/16 (3200 Pulses Per Rev).

For an example if you set a driver to a really high divide of say 20’000 Pulses Per Rev and start sending some pulses you will notice that the motor will not move on every pulse and you indeed to need to send say 10 pulses before the motor moves to the desired position.
Also the higher the Micro step the less holding torque of the motor.

Conclusion

So if you need a better resolution then decrease the pitch of your ballscrew, like say a 2mm pitch which would give you 2.0/1600= 0.00125mm resolution could be a better option for accuracy.
As usual everything has it trade off’s and by increasing the resolution you will need to make sure you have a controller that  can send fast pulse trains, again this is where the PTHAT comes into it’s own and will be explained further down this page.

Most software out there likes you to specify the amount of pulses per unit of travel, so to find out how many pulses for 1mm when using a 5mm pitch ballscrew and 1/8 step would be 1600/5.0= 320 pulses.

Pulley and Belts

Now of course if you are not building a high torque CNC machine and you are moving a small mass, then you could use pulleys and belt as a drive system like 3D printers do.

Pulleys and belts will also divide the resolution, depending on what size pulleys you use and also the pitch of the belt.
The popular choice for 3D printers is to use GT2 (2.0mm) belts and the less teeth on your pulleys is going to give you a better resolution.

Calculating the Resolution

So first off lets take usage of a 2.0mm belt and 16 tooth pulleys, using 1600 Pulses Per Rev it would give us 0.02mm resolution, which gives us 50 pulses for 1mm of travel.

We can calculate the amount of pulses to travel 1mm by multiplying the pitch of the belt by the tooth count on the pulley 2.0*16=32 and then taking the Pulse Per Rev and dividing it by the result 1600/32=50. Then to get resolution just divide 1.0/50=0.02mm.

You have to be a little bit careful when choosing the amount of teeth on the pulley as you may end up with needing to send half a pulse to get your 1mm of travel and you cannot send half a pulse!.
For example lets take a 14 tooth pulley and do the same maths. 2.0*14=28 then 1600/28=57.14, as you can see you are not going to be able to send 0.14 of a pulse. So keep this in mind when calculating.

There are some handy online calculators such as this one that can make it easier.

 

View Link

The PTHAT Accuracy

The PTHAT uses a dedicated counter for each motor Axis and will monitor the pulse trains and keep an eye on how many pulses are being sent out to each Axis. When the target pulse count has been reached, it automatically stops the motor or continues on with the next pulse count command sent, even at very high speeds in ensures no extra pulses creep in or get missed.

Speed

Obviously altering the speed of the motors will increase or decrease the travel speed of the attached mechanics on your motors.

I like to work in mm/min (Millimetres Per Minute) where as others prefer mm/sec (Millimetres Per Second), but for this explanation I will stick to mm/min which is how many millimetres are travelled in 1 minute.

A simple example is to have a motor with a ballscrew that has a 1mm pitch. If we require to travel a distance of 2000mm over a minute (2000mm/min), we would run the motor at 2000RPM. Then as we increase the size of the ballscrew pitch we simply divide down the speed. So with a 5mm pitch ballscrew we would only need to run it at  400 RPM.

This why sometimes you see big CNC machines running at silly speeds, they are increasing their ballscrew pitch up to 20mm or higher and with strong motors and low speeds they can shift the gantry around with no problems. Obviously we are loosing resolution, so again workout what is important to you, speed or resolution and find middle ground.

A thing to remember is that the calculations are fine if you are moving a single Axis in a straight line and not using Interpolation between 2 motors (Interpolation covered further down), but when you are running 2 Axis’s to say draw an angle then you have to calculate based on the Vector Travel distance.

As you can see above if you ran both X and Y Axis’s at 1000mm/min you would actually be doing a speed of 1414.2136mm/min for your tool in the middle of the X/Y frame.

If you dropped the speed of the X-Axis and Y-Axis to 707.1068mm/min then the Vector Speed would be 1000mm/min as desired.

So keep this in mind when calculating your speeds.

Sending out Pulses

So easy enough to work out running speeds but we are sending pulses here to run the motors and if we have our Stepper drivers at to 1600 pulses per revolution and a ballscrew with a 5mm pitch then we know that it is 5.0/1600=320 pulses to travel 1mm. To travel 2000mm we would need to send 2000*320=640’000 pulses over exactly 1 minute.

How to send out our 640’000 pulses in exactly a minute is to convert our RPM to frequency in Hz.
1Hz is equal to one cycle per second or in our case one Pulse per second.
As there are 60 seconds in a minute then we can safely say that 1/60=0.01666666666Hz is the speed of the cycle per minute.

Calculating the RPM

To calculate our target speed of 400 RPM we can do it a couple of ways.

As we know that we need to send 640’000 pulses in a minute then we can take our 640’000 pulses and multiply it by our result of cycles per minute 640000*0.01666666666=10666.66Hz.

Or we can take our Pulses Per Rev of 1600*0.01666666666=26.666666656 and multiply the result by the required RPM required 400*26.666666656=10666.66Hz


The frequency needed to get 400 RPM with a motor set to 1600 Pulses Per Rev, we would need to drive it at 10666.66Hz (10.66666kHz)

Conclusion

As you can see by our example above we need our pulses to be spot on and a resolution of two decimal places.

With the PTHAT are using Direct digital synthesizer processors (DDS) on each channel, which give a very accurate, clean pulses and allows us to go to speeds that you will probably never need.
Also having the resolution allows us to get better interpolation between each Axis as will be explained further down the page.

Ramping

Using Ramping

Stepper motors, unlike DC motors need to be ramped up/down to speed and you cannot simply just start sending out high speed pulse trains without expecting to see the motors jam and stall. This is why you get some almost nice musical notes coming out of the motors when following toolpaths with tight curves or where a change of direction is needed while moving.

Here is a typical chart of ramping up a stepper motor.

PTHAT Ramping Routines

With the PTHAT we have built in very simple ramping routines that gives you a divisor of the target speed and also a timing marker that will be used to determine when the next divisor speed is triggered. This method works very well across the range of speeds and also if very slow ramping speeds are needed, the firmware will detect if there is enough time to complete the ramp over the distance. If there is not enough time, then it will automatically re-calculate and start ramping down.

Calculating the Ramping Routines

If we have a target speed of 10000Hz and we set a divisor of 100 and a pause of 10ms then it would divide the 10000/100 and ramp up/down in increments of 100Hz. The ramp up/down time would be 1000ms and the total time at target speed would be dependant on the amount of pulses that needed to be sent.

Conclusion

The PTHAT will automatically work out when ramping up would finish and when the start of ramping down starts. If a pause/resume command is sent the PTHAT again will re-calculate the ramp up/down needed to continue.
Also with the PTHAT you can send a command with only a start ramp or only a finish ramp. This then allows the use of buffered commands that can change the speed on the fly and you only have to ramp down when changing direction.

Linear Interpolation

Inter who? I hear you shout !

Interpolation with motors is to have all motors start and stop at the same time, no matter what the distance is, and even if the distance is different for each Axis.

Simple I hear you shout again!, if we have one motor that needs to have 1000 pulses sent to it and the other motor needs 2000 pulses sent to it and we want them to start and stop at the same time. We simply send 1 pulse to motor1 and 2 pulses to motor2. Yep that will work but what if we need to send 1000 pulses to motor1 and 2222 pulses to motor2, can we really send 1 pulse to motor1 and 2.222 pulses to motor2?. No we cannot as we cannot sent 0.222 of a pulse and also saving up the 0.222 pulses, till we get a full pulse and then sending it, also throws the motors out of sync at so many steps and it gets very complicated.

So this is where again the PTHAT comes in handy as it will allow high resolution frequency pulse trains be produced via the on board DDS processors.

Calculating Interpolation

Lets say we have motor1 that needs 1000 pulses and motor2 that needs 2222 pulses to reach the target travel distance.

As in other examples above we have ballscrews with a 5mm pitch and motor drivers set to 1600 Pulses Per Rev.

We want to go at 100 RPM, so lets do the calculations on the biggest amount of pulses first motor2.
We take our Pulses Per Rev of 1600*0.01666666666=26.666666656 and multiply the result by the RPM required 100*26.666666656=2666.66Hz.

That is motor2 frequency calculated to 2666.66Hz, so it runs at 100 RPM.

Now for motor1 we first divide motor2 pulse by motor1 pulses 2222/1000=2.222 and divide the frequency of motor2 by the result 2666.66/2.222=1200.11Hz

The final result being, is that we:
Run motor2 at 2666.66Hz (100RPM)
Run motor1 at 1200.11Hz (45.45RPM)
Now motor1 and motor2 will start and stop at the same time and both would of done the target pulses.

There are other ways of calculating these numbers and expressions to be used, but I want to try and break it down into easy steps for people to understand.

Here is a scope shot of the PTHAT loaded with the values above and sent to the X and Y Axis motors.

Scope Shots

Find below some scope shots taken from the PTHAT with all four channels running.

 

Share This