Hello friends
I have encountered a very strange problem, I have keil with MDK3.08a version. When i compiled program and loaded in the target the execution speed of the program becomes considerably slower (not in debug mode). I have compared the speed with the previous version of keil (i don't remember may be 3.20).
Furthermore when i interchange the location of C file in the work space it effects the execution speed. When I compared the output hex file of the same project with interchanged c files position in work space, i found they were different.
Please help me out of this
Split this into multiple problems.
1) Figure out why you get a speed difference of 10x by moving a function from one memory address to another.
2) Make sure that hw communication is using hardware acceleration where possible. With I2C in hardware, the code will not need to busy-loop. You will instead have an interrupt handler - or maybe a status bit to poll for completion.
3) When doing things not suitable for hardware peripherials, then you should split it into short and long delays.
- long delays are best handled using the timers. Either waiting for an interrupt, or busy-looping while polling an interrupt flag or comparing the current timer value with the expected timeout value.
- short delays can be handled by sequences of NOP instructions. But you can't have a design where you rely on the majority of the delay to come from the compiler output of C code. You could possibly have a loop where the NOP instructions gives - at least - the required delay, and that any C overhead gives an unknown extra delay. But you would still have to make sure that the compiler sees some form of side effect that stops it from throwing away the loop in the first place. Good compilers normally treats their NOP intrinsic as a magic operation with side effects. The question you have to ask is if you want to rely on the compiler doing that - and that the compiler will continue to do that even if you are upgrading to a newer version - or maybe if you moves the code to a different compiler.