Arduino skips code on liquid filler

Late response but I incorporated the changes you suggested and it works flawlessly now, thank you very much!
For the curious this is the main change I made:

int ObtenerFrecuecia()  //Function for obtaining the frequency of the flow sensor
{
 noInterrupts(); //Reset pulse count
 int frecuencia;
 NumPulsos = 0;   //Pulse number is reset
 interrupts();    //Re-enable interrupts for polling
 delay(500);   //500 ms sample
 noInterrupts(); //Re-disable interrupts to get the frequency
 frecuencia=NumPulsos; //frequency is saved
interrupts(); //Re-enable interrupts to avoid sabotage of other functions.
 return frecuencia;
}