1

I making a Localization project Using Arduino and Xbee Zg where i need to measure time in nano second resolution im using arduino due board with 84 Mhz clock and arduino 1.5.2 IDE

im trying to use clock_gettime function i already included time.h but i get the same compiling error clock_gettime is not declared in this scope

this is just a part of my Distance_Measurement.c file

#include "Distance_Measurement.h"
#include "time.h"
struct timespec start, stop;

bool Start_Time()
{
 if(clock_gettime(CLOCK_REALTIME,&start) == -1)
    return false;
 else 
    return true;
}

bool Stop_Time()
{
  if(clock_gettime(CLOCK_REALTIME,&stop) == -1)
    return false;
  else 
    return true;
}

double Cal_Time_Nano()
{ 
    return (stop_time.tv_nsec - start_time.tv_nsec);
}

please help me

PrinceOfEgy
  • 21
  • 2
  • 5
  • 1
    For reference, 84 MHz =~= 11.9 ns/cycle. You're simply not going to get true nanosecond resolution, just an approximation based on 11.9ns ticks (if even that). – cHao Dec 22 '13 at 18:21
  • long-shot, but seeing as _GCC looks for headers requested with #include "file" first in the directory containing the current file, then in the directories as specified by -iquote options, then in the same places it would have looked for a header requested with angle brackets. For example, if /usr/include/sys/stat.h contains #include "types.h", GCC looks for types.h first in /usr/include/sys, then in its usual search path._, check your `-iquote` options, or try `#include ` – Elias Van Ootegem Dec 22 '13 at 18:24
  • Yeah i know the signal propagates 1m in 3.3 ns so i will get an error +- 4m in measured distance which is acceptable – PrinceOfEgy Dec 22 '13 at 18:24
  • i first used #include i got the same error i have found that visual studio have included anther time.h not time.h in arduino gcc so i copied the last one and pasted it to arduino libraries path with my distance measurement library – PrinceOfEgy Dec 22 '13 at 18:33
  • @PrinceOfEgy: Since you are using visual studio: are does the IDE auto-compllete the `clock_gettime` function, for example? if it doesn't, have a look at the `time.h` file that is included, and compare the two, perhaps they include some Microsoft derivative version of the time header... does it use namespaces, in which case, you're dealing with a C++ header... could you specify the differences between the included header file and the one you're actually trying to use? do you have access to a *NIX system, and does your code compile there? are you including `stdfax.h`? – Elias Van Ootegem Dec 22 '13 at 21:38
  • well the first time.h doesn't mention any thing about `clock_gettime` the second one has this line written to it int _EXFUN(clock_gettime, and other parameters – PrinceOfEgy Dec 23 '13 at 15:23
  • As @cHao said, 84MHz ~= 11.9 nano seconds. You won't be able to get true nanosecond resolution. In the past, I've just used the `micros()` function. An example can be found here: [http://arduino.cc/en/reference/micros.](http://arduino.cc/en/reference/micros) Good luck. – Progo Jan 03 '15 at 16:27

1 Answers1

0

i first used #include i got the same error i have found that visual studio have included anther time.h not time.h in arduino gcc so i copied the last one and pasted it to arduino libraries path with my distance measurement library – PrinceOfEgy

Armali
  • 18,255
  • 14
  • 57
  • 171