# Thread: Timing calculation help!

1. Altera Pupil
Join Date
Mar 2014
Posts
8
Rep Power
1

## Timing calculation help!

Hi, I'm new to nios. I'm writing an app to calculate position of a moving point.

S = S0 - v*t.

I need help to implement the t value.
I'm thinking of using for loop

for (t=0;t<1000;t++) {
S = S0 - v*t;
}

As I understand, each t increase will be equivalent to 1 clock cycle so it will be 20ns (my clock is 50MHz). So if I want t to calculate in second I must do it like this:

S = S0 - v*t*20/1000,000,000

Is it usable or I must use timer interval core?

2. Altera Guru
Join Date
Jun 2013
Location
The Netherlands
Posts
524
Rep Power
1

## Re: Timing calculation help!

I have some limited experience with NIOS, so what I write is a more general answer.
Having said that, you need to look into the cycle count of each operation. This one line of code actually does three things:
1. multiply v and t
2. substract that result from S0
3. store that result in S

Then you need to know the types of the inputs and results. Floating point arithmetic may take longer than integer calculations.
Then you need to know how much of those 3 steps are run in one cycle. Generally the store comes "free" with any other operation, i.e. it does not have a cost in cycles. On top of this the compiler may do some compiler magic so you don't exactly know the cycle count until you take a look at the assembler code, or write your own assembly code. As long as you know the cycle count you can calculate the time it takes to execute one loop iteration (the a loop also takes instructions, unless it is unrolled).

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•