Clarification on SPI Encoders

So, I guess, I managed to make SPI Encoder work.
I am using 2 AMS5047P, one for each axis.

First of all, I had increaced SPI baud rate by factor of 2. Yes, increaced, it’s 2.625 MHz for encoders too, not just for DRV8301. The reason for that was that on 1.3125 MHz SPI bus sometimes was not able to update both encoders in time, it was counted as error and added to spi_error_rate. It’s line 48 in encoder.cpp:

    .BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16,

I also lowered maximum allowed spi_error_rate by factor of 10. It’s line 737 in encoder.cpp:

if (spi_error_rate_ > 0.05f) {

I did not remove 14th bit check. According to datasheet, it’s not error flag, it’s just always stays 0. And it helps to diagnose disconnected encoder cable :slight_smile:

I also recommend to change slew rate for SPI pins. It is set to “Very High”, which causes lot of ringing. “Low” or “Medium” is more than enought for 2.625 MHz. It’s line 107 in spi.cpp:


That’s it. Now spi_error_rate stays below 0.001 and everything works. It was tested on my custom PCB and on the genuine ODrive v3.6-56v (or, maybe, not genuine, I don’t know where it came from, but it seems to be genuine).


Thanks for the update (and the slew rate measurements)! I’ve compiled these changes into a pull request.