Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com 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.

Generating a clock in C

Status
Not open for further replies.

GeekWizard

Full Member level 1
Joined
Oct 24, 2004
Messages
98
Helped
5
Reputation
10
Reaction score
2
Trophy points
1,288
Location
United Kingdom
Activity points
853
Hello all,

I want to generate a clock signal in 'C/C++' and then send it directly through the parallel port to the outside device.

Can anyone guide me how to go about this please.

Many Thanks.
 

The following code will generate a square wave of approximately 500 Hz on D0 line (Pin 2) of parallel port having address 0x378. For delays smaller than 1mS...i think you need to use assembly language routine for your delay.
Code:
#include <stdio.h>
#include <conio.h>

void main(void)
{
	char key;
	while((key = toupper(getch())) != 'Q')
	{
		outputrb(0x378, 0x01);
		delay(1);
		outportb(0x378, 0x00);
		delay(1);
	}
}
 

it won't be an accurate clock since the OS is multitasking and can suspend your task for up to milliseconds, intensive HD access can cause delays and so on. Use the Win API calls QueryPerformanceCounter and QueryPerformanceFrequency to establish a timebase and frequency. I used it to drive 2 stepper motors with good results.
 

I too agree with jhbbunch. I have used QueryperformanceCounter and QueryperformanceFrequency APIs in VB with very good results.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top