Digital Command and Control. What am I missing in this circuit in order for it to function consistently?

Thread Starter


Joined Jul 23, 2020
I am a keen Railway Modeller. ( Fanatical is probably a more accurate description). I have been working on a simple?? circuit to turn one or more LEDs on and off inside a carriage using the now ubiquitous digital command and control system. The dcc system powers the track with a square wave at nominally about 9kHz which looks like this.

Using information which has been posted elsewhere I designed the following circuit.
Schematic_lighting circuit_2020-07-23_12-56-34-1.png
What we have here is a 5v supply ( The bridge rectifier (Part 1 DB107) supplies about 12.3v dc to the voltage regulator (J10)and I get spot on 5v out) and an optocoupler (6N137) circuit see ( I built this circuit first on perf-board and the system worked. Since space is limited I allowed for the inclusion of a 1000microF capcitor at P2 after the bridge rectifier to give a "stay alive" function for the 5v supply if and when the track voltage was temporarily interrupted. The capacitor sits inside the carriage and the LEDs etc are in the roof space. The headers allow for the connection of an ATTiny85 USB board which supplies the "decoding" of the digital signal with the input at pin 2 with potential controlled outputs of 3-5v on P0,P1, P3,P4, P5 of the ATTiny85 USB board connected to LEDs and current limiting resistors. This worked and I now have two working models which happily run around a track and I send a dcc signal the lights go on, I send another signal the lights go off. More crucially the stay alive appears to work since the lights are flicker free.
Here is where the fun begins. I then designed a PCB. The PCB is identical to the perfboard in all respects and I have eliminated any possibility that there is any problem with the board layout, although I am more than willing to be corrected if there is an error.

working version 4_pcb.png
I populated the board and the system works right up until the point at which the capcitor is added. When the capcitor is added at P2 in the circuit ( or at any other point for that matter) all digital control is lost. I know the signal is being sent since I can monitor this on the dcc base station. I have had some help from other forums and it is known that a capacitor in a dcc system will screw up the dcc signal. If I place a resistor anything from 10R to 1kR in the positive leg of the capcitor at P2 then dcc function is restored but the stay alive is useless and the lights flicker or continually reset the AtTiny85 rendering the whole thing useless. I should say that if you place the lighting circuit including a capacitor minus the optocoupler circuit on to a dcc track, the lights go on and it has no effect on any other dcc signal so whatever is interfering on the circuit board is limited to that system.
On the PCB I have allowed for separate inputs to both the 5v supply side of the circuit and the dcc side but separating them out makes no difference all digital control is lost with the capcitor in place. I have also tried physically separating the two halves of the circuit with the same result. I have tried multiple combinations all with the same result. The ATTiny also has its own 5v regulator so I have tried this with a 12v input to the Attiny85 with the same result.
Since the capacitor is the issue and the optocoupler circuit works I assume that in essence the 5v supply is "interfereing" withe the dcc side,
so I have the following questions:
Can someone explain how the interference is happening?
Is there some way to isolate the 5v. I wonder whether using a low pass filter I could clean up the 5v supply to block out any of the higher frequency noise.
Could I also place a high pass filter on the dcc side to filter out any dc noise. ( With the system on the track if I put an input onto the dcc side of the circuit direct from the controller then it does work with the capacitor in place)
Is there some other solution.
I think my frustraion level would be less if the thing had never worked but having got it to work I have been simply unable to recreate the same result on a consistent basis.
Many thanks for taking the time to look at this. There must be a solution somewhere.


Joined Jul 10, 2017
The problem of flicker and tiny reset is being caused by dropouts and code signals appearing on the regulated 5V supply. Put your smoothing capacitor across the 5V rather than the across12V and power the tiny from the regulated 5V.


Joined Oct 2, 2009
You are missing vital control capacitors on the LM78L05.
All three-terminal voltage regulators need input and output capacitors otherwise they are in danger of oscillating.
Follow the recommendations in the manufacturers datasheet.
Or you can simply try 0.1μF on both input and output pins. Along with those I would leave 1000μF after the bridge and add 10μF where the 5V goes out.