Problem Programming pulse counter

Hello

I need to make a pulse counter that gives me the time between two pulses vor rpm calculating.
i will count pulses from a rpm sensor with 6000-20000prm
Arduino Uno pins usage
-pulsein on PD6(AIN1)
-20k resistor on PC1(ADC1) to GND?? <-- is this resistor really needed?

I found the Pulsein function:

pulseIn()
Description

Reads a pulse (either HIGH or LOW) on a pin. For example, if value is HIGH, pulseIn() waits for the pin to go HIGH, starts timing, then waits for the pin to go LOW and stops timing. Returns the length of the pulse in microseconds. Gives up and returns 0 if no pulse starts within a specified time out.

The timing of this function has been determined empirically and will probably show errors in longer pulses. Works on pulses from 10 microseconds to 3 minutes in length.

the problem is that i will have up to 340 pulses per second that will be around 3ms between the pulses!
will it work with pulse in or do you have a better solution?

best regards
Michael

A better solution is to feed the signal to one of the external interrupt pins (digital pins 2 and 3 on a Uno). In the interrupt service routine, read the time using micros(), subtract the time of the last interrupt to get the interval, and store the current time for use at the next interrupt.

thanks for your fast reply

So interrupt pins should be Digial pin 2 and 3 on uno correct!?

This is my first arduiono project, do you have some hints?
or maybe an complete example code to play with?

Michael

Michael_Schmidt:
thanks for your fast reply

So interrupt pins should be Digial pin 2 and 3 on uno correct!?

This is my first arduiono project, do you have some hints?
or maybe an complete example code to play with?

Michael

volatile unsigned long interval;
unsigned long lastTime=0;
volatile bool hadInterrupt = false;

void setup()
{
   attachInterrupt(0, my_isr, RISING);
}

void my_isr()
{
   unsigned long now = micros();
   interval = now - lastTime;
   lastTime = now;
   hadInterrupt = true;
}

void loop()
{
  if (hadInterrupt)
  {
    Serial.println(interval);
    hadInterrupt = false;
  }
}