Add Real-Time Control To QuickBasic

June 12, 2000
Even though Windows-based applications are now the market standard, DOS-based industrial applications or prototypes still find a place in the field of real-time control. For these applications, a simple and deterministic OS (DOS) might be the only...

Even though Windows-based applications are now the market standard, DOS-based industrial applications or prototypes still find a place in the field of real-time control. For these applications, a simple and deterministic OS (DOS) might be the only solution to time-critical situations, even successfully working with low-end and low-cost PCs (i.e., 486-based machines, which are still very common in industrial environments).

Working under DOS, QuickBasic has demonstrated itself to be an easy, fast, compact, and reliable programming environment. Unfortunately, the standard real-time clock (RTC) provided by QuickBasic (ON TIMER) isn’t suitable to industrial real-time control due to its low resolution (one second).

This idea implements a simple highspeed RTC mechanism, using standard PC hardware interfaces and QuickBasic-available primitives. A PLC, based on this idea and fully programmed in QuickBasic 4.5, is now running in the field on a 486DX-100 PC. Many other successful real-time experiments have been conducted with both QuickBasic 4.5 and VisualBasic 1.0 for DOS.

There are two simple approaches to providing RTCs to QuickBasic using standard hardware. One uses a game port, the other uses a COM port (COM1 or COM2).

In the game-port approach, the joystick buttons are connected to GND (pins 4-5) in the D-type (15-pin) connector of the port, providing up to four RTCs associated to STRIG(n) primitives in QuickBasic. The frequency of these RTCs is 18.2 Hz (approximately 55 ms), i.e. the OS (DOS) tick. See Table 1 for pin assignments.

The program for a basic game-port implementation in QuickBasic (one RTC version) is shown in Listing 1.

Using up to four software interrupts at the same frequency (55 ms) allows for different priorities (in other words, it’s possible for STRIG(4) to interrupt STRIG(0), but not the opposite, see Table 1). This is nice for building a simple foreground/background scheduler, with several background processing priorities (up to four in this idea).

Using the standard COM ports (COM1 or COM2), RTCs as fast as approximately 0.5 ms can be implemented while using just 15% of computer time for context switching with a 486DX-100 PC. This can be significantly improved, of course, by using faster Pentium processors.

The only drawback is the few (two) ports available to QuickBasic, and the possible use of these ports with your application (in this application, the COM2 port was available). The selected COM port must be locally wired in loopback mode (Table 2).

The program for the COM-port implementation in QuickBasic using COM1 is shown in Listing 2.

The RTC frequency can be computed using the following formula:

TINT = (1/Baud) * (1 + parity + data + stop) + tL (Table 3)

where tL is the latency time for the given PC—approximately 100 µs for a 486DX-100 PC, and less than 20-30 µs for a Pentium III.

By setting the COM port at the maximum speed of 115,200 baud and working with a Pentium III processor, an RTC can be realized that’s capable of 10-kHz interrupts. To set the COM port at 115,200 baud, setup data must be written directly to the UART registers, since the maximum speed allowed by the QuickBasic “OPEN” statement is 19,200 baud (Listing 3).

Sponsored Recommendations

What are the Important Considerations when Assessing Cobot Safety?

April 16, 2024
A review of the requirements of ISO/TS 15066 and how they fit in with ISO 10218-1 and 10218-2 a consideration the complexities of collaboration.

Wire & Cable Cutting Digi-Spool® Service

April 16, 2024
Explore DigiKey’s Digi-Spool® professional cutting service for efficient and precise wire and cable management. Custom-cut to your exact specifications for a variety of cable ...

DigiKey Factory Tomorrow Season 3: Sustainable Manufacturing

April 16, 2024
Industry 4.0 is helping manufacturers develop and integrate technologies such as AI, edge computing and connectivity for the factories of tomorrow. Learn more at DigiKey today...

Connectivity – The Backbone of Sustainable Automation

April 16, 2024
Advanced interfaces for signals, data, and electrical power are essential. They help save resources and costs when networking production equipment.

Comments

To join the conversation, and become an exclusive member of Electronic Design, create an account today!