Calculating Number of Loops for Time Delay Using Micro-controller

How many loops do we need for a 130 ms time delay using a Micro-controller with 20-MHZ bus clock and 150 E-cycles in total?

The formula for calculating the number of loops needed to create a desired time delay is:

N = (T * F) / E

Where:

N is the number of loops

T is the desired time delay in milliseconds

F is the clock frequency in megahertz

E is the number of E-cycles per loop

In this case, we have:

T = 130 ms

F = 20 MHz

E = 150

Plugging these values into the formula, we get:

N = (130 ms * 20 MHz) / 150 = 193 loops

Therefore, we need to execute 193 loops to create a 130 ms time delay.

Detailed Calculation Process:

1. Convert the desired time delay from milliseconds to seconds:

130 ms / 1000 = 0.13 s

2. Multiply the time delay in seconds by the clock frequency in megahertz:

0.13 s * 20 MHz = 2.6 MHz

3. Divide the number of clock cycles by the number of E-cycles per loop to get the number of loops:

2.6 MHz / 150 = 193 loops

Therefore, we need to execute 193 loops to create a 130 ms time delay.
← Creative nail shapes squoval nails The stopping distance of a passenger car traveling at 55 m p h →