![]() ![]() Below is an example of a program for working with time intervals.ĭisabling interrupts with the noInterrupts() function for a long time may disrupt the system clock. To measure a time interval, it is necessary to read the system time at the beginning and end of the interval and calculate the difference of these values. The time is counted in a parallel process and does not depend on the algorithms of program execution, stops, including the function delay(), etc. In fact, this is a function of reading the Arduino system time. The time value overflows after 1193 hours, approximately 50 days. The function returns the time in ms, since the start of the current program. Stopping the program even for several tens of microseconds will not cause disastrous consequences.Short periods of time are difficult to implement with other methods.It is quite acceptable for use in practical programs for two reasons. The analogue of the function delay (), only provides shorter program stops. The function suspends the program for the time specified in μs.ĭelayMicroseconds (50) // pause for 50 µs In some applications, for example in a clock, the error can accumulate and lead to unacceptable errors. For example, the MsTimer2 library sets the time in ms. It is only necessary to understand that this method provides a stable cycle time, but it may differ slightly from the specified one. As a result, the cycle time can only be determined approximately.įor the organization of cycles with a given time, it is better to use a timer interrupt ( lesson 10). The transition time to the beginning of the cycle is also not defined exactly. The program block time may vary depending on the program execution algorithm. The cycle time is equal to the sum: the specified time 100 ms, the execution time of the program block and the transition time to the beginning of the while() cycle. For example, the time of the next cycle will not be exactly 100 ms. In addition, the function does not allow you to create cycles that exactly work out the specified time. This is not a permissible luxury, only valid in debug modes. The program does nothing for a given interval of time. In practical programs, the function is rarely used. More often it is used in debugging programs. We have already used this function in previous lessons. ![]() The function suspends the program for the time specified in ms. There are 4 standard functions for working with time in the Arduino system: Previous lesson List of lessons Next lesson Develop a sports stopwatch based on the Arduino board. ![]() We will consider the Arduino functions for working with time. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |