# Arduino SPI slave, how fast can it go and write to PWMs?

I have a Arduino(Micro) that acts as a motor controller for four motors over PWM.
It gets speeds for each motor over an SPI interface with a RaspberryPi.

My target control loop (Pi -> Arduino -> PWM) is 200Hz plus or minus 50Hz. I'm only moving 8bytes per loop. Does the Arduino have the power to read 8Bytes over SPI and analogWrite(...); to four pins in that amount of time?

I'd also really like to know how to calculate these things, and find the information on the data sheets to do so.

I'd also really like to know how to calculate these things

Calculation is possible but very tedious. It involves taking the compiled code and looking at the machine code instructions. Each machine code is then looked up in the data sheet for how many clock cycles it takes to do. You then translate that into a real time by using the clock frequency of the chip which in the case of the Arduino is 16 MHz.
Almost no one does this on account of how long it takes. More realistically you would take a piece of code, and set a pin high at the start and low at the end and measure the time on an oscilloscope. Using direct port addressing you get a much more accurate result as there is little tie spent setting and clearing the timing pin.

My target control loop (Pi -> Arduino -> PWM) is 200Hz plus or minus 50Hz.
Does the Arduino have the power to read 8Bytes over SPI and analogWrite(...); to four pins in that amount of time?

I would say yes as SPI transfer can take place at at least 1MHz and an analogue write is only about 6uS.

If you don't have an oscilloscope write a short program that repeats the code you want to time about 1000 times and record micros() or millis() before and after.

I suspect you could easily do what you want to do using the serial interface and SPI should be much faster.

I wonder can the motors respond quickly enough to changed PWM values to need a 200Hz PWM update.

...R

Robin2:
I wonder can the motors respond quickly enough to changed PWM values to need a 200Hz PWM update.

The Arduino is actually write to several ESC's on a quadcopter, which I believe the refresh rate to be something close to 400-500Hz. I'm using middle of the road ESC's that claim 490Hz but either way considerably fast enough.

matutter:
The Arduino is actually write to several ESC's on a quadcopter, which I believe the refresh rate to be something close to 400-500Hz. I'm using middle of the road ESC's that claim 490Hz but either way considerably fast enough.

That does not require the data flow between the PI and the Arduino to be that fast. The Arduino can repeat a value several times if necessary to match the expectation of the ESC.

Don't ESCs expect a servo signal rather than the PWM produced by analogWrite() ?

...R