To test the accuracy of the stepper driver I am using a large test rig with a pointer to indicate the position. There is also an optical encoder mounted on the back of the stepper motor and the TMC5161 chip can read the pulses from this and make it's own conclusions about missed steps. So thought it would be good to wire up the encoder and see how it behaves.

 

Wiring the encoder

 

From the datasheet

ABN Incremental Encoder Interface The TMC5161 is equipped with an incremental encoder interface for ABN encoders. The encoder inputs are multiplexed with other signals in order to keep the pin count of the device low. The basic selection of the peripheral configuration is set by the register GCONF. The use of the N channel is optional, as some applications might use a reference switch or stall detection rather than an encoder N channel for position referencing. The encoders give positions via digital incremental quadrature signals (usually named A and B) and a clear signal (usually named N for null or Z for zero).

Note that on the encoder the N channel is labelled Z and on the evaluation board it is N.

 

As mentioned in the comments against the roadtest, the encoder has push pull signals for the outputs. This should make it good for noisy environments. The evaluation board on the other hand has just one input pin per channel.

trinamic_lisa  provided a breakout cable from the encoder to bare ends. So I wired up the connectors as follows:

At the same time I extended the cables on the motor in preparation for the testing with the test rig.

 

Setup

 

The TMCL-IDE has a tool to check the registers of the TMC5161 and there are several to do with configuration of the encoder. Given the wiring of the hardness the ones that were of main interest were the encoder mode Pol_A, Pol_B and Pol_N.

After a bit of experimentation I discovered a loose wire in my harness and that the default values for these registers works fine so I did not need to change these.

 

Reading the encoder position

 

Using the velocity mode, I set the motor moving at a reasonable speed.

 

One method to read the encoder position is to use the "Direct Mode" this has an option to "get axis parameter" for "209 encoder position". This gets you a snapshot value for the encoder in the answer box.

 

The other is to use the register browser and display the X_ENC value. This will update automatically.

 

I found the latching and clearing registers quite confusing but it does seem that you can configure these in such a way that it captures a value X_ENC into ENC_LATCH when the N signal is triggered. This could be used to snapshot fast moving values, automatically determine steps per revolution or to measure the position of an end stop.

For my purposes the X_ENC values should be sufficient so I'm not planning to investigate the latching mechanics any further at this time.

One final tip. The encoder cable is quite tricky to remove. Squeeze in the middle section and gently pull it out, I found levering the ends helped a little here.