can arduino handle 4 motor encoders at at time?

I am using atmega328p to control 4 motors with position encoders.my encoder pin pulses at 2500 pulses per second. So its around 5000 pulses per motor per second.apart from this my atmega328p is also communicating with 2 sensors through I2C and rpi via UART. So will the controller be able to handle these many things?

4 x 5000 = 20,000 pulses per second. If they were evenly spaced that would allow about 50 microsecs per pulse. But they won't be evenly spaced so the interval between some pulses from different motors will be close to 0 microsecs.

Even with evenly spaced pulses a 16MHz Arduino would be challenged to keep up and do something else as well.

If it was my project I think I would use one Arduino (or Atmega chip) per motor.

What is the purpose of the encoders? If it is just to control motor speed then a single pulse per revolution would probably be sufficient.

...R

The purpose of the encoder here is to move the robot precisely for a certain distance , control the angle of rotation of the bot and speed control obviously.

There is the option of offloading this to hardware.

YMMV

Position control will not be as accurate as you may think, due to wheel slip. Even worse with rotations, where you can not know the precise pivot point, and the encoder readings become inconsistent.

Counting can be based on one channel but should honor both pulse edges, so that again 20k interrupts/s have to be handled. Using PCINT with multiple encoders tied to the same port can reduce the interrupt rate and will be less sensitive to unevenly spaced pulses. But I'm not sure what the Arduino then can do apart from counting pulses.

Can you get Gray code from the encoders? Even if you miss a few pulses the code should give you position.

Why not use pin change interrupts to catch the pulses and flag them then read flagged Gray codes and use flash table lookup and some math to get positions.

Consider 2 arduino DUE: each one has 2 hardware quadrature decoder either for position or speed detection. With 10000 pulses per second per DUE, the CPU utilization will be pretty minimal.

Or maybe an FPGA (there's kits) would be best?

How would you connect an FPGA counter to an Arduino?

CPLD rather than a full blown FPGA surely?

I haven't had the chance to mess with either.