8254 Driver
A simple driver is provided to perform basic counter/timer operations on this board. Source code for the
driver and a sample program showing how to use the functions are located in the DOS\CSAMPLES
directory. The following functions are provided:
Frequency Measure
The Frequency Measure function of the 8254 Counter Driver has the ability to measure an unknown
frequency from 1KHz to 2MHz. This function requires as input the Base Address of the board. The
unknown frequency is applied to the CLOCK IN pin of the board (P1 pin 5). The function will return the
frequency as a long integer in Hz.
long frequency_measure(unsigned BaseAddress);
Event Counter
The Event Counter function has the ability to trace the number of events that have occurred. This
function requires the Base Address and an additional parameter that identifies which features should be
implemented on this call to the function. Each feature can be identified by its unique integer value.
Multiple features can be run in a single call to the function by ORing the respective integer values
together. Features will be executed in increasing integer order. The CLOCK IN pin of the board (P1 pin
5) is the point of application for the incoming events. (Note: This function is limited by the input speed of
the 8254 counter, and slow signals are preferred. Further only 65,535 events are possible without a
RESET.) The function returns the number of events (based on priority) or 0 for those features that do
not specify a return value.
Features:
INITIALIZE
= 1;
initialize the counter
START
= 2;
begin counting
SINCESTART = 4;
return the number of events since the start
SINCELAST
= 8;
return the number of events since last check
STOP
= 16;
stop counting events
RESET
= 32;
reset number of events to 0
unsigned event_counter(unsigned BaseAddress, int feature);
Generate Frequency
The Generate Frequency function will generate a square wave (0 to +5V) with the desired frequency.
The Base Address of the board as well as the frequency are required as input to the function. The
counter can generate a frequency with a range of 1Hz to 250KHz. The square wave can be read on the
CLOCK OUT pin of the board (P1 pin 9).
void generatefrequency(unsigned BaseAddress, unsigned long frequency);
Pulse Width
The Pulse Width function will measure the width of an applied event from its rise to its fall (effectively
one half the period). The Base Address of the board is required as input to the function. The signal
should be applied to the GATE IN pin of the board (P1 pin 7). Software latency will be affected by the
operating system and will set a limit on the precision of the measurement.
unsigned pulse_width(unsigned BaseAddress);
Manual 104-DIO-48E, 24E
25