ESP32 a3144 halleffect getting strange values for RPM?

Hey,

I've trying to get the RPM with esp32 and a A3144 Hall Effect Sensor.
When I start the Sketch, I'm getting back the "count" (rounds) but the RPM are only in 60x steps
I've tried several devices like a fidget spinner with magnet or a small fan. Also when I move the magnet with the hand I'm getting back "60"?

Do you have a clue what I'm missing here?

Wiring

const byte hallPin = 26;

float value=0;
float rev=0;
int rpm,count=0;
int oldtime=0;
int _time;

void IRAM_ATTR ISR()
{
  rev++;
  count++;
}

void setup()
{
  Serial.begin(115200);
  attachInterrupt(hallPin, ISR, RISING); // Interrupts are called on Rise of Input
}

void loop()
{

  delay(1000);
  detachInterrupt(hallPin);    // detaches the interrupt
  _time = millis() - oldtime;  // finds the time
  rpm = (rev / _time) * 60000; // calculates rpm
  oldtime = millis();          // saves the current time
  rev = 0;

  attachInterrupt(hallPin, ISR, RISING);

  Serial.print(rev);
  Serial.print(" | ");
  Serial.print(count);
  Serial.print(" | ");
  Serial.println(rpm);

}

My Serial.print

0.00 | 1 | 57
0.00 | 1 | 0
0.00 | 1 | 0
0.00 | 2 | 60
0.00 | 2 | 0
0.00 | 4 | 120
0.00 | 7 | 180
0.00 | 8 | 60
0.00 | 8 | 0
0.00 | 8 | 0
0.00 | 8 | 0
0.00 | 8 | 0

It is possible that the ESP is too slow to read such a fast-turning object. Try slowing it down to see.

1 Like

If i rotate very very slow I got the following output

.00 | 1 | 0
0.00 | 1 | 0
0.00 | 2 | 60
0.00 | 2 | 0
0.00 | 3 | 60
0.00 | 4 | 60
0.00 | 5 | 60
0.00 | 6 | 60
0.00 | 6 | 0

What are you trying to do with the interrupt? What's IRAM_ITTR doing here? What is the delay statement doing?

1 Like

just a few more things:

  1. move rev and count to the top of the sketch and make them volatile global variables:

volatile float rev=0.0;
volatile int count=0;

  1. Don't re-attach the interrupt service routine in the loop. Once is enough in setup.
1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.