Hi All,
For my own purposes, I wanted to know what the timing was like between the time you exit the loop() function, and when it is re-entered. I know the firmware is doing work during that time maintaining the WiFi and Cloud functionality. I have a project in mind where deterministic times around the loop() will be critical. So, I did a series of software experiments, and here are the results. I hope this information is useful to the community.
Tested: Photon
Firmware Version: 0.4.3
Unless otherwise stated, all times are from loop() exit until it is re-entered.
Automatic Mode
Typical: 998 µS
Maximum: 14,383 µS
Note: I tried creating cloud variables and calling cloud functions. None of that significantly increased these numbers
Semi Auto Mode
No WiFi or Spark Connection
Typical: 3 µS or 8 µS
Maximum: 45 µS
WiFi Connected but not Spark
Typical: 3 µS or 8 µS
Maximum: 270 µS
Spark Connected
Typical: 997 µS
Maximum: 13,698 µS
Manual Mode
No WiFi or Spark Connection
Typical: 3 µS or 8 µS
Worst Case: 45 µS
WiFi Connected but not Spark
Typical: 3 µS or 8 µS
Maximum: 267 µS
Spark Connected
Typical: 5 µS
Maximum: 129 µS
In Manual mode calling Spark.process() manually takes …
Typical: 992 µS
Maximum: I didn’t test this, but I bet it is like 13,000 or 14,000 like in automatic mode
Finally, I wrote a tight while(1){}
and never exit the loop() function
No WiFi or Spark Connection
Typical: 0.1 µS
Maximum: 0.1 µS
WiFi Connected but not Spark
Note: Not sure if I can actually operate on WiFi (Didn’t try, I should probably test this.)
Typical: 0.1 µS
Maximum:0.1 µS
Spark Connected: HANGS Apparently you need to exit the loop() function for Spark.connect() to work
Note: This mode makes the Photon useless as a could device, and I suspect WiFi won’t work either.
Conclusion:
The worst case I saw was the return to loop taking 14,383 µS. This is 0.014 seconds. This occurred rarely, and the typical loop() time was around 1,000 µS (or 0.001 seconds). It seems to me that for the vast majority of purposes this would be sufficient responsiveness of the loop() cycle. If for some reason you need loop to run faster or more predictably, then the manual modes would probably be for you and you could turn off Spark cloud functions until you need them.