2

I'm trying to calculate the rotation speed of a DC motor.

I'm using the sensor shown in the picture and a slotted disk attached to the motor. The results I was getting made no sense and after several tests I realised the following:

Most of the times I manually blocked or unblocked the sensor, two pulses were counted. That would mean that for each tooth of the slotted disk, up to four pulses were counted instead of one.

Below is a test code. I count pulses on the interrupt handler and reset the counter when calculating the motor speed.

Am I doing something wrong or is the sensor suffering from bouncing signals?

 int encoderCounter = 0;
 int encoderDiscSlots = 21;
 int encoderPin = 19;
 void encoderIncrementISR()
 {
 encoderCounter++;
 }
 double calculateMotorSpeed(int interval)
 {
 Serial.print("enc ");
 Serial.println(encoderCounter);
 double rpm = (encoderCounter*1.0/encoderDiscSlots)*60000/interval;
 
 encoderCounter = 0;
 return rpm;
 }
 void setup() {
 Serial.begin(9600);
 pinMode(encoderPin, INPUT_PULLUP);
 attachInterrupt(digitalPinToInterrupt(encoderPin), encoderIncrementISR, RISING);
 }
 void loop() {
 // put your main code here, to run repeatedly:
 delay(1000);
 double rpm = calculateMotorSpeed(1000);
 Serial.print("rpm ");
 Serial.println(rpm);
 }

enter image description here

The sensor uses the LM393 IC from TI, a spec sheet can be found here

Rohit Gupta
6122 gold badges5 silver badges18 bronze badges
asked May 15, 2019 at 23:01
2
  • 2
    the picture does not tell us anything about the sensor, other than validating the type of the sensor .... please add a link to the datasheet in you question above Commented May 16, 2019 at 1:12
  • @jsotola added aditional sensor information to the question. Commented May 16, 2019 at 22:03

1 Answer 1

2

I've done some more search on the interwebs and found someone (in Spanish) describing the same problem. That person owns an oscilloscope and could confirm that there is some bouncing on the data signal both going up and down.

The hardware solution presented is to place a 100 nF capacitor between the signal pin and ground.

I've tried it and it works.

answered May 16, 2019 at 23:51

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.