Go Down

Topic: newbie time problem (Read 932 times) previous topic - next topic

matejj

hi all,
I'm trying to evaluate the time necessary to run a function but seem to have an issue with units. Here's the code :
Code: [Select]

  unsigned long timeNecessary1 = 0;
  unsigned long timeNecessary2 = 0;
  timeNecessary1 = micros();
  IRscan(); // this is my function
  timeNecessary2 = micros();
  Serial.begin(9600);
  Serial.println("");
  Serial.println(timeNecessary1,DEC);
  Serial.println(timeNecessary2,DEC);


Then i substract one from the other. The problem is the numbers don't make any sense. The results are :

  • timeNecessary2 is 2483394992

  • timeNecessary1 is 23462246


When i substract one from the other i get 2.12*10^3 seconds wich does not make sense. Do you guys see any issues with the code?

baum

Code: [Select]
micros()
returns the microseconds. 1 micro (u) second = 1/1000000 of a second. So 2.12e3 or 2120 micros actually =s 2120 millionths of a second. This equals 2.12 thousandths of a second, or 2.12 milliseconds, which in turn equals .00212 seconds.

good luck!

MarkT

Well you need to check your arithmetic:  2483394992 - 23462246  = 2459932746 us = 2.46e3 seconds, not 2.12e3

Also how long does the function actually take?  Are you using timer0?
[ I won't respond to messages, use the forum please ]

matejj

Thanks for quick reply. I do not know how long my function takes, this is why I am doing this test. Is there a better way MarkT?

Coding Badly

The code you posted, does it run with interrupts disabled?

matejj

i do not know. What does it mean and how can i figure this out? I am not using any delay() if this is what you mean.

Coding Badly

Is all the code yours or did you obtain some of it from someone else?  If it is all yours then interrupts are not an issue.  If you have obtained some of it from another source then search for "sei" and "cli" calls.

Which libraries are you using?

matejj


Is all the code yours or did you obtain some of it from someone else?  If it is all yours then interrupts are not an issue.  If you have obtained some of it from another source then search for "sei" and "cli" calls.

Which libraries are you using?



The code is all mine except for the SoftwareSerial library which I am also using to print the results.

Coding Badly

Code: [Select]
Serial.begin(9600);

...is that call inside loop?

matejj


...is that call inside loop?


No everything is done only once in Setup. But i did find the problem and my units were wrong. Thanks guys for your support.

PaulS


The code is all mine except for the SoftwareSerial library which I am also using to print the results.

SoftwareSerial has been obsolete for a long time. It's time for you to upgrade to NewSoftSerial.

Go Up