Go Down

Topic: counting revolutions (Read 2260 times) previous topic - next topic



I am an Arduino-newcomer and have to realize a rpm-counter within the next 3 weeks. I get the Arduino Uno om Wednesday. so I want to ask for some tips in advance. I searched for similar topics here, but didn't found a properly fitting statement.

I have to count a 5V-signal from one channel of a shaft encoder, resolution 25 ppr, on a motor up to 3000 rpms.

Could I do this with this code, adapting some values and variables?? http://www.arduino.cc/playground/Main/ReadingRPM

In the next step I want to give the rpm value out with the PWM-function to a second measurement and display unit. For this  I think I only get out a resolution of about 10 rpms, because of the 8-bit resolution of the PWM-Out.

Can I do it this way??

best regards and thx, Simon


25 PPR and 3000 RPM by my math is 800 microseconds per pulse. That is definitely doable.

The code you reference looks reasonable, though you will have to adapt for your own PPR.

And you are right that in the best case 3000 RPM / 256 PWM steps gives 11.7 RPM resolution. You can get better resolution if you take over one of the 16-bit timers (Timer1A/Timer1B) and manually program in the timer parameters (i.e., write to the TCCR1A/B registers instead of using Arduino library functions). Also look at the Timer1 library:


The Ruggeduino: compatible with Arduino UNO, 24V operation, all I/O's fused and protected


The only thing that doesn't look reasonable is the 25 PPR. 25 pulses per revolution is one pulse per 14.4 degrees, which seems like a very strange spacing.


It could be a 3.6 degree spacing with two-channel quadrature decoder. If only using the rising edge of one channel you only get 1 event out of 4 transitions so 4*3.6 = 14.4 degrees.

The Flexible MIDI Shield: MIDI IN/OUT, stacking headers, your choice of I/O pins


THX very much for first replies!!!!!

It could be a 3.6 degree spacing with two-channel quadrature decoder. If only using the rising edge of one channel you only get 1 event out of 4 transitions so 4*3.6 = 14.4 degrees.

You're right! It has more increments, but only gives 25 ppr out.

Now I will wait for the board and try first steps. I think I will have more questions in future :)


Hey guys,

Can somebody explain me the connections between and functions of the "interrupt" entries in this prog????


THX and best regards, Simon


The Arduino has two pins to which external interrupts can be attached. These are pins 2 and 3, which correspond to interrupts 0 and 1.

The attachInterrupt function takes three arguments - the interrupt number (0, in the example), the name of (which translates to an address of) a function to call when the interrupt is triggered (rpm_fun in the example), and the type of change that triggers the interrupt handler (RISING, in the example).

Every time the pin changes from LOW to HIGH, the rising edge of the transition triggers an interrupt, which causes the interrupt handler (rpm_fun) to be called.


Ok, THX,

but what means the   '++'   in the 'void rpm_fun' -paragraph and what exactly does THIS interrupt do?? I do not really understand the sense of it. In my application I get 25 high-signals per round. I will be enough to run the prog-loop every 8 rounds (rpmcount=200). Do I have to adapt the interrupt function?


rpmcount++; is c shorthand for rpmcount=rpmcount+1;

Thus, the interrupt routine simply counts how many rising edges have been seen from the encoder - in your case, 25 per revolution.

Knowing this, and the time taken, you can calculate, in loop, the rpm.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131