Block Signal Program Description |
This page contains the source code portion of the Basic Stamp 2p program that controls the block signals. Note that this program is written using the PBASIC 2.5 version. The complete code and documentation can be downloaded using this link: BlockSignal.zip
====================================================================== ' BlockSignal.bsp 12-15-2005 ' ' Block Signal Control ' ' Note: This program is written using {$PBASIC 2.5} features. ' ' This program controls the CTC block signals on the D&B model railroad. ' Single lamp three color searchlight signals are modeled. One semaphore ' signal is modeled at L8. When reduced to simplest form, the trackplan ' consists of the following electrical blocks. ' ' L3> <L4 L9> <L10 ' /==B1==\ <L2 /=====B4=====\ <L8 /=====B7=====\===\ ' =====B3===== =====B6===== B9 B10 ' \==B2==/ L1> \=====B5=====/ L7> \=====B8=====/===/ ' L5> <L6 L11> <L12 ' ' Electrically isolated blocks are indicated above by a section of track ' identified by Bx. Each section is connected to a block occupancy ' detector circuit. See schematic sheet 2. Blocks B1 and B2 are used by ' the mainline control BS2 for hidden train hold over. Blocks B9 and B10 ' are the two yard bypass tracks. Blocks B3 through B8 are the primary ' blocks used for signaling of the mainline track in both directions. ' ' Searchlight signals are identified by Lx and include a character < or > ' to show the train direction controlled (or lamp reflectors if you want ' to think of it that way). The following rules are used to illuminate ' the signals. ' ' Signal Condition ' ------ --------- ' Off Unoccupied block not being approached ' Green Approaching unoccupied block ' Red Approaching occupied block ' Yellow Approaching unoccupied block; subsequent block occupied ' ' The mainline is a single track on the D&B model railroad. Trains travel ' in both directions. Since no direction information is available in the ' current design, the logic always sets the signals for both directions ' of travel. The careful observer may notice a green indication in the ' opposite direction of a block being vacated by a train. In the opposite ' direction, this is the block being approached and since it is empty, ' the green indication is correct. Proto-typically, this signal would ' probably be off. The green indication will change to off once the train ' moves another block forward on the mainline. ' ' The following truth table was used when developing the signal color ' control logic in the ProcBlock routine. The table will be easier to ' visualize using color markers and the above track diagram. ' ' x = Active Block r = red, g = green, y = yellow ' 1-2 3 4 5 6 7 8 9-10 L1 L2 L3 L4 L5 L6 L7 L8 L9 L10 L11 L12 ' -------------------- --------------------------------------- ' x g y ' x r r g y g y ' x y g r r g y ' x y g r r g y ' x y g y g r r g y g y ' x y g r r ' x y g r r ' x y g y g ' x x r r g y g y ' x x r r r r g y g y ' x x y g r r y g r r g y g y ' x x y g y g r r r r g y ' x x y g r r y g ' x x x r r g y r r g y ' x x x r r y y r r r r g y g y ' x x x y g y g r r r r g y r r ' x x x y g y g r r g y r r ' x x x x r r r r y y r r g y g y ' x x x x r r y y r r r r r r g y ' x x x x y g y g r r r r r r g y ' x x x x x r r r r y y r r g y r r ' ' Each searchlight signal is equipped with a bi-color (red and green) ' Led. One power polarity causes red illumination and the other power ' polarity causes green illumination. Yellow illumination is created by ' rapidly switching between red and green. ' ' The shade of yellow obtained when switching the Led's is controlled by ' the percentage of red and green 'on' time. All signal Led's should be ' of the same part number and manufacturer to minimize the effect of ' red/green color intensity variations. Two program constants (RedOn and ' GrnOn) are used to fine tune the 'on' duration times; equal values ' result in 50/50 times. The two counts combined effect the overall yellow ' toggle repetition rate so each value should be kept as small as possible. ' Some experimentation with the values of RedOn and GrnOn may be required ' to achieve the desired shade of yellow based upon the led's used. It may ' also be necessary to use diodes in series with the bi-color led to coarse ' adjust the red/green intensity. ' ' The purity of the yellow signal color is dependent on the Led red/green ' switch rate. In order to achieve the highest rate possible, the code has ' been optimized for speed. A number of additional working variable are ' used to permit rapid execution of frequently used routines. The program ' is further complicated by no BS2 support for two bit variables. (Would ' that be a twit?) ' ' Hardware Description ' ' Refer to schematic sheet 6. The Basic Stamp BS2p40 is used to control ' the block signaling. Two BS2 I/O bits are assigned to each signal for ' the four possible states of a lamp; twelve signals, twenty-four bits. ' A pair of 74HC151's are used to address the block detector inputs. ' ' A block occupancy detector reports an active condition when power is ' being drawn within its block. This is caused by the locomotive, cars ' with internal lighting, or cars equipped with resistor wheels. ' ' With the exception of L8, the Led's used in this circuit are the two ' lead type. Each Led is wired to a pair of BS2 I/O bits and a series ' resistor. Setting the two BS2 I/O bits to 0 and 1 causes the Led to ' light red. Setting the bits to 1 and 0 causes it to light green. ' ' The signal at L8 is a moveable arm semaphore. It has an incandescent ' lamp and uses a R/C servo to position the signal arm/color. One of the ' two BS2 I/O control bits is connected to the servo input. The BS2 ' PULSOUT command is used to position the servo. The other I/O control ' bit is used to drive the on/off state of the lamp. ' ' When selecting the bi-color led, refer to the spec sheet and choose ' one that has similar red and green intensities. A red or green that ' is brighter will be difficult to balance into a good shade of yellow. ' Select a led with an opaque lens instead of a clear one. The red and ' green colors blend better with the opaque lens. ' ' Led's with differing red/green intensities can be used but additional ' series diodes will be needed. General purpose silicon diodes (1N914, ' 1N4148) drop .6 volt. Adding two or more diodes in series with the ' brighter color will lower the voltage applied to that color. One diode ' for the other color will be necessary to provide a current path. Some ' bi-color led's used on the D&B model railroad required five diodes in ' series with the red color and one diode in series with the green color ' to achieve a good yellow color. Alternately, two diodes and a variable ' resistor can be used. See the hardware schematic for more details. ' ' An output pin of the Basic Stamp is connected to a Led and used to ' indicate operation (heartbeat). Flashing indicates that the code ' is cycling in the main program loop. ' ' An input pin of the Basic Stamp is connected to an on/off switch. When ' this switch is set to off (1), normal program operation is performed. ' When set to on (0), exercise/test mode is run. In exercise/test mode, ' all signals are cycled through the sequence red, green, and off three ' times. The block detector inputs are then read. The input block detector ' states are displayed on L1 through L10 respectively; off for inactive, ' yellow for active. After approximately three seconds, the cycle is ' repeated. Changing the mode switch from on to off causes exercise/test ' mode to be exit and normal mode to be run. ' ======================================================================
Navigation: Block Signal D&B Home Buczynski.com Index
Copyright © 2006 Don Buczynski
San Diego, California