This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RM48 delay function

Other Parts Discussed in Thread: HALCOGEN

Hello

I have been working on Rm48USB development kit. I have used RTI for 1 sec interrupt but now I need to use polling method. 
I have enabled only GIO driver from halcogen, and 

#include "het.h"
#include "gio.h" 

in sys_main.c

So how can I create exactly 1 sec of delay ?
I already read following link but didn't understood.


e2e.ti.com/.../455575

  • Hello Ankush,
    If you want exactly 1 second then using RTI is your best option. The other post suggests to use a software method to count time. It is normally not a very accurate method. For example, if you write a simple loop like for (i-0;i<10000000; i++), this loop can translate into certain time delay. Let's say the CPU is running at 100MHz so each CPU cycle is 10ns. For the CPU to execute one loop, let's say it takes 10 CPU cycles to complete. This means that one loop creates a delay of 10ns * 10 = 100ns. Since you are looping for 10000000 times then it gives you roughly 1 second as 10000000 * 100ns is 1 second. There could be several factors you need to take into account in your application when using software approach.

    1. The number of cycles to execute one loop depends the flash memory wait states. The program is stored in the flash so the CPU must fetch the instructions from the flash. The number of cycles to read one instruction depends on the the speed of the flash access relative to the CPU frequency and also the flash pipeline architecture. For example, let's say it takes 20ns to read the flash data. At 100MHz CPU frequency, it needs to take two cycles to retrieve the data. But if you run the CPU at 200MHz you will need to wait 4 cycles to retrieve the data. The flash controller also has built in pipeline logic so that it can prefetch the next sequential data in advance. For a pipeline line hit, it just waits one cycle for the data but for a pipeline miss it takes 4 cycles. These factors may cause your software delay loop to be inaccurate.
    2. What if in the middle of your software wait loop that you have an interrupt from a different source such as SPI or UART message that the CPU needs to service. This interrupt events will interrupt the CPU from counting the software delay. Your 1 second delay can become slightly more than 1 second now.
    3. Waiting in a loop for 1 second means the CPU is not doing anything useful.

    With this much said, you can come close to your 1 second target but even in an idea situation you may only come close to 1 second plus or minus some CPU cycles.
  • Hi Charles

    Thanks for your wonderful explanation.
    I just want to know, is there any delay function already created in any header files, so that I can include them and use it ?