Hey,
So SPI is a very good option. Depending on whether the sensor is on-pcb or via a cable, length of cable, shields, etc speeds of 2MHz to 20MHz are quire realistic, though most sensors seem to support no more than 10MHz.
That’s the SPI clock speed. SPI is a synchronous protocol, so you receive something as soon as you send, and depending on the sensor model this can be directly the angle value you need, while other sensors make you do 2x 16bit reads to get a fresh value. It varies.
Either way, it is quite realistic to get loop speeds of 3kHz or more while reading from SPI sensors.
PWM sensors very typically have 1kHz PWM frequency - so that means you can’t get more than 1kHz loop speed, it takes 1ms to read the sensor. Basically that is too long to interrupt the commutation, and so unless you used MCU support (the timer/counter hardware) to do it asynchronously, PWM is a very bad option.
Some sensors support PWM variants like short code, which can be a bit faster, but we have no support for this in SimpleFOC.
SSI is basically like unidirectional SPI, and can be very fast.
I2C is much slower. While most MCU/Sensor combos can support 400kHz operation (Fast Mode) this is still not very fast, and I2C’s bi-directional half-duplex nature (SDA used in both directions for data) means any communication involves a lot of latency: first you send a read command, then the sensor sends back some data, one after the other, with pauses in between to respect protocol timings.
So you won’t get much beyond 1kHz main loop speed when using I2C, and that’s really a bit slow.
The advantage of I2C is that it supports longer cables due to its slower speeds, and its easier to wire up. For many less “real-time sensitive” communication tasks it is an excellent choice.
Another one to consider is quadrature encoder ABI type interfaces. Many magnetic sensors (like the AS5047 and AS5147 models from AMS, but also the MA732 and others from Monolithic) support ABI / ABZ type interfaces, and there are a wide variety of other position sensor types with ABI interfaces.
SimpleFOC supports these with an interrupt-based implementation, which is limited by MCU speed / interrupt processing speed. But for STM32 MCUs we also have a hardware driver in our Drivers Repository. Many MCU types have hardware support for ABI interfaces.
This way of attaching the sensor combines the best of everything: instant updates (no comms latency), high precision and no MCU overhead.