This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Timer increases, but variable not ...

Hello, I have a problem with this code:

void test(void)
{
  unsigned long time_start, time_diff;
  unsigned int x=2;

  time_start = timer_value;

  while (x<5)
  {
        time_diff = timer_value;
        if (time_diff-time_start >= 2ul) x=5;

	//  printf("%X\n", time_diff-time_start);
  }
}

timer_value is incremented by Timer T0 10 times a second (IRQ-Routine). This part of code should wait for approx. 0.1 .. 0.2 seconds. But if there is no printf-Command timer_diff doesn't increment. If I stop the Debug-Mode of uVision and take a look at timer_value then it really increased, but time_diff still got the same value as time_start. Why?
If the printf-Command is included, everything works fine ...

Thanks for any hint

Torsten

0