Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

Timing calculation help!

Altera_Forum
Honored Contributor II
1,000 Views

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?
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
341 Views

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).
0 Kudos
Reply