user76504: I created a program that measures the pulses set out by the encoder (part of the dc motor with encoder inbuilt), and uses the ppr value (pulses per rotation) to calculate the rotations per minute (rpm)
However, the serial monitor continuously shows 0 for the variable "pulsecount", that maintains the total pulses sent.

code:
float ppr=512.0;
int encpin=3;
volatile long pulsecount=0;
float revs;
float rps;
float rpm;
unsigned long time;


void setup()
{
  pinMode(encpin,INPUT);
  Serial.begin(9600);
  attachInterrupt(digitalPinToInterrupt(encpin),function,RISING); //when pulse is detected
                                           //interrupt triggered,
                                           //function callled  
}
void function(){
  pulsecount+=1;
}

void loop()
{
 revs= pulsecount/ppr ;
 time=millis()/1000;
 rps=revs/time ;
 rpm=revs*60;
 Serial.println(pulsecount);
}


user70020: You code counts pulses just fine when tested here.
Fan/motor tachometer outputs and encoders frequently are set to switch your signal contact to ground, either with a transistor or mechanically.  When the ground contact is not being made, the signal connection is floating and not reliably HIGH.  So, you need a pullup resistor on the pin, just like you do for a typical push button switch configured to switch to ground.
My comment on the question:

What happens if you use INPUT_PULLUP rather than INPUT?

was referring to doing this in your code:
pinMode(encpin, INPUT_PULLUP);

At higher frequencies, higher RPM, you may need to use an external resistor to get a lower resistance value than the 20k-50k of the internal pullup resistor that INPUT_PULLUP enables.
It is best to turn off interrupts when you retrieve your volatile pulse counter variable so that there's no tearing of the value where the ISR interrupts your code mid-read and updates the latter half of the value.
e.g.:
// Note I've switched your pulsecount variable
//  to unsigned long for this example.
unsigned long get_pulsecount() {
  noInterrupts();
  const auto r = pulsecount;
  interrupts();
  return r;
}

Note you can probably avoid float usage altogether, and should if you can.

76504: <p>I created a program that measures the pulses set out by the encoder (part of the dc motor with encoder inbuilt), and uses the ppr value (pulses per rotation) to calculate the rotations per minute (rpm)</p>
<p>However, the serial monitor continuously shows 0 for the variable &quot;pulsecount&quot;, that maintains the total pulses sent.
<a href="https://i.stack.imgur.com/bLGW7.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bLGW7.jpg" alt="enter image description here" /></a></p>
<p>code:</p>
<pre><code>float ppr=512.0;
int encpin=3;
volatile long pulsecount=0;
float revs;
float rps;
float rpm;
unsigned long time;


void setup()
{
  pinMode(encpin,INPUT);
  Serial.begin(9600);
  attachInterrupt(digitalPinToInterrupt(encpin),function,RISING); //when pulse is detected
                                           //interrupt triggered,
                                           //function callled  
}
void function(){
  pulsecount+=1;
}

void loop()
{
 revs= pulsecount/ppr ;
 time=millis()/1000;
 rps=revs/time ;
 rpm=revs*60;
 Serial.println(pulsecount);
}
</code></pre>
 70020: <p>You code counts pulses just fine when tested here.</p>
<p>Fan/motor tachometer outputs and encoders frequently are set to switch your signal contact to ground, either with a transistor or mechanically.  When the ground contact is not being made, the signal connection is floating and not reliably HIGH.  So, you need a pullup resistor on the pin, just like you do for a typical push button switch configured to switch to ground.</p>
<p>My comment on the question:</p>
<blockquote>
<p>What happens if you use <code>INPUT_PULLUP</code> rather than <code>INPUT</code>?</p>
</blockquote>
<p>was referring to doing this in your code:</p>
<pre class="lang-cpp prettyprint-override"><code>pinMode(encpin, INPUT_PULLUP);
</code></pre>
<p>At higher frequencies, higher RPM, you may need to use an external resistor to get a lower resistance value than the 20k-50k of the internal pullup resistor that <code>INPUT_PULLUP</code> enables.</p>
<p>It is best to turn off interrupts when you retrieve your <code>volatile</code> pulse counter variable so that there's no tearing of the value where the ISR interrupts your code mid-read and updates the latter half of the value.</p>
<p>e.g.:</p>
<pre class="lang-cpp prettyprint-override"><code>// Note I've switched your pulsecount variable
//  to unsigned long for this example.
unsigned long get_pulsecount() {
  noInterrupts();
  const auto r = pulsecount;
  interrupts();
  return r;
}
</code></pre>
<p>Note you can probably avoid <code>float</code> usage altogether, and should if you can.</p>
