Arduino Asynchronous Function Crash I'm trying to make two functions one will be running in a loop the second one will be running with a time interval of 1 seconde
I made a piece of code to do so it runs fine in the beginning but after a bit of time (aproximately 35 secondes) the code loses its mind and starts executing without caring about the delays.
I don't know what's going on
here is my code  

void loop() {
  if(millis()-prev&gt;=gap){
    Serial.print("Prev: ");Serial.println(millis()-prev);
    prev = millis();
  }

  Serial.print("Prev2: ");Serial.println(millis()-prev2);
  delay(mils);
  prev2 = millis();
}


You can try it yourself the code runs fine at the begining but bugs after some time.
What i'm trying to acomplish is having some code that runs in a loop and a function that will run each seconde.
the code is tried on multiple boards of Arduino Uno.
Your problem is that you use delay() in your loop. This stops the code execution for the given time, so no wonder your code starts to frickle after some time.

To achieve what you want try this:

void loop() {
  if(millis() - prev &gt;= gap){
    Serial.print("Prev: ");Serial.println(millis()-prev);
    prev = millis();
  }
  if(millis() - prev2 &gt;= mils){    
  Serial.print("Prev2: ");Serial.println(millis()-prev2);
  prev2 = millis();
 }
}


EDIT If you try to create a frequency generator, it won't work that way - read this thread and look at the program in the last third which uses bitbanging technique to achieve that. Here an example of a wave generator (with extra hardware)