DCC++ and auto-reverse question

Erik84750 Apr 28, 2017

  1. Scott Eric Catalano

    Scott Eric Catalano TrainBoard Member

    205
    57
    6
    I'd be interested in seeing your schematic or pictures of how you accomplished this. Thanks
     
  2. Erik84750

    Erik84750 TrainBoard Member

    334
    134
    12
    Sure, as soon as I have some decent schematic ready I will publish it here. Basically a 1 USD microcontroller with 3 photocells, a relay and some software (see above for the flowchart in textformat).

    Kind rgds,
    Erik
     
    Scott Eric Catalano likes this.
  3. Erik84750

    Erik84750 TrainBoard Member

    334
    134
    12
    Hi,

    after a few days of testing I want to present to you my version of a full automatic bi-directional auto-reverser. The drawing is based on a drawing by Dutch-Master who of course is given due credit in the attached drawing.

    The drawing I made with Adobe Illustrator, I am not too proficient with that program, it took me 6 hours to have it done.

    I decided not to include frog powering (see Dutch-Master diagram above) because that is part of the switch command hardware.

    Design constraints:

    1. create a full automatic autoreversing controller
    2. for bi-directional use
    3. with no stopping of the loco/train
    4. without use of short-circuit detection (IMO this is a rather crude way of automating a project). But if you definitely want to use short-circuit detection then this is also allowed, just make sure that proper HIGH or LOW signals are given.
    5. with the use of any type of sensor (optical, inductive, capacitive, reed-relay, .. just anything that 100% reliably detects a loco above or underneath it), with preferably (but not necessarily: I just need to change the code a bit) a LOW signal when nothing is detected and a HIGH signal when detection occurs
    6. cheap (I used for testing a ATtiny85 (1.5EUR), and 3 LDR's (1EUR for 20) and a 1EUR DPDT relay (4-pole must be used if the optional tracks are cut): total cost less then 5EUR in hardware.
    7. reliable: it all depends on the sensors used; the software is foolproof and thoroughly tested.
    8. any type of Atmega controller can be used: Arduino, Pro-Mini, ATtinyxx, etc..
    9. 5V power supply for relay, sensors, controller
    10. Must be able to be used for nested reversing loops, sequenced reversing loop, multiple reversing loops, etc..

    If needed I can program the controller for you, just send me 2 units: one for return programmed and one to cover postage; just pm me.

    The ATtiny I used has following connections (see also the code):

    PB0 = LDR1 (the one inside the loop)
    PB1 = LDRa
    PB2 = LDRb
    PB3 = Relay output (EDIT: beware: a controller supplies a max of about 10 to 20mA safely per output: use a high impedance relay https://www.aliexpre...d-58936f8fd807 which in turn drives the power relay).

    Make sure you cut the trace to the LED connected to PB1 or the voltage divider used for the LDR will not work properly. But best of all is to use an LDR driving a comparator, no need for calibration.

    This is the controller I use: https://www.aliexpre...d3-7dd445f0e91d

    Sensors of any shape, type, price can be found on that site. So far I have ordered 450+ items from them and just a few never arrived for which I got my money back.

    My code (actually the code has just 4 read lines and 4 command lines, so fairly easy to read):
    Code:
    const byte Relay = 3;
    const byte LDRa = 1;
    const byte LDRb = 2;
    const byte LDR1 = 0;
    boolean A = LOW;
    
    void setup() {
      pinMode(Relay, OUTPUT); //setting the pin mode to Output
      digitalWrite(Relay, LOW);
    }
    void loop() {
      int stateLDRa = digitalRead(LDRa);
      int stateLDRb = digitalRead(LDRb);
      int stateLDR1 = digitalRead(LDR1);
      int stateRelay = digitalRead(Relay);
      if (stateLDRa == HIGH && stateLDR1 == LOW && stateLDRb == LOW)  //condition 1; clockwise
      { digitalWrite(Relay, HIGH);
        A = HIGH;
      }
      if (stateLDRa == LOW && stateLDR1 == HIGH && stateLDRb == LOW && A == HIGH) //condition 2; clockwise
      { digitalWrite(Relay, LOW);
      }
      if (stateLDRa == LOW && stateLDR1 == LOW && stateLDRb == HIGH) //condition 3; clockwise and counterclockwise: set relay low
      { digitalWrite(Relay, LOW);
        A = LOW;
      }
      if (stateLDRa == LOW && stateLDR1 == HIGH && stateLDRb == LOW && A == LOW)  //condition 4; counterclockwise: set relay high
      { digitalWrite(Relay, HIGH);
      }
    }
    
     

    Attached Files:

    Last edited: May 4, 2017
    chi.sp and Scott Eric Catalano like this.
  4. CSX Robert

    CSX Robert TrainBoard Member

    1,502
    638
    41
    I agree that when possible it is better to prevent the short than to detect it and correct it. I wish I had seen this thread earlier, I might have saved you some trouble. In a simple loop like you have illustrated, there is a much simpler way to control the phase (AC version of polarity) of the loop. Since you can not enter or exit the loop without the turnout being aligned to the correct end, you can simply have the phase of the loop controlled by the position of the turnout.
     
    Scott Eric Catalano likes this.
  5. Erik84750

    Erik84750 TrainBoard Member

    334
    134
    12
    You will have to align turnouts manually. I my case it will be automatic; you can either manually or automatically select an entry direction (clockwise or counterclockwise), exit turnout setting will be automatic.
     
    Scott Eric Catalano likes this.
  6. CSX Robert

    CSX Robert TrainBoard Member

    1,502
    638
    41
    I think you misunderstood what I was saying - whatever method you are using to control the turnouts, you could have the direction of the turnout directly control the phase of the loop and you would not need the sensors or even the Arduino for the reversing section.
     
    Scott Eric Catalano likes this.
  7. Erik84750

    Erik84750 TrainBoard Member

    334
    134
    12
    This would be true for reversing loops with one turnout only. But my goal is to have a controller that does not depend on turnout settings because all too often during operations turnouts tend to be forgotten to be set. So it all depends on 1. I want to control operations manually, or 2. I want to use automation to remove human error.

    By the way: I started a now thread on this subject: http://www.trainboard.com/highball/...directional-reversing-loop-controller.105591/
     
    Scott Eric Catalano likes this.
  8. w8one

    w8one TrainBoard Member

    89
    109
    5
    Good job Erik84750, Your first problem is using the term auto-reverse this applies exclusively to a dc only system. In DCC you do not need a reversing circuit you need a non shorting circuit. The goal is to keep the trucks of the engine from shorting the gaps as they pass over them. If you use three sensors, one at both gaps and one in the middle, you would be able to A: Determine the direction of travel which sensor was triggered first. B: When it is safe to flip the wires to avoid a short, center sensor. C: Trigger the points in the turnout loop to let the train out, last sensor. If at power on you set to lets say to left and their after you keep track of the position, or software input to change you will always know where it was at.
     
    Scott Eric Catalano likes this.
  9. Erik84750

    Erik84750 TrainBoard Member

    334
    134
    12
    Hi w8one,
    I had initially thought 3 sensors would be enough until someone pointed out to me that if a sensor is used before each of both isolators and one center sensor the there would be a problem if a locomotive crosses the entry sensor and thne decides to return back over the initial isolation after having passed the center sensor.
    Therefor a sensor is needed both before and after each isolation: so a train can enter and/or leave a reversing loop over the same isolation.

    I posted sensor info here: http://www.trainboard.com/highball/index.php?threads/reversin-loop-automation.105909/
     
    Scott Eric Catalano likes this.
  10. w8one

    w8one TrainBoard Member

    89
    109
    5
    If sensors are placed 3 inches or 8 cm from the points inside the loop (assuming the cuts are right at the points) and you already know which way the points are going (left or right) you can use just 2 sensors 1 tells you when a train is coming in and one for going out (switching just before leaving). if the points position is unknown put the 3rd sensor on the points to tell you which way your going to go (the train has to go with the points or it will derail). The 3rd points sensor will let you align relay to what ever direction the points are going even if the points are changed from software or a physical change to the points.
     
    Last edited: Jun 17, 2017
    Scott Eric Catalano likes this.
  11. Erik84750

    Erik84750 TrainBoard Member

    334
    134
    12
    I am not sure I understand what you write: can you maybe post a drawing?
     
    Scott Eric Catalano likes this.
  12. w8one

    w8one TrainBoard Member

    89
    109
    5
    turnout.jpg
    Sensor 3 will show you which way the train is going. See if 1st sensor has been tripped within a set time then set sensor 2 to switch the polarity and the points (or signal whatever controls the turnout to change them). If the points are changed sensor 3 can tell your turnout controller to change the polarity to match the points.
     
    Last edited: Jun 18, 2017
    Scott Eric Catalano likes this.
  13. Erik84750

    Erik84750 TrainBoard Member

    334
    134
    12
    I'd rather use this sensor to tell me if my beer sits in the right place :giggle:

    This setup is useless for controller purposes: if I design a controller with train detection, I want to know where a train actually IS, not where a train MIGHT be. You can just as well use the switch motor controller output to do the same. Or put the sensor on the track that you intend to detect on. But I would say: do as you please.

    But furthermore, for reversing loop automation I posted here (http://www.trainboard.com/highball/index.php?threads/reversin-loop-automation.105909/), using just two sensors.
     
    Scott Eric Catalano likes this.
  14. RT_Coker

    RT_Coker TrainBoard Supporter

    516
    32
    13
    Did I miss something? Is it not possible to change the DCC++ code so that DCC++ will try reversing the DCC-phase for a short condition (or based on a sensor inputs)? Wouldn’t this be the cheapest and most direct solution?
    Bob
     
    Scott Eric Catalano likes this.
  15. Erik84750

    Erik84750 TrainBoard Member

    334
    134
    12
    Yes you missed a few things. For a recap, here is a link to my most recent posting with a solution for reversing loop controlling: http://www.trainboard.com/highball/index.php?threads/reversin-loop-automation.105909/

    Changing DCC++ code? Have a go at it. And short-circuits are to be avoided anytime, and if you have one then that is why you have circuit breakers.
     
    Scott Eric Catalano likes this.
  16. Jimbo20

    Jimbo20 TrainBoard Member

    274
    178
    11
    The phase must only be reversed on the loop; if the phase is reversed at the DCC++ output then both the loop and non-loop sections will still be out of phase and the the short condition will still exist.


    Jim
     
    lnxlnx, RCMan and Scott Eric Catalano like this.
  17. Erik84750

    Erik84750 TrainBoard Member

    334
    134
    12
    You explained it better than I could. Thank you.
     
    Scott Eric Catalano likes this.
  18. RT_Coker

    RT_Coker TrainBoard Supporter

    516
    32
    13
    If I am not mistaken the DCC to the reverse-loop typically goes through a relay (or switch) that is switched to avoid (or relieve) the short, and there are extra input/output-ports available on the DCC++ unit. All I am saying is that the DCC++ hardware should also be able to handle a reverse loop either by short-detection or sensor-input without additional hardware (except for the reverse-loop-relay). And DCC++ would also work as an auto-DCC-phase-switcher on layouts that use multiply DCC++ units.

    Bob
     
    Scott Eric Catalano likes this.
  19. Erik84750

    Erik84750 TrainBoard Member

    334
    134
    12
    Hi Bob, every commercial DCC reversing loop controller uses short circuit detection to direct the loop polarity. And that has been my purpose since the beginning of all my posts on this subject: to avoid having to have short circuits at all to direct reversing loop polarity.

    The unit I developed costs less then USD20 for materials and does a better job for reversing loops than any commercial unit. Sorry to sound boastful but after all these postings on the subject I hope some people read up these posts so they understand what they are about.
    With my optical detector only one unit and a relay is needed to do the job. If the current detector board is used then two of them plus a relay do the job.

    http://www.trainboard.com/highball/index.php?threads/reversin-loop-automation.105909/
     
    Scott Eric Catalano likes this.
  20. JimDo

    JimDo New Member

    3
    1
    5
    Eric,

    I thought I would chime in. I am just getting into model railroading now. I realize that I am late to the party. I have been thinking about AR for a while as I struggle with how to set up my loops without the use of short circuit detection. I think the flowing is the complete list of scenarios. Using 3 detection blocks in your example, DET-a, DET-b and DET1.

    Additional assumptions:
    Train must fit in its entirety in DET1. As a result, train wont be in all 3 zones at once. This is important for other reversing scenarios not depicted here.

    Default state of relay should be low. If I understand the micro-programming logic, this is arbitrarily assumed to be equal polarity with DET-a.

    An additional variable is need to keep track of train entry point into the loop, to know where it came from since keeping track of the state of the relay is not sufficient. In the loop, this will tell us the polarity of the next zone to be encountered.

    Logic will set loop polarity to that of the default whenever possible. First two cases ensure loop is set properly upon entry.

    • Use Case DET-a DET-b DET1 FromZone Action
    • blk-a HIGH ---- ---- ---- Set NextZone=HIGH, Relay-LOW
    • blk-b ---- HIGH ---- ---- Set NextZone=LOW, Relay=HIGH
    • All blks empty LOW LOW LOW ---- Set Relay=LOW
    • Enter Det1 from blk-a HIGH LOW HIGH ---- Set Relay=LOW
    • Enter Det1 from blk-b LOW HIGH HIGH ---- Set Relay=HIGH
    • Det1 only LOW LOW HIGH ---- Set Relay=NextZone (once train fully in loop, use next zone polarity)
    • Error condition 1 HIGH HIGH HIGH ---- Set Relay=LOW (you have a short or a detection problem, or a train too long, but you cant control it anyhow)

    As you see, logic does not really care about status of relay, rather where the train came from and where it is headed to. Now loop zone polarity is set to the zone polarity from which the train entered and immediately changes to the polarity of the exiting zone once zone transition is complete.

    Jim
     
    Scott Eric Catalano likes this.

Share This Page