The ideas below describe what I've come up with in the last couple of
months. Please let me know if you've seen them elsewhere.
DCC loco position detector
Many of the proposals I've seen on the web about loco position detection
seem to be universally applicable in that they'll work for cars
too. I propose something which is utilising the unique
feature of railroads: sleepers at regular intervals.
Placing a pair of infrared leds (emitter-receiver) on an engine makes
it possible for such an engine to detect when a sleeper is passing
underneath, under the assuption that sleepers are rather different in the
colour from a layout. For instance, sleepers seem to be often black
and a layout is generally not :)
Placing three leds (two emitters/receiver or one transmitter/two
receivers) could make it possible to detect the direction of train
movement. Although DCC engines know which way they are going, I
suspect that under certain conditions a train may actually slip in a
direction opposite to what an engine thinks it is going. For example,
if a heavy train takes a steep hill, it may have enough kinetic energy
to get some way up at which point it will stop with loco's wheels
slipping and may slide down. Not sure whether one should plan for such
an eventuality but Rapid's led pricing (15p+VAT/pair for 100pairs or so as
I recall) seems to permit over-engineering.
A current feedback from a loco can be used to send the location back
to a controller.
Ideas on improvement of BC1a power supply
Current sensing
The BC1a power supply uses a
pair of 0.33 ohm resistors as a current sensor to detect an overload
condition so that a PIC can take an action. Two potentially less than
desirable things about such as sensor are:
- Resistors unnecessarily
consume power (albeit just a bit).
- The design does not limit
current passing through MOSFETs due to the low resistance of these
resistors - current limiting is accomplished via the stabiliser chip
LM338. It may potentially be a better idea to have a
current limiter which is independent of the LM338 and the PIC.
Borrowing an idea from PC motherboard voltage regulators (output
voltage 1.6v, current 30A), current sensing can be based on the fact that when used as switches,
MOSFETs act as resistors with the resistance
slightly dependent on the current through them.
In the context of
BC1a, measurement of the voltage on the track rail closest to the ground
can provide an indication of the current through the lower (Q8/Q9) MOSFET
and thus the current through whatever is there on the track. According to the
MTP3055 datasheet,page 3, this resistance is around 0.095
Ohm for the range of currents between 3 and 6 Amp and gate-source voltage of 15v. I believe the resistance will
be similar for lower currents. Consequently, for the 0-6Amp load the
voltage on the lower track rail will be between 0 and 0.6V.
Current measuring
With both the resistor-based and the
MOSFET-based current sensing, we get a small voltage close to the
ground. Typical electronics does not like either - PIC16F87X
datasheet claims that reference voltage has to be at least 2V for the
10bit accuracy to be achieved (page 170); PIC18FXX2 datasheet states
that this has to be 3V min (page 287). I interpret this such that
unless we amplify 0.6V to at least 3V, the accuracy of A/D conversion
will be reduced. This will in turn limit the achievable current feedback
from the locos; even if we do not need all the 10 bit, reduction of the
accuracy can be used to speed-up the conversion process. The task is
thus to amplify 0..0.6 V to some uu ... uu+3V in a reasonably linear
way under constraints of BC1a such as absence of a negative power
supply and uu+3V having to be under 5V (for the PIC).
Proposed solution for the MOSFET-based current sensor:

The amplifier is a common-base one which is consequently
non-inverting. I had trouble getting a `conventional' common-emitter
amplifier perform as well as I wanted under the given
constraints.
- 5V is the PIC power voltage,
- 6.2 is expected
to be obtained using a zener diode from 15V (here and below this refers to the voltage from the LM338),
- 0V is the current-sense
voltage which is varied for simulation shown below
- 12V is the voltage on the
second track which does not affect the results as long as it is above 5V.
Rail 1 and rail 2 are connections to the two rails. The way they are connected, rail2 has 12V and rail1 is near the ground and voltage on it is consequently used to sense the current. If resistor-based current sensing is used, a single diode will do or otherwise resistor values will need changing.
Please note that both transistors above are Q2N3904 because BC547
is not available in the `student' version of the PSPICE. The result
of the simulation is shown below, with colour curves showing voltages at points with similar-coloured probes. The
current-sense voltage is on the horizontal axis (also shown in green)
and the yellow curve is the output to the PIC.

I've prototyped
the above (without the emitter-repeater) on a bread-board with BC547
and the it performed rather similarly to the result of the simulation,
altough was slightly less linear. The signal generator was my PC sound card.
Specific things to note:
- The collector of Q1 is connected to 6.2V to imrove the characteristics
of the amplifier. Since the minimal voltage on the collector is about
1V (diode drop + min emitter-collector) this gives the maximal collector
current of 7ma (low collector current helps to avoid overloading
the base voltage divider). With such a current, around 6.2V can be
obtained easily from 15V using a zener diode and a resistor.
-
The emitter repeater serves two purposes: reduces the output impedance
(this is necessary to charge all PIC's capacitors fast enough to
obtain reasonable A/D conversion times) and clamp the output voltage
to under 5V. The fact that Q1 goes just a bit above 5V and Q2 gets it
0.7V lower helps avoid distortion.
- When rails are unconnected, the circuit maxes out the output
voltage. One can connect a typical RC-transistor trip to it sensing
the output voltage getting over a particular limit (like this is done
in BC1a with Q5) and use the output of this trip to shut the MOSFETS down (for
instance, by pulling the emitters of BC1a's Q3 and Q4 to the
15V). Once tripped, such a trip will keep track rails unconnected until a
user resets it. I think this is a good idea since one could use such a
trip to detect overloads which PIC did not react to. Since under
normal conditions this should never occur, an occurrence of such condition
should be flagged as a serious problem.
Current limiter
This is at present no more than an idea, but
I think it could be useful, particularly if one decides to replace
LM338 with something simpler. The paragraph below describes why this may be considered and the one after that outlines the idea.
From the MOSFET datasheets it appears that at 5Amp we are losing about
2.5 volts on them, plus 1.6V in decoder diodes, perhaps 0.5V on a
track and 0.5V in decoder MOSFETs. If one would like to run an engine
at 12V, the voltage applied to BC1a's MOSFETs has to be 17V. This
means a voltage stabiliser only has 3V room (20V coming from the
bridge rectifier and 17V output) which is not a lot, potentially
prompting usage of a different stabiliser, which may not include
over-current protection.
Generally-speaking, MOSFETs are programmable current sources. This
means that the voltage on a gate can be used to limit the output
current. In the context of BC1a, the lower MOSFET (Q8/Q9) could be connected
as described in the BC1a shematics but the upper one (Q6/Q7) be used to limit the
current through track rails as needed. The output current sensor using
`lower rail' and the common-base amplifier could have its output
connected to the gate of an `upper' MOSFET. As the current through the
lower MOSFET goes up, so does the amplifier output, bringing the gate
of the upper MOSFET closer to the 15V power supply and thus limiting
the output current. An obvious disadvantage is having to ensure that
0.6V sensed from the lower rail translates into the appropriate
voltage for the MOSFET, with all the spread of parameters.
me (replace _ in the email address with @)
Last modified: Sun Feb 9 22:13:44 GMT 2003