timing problem with the arduino.

hello my arduino friends.

i got some strange problems with my arduino,

i want it to do a task every second. (this should be near precisely)
so, i wrote this time function:

aktuelleZeit = millis();
if(aktuelleZeit > naechsteZeit){
standBy();
naechsteZeit = millis() + closingTime;
}

but the problem is now, it doesnt do it nearly rhythmic. the value changes strangely. some times, it leasts nearly 2 secs until he starts the task.

has anyone an idea how to do this?

thank you!!!

What does StandBy() do? Since you're checking millis() above the call to StandBy, then again after it, you'll get two different results for millis() depending on how long StandBy takes to complete.

Replace the first call to millis() with an assignment to a temporary variable, and in the second use that variable instead of calling millis() again.