Skip to content

Spindle sync developer reference

Terje edited this page Feb 25, 2021 · 2 revisions

Spindle sync developer reference

Encoder data logging

Two inputs are required...

For best performance one event timer and one pulse counter is used.

Event timer:

The event timer is a free running timer, typically 32 bit, clocked at a fairly high frequency. This is used to timestamp encoder pulse events. If the ARM 24-bit systick timer is used care must be taken to handle timer overflows correctly.

A 24 bit counter running at 1 MHz will overflow after ~17 seconds. A 32 bit counter running at 1 MHz will overflow after ~71.5 minutes.

It is assumed that no spindle synced motion will outlast the run time of a 32 bit counter running at 1 MHz.

Encoder pulse handling:

The pulse counter has its clock wired to the main pulse input from the encoder. It is used reduce CPU load and facilitate a bit of low pass filtering of the pulse train. This is achieved by using a compare register to set the next count when an interrupt is to be generated. When this interrupt is handled the current and total count is incremented and the compare value moved forward with number of pulses for when the next interrupt should take place. This event is then timestamped with the current count from the timestamp timer and the time difference from the last event recorded.

If a 16 bit counter is used overflows must be handled.

Index pulse handling:

The index pulse is connected to a "normal" interrupt capable pin. When this interrupt is handled the current pulse count is saved and the index pulse count is incremented. Again, this event is timestamped with the current count from the timestamp timer.

Note: some processors has advanced timer functionality where events can be used to capture the timer count. This could be used for precisely recording the pulse event timestamps. The timestamps recored directly from the counter value in the interrupt handlers will suffer from a bit of jitter since the time taken from the event occuring to it beeing handled is not 100% deterministic. However, in the grand scheme of things this may not matter much.

RPM calulation:

This is done on the fly when requested from data logged in the interrupt handlers. The time taken for the last encoder pulse interval is multiplied with a precalculated value. If the number of pulses per interrupt is > 1 then the recorded time interval is typically divided by this number to get the average, this then acts as a simple low pass filter.

Anglar position calulation:

This is done on the fly when requested from data logged in the interrupt handlers.

Standstill detection:

If the last pulse time is > 250 ms it is assumed tha the spindle is not running.