COMPIM

COMPIM Model Help

Introduction

Traditionally, simulation systems have had no direct connection to the physical world around them. This meant that if you wanted to simulate part of a much bigger system of interconnected units, one had to either create simulations of the other units, or create files containing test data.

The Virtual System Modelling capabilities of Proteus VSM allow the creation of models that can actually interact with the physical world. We call such models Physical Interface Models or PIMs for short.

The COMPIM model is a Physical Interface Model of a serial port. Incoming serial data is buffered and presented to the circuit as a digital signal, whilst serial digital data generated by a CPU or UART model appears at the PC's physical COM port. The COMPIM model also provides for baud rate translation, and for optional hardware or software handshaking on both the physical and virtual sides of the device.

This allows any real world hardware equipped with a serial port to interact with a VSM simulation. For example, you could use it to develop a program for a microprocessor within Proteus VSM that would operate a real physical modem, perhaps as part of a security or home automation system. Alternatively, a monitor debugger running on one PC can be used to debug a simulated design running within VSM.

The COMPIM model can also be used for some simple digital I/O: the CTS, DSR, DCD and RI lines on the physical serial port can act as rudimentary digital inputs from external stimulus, such as switches; the RTS and DTR lines on the physical serial port can act as rudimentary outputs. Bear in mind that these signals may need addition physical signal conditioning, depending on application and port type.

Device Layout

COMPIM has eight pins: TXD, RXD, CTS, RTS, DSR, DTR, DCD and RI.

  • TXD, RTS and DTR are inputs to the device and become outputs on the physical port.
  • RXD, CTS, DSR, DCD and RI are inputs from the physical port that become outputs on the device.

This means that the COMPIM represents a DCE on the schematic. By contrast, the VTERM model (being a terminal) is wired as a DTE. The physical COM port itself is wired as a DTE (TXD is an output).

When a simulation is initiated, the terminals of the DB-9 connector inside the COMPIM device symbol become indicators. The TXD and RXD terminalss indicate activity on the corresponding physical port pins. The indicators for CTS, RTS, DSR, DTR, DCD and RI show the state of the physical port pins.

Two further square indicators are present, either side of the word 'ERROR'. These indicators show red whenever an error is detected on either the virtual port or the physical port. The indicator nearest the pins flags an error on the virtual port. The indicator under the DB-9 terminals flags that an error occurred on the physical port. The errors indicated include framing and parity errors. The simulation log window may give more information as to the nature of the error.

Handshaking Modes

Flow control signals, if active, do not directly pass through from the physical to virtual port, or vice versa, they instead interact with high and low thresholds on the data buffers that are in COMPIM and the operating system. This means that although flow control may be accepting or blocking data at one physical/virtual port, the other virtual/physical port may not necessarily propagate this state, unless the buffers become close to overflowing or under flowing.

Put another way, if either Physical or Virtual hardware handshaking is enabled, the RTS input pin of the COMPIM will cease to have any direct effect on the RTS line of the COM port. This behaviour is correct and by design.

Buffering

The COMPIM model provides buffering for both incoming and outgoing data. As well as covering the situation where the VSM simulation fails to keep up with real time, the input buffering works even when the simulation is paused. This feature can be remarkably useful since the VSM debugging tools may be used to single step the processing of the data long after the physical hardware device attached to the COM port actually transmitted it.

The output buffering is most relevant where the baud rate in the virtual circuit exceeds that being used to communicate with the physical device.

Properties

The COMPIM model supports the following properties:

Name | Property | Default | Description
Physical port | P_PORT | COM1 | Specifies which physical serial device the model is to connect to.
Physical Baud Rate | P_BAUDRATE | 9600 | Specified the baud rate the physical port should be set at. The bounds for this are 50 to 1000000 baud, though your hardware may place additional limits on the permitted values.
Physical Data Bits | P_DATABITS | 8 | Specifies the number of data bits used on the physical port. 7 and 8 data bits are presently supported.
Physical Parity | P_PARITY | NONE | Specifies the parity used on the physical port. This can be NONE, ODD, EVEN, MARK and SPACE.
Physical Stop Bits | P_STOPBITS | 1 | Specifies the number of stop bits used on the physical port. 1 and 2 stop bits are presently supported.
Physical XON/XOFF flow control | P_SOFTFLOW | 0 | Specifies if XON/OFF flow control is to be used on the physical serial port.
Physical RTS/CTS flow control | P_HARDFLOW | 0 | Specifies if hardware RTS/CTS flow control handshaking is to be used on the physical serial port.
Physical XON character | P_XONCHAR | 17 | Specifies the XON character used on the physical interface.
Physical XOFF character | P_XOFFCHAR | 19 | Specifies the XOFF character used on the physical interface.
Virtual Baud Rate | V_BAUDRATE | 9600 | Specifies the baud rate of the virtual port. The bounds for this value are from 50 to 1000000 baud.
Virtual Data Bits | V_DATABITS | 8 | Specifies the number of data bits on the virtual port. 7 and 8 data bits are presently supported.
Virtual Parity | V_PARITY | NONE | Specifies the parity used on the virtual serial port. This value can be NONE, ODD, EVEN, MARK and SPACE.
Virtual Stop Bit | V_STOPBITS | 1 | Specifies the number of stop bits on the virtual serial port. 1 and 2 stop bits are presently supported.
Virtual XON/XOFF flow control | V_SOFTSLOW | 0 | Specifies if XON/XOFF flow control is used on the virtual serial port.
Virtual RTS/CTS flow control | V_HARDFLOW | 0 | Specifies that hardware RTS/CTS handshaking is to be used on the virtual port.
Virtual XON character | V_XONCHAR | 17 | Specifies the XON character used the virtual interface.
Virtual XOFF character | V_XOFFCHAR | 19 | Specifies the XOFF character used on the virtual interface,
Size of data input buffer | INPUT_BUFFER_SIZE | 65536 | Indicates the upper bound on the size of the serial input buffer, from physical interface to virtual interface, in bytes. The minimum being 1, the maximum 4194304.
Size of data output buffer | OUTPUT_BUFFER_SIZE | 65536 | Indicates the upper bound on the size of the serial output buffer, from virtual interface to physical interface, in bytes. The minimum being 1, the maximum 4194304.[

Additional notes

A known problem with Windows 95/98/ME serial port API behaviour causes incorrect ring indicator operation. This appears to manifest itself as the ring indicator line correctly performing a low to high transition but never performing the high to low transition, consequently the RI line gets stuck high until the simulation is stopped.

No matter what the values of INPUT_BUFFER_SIZE and OUTPUT_BUFFER_SIZE the operating system and hardware carries out some limited buffering.

Limitations in the way the Win32 serial port API reports a line break condition mean that COMPIM has to infer the end of a line break by other activity occurring on the physical serial port. This means that a line break condition may continue to be active on the virtual port after the condition has been removed from the physical port.

The indicators on the COMPIM device try to reflect the state of the physical port, however, the operating system and hardware perform some buffering before COMPIM.DLL has a chance to examine the data, which means the indication may possibly lag the true state of the physical port.