From RepRap
Jump to: navigation, search

Hyperbolic Speed

The PIC microcontrollers used in the RepRap project express timer and speed values as a number from 0 to 255.

When this is used to represent a speed, 0 is the slowest and 255 is the fastest. However these figures actually represent counter start values and don't correspond directly with physical speed. It is easiest to think of these in terms of delay, where you wait 256 - n time periods.

For example, a speed value of 255 will wait for a period of 256 - 255 = 1 time unit between each step or pulse.

A speed value of 0 will wait for 256 - 0 = 256 time units. Note that this is actually moving and is not a physical speed of 0.

Also note that a speed of 255 is twice as fast as a speed of 254. A PIC speed of 0 is 1/256th as fast as 255.


In general, to convert a speed value to a physical speed, use the following:

v_ = _r / (256 - _s_)


  • _v_ = the actual velocity travelled
  • _s_ = the pic speed selected
  • _r_ = the rate of movement of the motor at top speed, which depends on the motor. Measure this in whatever unit is convenient, such as radian per second or meters of linear travel.

Conversely, to calculate the PIC speed for a given velocity, use:

s_ = 256 - _r / _v_


  • _s_ = the pic speed to set
  • _v_ = the desired velocity
  • _r_ = the rate of motion of the motor as before.

The level of precision of speed is much greater in the lower speed range.

To convert a linear true velocity value from 0 to 255 to a PIC velocity from 0 to 255, compute:

If v_ < 2 then, _s = v


s_ = round(256 - 256 / _v)


  • _s_ = the pic speed to set
  • _v_ = the velocity as a value from 0 to 255

This probably isn't a useful technique since it would only provide 30 distinct speeds. That is one of the reasons this conversion is not performed in the PIC itself. It is better to use a full precision (real) velocity value which allows for a greater range of speeds.

Stepper motors

The value of _r_ can be easily calculated for a stepper motor.

  • PIC clock speed is 4MHz
  • Stepping timer divider is currently 1:1 ratio which will increment every instruction cycle, which is 1/4 of the master clock speed, ie 1MHz clock.
  • The stepper motor steps at 1.8° per step, but is half stepped so steps 0.9° per step. This is equivalent to 1/400th of a revolution (π / 200 radians) per step.
  • Thread pitch is xxx mm (xxx m). 1.5mm?

Therefore for speed 255, there are xxx steps per second or yyy revolutions per second. 9.6 rev/sec?

This corresponds with a maximum theoretical linear speed of zzz m/s (zzz mm/s).

Stepper motors will not run at full speed under a high low. So consider a more conservative speed of 10% of max speed (pic speed 246). That is a speed of approximately 0.96 revs/sec or a linear speed of 1.44 mm/sec.

For a carriage length of 300mm, travel would take 208s or 3.5 minutes.

For a 2-axis movement, the longest path is 424mm which would take 294s or 5 minutes.


-- Main.SimonMcAuliffe - 03 Apr 2006