2

I am designing a driver for a Bipolar stepper motor using Arduino Mega 2560 and DRV8825 Stepper driver.

In my application, a stepper motor (Nema 24) will run for 5 minutes and stop for 2 minutes. I have doubts about is what is the maximum time an Arduino Mega can delay the process, or how much a maximum time delay() function will last, or work in programming?

3

Note: there's an existing question here this should be closed as a duplicate of, but that is proving hard to find. So until someone does find it...

The arduino delay() function creates a blocking delay of the provided number of milliseconds. The argument is an unsigned long which on a 16-bit Arduino is a 32-bit unsigned integer type, having a maximum value of 4,294,967,295. Since these are milliseconds, the maximum delay() would be 4,294,967.295 seconds, or about 49 days.

However, you can easily achieve longer delays by using counting variables to count up instances of shorter delays. At an extreme, by using up available memory for keeping track of such counting, you can readily achieve theoretical delays exceeding the age of the universe.

Note that the Arduino delay() function is blocking, which is to say that nothing else (except interrupts and on-chip hardware peripherals) runs during it. This is often undesirable. A more useful solution might be to make a loop taking say 20 milliseconds to run, as the result of a delay() and a few housekeeping operations, and then run this over and over again while counting. Or you could make a 1 second loop, or whatever you choose.

|improve this answer|||||
-2

what is the maximum time an Arduino Mega can delay the process,

practically infinite -> as it depends on your code and the hardware.

or how much a maximum time delay() function will last,

the counter is a 32-bit type so the max it can handle is 2^32 before overflowing.

that means 2^32ms -> ...

or work in programming?

that depends on your code. you can easily expand its range beyond the number suggested earlier.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.