Thermocouple - continuous stepper speed control

I want to precisely control the speed of a stepper motor based on a temperature input from a thermocouple.

The thermocouple reading needs to be averaged over a period of about 2.5s, but the stepper motor must remain functioning at a precise speed while the arduino is reading the thermocouple. (The stepper controls fluid flow in a peristaltic pump, which needs to be carefully adjusted based on temperature of the fluid)

I'm not sure how to maintain the stepper output with any accuracy while also reading the temp input. Would I simply be able to do the temperature calculations in the time (as short as 3ms) between steps? And then how do I still keep the step time constant if i'm doing different calculations between different steps?

I have a pretty decent understanding of many things arduino but the clock and things of critical timing nature are still a bit confusing.


In general, 3ms is a "long" time for things like temperature computations. I'm guessing you're just going to be adding temperature readings to a running sum and taking the average? That's very little work compared to what 3ms affords you.

See the BlinkWithoutDelay example sketch for how to make things happen at precise intervals.

Beyond that, you can dig into interrupt-based processing for even finer control. But I doubt that will be necessary for your application.

-- The Rugged Motor Driver: two H-bridges, more power than an L298, fully protected

3ms is oooodles of time to compute temperature - which I assume is taken an analog reading or two, doing some math -multiply etc, even fancy functions, to map the analog read into a "temperature".

I suspect your worry is keeping the steps. Look at the blink-without-delay example. The same technique enable you to send steps to your motor at intervals determined by the delta to the last millis() og micros(), after having "wasted" a lot of CPU doing the calculation.

The only thing to watch out for is doing Serial output, it will block your loop, unless done in small writes.

Aha! I forgot about millis() entirely.

I Don't think Serial output will be used. I'll have to output to a 16x2 parallel display, though, and i'm not sure how the "mbed.h" and "TextLCD.h" libraries function so they may cause some problems.

Thanks for the suggestions!