Calling a routine every x miliseconds
Pseudo code:

volatile int ms_counter;
volatile bool passed_1ms;
volatile boole passed_20ms;

(ISR executed every 1 ms through a timer interrupt - platform dependent)
ISR {
  ms_counter++;
  if (ms_counter % 20 == 0) {
    passed_20ms = true;
  }      

  passed_1ms = true;
}


main()
{

  // configure timer to trigger an interrupt every 1ms

  while(true) {
    if (passed_1ms) {
      // 1ms has passed, do something
      passed_1ms = false;
    }
    if (passed_20ms) {
      // 20ms tasks go here
      passed_20ms = false;
    }
    // Do other tasks
  }
}