Autor Beitrag
Martin91
Hält's aus hier
Beiträge: 5



BeitragVerfasst: Do 31.05.07 12:02 
Hi,
Mein name ist Martin Funk bin 16 jahre alt und komme aus dem raum Geilingen an der Steige.

Ich suche eine möglichkeit zeitabstände kleiner 1ms zu messen wie geht das geht das überhaupt?

MfG Martin
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Do 31.05.07 12:06 
Such mal nach
QueryPerformanceCounter
Damit kannst du Zeiten messen, aber sowas wie nen Timer der kleiner als 1ms ist geht nicht. Die kleinste Zeiteinheit ist 8 oder 16 msek.
Ansonsten musst du eine Endlosschleife machen und darin selbst die Zeit berechnen (deshalb laufen Echtzeitspiele auch immer auf 100% Prozessorauslasung)
Hat etwas mit dem Threadwechsel zu tun etc.

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
Martin91 Threadstarter
Hält's aus hier
Beiträge: 5



BeitragVerfasst: Do 31.05.07 12:16 
Und woher weis ich wie lang ich zählen muss?
passiv
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 270

WIN XP Professional
Delphi 7 Enterprise, Java (Eclipse), Python 2.5, Django 1.1
BeitragVerfasst: Do 31.05.07 12:36 
probiers mit gettickcount. ich glaub der liefert das kleinste was an zeit zu liefern ist. aber auch nur milliseks

_________________
Die Probleme, die es in der Welt gibt, sind nicht mit der gleichen Denkweise zu lösen, die sie erzeugt hat.
Albert Einstein
azubi_20
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 593

WinXP SP2, Ubuntu 8.4
D7 Enterp., D2005 Prof., Java (Eclipse 3.4.0)
BeitragVerfasst: Do 31.05.07 12:43 
@user profile iconMartin91: Nur mal so aus Interesse, wofür brauchst du das denn?
Tastaro
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 414
Erhaltene Danke: 23



BeitragVerfasst: Do 31.05.07 13:20 
Vielleicht hilft dir ja das weiter:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
unit uTimer;

interface

uses
   windows,
   sysutils;

type
   to_timer = class(tobject)
   protected
      dTicksPer_s: double;
      dTicksPer_ms: double;
      dTicksPer_us: double;
      i64Start: int64;
      i64Stop: int64;
      boWrap: boolean;
      procedure wait(i64Delay: int64 );
   public
      constructor create;

      procedure delay_s(const i64Value_s: int64);

      procedure delay_ms(const i64Value_ms: int64);

      procedure delay_us(const i64Value_us: int64);

      procedure start_s(const i64Value_s: int64);
                overload;
                
      procedure start_s(const rTime_s : real);
                overload;

      procedure start_ms(const i64Value_ms: int64);

      procedure start_us(const i64Value_us: int64);

      function is_off: boolean;

      function is_running: boolean;

      function elapsed_s: double;

      function elapsed_ms: double;

      function elapsed_us: double;

      function elapsed_ticks: int64;

      function due_s: double;

      function due_ms: double;

      function due_us: double;

      function ticker: int64;
   end;


implementation


constructor to_timer.create;
var
   i64Actual: int64;
begin
   inherited create;
   i64Start := 0;
   i64Stop := 0;
   boWrap := FALSE;
   queryperformancefrequency(i64Actual);
   dTicksPer_s  := i64Actual;
   dTicksPer_ms := i64Actual / 1E3;
   dTicksPer_us := i64Actual / 1E6;
end;

procedure to_timer.wait(i64Delay: int64);
var
   i64Actual: int64;
   i64StartInternal: int64;
   i64StopInternal: int64;
   boWrapInternal: boolean;
begin
   queryperformancecounter(i64StartInternal);
   i64StopInternal := i64StartInternal + i64Delay;
   boWrapInternal := (i64StopInternal < i64StartInternal);
   if boWrapInternal then
   begin
      repeat
         queryperformancecounter(i64Actual);
      until (i64Actual >= i64StopInternal) and (i64Actual < i64StartInternal);
   end
   else
   begin
      repeat
         queryperformancecounter(i64Actual);
      until (i64Actual >= i64StopInternal);
   end;
end;

procedure to_timer.delay_s(const i64Value_s: int64);
begin
   wait(round(i64Value_s * dTicksPer_s));
end;

procedure to_timer.delay_ms(const i64Value_ms: int64);
begin
   wait(round(i64Value_ms * dTicksPer_ms))
end;

procedure to_timer.delay_us(const i64Value_us: int64);
begin
   wait(round(i64Value_us * dTicksPer_us));
end;

procedure to_timer.start_s(const i64Value_s: int64);
begin
   queryperformancecounter(i64Start);
   i64Stop := i64Start + round(i64Value_s * dTicksPer_s);
   boWrap := (i64Stop < i64Start);
end;

procedure to_timer.start_ms(const i64Value_ms: int64);
begin
   queryperformancecounter(i64Start);
   i64Stop := i64Start + round(i64Value_ms * dTicksPer_ms);
   boWrap := (i64Stop < i64Start);
end;

procedure to_timer.start_us(const i64Value_us: int64);
begin
   queryperformancecounter(i64Start);
   i64Stop := i64Start + round(i64Value_us * dTicksPer_us);
   boWrap := (i64Stop < i64Start);
end;


procedure to_timer.start_s(const rTime_s : real);
begin
   if (rTime_s < 1e-3) then
      start_us (Round (rTime_s * 1e6))
   else if (rTime_s < 1) then
      start_ms (Round (rTime_s * 1e3))
   else
      start_s (Round (rTime_s));
end;


function to_timer.is_running: boolean;
var
   i64Actual: int64;
begin
   queryperformancecounter(i64Actual);
   if boWrap then
      Result := (i64Actual >= i64Start) or (i64Actual < i64Stop)
   else
      Result := i64Actual < i64Stop;
end;

function to_timer.is_off: boolean;
var
   i64Actual: int64;
begin
   queryperformancecounter(i64Actual);
   if boWrap then
      Result := (i64Actual >= i64Stop) and (i64Actual < i64Start)
   else
      Result := i64Actual >= i64Stop;
end;

function to_timer.elapsed_s: double;
var
   i64Actual: int64;
begin
   queryperformancecounter(i64Actual);
   if i64Actual > i64Start then
      Result := (i64Actual - i64Start) / dTicksPer_s
   else
      Result := (high(int64) - i64Start + i64Actual) / dTicksPer_s;
end;

function to_timer.elapsed_ms : double;
var
   i64Actual: int64;
begin
   queryperformancecounter(i64Actual);
   if i64Actual > i64Start then
      Result := (i64Actual - i64Start) / dTicksPer_ms
   else
      Result := (high(int64) - i64Start + i64Actual) / dTicksPer_ms;
end;

function to_timer.elapsed_us: double;
var
   i64Actual: int64;
begin
   queryperformancecounter(i64Actual);
   if i64Actual > i64Start then
      Result := (i64Actual - i64Start) / dTicksPer_us
   else
      Result := (high(int64) - i64Start + i64Actual) / dTicksPer_us;
end;

function to_timer.due_s: double;
var
   i64Actual: int64;
begin
   queryperformancecounter(i64Actual);
   if i64Actual < i64Stop then
      Result := (i64Stop - i64Actual) / dTicksPer_s
   else
      Result := 0;
end;

function to_timer.due_ms: double;
var
   i64Actual: int64;
begin
   queryperformancecounter(i64Actual);
   if i64Actual < i64Stop then
      Result := (i64Stop - i64Actual) / dTicksPer_ms
   else
      Result := 0;
end;

function to_timer.due_us: double;
var
   i64Actual: int64;
begin
   queryperformancecounter(i64Actual);
   if i64Actual < i64Stop then
      Result := (i64Stop - i64Actual) / dTicksPer_us
   else
      Result := 0;
end;

function to_timer.elapsed_ticks : int64;
var
   i64Actual: int64;
begin
   queryperformancecounter(i64Actual);
   if i64Actual > i64Start then
      Result := (i64Actual - i64Start)
   else
      Result := high(int64) - i64Start + i64Actual;
end;

function to_timer.ticker: int64;
begin
   queryperformancecounter(Result);
end;

end.


Beste Grüße
Tastaro
Martin91 Threadstarter
Hält's aus hier
Beiträge: 5



BeitragVerfasst: Fr 01.06.07 11:36 
Hi,
@azubi_20: Ich will ein Servo über den LPT ansteuern.

@Tastaro: danke werd ich mir mal ansehen!

MfG Martin