A timer in a function

You should initialize local variables.

bool xInit;

if (xInit== 0)