Page 190 - ARM Based Microcontroller Projects Using MBED
P. 190

176                          8. INTERMEDIATE LEVEL PROJECTS











                 FIG. 8.36  Typical display from the program.

                                    BEGIN
                                           Display heading
                                           J = 10,000
                                           DO 10 times
                                                  Start Timer
                                                          DO J times
                                                          ENDDO
                                                  Stop Timer
                                                  Display J and Elapsed time
                                                  J = 2 * J
                                           ENDDO
                                    END

                 FIG. 8.37  Program PDL.

                               TABLE 8.3 Timer Functions
                               Timer Function            Description
                               stop                      Stop the timer
                               start                     Start the timer
                               reset                     Reset timer to 0
                               read                      Read the elapsed time in seconds
                               read_ms                   Read the elapsed time in milliseconds
                               read_us                   Read the elapsed time in microseconds

                   Table 8.3 presents the various Timer functions available with Mbed. The following steps
                 show how to measure the elapsed time in part of a program:

                 • Define a Timer variable, for example, Timer tim
                 • Start the Timer, for example, tim.start()
                 • Program code whose duration will be measured
                 • Stop the Timer, for example, tim.stop()
                 • Read the elapsed time in seconds, for example, tim.read()
                 • Reset the Timer to 0, for example, tim.reset()
                   The elapsed time can be read in seconds, milliseconds, or in microseconds. It is important
                 that the Timer should be reset to 0 before it is used successively.
   185   186   187   188   189   190   191   192   193   194   195