How to write RPM Counter Code

Dear All,
Good Day

Please, I need a help of how to write RPM Counter Code, to measure rpm of diesel engine. i will use a inductance proximity switch npn.

FYI , I will tell you what point i did reach. i could count the change of state of the input pulse, but what i need is how to count it with in 60 seconds, to measure the value of revolution per min't.

if you could help me, it will be highly appreciated.

Kind Regards

There are lots of threads on tachometers on the forum.

Record millis() value, count until millis() == that value + 60000.

If you need a faster response do it for less time and calculate the value.

If you need really fast response time the pulses and do the maths.


Rob

@Nassrallah
No need to PM, it's best to have questions and answers here so future searches can find them.

Speaking of which have you searched for "tachometer" yet as Paul suggested?

I think my first example was pretty clear, here it is again in pseudo code

int rpm = 0;
long last_millis = millis();

loop () {
   if millis() - last_millis > 60000 {
            last_millis = millis()
            print "RPM="
            print rpm
            rpm = 0
   }
   if your_current_pulse_detection_function() == new pulse {
        rpm++
   }
}

Do some research, try to write some code then show us what you have.


Rob

The usual way to measure RPM is to have the input trigger an interrupt. In the interrupt service routine, call micros() to get the current time since startup, and store it. From the difference in time between two consecutive interrupts, you can get the time between interrupts, and hence calculate the RPM. This gives you greater resolution and faster response than measuring the number of pulses in a given period of time. See help in making engine digital RPM meter - #27 by dc42 - Programming Questions - Arduino Forum and other posts in the same thread for code examples.

Dear dc42 member,
Many thanks for your kind cooperation.

I checked your suggested code, but because of my poor experience in arduino uno programming, i could not understand most of the code.
Please, could you explain to me your suggested code, with my regards.


Eng_Nassrallah

Here is a very good tutorial that should help you: Arduino Tachometer - Hardware | PyroElectro - News, Projects & Tutorials