Optimization might be deleting the loop processing.
You can prevent the deletion of loop processing by calling the nop* intrinsic function in the for statement or by qualifying the loop variable i as volatile.
However, the version of the compiler and compiler options may affect the output code, so the processing time might be different even for the same C code.
Thus, if you change compiler versions or options, you need to check if the processing time is still as you expected.
If you write the code to set up the specified waiting time in assembly rather than C, the above phenomena will not apply.
If interrupt processing also proceeds within the loop, the time for this will also be included, so this must also be considered in choosing the number of times to loop when adjusting the waiting time.
If the waiting time requires precision, we recommend using a timer of the MCU to measure the time, instead of a software timer where the time is set up by program code.
*: The nop function differs according to whether it is the nop function of CC-RX or the __nop function of the CC-RH and CC-RL compilers. Refer to the user's manual of the given compiler for details.
- C Compiler Package for RH850 Family (CC-RH)
188.8.131.52 Embedded Functions
- C/C++ Compiler Package for RX Family (CC-RX)
4.2.6 Intrinsic Functions
- C Compiler Package for RL78 Family (CC-RL)
4.2.5 Embedded Functions
|CS+ (formerly CubeSuite+)|
|C Compiler Package for RH850 Family|
|C/C++ Compiler Package for RX Family|
|C Compiler Package for RL78 Family|