Go Down

Topic: delays at the start (Read 3341 times) previous topic - next topic


I was looking at interfacing something new. The code written for another system starts with a delay; presumably for power to come up and stabilize. This is similar to what is at the start of other device drivers eg LiquidCrystal which I know pretty well.

It suddenly struck me that Millis() counts from power up. Is it generally more appropriate to just read millis() and check to see that it is greater than a specific number? On the face of it this seems right, BUT

In my speicific case the first move I made away from copying working sketches was to pull the LCD ooff the breadboard and slide it into the digital pins on the far end of the mega. I WAS LUCKY. To make this work I needed to set a digital pin high to provide power. So in that  case the optimization would have stopped me cold. I'm curious what other people think. Those delays are often on the order of seconds and in general it seems like the idea in the second paragraph is reasonable.


The point is that with multiple devices to start up or in a situation like Liquidcrystal (where begin() reboots the device) a delay to let the power settle could be MUCH shorter if you can look at millis() and just be sure the power has been on long enough. But this doesn't seem to be accepted practice


No comments. Fascinating.

So should all the delays for devices to boot get changed from

while (millis() < x) {}            ?

The lack of nay saying makes me think the answer is YES.

Then you would initialize your fastest to warm up device first; save the slowest for last. If the user does something goofy like power a device from a digital pin, he would be responsible for noting millis() when he powered on and putting in his own delay (possibly initializing other things in between) before calling the initialization for that device.

This could save seconds at start time over what seems to be standard practice.


The lack of nay saying

Perhaps (like me) people didn't reply because they didn't understand what you were getting at?

In most cases, your startup delay is taken care of by the bootloader.
Some people are like Slinkies.

Not really good for anything, but they bring a smile to your face when pushed down the stairs.


That does remind me of something that Don Weiman pointed out to me once: startup delays ARE unnecessary if power is applied during the bootloader process.

To TEST startup delays you have to be sure that you power down and run the code from flash memory at power up.

Go Up