Arduino Asynchronous Function Crash
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)