Truncated match.
PICList
Thread
'Measuring Time on the PC'
1997\02\25@162512
by
Norm Cramer
I need write some PC software that measures the time between pulses. The
pulses are being generated by a PIC. I know I can use a logic analyzer but
would like the PC to do some processing on the data. How can I get the PC
to measure the time down to the usec level. I found C routines that
measure down to the msec level but no further. Does the PC have a timer
that can be used? Where can I get more info?
Thanks,
Norm
1997\02\25@180752
by
ags
> I need write some PC software that measures the time between pulses. The
> pulses are being generated by a PIC. I know I can use a logic analyzer
but
> would like the PC to do some processing on the data. How can I get the
PC
> to measure the time down to the usec level. I found C routines that
> measure down to the msec level but no further. Does the PC have a timer
> that can be used?
Yes, it is an Intel 8254 (or compatible). Go to http://www.intel.com for the data
sheets.
If you are using Win32 (Win95 or WinNT) then the system already gets a
timer for you.
(They program one of the channels of the Intel 8254.)
You can get to it at the user level (through the Multimedia API functions)
or at the Kernel level.
(If you are a device driver.)
Hope this helps,
Alan G. Smith
+---------------------------------------------------------
| Alan G. Smith
| spam_OUTagsTakeThisOuT
poboxes.com
| http://www.innovatus.com/ags
1997\02\25@192606
by
David Tait
I learnt a lot by reading Kris Heidenstrom's amazing PC timing FAQ.
It's available from any SimTel site under the subdirectory "info" as
pctim003.zip (or similar). It is certainly possible to
measure/generate pulses with microsecond resolution with a little
care.
David
--
http://www.man.ac.uk/~mbhstdj
1997\02\26@092623
by
Shawn Ellis
|
I'm doing instrument control, and have been forced to use external PIC's as
my only reliable time base because of this non-real-time OS that Windows
is... Is there a way to suspend the multitasking and get reliable
execution speed out of windows? Is this possible from high-level languages
(like VB?) Or must one write a device driver/DLL?
----------
> From: Alan G. Smith <.....agsKILLspam
@spam@POBOXES.COM>
> To: PICLIST
KILLspamMITVMA.MIT.EDU
> Subject: Re: Measuring Time on the PC
> Date: Tuesday, February 25, 1997 6:06 PM
>
> > I need write some PC software that measures the time between pulses.
The
> > pulses are being generated by a PIC. I know I can use a logic analyzer
> but
> > would like the PC to do some processing on the data. How can I get the
> PC
> > to measure the time down to the usec level. I found C routines that
> > measure down to the msec level but no further. Does the PC have a
timer
> > that can be used?
> Yes, it is an Intel 8254 (or compatible). Go to http://www.intel.com for the
data
> sheets.
> If you are using Win32 (Win95 or WinNT) then the system already gets a
> timer for you.
> (They program one of the channels of the Intel 8254.)
> You can get to it at the user level (through the Multimedia API
functions)
> or at the Kernel level.
> (If you are a device driver.)
>
> Hope this helps,
>
> Alan G. Smith
> +---------------------------------------------------------
> | Alan G. Smith
> | .....agsKILLspam
.....poboxes.com
> | http://www.innovatus.com/ags
1997\02\26@095139
by
Antti Lukats
At 09:21 AM 26/2/97 -0500, you wrote:
>I'm doing instrument control, and have been forced to use external PIC's as
>my only reliable time base because of this non-real-time OS that Windows
>is... Is there a way to suspend the multitasking and get reliable
>execution speed out of windows? Is this possible from high-level languages
>(like VB?) Or must one write a device driver/DLL?
>
[snip]
NOP, you can "Enter Critical Section" to prevent task-swithcing
(not direct from VB) but this is not enough.
VxD ( or code running at ring-0 ) is the only way to have exact
timing/critical response under Windows.
Any normal code may be interrupted by some Windows internal tasks.
A CLI (Clear Interrupt) only marks a software flag for a VM machine
it does nothing more.
antti
-- Silicon Studio Ltd.
-- http://www.sistudio.com
1997\02\26@101650
by
Bruce Bowling
|
> I learnt a lot by reading Kris Heidenstrom's amazing PC timing FAQ.
> It's available from any SimTel site under the subdirectory "info" as
> pctim003.zip (or similar). It is certainly possible to
> measure/generate pulses with microsecond resolution with a little
> care.
>
> David
> --
> http://www.man.ac.uk/~mbhstdj
>
The part of the above FAQ which does microsecond timing is snipped
and provided here:
-------------------------------- snip snip snip --------------------------------
/*
Sample program #15
Demonstrates absolute timestamping in mode two
Part of the PC Timing FAQ / Application notes
By K. Heidenstrom (EraseMEkheidensspam_OUT
TakeThisOuTactrix.gen.nz)
Save this file to SAMPLE15.C and compile with:
bcc -I<inc_path> -L<lib_path> -ms sample15.c
Where inc_path is the path to your C header files and your startup modules
C0x.OBJ, and lib_path is the path to your C libraries Cx.LIB.
*/
#pragma inline; /* Required for asm pushf, popf, cli, and sti */
#include <bios.h> /* Needed for bioskey() */
#include <stdio.h> /* Needed for printf() */
#include <stdlib.h> /* Needed for exit() */
#define FALSE 0
#define TRUE 1
typedef struct {
unsigned int part;
unsigned long ticks;
} timestamp;
#define BIOS_TICK_COUNT_P ((volatile unsigned long far *) 0x0040006CL)
void set_mode2(void) {
auto unsigned int tick_loword;
tick_loword = * BIOS_TICK_COUNT_P;
while ((unsigned int) * BIOS_TICK_COUNT_P == tick_loword)
;
asm pushf;
asm cli;
outportb(0x43, 0x34); /* Channel 0, mode 2 */
outportb(0x40, 0x00); /* Loword of divisor */
outportb(0x40, 0x00); /* Hiword of divisor */
asm popf;
return;
}
void get_timestamp(timestamp * tsp) {
auto unsigned long tickcount1, tickcount2;
auto unsigned int ctcvalue;
auto unsigned char ctclow, ctchigh;
asm pushf;
asm cli;
tickcount1 = * BIOS_TICK_COUNT_P;
outportb(0x43, 0); /* Latch value */
ctclow = inportb(0x40);
ctchigh = inportb(0x40); /* Read count in progress */
asm sti; /* Force interrupt ENABLE */
ctcvalue = - ((ctchigh << 8) + ctclow);
tickcount2 = * BIOS_TICK_COUNT_P;
asm popf;
if ((tickcount2 != tickcount1) && (ctcvalue & 0x8000))
tsp->ticks = tickcount1;
else
tsp->ticks = tickcount2;
tsp->part = ctcvalue;
return;
}
void main(void) {
auto timestamp ts, ts1, ts2;
auto unsigned int sched;
auto unsigned int ch;
printf("Sample program #15 - Demonstrates absolute timestamping\n");
printf("Part of the PC Timing FAQ / Application notes\n");
printf("By K. Heidenstrom (kheidens
spam_OUTactrix.gen.nz)\n\n");
printf("Press any key to get timestamp; press <Esc> for continuous test\
n\n");
set_mode2();
do {
ch = bioskey(0); /* Get a keypress */
get_timestamp(&ts); /* Get timestamp */
printf("Absolute timestamp: 0x%04X%04X%04X units of 0.8381 us\n"
,
(unsigned int) (ts.ticks >> 16),
(unsigned int) (ts.ticks & 0xFFFF),
ts.part);
} while ((ch & 0xFF) != 27);
printf("\nProgram is now performing continuous timestamp test\n\n");
printf("Press <Esc> to exit\n\n");
while (1) {
ts2.ticks = ts1.ticks;
ts2.part = ts1.part;
ts1.ticks = ts.ticks;
ts1.part = ts.part;
get_timestamp(&ts);
printf("0x%04X%04X%04X\r",
(unsigned int) (ts.ticks >> 16),
(unsigned int) (ts.ticks & 0xFFFF),
ts.part);
if ((ts.ticks < ts1.ticks) || ((ts.ticks == ts1.ticks) &&
(ts.part < ts1.part))) { /* Went backwards? */
printf("Timestamp went backwards: 0x%04X%04X%04X, 0x%04X
%04X%04X, then
0x%04X%04X%04X\n",
(unsigned int) (ts2.ticks >> 16),
(unsigned int) (ts2.ticks & 0xFFFF),
ts2.part,
(unsigned int) (ts1.ticks >> 16),
(unsigned int) (ts1.ticks & 0xFFFF),
ts1.part,
(unsigned int) (ts.ticks >> 16),
(unsigned int) (ts.ticks & 0xFFFF),
ts.part);
}
++sched;
if (!(sched & 0xFF))
if (bioskey(1))
if ((bioskey(0) & 0xFF) == 27)
break;
}
exit(0);
}
-------------------------------- snip snip snip --------------------------------
It works as advertised.
- Bruce
--
-----------------------------------------------------
<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-----------------------------------------------------
Bruce A. Bowling
Staff Scientist
Thomas Jefferson National Accelerator Facility
12000 Jefferson Ave - Newport News, VA 23602
(804) 249-7240
@spam@bowlingKILLspam
cebaf.gov http://devserve.cebaf.gov/~bowling
-----------------------------------------------------
<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-----------------------------------------------------
1997\02\26@124654
by
Martin McCormick
|
It is really pretty hard to find a modern operating system that
has accurate foreground timing because most systems make heavy use of
interrupts for processing random events such as disk access, key strokes,
incoming data, etc.
As a totally useless bit of activity, I once wrote an assembly routine
for the 8086 that toggled the DC signal to the speaker based on a count-down
loop. What you get is not a tone like you can get on an Apple II or if you
write a similar routine with a PIC, but instead sounds like a ragged buzz
from a saw blade. This is because the P.C. is busy servicing the real-time
clock as well as any other system interrupts that come along. When it
does that, the buzz loop gets shut down for the duration of the ISR and
you can hear it as a tiny break in the tone. There are so many of those
that what you hear just sounds weird and not anything like a tone. This means
that you can't count on any timing routines that simply run in the foreground
because you don't know how often they got hijacked for a few microseconds
here and there so that some important task could be done.
This is just the nature of the beast when one CPU has to do everything.
Martin McCormick WB5AGZ Stillwater, OK 36.7N97.4W
OSU Center for Computing and Information Services Data Communications Group
1997\02\26@145147
by
Shawn Ellis
> NOP, you can "Enter Critical Section" to prevent task-swithcing
> (not direct from VB) but this is not enough.
>
> VxD ( or code running at ring-0 ) is the only way to have exact
> timing/critical response under Windows.
> Any normal code may be interrupted by some Windows internal tasks.
> A CLI (Clear Interrupt) only marks a software flag for a VM machine
> it does nothing more.
>
> antti
>
What's a VxD and how does one write one?
1997\02\26@152619
by
Antti Lukats
|
At 02:19 PM 26/2/97 -0500, you wrote:
>> NOP, you can "Enter Critical Section" to prevent task-swithcing
>> (not direct from VB) but this is not enough.
>>
>> VxD ( or code running at ring-0 ) is the only way to have exact
>> timing/critical response under Windows.
>> Any normal code may be interrupted by some Windows internal tasks.
>> A CLI (Clear Interrupt) only marks a software flag for a VM machine
>> it does nothing more.
>>
>> antti
>>
>What's a VxD and how does one write one?
Oh NO folks! not again :)
VxD stands for "Virtual -something - Driver" and they build the core
of Windows kernel, in the matter of fact Windows kernel is a bunch
of VxD's
They may be separete files .386 or .VXD however Win 95 builds his
kernel at setup, those many system VXD are merged to build the kernel.
The biggest difference between normal (user programs, drivers DLL) is
that VXD run at highes priority level and can do anything the raw x86
or pentium processor can do. If you disable ints at VXD everything stops.
if you write to page translation tables, you guess what happens.
VXD have many functions, one of them is hardware virtualization, making
(or trying to) allow different tasks to work with same peripherals.
any critical code should be handled in VXD. Interrupt latency time
is very much shorter for VXD handlers. In the matter of fact all
interrupts are handled by VXD anyway, only if the 'user handler'
is not VXD (but DOS WIN program or DLL) then interrupt will be
'posted' to the task that installed the handler, execution of
the user int handler will not be instant, it will be next time
the virtual machine gets his timeslice - and this time maybe
somethimes really long, if Windows as example wants to swap to
disk something :(
It is possible to handle timecritical things in good VXD code,
as example frame interrupt based (50 Hz) data acquizition board
with software polled reads can take a constant stream of
100 KB per second on a slow 486-33 in background without any
slowdown of the machine. Try that without VXD, no way many
frames would be missed, and computer freezes.
How to Write them?
subscribe to MSDN, receive > 100 CD-ROM's per annum, check them all and
there you go!
Well isnt that bad, but almost :(
antti
-- Silicon Studio Ltd.
-- http://www.sistudio.com
1997\02\26@174203
by
Maurizio
Dear Norm Cramer,
I want'n thread this off topic, but for my personal
skill I think that microsecond measure or more,
microseconds processing on PC without an external
co-processor (e.g. PIC with time capture or PWM etc..
is simply an utopia!!
1) The timer 8254 inside all PC have a clock of
1,190,000 Hz. How is possible to hope to sample
1uS with such device???
2) If you want make decisions after every sample,
you lost precious time that reduce the global
performance to less of 1mS
3) What ???? Win 95, Win32s ???
We are more crazy than Riccardo Bianchi :-)
If you are a good DOS programmer, you know some
implications that make W95 (and NT) absolutly
not indicate for real time task.
Maurizio Conti
Iper-Net s.r.l.
Internet Services
Via Mirandola 47
47037 Rimini (RN)
KILLspammcontiKILLspam
iper.net
http://www.iper.net/giudizi
More... (looser matching)
- Last day of these posts
- In 1997
, 1998 only
- Today
- New search...