Centronics port generates narrow pulse widths

-August 02, 2001

Variable-pulse-width signals are useful in control circuitry for positioning and holding purposes in robotics and power electronics. Frequently, the need arises for pulses with width less than 1 msec. Delays less than 1 msec are usually not available in most programming languages, so generating such pulses can be a problem. To generate a fractional-millisecond delay you can use a PC's 8254 16-bit timer (Counter 2), which normally controls the PC's speaker. The desired pulse is available at the PC's Centronics port (Figure 1 ) through a buffer stage, which protects the port from overload damage. Counter 2 operates at a clock frequency of 1.193181 MHz. To generate a pulse width less than 1 msec, you operate Counter 2 in mode 2 as a rate generator. You do this by setting the control-word value to 0B4h and by writing this data to the control-register port, address 43h. Initially, Counter 2 contains FFFFh at address 042h. Bit 0 of port 61h is at logic 1 to enable the counter, and bit 0 of the printer port (in this case, 0378h, printer_port) is at logic 0. Listing 1 contains the software necessary for controlling the pulse-generation process.

Setting bit 0 of port 61h enables Counter 2. The counter decrements by one every 0.8380958 µsec. Before the generation of the pulse, it's necessary to compute Counter 2's required count (required_count) to generate a pulse of desired duration (desired_time). When the counter is enabled, a "while" loop reads back the counter's count through port 42h in two read cycles. This count (counter_data) data helps to compute the counts that have elapsed (count_elapsed), and, once the required count arrives, the software exits this read loop. The software disables the counter by setting bit 0 of port 61h to logic 0. The pulse goes low for the desired time (for example, 10 msec Off_Time). This cycle of pulse generation with a desired width repeats until you press the "Q" or "q" key. The software performs all its calculations during the pulse's off (low) time.

The software in Listing 1 uses Turbo C++, Version 3. Using this software, you can increase or reduce the pulse width (desired_time) in variable time steps (for example, 50 µsec per Time_Step) by using the numeric keypad's keys 6 and 4, respectively. By pressing Key 5, you can fix the pulse's duration at a nominal value (for example, 500 µsec Neutral_Time). Key 8 fixes the pulse's duration at the maximum desired pulse width (for example, 750 µsec Max_Time). Key 2 fixes the pulse's minimum desired width (for example, 250 µsec Min_Time). The hardware we used for testing the software is a P-II system running at 400 MHz, with 32 Mbytes of RAM, operating in MS-DOS mode.

Loading comments...

Write a Comment

To comment please Log In