Fast microcontroller alternatives

Hello, newbie here.
I'm currently using an Elegoo v3 (Arduino nano) which runs at 16MHz. For my project it should sense some inputs, and one of them in particular could last just for some milliseconds before disappearing. The project is a gear with a magnet on it and a hall sensor (A3144) which senses when the gear completed one cycle, but the gear spins so fast that in a normal case scenario it revolves in 50ms, and in an extreme case scenario it could reach 20ms. Given that the magnet is only in a part of the gear, the hall sensor have just some milliseconds to read the presence of the magnet. If I'm right that's not a problem as the hall sensor polls enough times (please correct me if I'm wrong, also I'm thinking of using Interrupts if necessary).

The problem is in the fact that, despite my best efforts, the code that must run after the sensor fired takes about 66ms to complete and more code is to come in the future. I think I need a faster microcontroller that has:

  1. Faster processor, I think at least 3 or 4 times faster than 16MHz.
  2. At least 5 analog pins (reading IR photoswitch, reading voltage, reading a rotary switch, i2c screen).
  3. Must have 5V pin or a way to use 5V devices as my screen is 5V, every guide I follow tells me to connect the sensor to 5V (but probably they will work even with 3.3V) and more importantly I must activate a logic level MOSFET that requires 5V (I actually can activate it just by setting the digital Pin connected to it HIGH, but I don't know if the digital pins are 5V or not).
  4. Compatibility with Arduino IDE and the arduino code.
  5. Costs about 10 €

What are my options?

I considered an ESP32 as it has a 80MHz processor and costs about 10 € but I'm not sure if the ADC pins work like actual analog pins and above all it only has 3.3V which I don't know if are enough for the MOSFET.

EDIT:
I see the ESP32 WROOM 32 board does seems to have 5V, so it's a plus for me

Actually ESP32 runs on 160 or 240 MHz. Some MOSFETs can be controlled directly by 3.3V or you can use an extra transistor to use MOSFET with higher Vgs. Most of sensors/modules can work from 3.3V or 3.3V is a “native” voltage for them.

So, most likely, ESP32 will fit your requirements.
However 66ms is very long time. Even at 16MHz controller can do around one million operation during that time. And milliseconds for hall sensor reading doesn’t sound correct as well. Widely used hall sensors have reaction time around hundred microseconds and can be read in 1 microsecond or so.

So I’d start with your code optimization.

The other advantage of using the ESP32 is you can put some code to be ran on one core and some other code to be ran on the other core. By splitting the tasks with the cores...

you have an MCU so use it. you can use input capture function of the timer peripheral to catch the pulse

ariesbreath:
. . .
3) Must have 5V pin or a way to use 5V devices as my screen is 5V, every guide I follow tells me to connect the sensor to 5V (but probably they will work even with 3.3V) and more importantly I must activate a logic level MOSFET that requires 5V (I actually can activate it just by setting the digital Pin connected to it HIGH, but I don't know if the digital pins are 5V or not).
. . .

What kind of screen are you using? Full screen updates on large (by Arduino standards) displays are often time consuming and I/O rather than processor speed limited. If the screen update is blocking other processing, that's a potential problem.

alesam:
Some MOSFETs can be controlled directly by 3.3V or you can use an extra transistor to use MOSFET with higher Vgs.

I'm using a IRLB 3034, do you think it will be good? I think I once read that the greater the voltage, the greater the current that can pass through the mosfet, do you think that with 3.3V will pass less current? (it will be connected to an 11.1v battery)

alesam:
However 66ms is very long time. Even at 16MHz controller can do around one million operation during that time.
So I'd start with your code optimization.

You are absolutely right, but as I said this was my best effort and I don't know where to start to optimize the code

MrMark:
What kind of screen are you using?

I'm using an i2c OLED screen 128x32 SSD1306. But I'm not sure it is the problem because I removed that part and it still takes exactly the same time to close a cycle

EDIT:

MrMark:
If the screen update is blocking other processing, that's a potential problem.

I edited the code removing the screen refreshing and actually the timing got down to about 37ms, but that's still a lot and the problem of long processing times remains

ariesbreath:
I’m using a IRLB 3034, do you think it will be good? I think I once read that the greater the voltage, the greater the current that can pass through the mosfet, do you think that with 3.3V will pass less current? (it will be connected to an 11.1v battery)

Controlled by 3.3V this MOSFET can provide around 200Amp. Is it OK for your application?

alesam:
Controlled by 3.3V this MOSFET can provide around 200Amp. Is it OK for your application?

ahahah yes, sorry for the dumb question

ariesbreath:
I'm using a IRLB 3034, do you think it will be good? I think I once read that the greater the voltage, the greater the current that can pass through the mosfet, do you think that with 3.3V will pass less current? (it will be connected to an 11.1v battery)You are absolutely right, but as I said this was my best effort and I don't know where to start to optimize the code

The answer, as almost always, is in the datasheet. Figure 1 shows voltage/current curves for selected gate voltages. The closest one less than 3.3 V is the third from the bottom for 3.0 V.

It shows up to about 200 amps on the right, but with a large (about 20 V) drop across the transistor at which point it would be dissipating an enormous amount of power. You're really interested in the left side of the curve which is about 30 amps with a 0.1 V drop implying 3 W dissipation in the transistor.

irlb3034.PNG

So what you heard about gate voltage is correct, that is higher voltages enable greater current, but the device may still usable in a particular application at a lower gate voltage.

irlb3034.PNG