Continue to Site

Welcome to

Welcome to our site! is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Time Interval measurement from C

Not open for further replies.

Ramesh Maharjan

Newbie level 1
Mar 7, 2006
Reaction score
Trophy points
Activity points
hardarware level time interval measurement by interfacing
with parallel port without external timer and oscillator

This is unclear, try to explain more!

Dear Ramesh Maharjan,

Genraly U can Mesure time interval by Parallel Port But the smallest measurable Unit will depend on Speed of PC and U will Use all Resource of PC just for time mesurement.

To do that (mesure time by PC w\o external timer) frist CONVERT the time interval to electrical signal +5V and 0V say U express the begineng of time interval by fall edge and end by rise edge.
second input this signal on any data pin of LPT and scan falling edge then start count up tp detect falling edg.

But U'r PC can not do any other thing During Mesurment.

U can use external timer or Interrupt of ISA Bus to do this.

u can implement a software clock program using c and u can use to evaluate real time by the cpu. And the easiest way is to write a program using delay statements and calculate the time

you should prepared dos based program for this
you should boot your computer in dos and launch that program
this reduces the error in measurement

here is code
/* Project To mesure the velocity of the moving vehicle */
/* Uses two status port of parallel pin no. 10 and 11 */
/* For pinouts Reference */
/* Base address for parallel port is 0x378 in hex */
/* Base address for parallel input port is 0x379 in hex */

# include<stdio.h>

/* conio.h is needed for the clrscr() and gotoxy() */

/* dos.h is needed for the inportb() and delay()*/
#define PORT 0x379 /* Assign the address of parallel port to PORT */
#define MAX_COUNT 3000

void main()
/* Defines the count variable to store the counted time interval */
unsigned long count;

/* Defines the variable for the sensor data and the input port address */
int SENSOR_1, SENSOR_2, data;

/* Assigns the input port address to variable data */

data= inportb(PORT+1);

/* Assigns the Status of the sensor -1 to variable SENSOR_1 */
SENSOR_1=(data & 0x80)/0x80;
/* data&0x80 masks the binary value availabe in data with 0x80 and division by 0x80 returns the status of the Pin 11 */

/* Assigns the Status of the sensor -2 to variable SENSOR_2 */
SENSOR_2=(data & 0x40)/0x40;

while(!kbhit()) /* loop continues until any key is pressed */
while (!(SENSOR_1&SENSOR_2)) /* Scans whether both port data is one or not */
{ ;
while (SENSOR_1) /* checks whether sensor-1 data changed to zero or not */
for(count=0; ;count++) /* Counts the time interval with 1ms Precision */

if(SENSOR_2!=1&&count==MAX_COUNT) /* Checks whether sensor-2 data has changed to zero or not and stops count porcess */

printf("Velocity= %.3ul m/s",1000/count);

/* End of the program to compute velocity of moving vehicle */

Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to