Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how2 calculate the delay cycle time4 MCU in C programming?

Status
Not open for further replies.

brennbar67

Member level 3
Joined
Jul 26, 2004
Messages
54
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
580
i'm not sure how2 calculate delay time by using for loop.
If using 8Mhz clock, what is the delay time for this example below:

for(i=1; i<20; i++);

Is it calculate like this? 19 x( 1/8Mhz) = 2.375us

I just know how2 using assembly language calculate, but i dunno is it C program similar with assembly.

Anyone know??
 

if you have emulator, just calculate the corresponding assembly code, if you don't have an emulator, then you can make your C compiler to output the assembly list, it can help you too.
 

Re: how2 calculate the delay cycle time4 MCU in C programmin

no,i dun have emulator.
But i want to learn calculate using C program.
 

It's impossible to calculate the CPU execute cycle by counting C code. the cycles depend on the assembly code, different C compiler will make different result.
But if you just want to know the delay time roughly, you can use the timers in the MCU to help you out, you can start the timer before the loop, then get the timer count after the loop. you will know the time, the precision depend on the timer's clock source.
 

Re: how2 calculate the delay cycle time4 MCU in C programmin

It's true you can't count it simply by looking at the C source code. C compilers for PICs are simply C-to-asm translators. Since only asm instruction timings are provided, you'll have to know how the translation is done before you can count the timings. If you understand asm and only want to count a segment of the code, you could compiler the code first, look at the lst file and count the timings.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top