Multitasking while one loop takes more time then second loop interval

So I'm trying to keep my stepper motor rotate at a constant speed, and read the temperature. My idea was to use a moving event concept using millis(). (Just an idea code below)

const unsigned int motorInterval = 6;
const unsigned int tempInterval = 50;

unsigned long motorPreviousTime = 0;
unsigned long tempPreviousTime = 8;

unsigned long currentTime = 0;

void loop(){
currentTime = millis();

if( currentTime - tempPreviousTime >= tempInterval){

    ;measure temp + print to lcd
    tempPreviousTime = currentTime;
}

if( currentTime - motorPreviousTime >= motorInterval){

    ;do single step
    motorPreviousTime = currentTime;
}


}

The problem is to keep my motor rotate 50 rpm, I need to do a single step every 6 ms. And the temperature measurement takes 850 ms. At this point, my program fails. Temperature measurement
overlaps motor stepping causing much slower rotation (motor acts weird).

I use ds18b20 sensors with one wire interface and DallasTemperature.h library. Stepper motor with A4988 driver.

So you need a non-blocking way to read temperature.

you could step the motor in an interrupt triggered every 6 msec

gcjr:
you could step the motor in an interrupt triggered every 6 msec

Yeah, that should solve the issue !

And the temperature measurement takes 850 ms.

it really takes close to a second to read a temperature sensor?

gcjr:
it really takes close to a second to read a temperature sensor?

Yes, if you use the most commonly used library, which is blocking. The temp IC is horribly slow. There are much better temperature sensors on the market.