You can do that by one or several counters decrements by a timer interrupts.
Here the code to initialize and handle the interrupt :
volatile unsigned long myCounter = 0;
void setup()
{
TCCR1B = (TCCR1B & ~_BV(WGM13)) | _BV(WGM12); // Set CTC mode (Clear Timer on Compare Match)
TCCR1A = TCCR1A & ~(_BV(WGM11) | _BV(WGM10)); // ...
TCCR1B = (TCCR1B & ~(_BV(CS12) | _BV(CS11))) | _BV(CS10); // No prescaler
OCR1A = 160; // Set the compare register (16e6 Hz / 100000 Hz = 160) for 10 uS
TIMSK1 |= _BV(OCIE1A); // Enable interrupt when TCNT1 == OCR1A
}
ISR(TIMER1_COMPA_vect)
{
if (myCounter)
{
myCounter--;
}
}
Then in your loop you can initialize the counter(s) to execute or not execute parts of code :
void loop()
{
// code always execute
// ...
// ...
if (!myCounter)
{
// code execute only each 2 milliseconds
// ...
// ...
myCounter = 200 // value for 2 milliseconds
}
// code always execute
// ...
// ...
}
JLB