Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - This delay is different from the delay function I have seen before. How to understand the following passage?
This delay is different from the delay function I have seen before. How to understand the following passage?
The delay of idle operation through the loop can be approximated without multiple processes.

The specific method is similar to this.

Calculate the number of cycles according to the number of microseconds to be delayed.

This calculation ratio is 5/4 in this example, probably 1.25.

In other words, it takes about 0.8 microseconds to execute a for loop.

In this way, if a delay of 1000 microseconds is required, a cycle of 1000/0.8 is required, that is, 1000*5/4. When the delay value is not a multiple of 4, the calculation will have an error.

The maximum error is 3 cycles, that is, 3*0.8=2.4 microseconds. Generally speaking, such an error should be acceptable.

As for the specific value of this parameter, it depends on the time required to execute a for loop operation, that is, the time to add and judge once.

This should be calculated according to the CPU frequency and can also be measured.