There are now two programs for this project. The first is the original 'Signal Loop' sequencer created for use on the Crompton fields 'tail chaser' layout. The second has been created for use on Highbridge Road, although this is also a 'loop' layout trains operate from fiddle yard to fiddle yard rather than endlessly chasing their own tails in a continuous run.
This is exactly what it says. A photo transistor is obscured by a passing train. A circuit (the OD2 designed and built many years ago by Steven Spreadborough ) generates a 5 volt signal when this occurs. A PIC controller uses this signal in order to control a three aspect colour light signal. The controller does two things when a train is detected. First it sets the signal to red. Second it records the time since the train was last detected and uses this to calculate the timing for returning the signal to green (the time is divided by four and each aspect gets one quarter of the total time), moving through the appropriate aspects. Simple but pleasingly effective on a continuous run display layout, Crompton fields.
As I'm using optical detectors there was a problem with the gaps between vehicles re-triggering the unit. To get round this I simply perform the cycle calculation on first detection and ignore any subsequent detection whilst the red aspect is displayed.
I have considered a variant of the program to sequence a signal guarding the entrance to a fiddle yard or storage area where the train doesn't come back around, i.e. it has no cyclic period. There is a built in 'maximum time' that could be used for this but the sequence time should reflect the length and speed of the train. To do this I'd suggest timing how long it takes for the whole train to pass over the detector and multiply this up to give the sequence time. As there's been no application to use this to date I've not bothered to develop it.
The code is extremely crude having been written in a rush to get something working in time for a show. As the code worked satisfactorily I've never bothered about going back and tidying it up. One last thing to mention, each PIC can sequence two signals.
PIC source code sig_loop.asm and it's MP-LAB project sig_loop.pjt.
This picks up where the loop sequencer left off. It starts with the variant mentioned above where the signal guards the entrance to the fiddle yard, also Highbridge Road is long enough that, with a bit of license, there are two signals in each direction on the visible portion of the layout. In this case there is a separate micro controller for each signal which drives the signal aspects, monitors the train detector and continually transmits the aspect being displayed along with the detector state to the 'previous' signal.
If the controller is receiving information from the 'next' signal it uses both it's own and the 'next' signal's detector state to run a state machine for occupancy of it's signal block (state diagram for 'this' signal block). If the block is occupied a red aspect is displayed, if the block is not occupied the aspect to display is derived from that of the 'next' signal (this is where the 'Cascade' part of the name comes from).
If the controller is not receiving information from the 'next' signal and the data input is at a logic 'low' voltage then the controller simply uses it's detector and automatically sequences it's displayed aspects in a manner similar to the loop sequencer, but with fixed timing of the aspects (state diagram for simulated 'next' signal block). If the controller is not receiving information from the 'next' signal and the data input is at a logic 'high' voltage then a red aspect is displayed. This latter feature has been incorporated to allow a manual override of the signal and also so that the data stream could be routed through switches co-acted with turnouts such that a red aspect is displayed when a trailing turnout is set against the route from the signal. Regardless of the mode of operation the controller will always transmit it's status so this is available to any 'previous' signal.
Lastly it's necessary to detect both when a train arrives at a detector and when it clears the detector in order to run the block occupancy state machine. This means ignoring gaps can't be achieved by simply using first detection as for the loop sequencer. Instead two photo diodes are used in series and these are positioned so that one is exposed by the gap between vehicles the other is obscured.
PIC source code sig_sqnc.asm and it's MP-LAB project sig_sqnc.pjt. As this is the development version of the program it includes, asyn_srl.inc and pic_mntr.inc.