测量时差 [英] Measuring time differences

查看:75
本文介绍了测量时差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!


我目前正在实施一项通过外部USB-AD转换器测量电压的程序。它应该输出这些值作为时间/电压

对。


我的问题是测量输出时间(自程序以来经过的时间

start会很好) - 它应该尽可能精确,因为

两次测量之间可能只有几毫秒的差异。


目前我正在使用(clock()/ float(CLK_TCK))作为时间值,这不足以让我足够准确,因为我得到类似的东西:


时间电压

0 0

0 0.062474

0 0.124792

0.01 0.186798

0.01 0.248337

0.01 0.309255

0.01 0.3694

0.02 0.428622

0.02 0.486773

0.02 0.543707

0.02 0.599282

0.02 0.653359

0.03 0.705803

0.03 0.756483

0.03 0.805272

0.03 0.852048

0.03 0.896695

0.04 0.939101

0.04 0.979159

0.04 1.01677


所以我需要一种更精确的方法来测量时差。什么

函数在C中可用?我想保持我的程序尽可能便携,但最后它应该只在Windows / DOS

机器上运行,所以我也可以使用DOS-只有在必要时才有功能。


非常感谢!

你的,

多米尼克·沃尔纳

解决方案

你可以在启动时使用gettimeofday(),然后在它之后定期调用

,将值与开头的值进行比较

的实验。 gettimeofday()以秒为单位返回当前时间

和微秒。


" coder1024" <共******* @ gmail.com>写道:

你可以在启动时使用gettimeofday()然后定期调用它,然后将值与实验开始时的值进行比较。 gettimeofday()以秒为单位返回当前时间
和微秒。




请阅读< http://cfaj.freeshell.org/google/> 。


gettimeofday()不是标准C.事实上,它是由POSIX

标准定义的,因为OP使用的是Windows / DOS环境,它可能无法获得



-

Keith Thompson(The_Other_Keith)< a href =mailto:ks *** @ mib.org> ks *** @ mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。


Dominik Wallner< do ******* @ yahoo.de>写道:

我正在实施一个通过外部USB-AD转换器测量电压的程序。它应该输出这些值作为时间/电压对。

我的问题是测量输出的时间(自程序开始以来经过的时间会很好) - 它应该尽可能精确,因为两次测量之间可能只有毫秒差异。

目前我正在使用(clock()/ float(CLK_TCK))作为时间值,因为我得到的东西不够准确:
[snip]


clock()测量CPU时间,而不是实时。

所以我需要一种更精确的方法来测量时差。 C中有哪些功能可用?我想保持我的程序尽可能便携,但最后它应该只能在Windows / DOS机器上运行,所以如果需要,我也可以使用仅限DOS的功能。



标准C中没有便携式功能可以用任何

特定精度来测量时间。 time()函数返回一个时间值

time_t,这只是一个能够表示

次的算术类型;典型的分辨率是1秒,但没有保证。


您应该在DOS或Windows新闻组中询问。


-

Keith Thompson(The_Other_Keith) ks***@mib.org < http://www.ghoti .net / ~kst>

圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。


Hi!

I''m currently implementing a program which measures voltages through an
external USB-AD-converter. It should output those values as time/voltage
pairs.

My problem is to measure the time to output (time elapsed since program
start would do just fine) - it should be as precise as possible, as
there may be only differences in milliseconds between two measurements.

Currently I''m using (clock()/float(CLK_TCK)) as time value, which is not
accurat enough as I get something like:

Time Voltage
0 0
0 0.062474
0 0.124792
0.01 0.186798
0.01 0.248337
0.01 0.309255
0.01 0.3694
0.02 0.428622
0.02 0.486773
0.02 0.543707
0.02 0.599282
0.02 0.653359
0.03 0.705803
0.03 0.756483
0.03 0.805272
0.03 0.852048
0.03 0.896695
0.04 0.939101
0.04 0.979159
0.04 1.01677

So I need a more precise way of measuring time differences. What
functions are available in C to do so? I''d like to keep my program as
portable as possible, but finally it should run only on a Windows/DOS
machine, so I can also use DOS-only functions if neccessary.

Thank you very much!
Yours,
Dominik Wallner

解决方案

you could use gettimeofday() when you start and then call it
periodically after that, comparing the values with the one at the start
of the experiment. gettimeofday() returns the current time in seconds
and microseconds.


"coder1024" <co*******@gmail.com> writes:

you could use gettimeofday() when you start and then call it
periodically after that, comparing the values with the one at the start
of the experiment. gettimeofday() returns the current time in seconds
and microseconds.



Please read <http://cfaj.freeshell.org/google/>.

gettimeofday() is not standard C. In fact, it''s defined by the POSIX
standard, and since the OP is using a Windows/DOS environment, it''s
likely not to be available.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


Dominik Wallner <do*******@yahoo.de> writes:

I''m currently implementing a program which measures voltages through an
external USB-AD-converter. It should output those values as time/voltage
pairs.

My problem is to measure the time to output (time elapsed since program
start would do just fine) - it should be as precise as possible, as
there may be only differences in milliseconds between two measurements.

Currently I''m using (clock()/float(CLK_TCK)) as time value, which is not
accurat enough as I get something like: [snip]

clock() measure CPU time, not real time.
So I need a more precise way of measuring time differences. What
functions are available in C to do so? I''d like to keep my program as
portable as possible, but finally it should run only on a Windows/DOS
machine, so I can also use DOS-only functions if neccessary.



There are no portable functions in standard C to measure time with any
particular precision. The time() function returns a value of time
time_t, which is merely an arithmetic type capable of representing
times; a typical resolution is 1 second, but there are no guarantees.

You should ask in a DOS or Windows newsgroup.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


这篇关于测量时差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆