Lock iconRectangle 1Rectangle 2 + Rectangle 2 CopyShapeRectangle 1

Super Mini-Node Interface Card (SMINI) - Part 1

 Click HERE to download a printable copy of Chapter 4.

Super Mini-Node Interface Card (SMINI) - Part 1 <- You are HERE
Super Mini-Node Interface Card (SMINI) - Part 2
Super Mini-Node Interface Card (SMINI) - Part 3

 

USER'S MANUAL v3.1: CHAPTER 4

SUPER MINI-NODE INTERFACE CARD (SMINI): Part 1

This chapter is devoted to showing how to set up your C/MRI as a serial interface, including step-by-step instruction for building the Super Mini-Node Interface Card (SMINI). Fig. 1-1, in Chapter 1, shows a photograph of the SMINI card. From the perspective of previous C/MRI components the SMINI combines enhanced features of the original design Universal Serial Interface Card, the USIC, with two output cards and an input card, placing everything on a single board not much larger than the original USIC. This combination provides a complete system node with 48 outputs and 24 inputs on a single card.

The SMINI provides everything required to set up a very capable node on a single card, at a very reasonable cost. For example, a single SMINI can drive 48 signal LEDs and read 24 detector and switch position inputs. Depending upon the size of your layout, this single card may be all you need to add signaling to your railroad.

If you desire more I/O than provided by a single SMINI, you can simply distribute additional SMINI cards around your layout to build up to whatever level of capability you desire. With an addressable capacity of 128 SMINI nodes, with 72 I/O lines per node, the maximum capacity of the C/MRI system using the SMINI is 9,216 I/O lines.

This distributed approach minimizes all local I/O wiring. Any device you wish to connect such as a wayside signal, occupancy detector, switch motor, switch contact, pushbutton, panel display LED, or almost anything else electrical, simply plugs into the nearest node.

At node locations requiring more than 72 I/O lines, you can group SMINI cards together. However, often a more attractive option is to use the new Super USIC. Using the SUSIC is the ideal approach for locations requiring large amounts of concentrated I/O such as at a lever-type CTC machine. The SUSIC option is covered in Chapter 10. 

SERIAL INTERFACE STANDARDS

The SMINI and the SUSIC can make use of four interface standards: Universal Serial Bus (USB), RS232, RS422 and a “full duplex” implementation of RS485. All four standards can be used to connect your computer to an SMINI and to an SUSIC. Additionally, in every case, the RS422 or the RS485 full duplex implementation is used to make the “daisy-chain” connection between multiple nodes.

The only requirement for connecting the C/MRI is that your computer has an RS232 serial port and/or a Universal Serial Bus (USB). This is the case for nearly every personal computer, although the RS232 serial port has mostly been phased out of the latest PCs. It can, however, frequently be added as an expansion item. By contrast, some Macintosh models provide an RS422/RS485 serial port. Each can work just fine with the C/MRI. Alternatively, if your computer has USB ports only, then it’s possible to add a USB to RS232 or USB to RS422/485 Converter Cable to make the computer to C/MRI connection.

The most straightforward approach, and the one that typically provides the best overall system performance, is using a computer with a built-in RS232 Serial Port. In general, this is the preferred option and Fig. 4-1 shows the typical setups.

Fig. 4-1. Serial interfacing example systems employing RS232 and RS422/485

Fig. 4-1a illustrates the simplest arrangement for systems comprising just a single node. It requires a single 3-wire RS232 cable to connect between the computer’s RS232 serial port and the RS232 header on the SMINI or the SUSIC. Alternatively, if your computer is limited to USB only, then you will need to incorporate a USB to RS232 Converter Cable to make the connection.

The typical multi-node setup is illustrated in Fig. 4-1b. Fundamentally, every multi-node application requires that all nodes, plus the connection leading toward the computer, need to be “daisy-chain” connected using RS422/485, a 4-wire cable. Each SMINI and SUSIC includes an adjacent pair of RS485 pins making the daisy-chaining easy to accomplish. An RS232 to RS485 Converter Card, such as the RS485 card supplied by JLC Enterprises and covered in detail near the end of this chapter, provides the required conversion to make the connection to the computer’s RS232 serial port. Alternatively, if your computer has USB only, then you will need to incorporate either a USB to RS232 Converter Cable between the computer and the RS485 card or a USB to RS422/485 Converter Cable connected between the computer and the RS485 header on the SMINI or SUSIC.

If you are starting out with a single node, with plans to expand at a later date to multiple nodes, then it’s a good idea to configure your first node for RS485. Then, you can use the Fig. 4-1 setup for connecting to your computer and have everything ready simply to connect additional nodes as your system expands.

Although many C/MRI users effectively make use of USB Converter Cables, their application can pose some challenges. These include adding another layer of complexity and added system overhead. The latter may not be a problem with small systems. However, it can substantially degrade system real-time performance with larger systems. Thus, whenever possible, I recommend implementing the simpler of the two choices, i.e. making use of a computer that has an available RS232 Serial Port. However, how to apply each of the different serial interfacing options, including detailed wiring information for each approach, is presented near the end of this chapter.

For readers interested in more information regarding serial interfacing, the following four subsections highlight each of the applicable serial interface standards. If you would rather skip the detail, please do not hesitate to jump ahead to the section, BAUD RATE SETTINGS.

Universal Serial Bus (USB)

The Universal Serial Bus (USB) was developed to make it fundamentally easier to connect external devices to PCs by replacing the multiplicity of different connectors typically located at the back of PCs. In addition it addresses the usability issues of existing interfaces, simplifies software configuration of all devices connected to USB, and permits greater bandwidths for external devices. Its first release was in 1996 and it has been gaining popularity ever since. As a result, USB has become the “commercial standard” for connecting all types of computer peripherals such as the mouse, keyboards, printers, scanners, digital cameras, personal media players, joy sticks, card readers, flash drives and external hard drives.  Similiarly, the USB can be used for connecting to the C/MRI.

The most common USB connector, referred to as Type A, has 4-conductors. This is the connector found on most modern peripheral devices and installed on most, if not all modern PCs. Two wires deliver 5Vdc power and ground. The remaining two wires provide ballanced-line, half-duplex communication. This means that in general, peripherals cannot communicate with the host, the PC, unless the host specifically requests communication. Data rates are up to 12Mbps for USB1.0 and even higher for USB2.0 and USB3.0. All of these rates are much higher than needed with our railroad applications and the C/MRI.

Although basic data rates are high, there is extra overhead and subsequent delays in the manner in which USB handles data to and from the computer. These delays, typically 1 millisecond or greater, are of little importance when driving a printer or scanning a document. However, with real-time applications such as the C/MRI the overall system performance can be degraded when using USB. This is especially true for large systems, such as the SVOS where we have 6 nodes with 140 I/O cards with the corresponding need to transfer 5480 bits during each pass through the real-time loop.

RS232 Standard

Prior to the domination now exhibited by USB, the RS232 standard was historically the most common serial interface. It uses a voltage of -12Vdc to define the Mark signal (Logic 1), and +12Vdc to define the Space (Logic 0).

Typically, RS232 ports use either a standard 9- or 25-pin, D-type male plug connector called a DB9P or DB25P respectively. Thus, to mate with them you need a female socket connector, a DB25S or DB9S. Pins 2 and 3 are the data wires, and are called the Transmit Data and Receive Data lines. Specific allocation of these two pins depends on whether the connected or peripheral device is configured as Data Terminal Equipment (DTE) or Data Communication Equipment (DCE). A DTE transmits on Pin 2 and receives on Pin 3, but DCE transmits on Pin 3 and receives on Pin 2. Some computers have DTE ports, while others have DCE, so the first step in setting up any RS232 interface is to determine the direction of data flow on Pins 2 and 3. The standard RS232 connections, used on most computer ports, are summarized in Table 4-1.

Table 4-1. Typical RS232 connections

 

Connector Type

and pin number

Function:

DB25P

DB9P

 Transmit Data

2

3

 Receive Data

3

2

 Signal Ground

7

5

 

Transmission and reception directions are defined from the perspective of the computer. These three wires (Pins 2, 3, and 7 or 5) suffice for bi-directional communication between two devices. The other pins, 22 in number for the DB25, are for handshaking between the computer and the peripheral device. For example, Pin 6, Data Set Ready on the DB25, is one that a printer might use to tell the computer it is ready to accept the next character.

There is less standardization in how computers and peripherals use the hand-shaking lines. Besides the interchange of Pin 2 and 3 functions, and the use in some terminals of a male DB25P connector while others have a female DB25S, there are good reasons why the RS232 is sometimes called “the most non-standard standard.” 

Length of cable also affects RS232 transmission capability and limits the maximum transmission rate. The specified maximum cable length with RS232 is 50 feet without an audio modem (modulator-demodulator) at each end. In practice, however, RS232 signals are routinely run for 100 to 200 feet and operated at high baud rates without problems. Such installations are not standard, but they do work. For more reliable, error-free transmission over long distances, you should use RS485.

The RS232 circuitry used with the original design USIC required both + and –12Vdc supply inputs. The updated circuitry used with the new cards generates its own + and – signal requirements (actually ±10Vdc) so that the latest design SMINI, SUSIC and RS485 cards only require +5Vdc power.

RS232 is limited to one receiver and one transmitter. That is suitable for many applications such as connecting a printer, modem or a single SMINI or SUSIC to your computer. However, to support a distributed system with multiple SMINIs (and/or SUSICs), RS232 will not do the job. You need to upgrade to RS485 or RS422, and later I will show you how to build an RS232 to RS485 converter card. Additionally, if your computer is limited to USB ports only, then you need to employ a USB to RS232 Converter Cable or as we will observe later in this chapter, a USB to RS422/485 Converter Cable.

RS422 Standard 

With the exception of some versions of the Macintosh that provide a direct RS422/485 connection, few if any other personal computers directly support RS422 or RS485. However the advantages of RS422, and even more importantly RS485 make their application important to the C/MRI. I will cover RS422 first and then look at the differences when taking advantage of added capability provided by RS485.

The main advantages of RS422, when compared to RS232, arise from RS422 using twisted-pair, balanced transmission lines. The difference between the voltages on the two wires signals a Mark or a Space.  If the difference is positive by more than 200mV, the receiver reads a Mark; if the difference is negative by more than 200mV, the receiver reads a Space. A secondary benefit arising from these levels is that the transmitters and receivers can easily be operated with the normal +5Vdc logic power supply.

RS422 is a full-duplex system, meaning that a device using RS422 can send and receive information simultaneously. Four wires are employed. One twisted pair is used for sending data and a second twisted pair for receiving data. Whereas RS232 can support communication between only two devices, an RS422 port can be connected with up to 16 devices, or nodes. Each additional node is simply daisy-chained, with the same 4-wire cable running from the computer to the first node, on to the second, to the third and so on up to a possible total of 16 nodes.

On one hand you can think of both RS232 and RS422 transmitting signals differentially, but RS232 suffers from using the voltage difference between the signal-wire and ground-wire. This is inferior because each end of the ground wire is locally grounded. Any difference in potential at the ends of the link causes current to flow through the ground wire, and the wire's resistance ensures a difference in ground potential at each end that can cause errors in the data.

RS422 grounding requirements are much less critical since local ground potential does not affect the Mark or Space signals. With the ground potential problem reduced, the RS422 can send its Mark and Space signals closer together to operate reliably at higher baud rates and over greater distances.

RS485 Standard

In many ways the RS485 standard is similar to RS422. The principal exception is that the RS485 specification is Half-duplex, meaning that it cannot send and receive data simultaneously. Although there is significant added complexity in controlling Half-duplex data flow with RS485, its advantage is that the 4-wire requirement with RS422 is reduced to 2-wires with RS485. Additionally, because RS485 was developed later than RS422, the RS485 transceiver ICs, a combination transmitter and receiver, exhibit higher input impedance and output drive capability. The result is an increase in maximum node handling capability from 16 to 128.

Although the C/MRI does not have a requirement for two-way simultaneous communication, there are definite advantages to its using a separate wire pair for sending and receiving data - namely reduced design complexity and easier system debug. For example, if there is activity on the one pair, we know data is flowing from the PC to the external hardware. Similarly, with activity on the other pair, we know that data is flowing from the external hardware to the PC. You avoid needing “data direction control circuitry. You also avoid the need of an oscilloscope to check for the direction of data flow and the possibility of device failure causing bus contention whereby data tries to flow in both directions simultaneously on the same pair of wires. Additionally, with separate send and receive wire pairs, it is easy to incorporate sending and receiving data LEDs as implemented on the JLC provided SMINI, SUSIC and RS485 cards.

The 4-wire design, as implemented by the C/MRI, takes advantage of both worlds, RS422 and RS485, by dedicating one set of the more advanced RS485 transceivers to sending data from the PC and a second set for handling data being received by the PC. And, because we are using the more advanced RS485 ICs, we expand our maximum node capability from 16 to 128. Because of this doubling up of the number of RS485 transceiver ICs and the corresponding use of 4-wires, this arrangement is typically referred to throughout the commercial and industrial world as a “Full Duplex” implementation of RS485. However, just because the 4-wire arrangement has the capacity for supporting simultaneous communication in both directions, it does not mean that the capability is always utilized, as is the situation with the C/MRI.

Because typical computer interfacing distances are very short compared to the 4000-foot limit of RS485, the type of cable used is not overly important. For some applications, regular 4-wire telephone cable provides acceptable performance. However, the model railroad environment can create a lot of electrical noise, especially when using high-frequency power-pulse systems like DCC. This electrical noise can easily couple into the RS485 cabling to create data transmission errors. Such cross-coupling effects become especially prevalent where RS485 cable runs are long and in close parallel proximity to DCC or Railcommand track wiring. To be on the conservative side, it is always best to use dual twisted pair shielded transmission cable for RS485.

Additionally, connections between nodes should be contiguous from the computer to the first node, then on to the next and then the next. A “star” configuration, where there are branches going off to different nodes from a central point, should be avoided. Also, it is generally recommended that cable be terminated with a resistor/capacitor combination equivalent to the characteristic impedance of the cable. Proper cable termination, a topic covered near the end of this chapter becomes increasingly important as cable length is increased.

BAUD RATE SETTINGS 

It is important to understand that all four serial interface standards allow different baud or data-transmission rates. This is significant because a serial interface transmits data sequentially, one bit after another, as opposed to a parallel interface, which for example might transmit one byte (eight bits) at a time.

In a serial interface the receiving and transmitting devices must operate at the same baud rate. The SMINI and the SUSIC are designed to operate with standard baud rates of 9600, 19200, 28800, 57600 and 115200 bits per second or bps. This range is considerably faster than the standard rates of 150, 300, 600, 1200, 2400, 4800, 9600 and 19200 provided with the original Classic USIC. Thus, combining nodes using the Classic USIC with the newer SMINI and SUSIC nodes requires operating at either the 9600 or 19200 baud rates – the rates where the two ranges overlap. At this point, let’s just focus in on the SMINI. 

SUPER MINI-NODE INTERFACE CARD (SMINI) 

Fig. 4-2 shows the parts layout for the SMINI card. It is a complete self contained node, being sort of a gee-wiz do-all type of card. I find it easiest to think of the SMINI card as being four cards combined into one, an SUSIC combined with two 24-bit output cards and one 24-bit input card.

Fig. 4-2. SMINI parts layout

 

I will refer to these “cards within a card” as “Cards 0 and 1” for providing the 48-outputs and as “Card 2” for providing the 24-inputs. You will find these nomenclatures used along the left, bottom and right edges of the SMINI card.[1]   

When using RS232, the serial connections between the computer and SMINI are made using the 3-pin header along the top right edge of the card. Two 5-pin headers are provided for use with RS485. The left header connects with the cable running back toward the computer and the right header connects with the cable running to the next node.  This setup facilitates easy daisy-chaining from node to node. The fifth, or bottom pin in each RS485 header, is provided to maintain continuity for the shield normally used with RS485 cabling. 

Because there can be up to 128 SMINI cards connected on the same 4-wire cable, the system must be able to discern between which SMINI is involved with communications at any point in time. This is achieved by giving each SMINI a unique address, 0 through 127, set by using the 7-segment address DIP switch SW1. These address settings follow the powers-of-two binary number scheme we established in Chapter 2 and the resulting DIP switch settings for typical card numbers are illustrated in Fig. 2-16.

The 4-segment DIP switch, SW2, sets the baud rate with all segments off corresponding to 9600 bps. To achieve each of the other 4 baud rates, the corresponding segment is set to the on, or up, position. If more than one segment happens to be turned on, the software within the SMINI defaults to using the baud rate corresponding to the highest switch segment with an “on” setting.

Connections between the SMINI and the railroad are made using Molex-style right-angle header connectors. These connectors, used on all previous C/MRI board designs, have proven to be extremely rugged, dependable and cost effective. The SMINI includes circuitry for two 24-pin output cards and one 24-pin input card. 

Although all the I/O lines are physically on the same SMINI card it is convenient to talk about them as being separate (I/O) cards within the same (SMINI) card. For example, the two sets of 24-pin outputs are noted as Cards 0 and 1 located along the left and bottom edge of the card. The 24-pin inputs are noted as Card 2 along the right edge. Each 24-pin grouping is subdivided into three ports labeled A, B and C. The 8-pins within the different ports are defined as A0 through A7, B0 through B7 and C0 through C7.

Each railroad device being interfaced simply connects directly to one or more of these pins. In “computer-ese” we refer to each pin, or line, as a bit and 8 bits become a byte. Thus each port handles 8 bits, or 1 byte of data, either input or output. The use of the terms bit and byte will become second nature as you begin to put the interface to use. 

Power connections, +5Vdc and ground, use the two screw terminals at the top right corner of the card. The supply must be regulated with a tolerance range of +4.75Vdc to +5.25Vdc. Most surplus computer power supplies easily meet this requirement and are typically available for zero or near zero cost. 

The heart of the SMINI is part U1, a Microchip Technology PIC16F877-20/P Microcontroller with built-in FLASH memory, making it a smart interface. PIC processors are the most popular family of microcontrollers and the 877 is ideally suited for our interfacing needs. This very capable Microcontroller IC is a single 40-pin

__________

[1] Note: The first SMINI production run cards labeled these “cards within a card” as 1, 2 and 3 versus the 0, 1 and 2 description provided in this manual. If you happen to have one of these early SMINI cards simply ignore the 1, 2 and 3 printing on the card and treat them as if they read 0, 1 and 2. See section Counting Cards/Nodes Using Number Zero in Chapter 2 for change in approach.

DIP containing a Micro-Processor Unit (MPU), 8K 14-bit words of FLASH Program Memory, 368 bytes of RAM Data Memory, 256 bytes of EEPROM data memory, a Serial Communications Interface (SCI), built-in baud generator, three programmable timers, and an abundance of I/O pins. It is a very rugged static protected design with built-in TTL compatibility including high sink/source current capability of 25mA per I/O line. These superior capabilities give the SMINI lots of power in a very rugged package.

The main advantage of a smart serial interface with built-in MPU and memory is great flexibility. The same design works whether we are using it plugged into the SMINI or the SUSIC and whether we are using RS232, RS422 or RS485 I/O. For RS232 the interface uses only the Pin-2 and Pin-3 data lines and the Pin-5 or Pin-7 ground lines, so it is independent of the sometimes unpredictable RS232 handshaking lines.

The PIC16F877 performs all the bookkeeping as to which particular bit the computer is sending and whether it is part of an address or data. When the computer is to read data from the SMINI input ports, it simply tells the PIC16F877, which gathers the data from the 3 input ports, sets it up in the prescribed format, and transmits it bit-by-bit back to the computer.

The three LEDs, L1-L3, indicate the operational status of the SMINI. L1 (green) blinks to show that U1’s internal program is operating correctly and also provides error codes when not operating correctly. The error codes have been significantly expanded over those provided with the original Classic USIC. LED L2 (amber) blinks when the SMINI is receiving data from the PC and L3 (red) blinks when the SMINI is sending data back to the PC.

Each of the 24 SMINI input lines feature optional input line filtering for maximizing immunity to electrical noise frequently encountered with pulse-type command control systems such as DCC and Railcommand. Each of the SMINI output ports is configurable for standard current-sinking or alternate current-sourcing. The majority of C/MRI applications use current-sinking whereby railroad devices are activated, i.e. turned on, by the SMINI completing the ground connection. Alternatively, with current-sourcing the SMINI provides the actual voltage that activates the railroad device. Current-sourcing is mainly used when driving 3-lead searchlight signal LEDs or for other special applications where railroad devices share a common ground connection. I will make use of both arrangements in later chapters.

Programming the PIC16F877 FLASH memory requires a special PIC Micro Programmer package. As a bare minimum the package needs to include a programming editor and an assembler that turns the user written assembly language code into 1s and 0s for loading into the PIC16F877 Microcontroller. A big advantage of the 877’s FLASH memory is that the ultraviolet erase cycle is not required as it was for the MC68701, used with the previous USIC. With the PIC16F877 everything is handled electronically. 

Do not worry about having to do any PIC programming. It is provided pre-programmed and tested in a working SUSIC from JLC Enterprises. The cost is $34. Besides being more than twenty times faster and much more powerful than the MC68701 used in the original design USIC, the programmed PIC16F877 is about half the cost.

You do not need to understand electronics to build the SMINI. Circuit cards and programmed PIC16F877 chips are readily available from JLC Enterprises; all you have to do is follow my instructions. If you prefer, all the circuit boards, including the SMINI, can be purchased fully assembled and tested or as complete kits from SLIQ Electronics. If you are interested in how the SMINI works, and in debugging it in case of trouble, I will explain what the SMINI does and give you a tour of its schematic. If you really just want to get started, skip ahead to SMINI Parts. If you have purchased your SMINI already assembled and tested, you may skip to Computer Connections.

SMINI FUNCTIONS 

Fig. 4-3 is a functional schematic illustrating what the SMINI does.

Fig. 4-3. SMINI functional diagram

 

Its main hardware functions are address decoding, baud rate generation, parallel-to-serial and serial-to-parallel conversion, input/output port selection, input port buffering and output port latching.

Most functions are handled directly by the PIC16F877 including all the parallel-to-serial and serial-to-parallel conversions and determining the operational timings for both the serial and parallel lines. It also keeps track of which information is data and which is address and determines when to activate each of the port enable lines for communication with the SMINI’s 9 different I/O ports – 3 for inputs and 6 for outputs. The arrows in Fig. 4-3 indicate the direction of signal flow, and double lines with a slash and number indicate multiple parallel wires – four, seven or eight in our case.

The SMINI has six 8-bit output ports labeled as Ports A, B and C for “Cards 0 and 1.” Similarly, the three 8-bit input ports are labeled as Port A, B and C for “Card 2.” Each I/O port includes an important buffer between the railroad’s connection to the SMINI card and the PIC16F877.  The functional blocks, noted as U9 through U13, perform as buffer/line-drivers for the 6 output ports. Also, these blocks provide a latching function to keep the output data constant during the period between output data updates. Blocks U3 through U5 perform as the input data buffers.

A single 8-wire I/O data bus connects the PIC16F877 to each of the 9 I/O buffering functions. There are also  9 separate I/O control wires – typically called port select or enable lines – joining the 877 to each of the 9 I/O buffering functions. One of these port select lines connects directly to the enable (EN) inputs for each of the port I/O buffer functions. By selectively activating only one of these 9 lines at any one time, the 16F877 sets up direct communication to and from the desired port via the single function 8-wire bi-directional I/O data bus.

For example, if the 877 wants to read data from Input Port A on Card 2 it activates the port enable line connected to the enable input on Input Buffer U3. Correspondingly, U3 transfers the input railroad data, via U3’s 8 input pins to the 8-wire data bus to be read into the 877.

For SMINI outputs, say Output Port C on Card 0, the PIC16F877 places the desired output data on the 8-wire I/O data bus and then activates the port enable line connected to the enable input on Output Buffer U11. Correspondingly, U11 takes the data found on the I/O data bus and transfers (and latches) it to the correct 8 output pins connected to the railroad.

On the serial side of the SMINI, one of two special I/O circuits couples the PIC16F877 to the serial I/O lines coming to SMINI from the main computer, the PC. Which circuit is used depends on whether you are using RS232, or RS485 (RS422) I/O. The basic function is the same, however, to buffer and convert the serial signal levels to be compatible with the +5Vdc and 0V logic levels used by the PIC16F877's Transmit (TX) and Receive (RX) lines.

To place multiple SMINI cards on the same RS485 4-wire cable, we must be able to set a unique SMINI Address, UA, for each card. This is handled by the 7-segment DIP switch feeding directly into the PIC16F877. The 7-segment switch can set 128 unique addresses, allowing up to 128 SMINI cards in an RS485 system. The 4-segment DIP switch feeding directly into the PIC16F877 sets the baud rate generator built into the 877 to the desired serial transmission rate.

SMINI SCHEMATIC

The schematic in Fig. 4-4 is simply an expansion of the functional diagram in Fig. 4-3. It looks complicated but breaking it down into its various components and visualizing that many wires run in parallel to identical devices performing the same function, it becomes quite easy to understand.

Fig. 4-4. SMINI schematic

Everything focuses on U1, the PIC16F877, so I will cover it first. Of its 40 pins, 33 are I/O lines, configured in three 8-bit ports, one 6-bit port and one 3-bit port.  Software within the 877 can configure each line of each port as either input or output. 

Table 4-2 summarizes the utilization of the 877’s I/O port lines for the SMINI application. Seven input lines, RA0-RA5 and RC4, are connected to DIP Switch SW1 for reading the SMINI’s node address, UA. These input lines have pull-up resistors, built into resistor network RN1, so each line is held high, +5Vdc, unless the corresponding segment of SW1 is closed, switching the line to ground.

Table 4-2. PIC16F877 port utilization for SMINI application 

Port

symbol

Number

of bits

Bit/line identifier(s) and function within SMINI

RA

6

RA0 – RA5 used as inputs to read in the SMINI Address DIP switch segments A0 – A5.

RB

8

RB0 – RB5 used as outputs to drive the 6 latch enable lines for separately activating each of the 6 SMINI output ports.

RB6 – RB7 used as outputs to drive 2 of the 3 input buffer enable lines for separately activating 2 of the 3 SMINI input ports.

RC

8

RC0 – RC3 used as inputs to read in the SMINI baud rate DIP switch segments.

RC4 used as input to read in the SMINI address DIP switch segment A6.

RC5 used as output to drive the transmitter enable line for enabling the RS485 transmissions from SMINI back to the PC.

RC6 used as output for sending serial data back to the PC.

RC7 used as input for reading in serial data coming from the PC. 

RD

8

RD0-RD7 used bi-directionally as inputs to read the 8-bit parallel data coming in from the 3 SMINI input ports and as outputs to send the 8-bit parallel data going to the 6 SMINI output ports.

RE

3

RE0 used as output to drive the 3rd SMINI input port enable.

RE1 spare – not used for SMINI application.

RE2 used as output to drive the green SMINI status indicator LED.

 

Four input lines, RC0-RC3, connected to DIP Switch SW2, set the SMINI’s baud rate. Pull-up resistor network RN2 keeps each line held high, +5Vdc, unless the corresponding segment of SW2 is closed, switching the line to ground.

U6 and U7 are identical RS485 transceiver ICs capable of transmitting and receiving over the same 2-wire transmission line to support half-duplex operation – two wires transmitting bi-directionally. The C/MRI is set up for full-duplex operation – two wires for transmitting from the PC and two wires for reception by the PC. Thus, two ICs are used where U6 is set up to receive data from the PC and U7 is set up to transmit data to the PC. This provides easier system operation and debugging capability.

U8, a dual RS232 transmitter and receiver IC, handles communication in both directions when using RS232. Three wires are used with RS232. These are signals from the PC, signals to the PC and ground.

Line RC7, Pin 26, is U1's serial data input Receive (RX) line, while RC6, Pin 25, is the serial data output Transmit (TX) line. These connect U1 to the SMINI's interface-unique circuitry for either RS232, or RS485 I/O. If you are using RS232 you simply install U8, or for RS485 you install U6 and U7. You should NEVER have U6 and U7 installed if you have U8 installed and vice versa. If you do, then U6 and U8 both fight to control the RX line resulting in faulty operation and possible IC damage.

Looking at RC5, Pin 24, the Transmit Enable (TXEN) line, this is a little more complicated. To support a distributed serial system, multiple SMINI receiver and transmitter ICs, U6 and U7, are connected in parallel on the same two sets of two wires leading back to the PC. Fig. 4-5 illustrates the situation.

Fig. 4-5. Multiple RS485 transmitter and receiver ICs connected in parallel

 

The arrows indicate the direction of data transmission for each two wire set. Two wires are used to send data from the PC to the SMINI cards and two wires are used to send data from the SMINI cards to the PC. 

When the PC transmits data, every SMINI card listens for its address. Having multiple SMINI cards listen is not a problem because:

  • Only one device is ever talking, which is the PC via the RS485 card. This way only one device, the driver IC on the RS485 card, is in command of the two transmit lines.
  • The receiving device on each SMINI, the U6 receiver IC, has a high input impedance corresponding to a ¼ unit load. The driver IC on the RS485 card is capable of driving 32 unit loads or 128 of the ¼ load devices. That is from where the limit of 128 nodes maximum per distributed system arises.

When it comes to the PC receiving data from the SMINI cards, the situation is more complex. Only one SMINI, as determined by the PC, may be permitted to communicate back to the PC at any point in time. When an SMINI is talking to the PC, the SMINI card’s U7 transmit IC is in effect operating in a low impedance state driving the two bus lines with ‘1s’ and ‘0s’. For this to happen without interference, the outputs from the U7 transmit ICs on all the other SMINI cards must be held in a high impedance state, effectively an open circuit to prevent loading down the bus.

This means that only the U7 transmitter on one particular SMINI can be permitted to be active at a time, otherwise there would be more than one U7 trying to pull the transmission line high or low at the same time resulting in a confused state. Such undesired action – called bus contention – must be avoided. For the system to work, only the transmitter IC from one SMINI can be allowed to seize, i.e. transmit over, the bus at any one time and all other SMINI cards must have their U7 ICs held in their high impedance (open circuited) states. This is accomplished by using RC5, Pin 24, as a transmit enable line connected to U7’s driver enable (DE) input.

When the C/MRI application software, resident in the PC, requests that a given SMINI node send the railroad data to be received as inputs on its 3 input ports, the U1 gathers the data, converts it to serial format, then activates U7’s DE enable line, which then seizes the serial bus for sending the input data to the PC. Because none of the other SMINI cards were addressed, their corresponding U7’s are held in their high impedance tri-state, effectively open circuited, to prevent conflict with the operation of the addressed SMINI.

The 8-lines of U1’s Port RD (Pins 19-22 and 27-30) are the bi-directional I/O data bus connecting U1 to the SMINI’s 3 input ports and 6 output ports. When U1 needs to read data from an input port, U1 software switches the eight Port RD lines to be inputs. When U1 needs to send data to an output port the U1 software switches the eight Port RD lines to be outputs.

Lines RB0-RB7 and RE0 perform as port enable lines to define which I/O port IC (U3-U5 for input or U9-U14 for output) is activated for each input and output operation over the I/O data bus connecting all the ICs to U1’s Port RD. For example, if U1 needs to write to I/O  Card 0 Port A, it first sets Port RD to be output then it places the data for output on the Port RD lines. Then it pulls line RB0, Pin 33, high to activate, or enable, U9. With U9 enabled it transfers the data from the Port RD lines, the I/O bus, to the 8-output pins associated with Card 0 Port A that are connected to the railroad. As soon as U1 pulls the U9 enable line low, U9 latches the output data so that it stays constant until the next output data update.

Likewise, when U1 needs to read from I/O Card 2 Port C, it first sets Port RD to be input then it pulls line RE0, Pin 8, low to activate, or enable U5 and then it reads the input data that U5 places on the Port RD lines.

Each of the port latch outputs from U9 through U14 pass through a transistor, Q1 through Q48, before reaching the SMINI card’s 6 output ports. These transistors, typically 2N4401 NPN transistors, operate in an open collector configuration to provide a sinking capability of .25A for loads up to 40Vdc. Railroad loads such as lamps, LEDs, relays, and switch motors are turned on and off by your PC software turning each output transistor on (transistor conducting with collector connected to ground) or off (transistor open circuited). By substituting a 2N4403 PNP transistor and changing card jumper locations it is also possible to obtain a current-sourcing output configuration which I will cover in the next section.

The R1, R2, D1 and C18 circuit ensures that the U1 Master Clear (active low) line is held low during the power-up sequence. This insures correct reset operation when power is cycled to the SMINI. Including the diode provides an ultra fast reset to minimize the wait time required when cycling power.

The three LEDs, L1-L3, indicate the operational status of the SMINI. L1 (green) blinks to show that U1's internal program is operating correctly and also provides error codes when the SMINI is not operating correctly. These error codes are significantly expanded over those supplied with the original USIC. L2 (yellow) blinks when the SMINI is receiving data and L3 (red) blinks when the SMINI is sending data. 

OPTIONAL OUTPUT CONFIGURATIONS – SMINI CARD 

The vast majority of C/MRI outputs make use of standard current-sinking, where the transistor switch, built within every C/MRI output line, completes a connection to ground to activate the connected railroad device. However for special cases that may arise, it is easy to vary the output configuration to handle the alternative current-sinking case. That is where the C/MRI’s transistor switch sources the voltage to activate the load by completing a connection to +5Vdc. Each SMINI output port is separately configurable by selecting the appropriate output transistor and installing the appropriate jumper.

Typically the alternative current-sourcing option is used only when driving:

  • 3-lead searchlight signal LEDs
  • Color light signals that are prewired with a common ground connection

If you do not have either one of these situations you can simply skip ahead to Input Line Filtering.

Fig. 4-6 shows a sub-schematic detailing the latch and output transistor portion of the SMINI card, configured for both the standard current-sinking and optional current-sourcing. Only one output line is illustrated because all are identical. For illustration I selected the line associated with transistor Q1.

Fig. 4-6. Current-sinking and current-sourcing configurations – SMINI

 

I will cover the standard current-sinking case first, which uses the 2N4401 NPN output transistor and the port configuration jumper installed in the long position, as shown in Fig. 4-6a. When the output of the latch goes high, the pull-up resistor RN12 pulls the output of the latch to +5Vdc. That causes Q1 to conduct and activate the load. When the latch output is low, Q1 is turned off and the load is de-activated. Software is used to define the latch output, and therefore we have total control of the load’s operation.

Circuit designers will be quick to observe that RN12 is not really required because the high output of the latch would turn on Q1 independent of having RN12. However, I have included RN12 for two reasons: it is required for the current-sourcing option and keeping it in place for the current-sinking option assists debugging by allowing easy determination of whether an output line failure is within the latch or the output transistor.

The current-sinking output format should work for most applications. It performs as if the computer interface were a large collection of toggle switches, where one side of each switch is connected to ground and the other side is available for connecting to external hardware. Each switch is separately controllable by software giving you total freedom to turn each circuit on and off as desired. Current-sinking is the preferred method of using digital electronics to drive external hardware.

However, you may find situations where you need to connect the interface to external hardware that is prewired with a common ground and what you need to do is switch the hot, or power side, of the loads. These situations can be handled by replacing the 2N4401 NPN transistor with a 2N4403 PNP, and installing the port configuration jumper in the short position as illustrated in Fig. 4-6b.

In this current-sourcing case, Q1’s emitter is connected to +5Vdc and the logic between the software and the load is reversed. When the latch output goes high, RN12 insures that the base of the transistor is pulled up to +5Vdc, turning the transistor off to deactivate the load. When the output of the latch goes low the base of the 2N4403 transistor falls below the emitter, causing the transistor to conduct to activate the load. Including the pull-up resistor is mandatory for the current-sourcing case to insure that the base voltage of the transistor is pulled sufficiently high when the latch is high so that the transistor is turned fully off.

Table 4-3 summarizes the logical relationship between latch output and the connected railroad device, both when it has been turned on (activated) and turned off (deactivated). The situation is exactly reversed when using alternative current-sourcing rather than standard current-sinking. 

Table 4-3. Operational logic for current-sinking versus current-sourcing

Mode of Operation

State of Latch Output

Transistor Status

Railroad Device Status (load)

Current-sinking

High

On

Activated

Current-sinking

Low

Off

Deactivated

Current-sourcing

High

Off

Deactivated

Current-sourcing

Low

On

Activated

 

With current-sinking, having the latch high turns on the load while with current-sourcing having the latch high turns off the load. Because your application software is controlling the latch output, it is easy simply to reverse the software outputs when driving current-sourcing outputs. Using this approach, all the other logic in the application program remains unchanged. I will follow this procedure in all of our application program examples.

The 2N4403 PNP transistor provides a drive capability of .3A. In the current-sourcing case the sum of all the load currents pass through the smaller +5Vdc card traces, whereas the larger ground traces are used in the current sinking case. It can therefore become necessary to limit the size and the number of loads that are turned on simultaneously when using current-sourcing. However, for railroading applications, current-sourcing is primarily used for driving 3-lead searchlight signal bicolor LEDs. Their maximum current draw, corresponding to displaying a yellow aspect with red and green both turned on, is only about .03A per signal. Current loading in this case is not much of an issue. The current-sinking design is more tolerant of driving heavier loads since the ground traces are wider and there are three ground pins per I/O card. Also, current-sourcing with the SMINI is limited to driving 5Vdc loads while current-sinking can drive loads up to 40Vdc.

INPUT LINE FILTERING – SMINI CARD

The SMINI card is designed so that each input line is wired from the external hardware directly into the appropriate pin on input buffers U3-U5. This works well for most applications, and is how the original input cards (the CIN24 cards using the 8255) function. However, the interface input lines connected from many hardware applications contain extensive electrical noise. Adding a noise filter to each input line can reduce the effects of this noise.

It is my personal experience that few applications require input line filtering. However, by contrast, there are many users that think input line filtering is one of the C/MRI’s greater assets. If you are unsure of the level of noise filtering you need, or for that matter if you need it at all, then a good approach is to assemble the SMINI cards without installing R6-R29 and C24-C47. Also, this reduces parts cost and reduces assembly time. Then later, if you find it desirable to add filtering, it is a simple task to cut the trace on the bottom side of the board and insert the desired parts. Thus, if you are not currently interested in implementing input line filtering, simply skip ahead to SMINI Parts. 

Adding a low-pass RC (Resistor-Capacitor) filter to each input line is easy with SMINI. Simply cut the narrower circuit trace located on the bottom side of the card under each of the resistor locations, and install the corresponding R6-R29 resistors and C24-C47 capacitors. The R and C combination is called a low-pass filter because it lets DC and low-frequency signals pass through with practically zero attenuation while attenuating high-frequency signals.

The product of the resistor and capacitor values (i.e. R x C), is called the filter time constant. The larger is this constant the greater is the filtering. The filter’s cut-off frequency (in units of cycles/second, or Hz), is calculated as 1/(6.28 x R x C), where R is expressed in ohms and C is expressed in farads. AC signals or noise above the cut-off frequency are severely attenuated, while signals below this frequency pass through with little attenuation.

The big question is, “How do we go about selecting the best values for R and C?” Well, first off the resistor should never be greater than about 100Ω. Larger values cause the input voltage into U3-U5 representing a logic low to rise to a point where it is too close to the .8Vdc switching threshold of the ICs, thereby actually increasing noise susceptibility.

Using less resistance is not good, because lower values do not adequately limit current surges resulting from the capacitor being discharged when the input line is switched to ground by the external hardware. Conclusion, fix the resistor at 100Ω and then adjust C to achieve your desired filtering level.

The maximum capacitor that fits on the card is 470µF, 10Vdc (Digi-Key P6217) which when combined with the 100Ω resistor produces a filter time constant of .047 seconds (calculated as .000470 x 100) or 47ms, and a cut-off frequency of 3.4Hz. This means that the noise would have to hold the input in the incorrect state for approximately 47ms before the software would receive an incorrect input. With the 3.4Hz cutoff, the input line would be very sluggish in responding to valid changes in input. This is extremely heavy filtering and probably more than needed for even the most severe situations.

Balancing the amount of filtering versus how fast you desire to track valid input changes is important. For example, using QuickBASIC with my Pentium in data acquisition, I read input bytes 200,000 times per second. If you are interested in such fast tracking of inputs, and you installed the filter time constant of 47ms, it would take about 9,400 samples before you detect an input change, a totally unacceptable situation when seeking high speed data acquisition. Thus, the upper bound on your filter time constant should be about half the time period you expect between reads. In this case the desired maximum capacitor value would be about .02µF, which is quite a difference. 

Large capacitors also have a disadvantage by creating longer-lasting surge-currents when card inputs are switched to ground by the external hardware. Using the 100Ω resistor, this current is 5V (the normal charge on the capacitor) divided by 100Ω or 50mA. Therefore, you would not want to drive this level of filtering if you are using TTL circuits in your external hardware to switch input lines to ground. Larger capacitors make these high-level currents present for longer time-periods exacerbating the drive requirement.

Table 4-4 provides examples for a wide selection of filter capacitor values, along with the resulting filter time constant and cut-off frequency. For example, if your requirement does not demand a fast response time for reading inputs, and you desire heavy filtering, I would suggest using the 100Ω resistor with the 10 or 22µF capacitor. You can adjust these values up and down per Table 4-4 as needed, based upon the speed of your program and the filtering level desired.

A frequently used technique is to start with the 100Ω resistor and the smaller size capacitors, and then gradually increase the capacitor size until any noise problem is solved. Select one size larger, for a design margin, and install the capacitors. Remember to always keep your filter time constant under half the time it takes your software to execute one loop, so that you read data in a timely manner. Also, for applications where you desire to filter out high frequency noise, it is better to use tantalum, disk ceramic or monolithic capacitors in place of the frequently lower-priced electrolytic capacitors, which are less effective at the higher frequencies.

Table 4-4. Input filter time constant and capacitor selection

Capacitor Value

(µF)

Filter

Time Constant

Filter

Break Frequency

.0047

.47 µsec

340 kHz

.01

1 µsec

160 kHz

.047

4.7 µsec

34 kHz

.1

10 µsec

16 kHz

.47

47 µsec

3.4 kHz

1

100 µsec

1.6 kHz

4.7

470 µsec

340 Hz

10

1 msec

159 Hz

22

2.2 msec

72 Hz

47

4.7 msec

34 Hz

100

10 msec

16 Hz

470

47 msec

3.4 Hz

                                                 Note: Table assumes an R value of 100Ω

In place of using hardware filtering, you can perform software filtering in your application program. The software simply checks to see that the input has remained stable for two or more samplings before it accepts any change in input. A disadvantage of software filtering is that it does require extra processing time, therefore slowing down your real-time loop. Its advantage is that extra hardware is not required and it is easy to vary the effective filter time constant. However, for most C/MRI users, myself included, I do not recommend employing software filtering. Doing so is contrary to my software motto which is:  Keep it simple, straightforward and easy to understand!

Any time I find I need to add input line filtering, I would much rather provide it by adding the simple RC hardware components rather than to complicate the software. I just cannot overemphasize the importance of keeping your software simple, straightforward and easy to understand!

Continued in Part 2