Notifications
Clear all

4 Way Crossing Polarity

62 Posts
5 Users
1 Likes
19.2 K Views
(@john40131)
Member
Joined: 5 years ago
Posts: 95
Topic starter  

I have another senarion which does work its quite a simple sketch prob a bit long winded,  just switching relays for polarity switching on my 4 way Cross over.... BUT .... I have a what IF..

I have 5 "Y" points which will have a switch on each one so can switch "Left or Right"..

So in my sketch I have switch" 1" switched on Track "1" to "Right" so crossing 1A is DCC+ on the top Frog and DCC- on the bottom Frog thats fine .

Know if I switch "2" which will switched to "Left" I need polarity to change on 1A is DCC- on the top Frog and DCC+ on the bottom Frog, but switch 1 is telling it i'm already the other way, so which takes priority or is there another way to do it. or does the last command take priority...

 

Regards John

void loop() {

switch1State = digitalRead(track1Switch);
switch2State = digitalRead(track2Switch);
switch3State = digitalRead(track3Switch);
switch4State = digitalRead(track4Switch);

if (switch1State == LOW){// Switch state Track going Right
routefrog1();
}
if (switch2State ==HIGH){ Switch State Track 2 going Left
routefrog2();
}

// if (switch3State == LOW){
// routefrog3();
// }

// if (switch2State == HIGH){
// routefrog20();
// }

// if (switch3State == LOW){
routefrog3();
// }
// if (switch3State == HIGH){
routefrog30();
// }
//if (switch4State == LOW){
// routefrog4();
// }
// if (switch4State == HIGH){
// routefrog40();
// }
}

void routefrog1() {
digitalWrite(frog1A,LOW);
digitalWrite(frog1B,LOW);
digitalWrite(frog1C,LOW);
digitalWrite(frog1D,LOW);
}
void routefrog2() {
digitalWrite(frog1A,HIGH);
// digitalWrite(frog2B,LOW);
// digitalWrite(frog2C,LOW);

}

This topic was modified 5 years ago by John40131

   
Quote
(@john40131)
Member
Joined: 5 years ago
Posts: 95
Topic starter  

This is picture..

DSC 0743

 

Frog is the coloured in Purple and Green..

i.e Purple is DCC +

     Green is DCC -

John

This post was modified 5 years ago by John40131

   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@john40131

Perhaps a H-Bridge (not necessarily this one), is what you need?
There is an explanation how a H-Bridge works, in a tutorial on this website:

   


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
 

When I right clicked the picture and selected Save image as ...
a 90K image is downloaded (size in post apparently).
However if I right click the picture and select Open image in new Tab and then select Save image as ...
I get 5.79MB
So I now get that you have always been attaching high resolution images.
As regards your question I did some reading but can't understand enough to decode the code.
I assume it is related to this kind of thing.
https://dccwiki.com/Wiring_Crossings

 


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
 

@john40131

I am trying to visualise how the setup shown in the picture above works logically and I have a couple of naive questions/observations. I have looked on the internet to find out what all this "frog" business is all about and have seemingly grasped the concept.

When you talk about DCC+ and DCC-, do you mean plus 12V-0V(Gnd)-minus 12V or just plus 12V-0V?

I assume that if the second case is true then all rails and frogs are pulled to ground, until power is applied to both main rail sections and the frogs that make up the sections between the powered rails to allow a locomotive to traverse the other rails after which the power to the frogs is disconnected.

After looking at the code posted above, which wouldn't work in a million years as is, that it is still only a small selection from the entire code sketch. If you just drag and drop the .ino file on to your next post, it would be interesting to see how the whole sketch is constructed and how I might be able to suggest some improvements.

There was one more thing, in the other thread, the concept was to control the Signal Lights, is your long term goal to integrate this frog control sketch into the LE control sketch, or will they operate separately?


   
ReplyQuote
(@john40131)
Member
Joined: 5 years ago
Posts: 95
Topic starter  

Sorry if a bit confusing, but a H bridge is not what I need I am not controlling a motor all I have to do is change the polarity of the FROGS on the tracks i.e the Purple bit and the Green bit or you would have a short between diamond crossing, all the rails and Frogs are osolated from one another as per the link in Caseys link but a lot more complex...so if I use toggle switches to change the Data pin on Arduino from Low to high on Track 1 then if I switch track to 2 from High to low if you look at sketch ( okay not put all setup bits on ) you will see in routefrog1() all outputs are LOW so know if I select switch to set routefrog2  frog1A is LOW and wants to turn high.... I think I have found a solution and instead of using toggle switch as that would remain on in that position but to use momentary push buttons so if I set track1 all LOW when Track2 is pressed there would be no conflict with wanting to change polarity... the polarity is eventually changed with a DPDT relay ... DCC signals going to COMMON and Rails connected to N.O or N.C side of relay ... the Arduino Data outputs would go were the switches are on this simulation drawing ..

Also not sure about picture size I just take picture with Phone or camera but seems to be a big file...

Frog switching V2

 

John


   
ReplyQuote
(@john40131)
Member
Joined: 5 years ago
Posts: 95
Topic starter  

@pugwash

I didnt want to put all the sketch in as it is basic for me and was partly copied from my previous sketch, I am a novice at sketches so I do know there is probably other ways to crack this but it does compile and will try when i get another Mega...Model Railway DCC is PWM on track rails  i.e Pulses positive and pulses negative and if you use the Arduino as a DCC controller with Motor shield and connect a couple of data links and install "DCC Base Station " off github, you have to outputs 1 for tracks and 1 for program track to program the locomotive..the power to the motor shield is 15 volts DC but you have to cut the Vin link on motor shield or Arduino goes POO..

There are other controllers but most are expensive Hornby starts at £75 and you can get a Z21 with WiFi for mega bucks ...

John

//Bolton Station 4 way crossing Frog switching
//Created Starting 20th October 2019
//Finished and working
//All frogs are switched seperatly via Opto-coupled to relays

const int frog1A = 1; //Set pin1 to operate Frog 1A;
const int frog1B = 2; //Set pin2 to operate Frog 1B;
const int frog1C = 3; //Set pin3 to operate Frog 1C;
const int frog1D = 4; //Set pin4 to operate Frog 1D;
const int frog2A = 5; //Set pin5 to operate Frog 2A;
const int frog2B = 6; //Set pin6 to operate Frog 2B;
const int frog2C = 7; //Set pin7 to operate Frog 2C;
const int frog3A = 8; //Set pin8 to operate Frog 3A;
const int frog3B = 9; //Set pin9 to operate Frog 3B;
const int frog4A = 10; //Set pin10 to operate Frog 4A;
const int point1 = 11; //Set pin11 to operate point1 Frog;
const int point2 = 12; //Set pin12 to operate point2 Frog;
const int point3 = 13; //Set pin13 to operate point3 Frog;
const int point4 = 14; //Set pin14 to operate point4 Frog;
const int point5 = 15; //Set pin15 to operate point5 Frog;

const int track1Switch = 20;// Track pins inputs for Track 1 to 5
const int track2Switch = 21;
const int track3Switch = 22;
const int track4Switch = 23;
const int track5Switch = 24;

int track1State = 0;
int track2State = 0;
int track3State = 0;
int track4State = 0;
int track5State = 0;

 

const int mainDelay1 = 500;
const int mainDelay2 = 1000;
int switch1State = 0;
int switch2State = 0;
int switch3State = 0;
int switch4State = 0;
int switch5State = 0;

void setup() {
pinMode(frog1A, OUTPUT);
pinMode(frog1B, OUTPUT);
pinMode(frog1C, OUTPUT);
pinMode(frog1D, OUTPUT);
pinMode(frog2A, OUTPUT);
pinMode(frog2B, OUTPUT);
pinMode(frog2C, OUTPUT);
pinMode(frog3A, OUTPUT);
pinMode(frog3B, OUTPUT);
pinMode(frog4A, OUTPUT);
pinMode(point1, OUTPUT);
pinMode(point2, OUTPUT);
pinMode(point3, OUTPUT);
pinMode(point4, OUTPUT);
pinMode(point5, OUTPUT);

pinMode(track1Switch, INPUT_PULLUP);
pinMode(track2Switch, INPUT_PULLUP);
pinMode(track3Switch, INPUT_PULLUP);
pinMode(track4Switch, INPUT_PULLUP);
pinMode(track5Switch, INPUT_PULLUP);

digitalWrite(frog1A, HIGH);// On startup all frogs are set HIGH to Left Frog switching
digitalWrite(frog1B, HIGH);// Setting frogs to low means points are thrown to right and frog switched accordingly.
digitalWrite(frog1C, HIGH);
digitalWrite(frog1D, HIGH);
digitalWrite(frog2A, HIGH);
digitalWrite(frog2B, HIGH);
digitalWrite(frog2C, HIGH);
digitalWrite(frog3A, HIGH);
digitalWrite(frog3B, HIGH);
digitalWrite(frog4A, HIGH);
digitalWrite(point1, HIGH);// On startup all Points are set to Left frog switching
digitalWrite(point2, HIGH);// and the switches are DPDT so servo module Arduino is switched at same time
digitalWrite(point3, HIGH);
digitalWrite(point4, HIGH);
digitalWrite(point5, HIGH);

}

void loop() {

switch1State = digitalRead(track1Switch);
switch2State = digitalRead(track2Switch);
switch3State = digitalRead(track3Switch);
switch4State = digitalRead(track4Switch);

if (switch1State == LOW){// Switch state Track going Right
routefrog1();
}
if (switch2State ==HIGH){ Switch State Track 2 going Left
routefrog2();
}

// if (switch3State == LOW){
// routefrog3();
// }

// if (switch2State == HIGH){
// routefrog20();
// }

// if (switch3State == LOW){
routefrog3();
// }
// if (switch3State == HIGH){
routefrog30();
// }
//if (switch4State == LOW){
// routefrog4();
// }
// if (switch4State == HIGH){
// routefrog40();
// }
}

void routefrog1() {
digitalWrite(frog1A,LOW);
digitalWrite(frog1B,LOW);
digitalWrite(frog1C,LOW);
digitalWrite(frog1D,LOW);
}
void routefrog2() {
digitalWrite(frog1A,HIGH);
// digitalWrite(frog2B,LOW);
// digitalWrite(frog2C,LOW);

}
void routefrog10() {
digitalWrite(frog1A,HIGH);
digitalWrite(frog1B,HIGH);
digitalWrite(frog1C,HIGH);
digitalWrite(frog1D,HIGH);
}

void routefrog20() {
digitalWrite(frog2A,HIGH);
digitalWrite(frog2B,HIGH);
digitalWrite(frog2C,HIGH);

}
void routefrog3() {
digitalWrite(frog3A,LOW);
digitalWrite(frog3B,LOW);

}
void routefrog30() {
digitalWrite(frog3A,HIGH);
digitalWrite(frog3B,HIGH);

}
void routefrog4() {
digitalWrite(frog4A,LOW);

}

void routefrog40() {
digitalWrite(frog4A,HIGH);

}

 


   
ReplyQuote
(@john40131)
Member
Joined: 5 years ago
Posts: 95
Topic starter  

Also there are a lot of what if senarios on this crossing that is why I am controlling each Diamond crossing seperately instead of originally Lin 1, Line 2, Line 3 etc..

But to program this into a sketch may take some time..is document below explains...

John....

4 Way Track crossing scenario

 

 

1/        If Track 1 is Live going R.H.

            Then Tracks 3, 5, 7, 9 can be available going R.H

            But no Tracks to L.H. side are available

2/        If Track 2 is Live going L.H

Then Tracks 3, 5, 7, 9  are available going RH or Tracks 4, 6, 8, available L.H plus 9, going R.H

3/        If Track 3 is Live going R.H

            Then Tracks 1, or 2, are available and 5, 7, 9 available going R.H

4/        If Track 4 is Live going L.H

            Then Tracks 2, 6, 8 available L.H and 5, 7, 9 available R.H

5/        If Track 5 is live going R.H

Then Tracks 1, 3 available R.H or 2, 4 available L.H and 7, 9 available going R.H

6/        If Track 6 is Live going L.H

            Then Tracks 2, 4, 8, available L.H and 7, 9, available R.H

7/        If Track 7 is Live going R.H

            Then 1, 3, 5, 9, are available R.H or Tracks 2, 4, 6 available L.H

8/        If Track 8 is Live going L.H

Then Tracks 2, 4, 6, are available L.H. and/Or Tracks 9 available going R.H


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
 

@john40131

Why can't you connect 1a, 1b, 1c and 1d to one common pin?

As I see from the drawing they are just connected to optocouplers that draw very little current, and all are LOW or HIGH simultaneously.


   
ReplyQuote
(@zeferby)
Member
Joined: 5 years ago
Posts: 355
 

Hi @john40131

I assume you would have some occupancy detection mechanism...something like 3 train sensors per turning point : 1 "east", 1 "west left", 1 "west right"

I would use 2 boolean statuses per diamond crossing :

  • 1 "polarity" state
  • and 1 "available" state (will be ON when the polarity actually can be changed)

Then you can manage some compound boolean states for the turning points 1 to 5 ability to switch left or right like this (I assume the 2B and 2C tags on the photo are wrong) like this pseudo-code :

  • canTurnLeft1 = true (always)
  • canTurnRight1 = (available1A && available1B && available1C && available1D)
  • canTurnLeft2 = (available1A)
  • canTurnRight2 = (available2A && available2B && available2C)
  • canTurnLeft3 = (available2A && available1B)
  • canTurnRight3 = (available3A && available3B)
  • canTurnLeft4 = (available3A && available2B && available1C)
  • canTurnRight4 = (available4A)
  • canTurnLeft5 = (available4A && available3B && available2C && available1D)
  • canTurnRight5 = true (always)

Establishing the way for turn point 1 switched to the RIGHT :

When you switch turn point 1 to the right (assuming canTurnRight1 is true !!!), you disable all the relevant crossings until the train has left the area :

Point1 turn right ==> locking 1A, 1B, 1C, 1D into the RIGHT position and NOT available until train has left the area

  • available1A = available1B = available1C = available1D = OFF
  • polarity1A = polarity1B = polarity1C = polarity1D = RIGHT

The consequences of this are :

  • canTurnLeft2 = false because available1A = OFF
  • canTurnLeft3 = false because available1B = OFF
  • canTurnLeft4 = false because available1C = OFF
  • canTurnLeft5 = false because available1D = OFF

The sensor trainSensor1WestRight should, later on, detect that the train has left the area and reset the relevant "available" flags ON :

  • available1A = available1B = available1C = available1D = ON

 

Eric


   
ReplyQuote
(@john40131)
Member
Joined: 5 years ago
Posts: 95
Topic starter  

@pugwash

My original idea was to connect Frogs on 1A, 1B, 1C, 1D etc etc on other lines but that means I can only run on tracks going to Left or Right and not say a train is on Line 2 going north so Frog1A is DCC + on LH rail and DCC- on RH Rail so know if I want to use a train on Line 4 south bound so Frog1B is DCC + on LH rail and DCC- on RH rail so as you can see there is a different polarity between Line 2 and  Line 4 ... rule of thumb all LH rails are say DCC + and RH Rails are DCC- no matter which way trains are going or if you swap rail polarity you will finish up with a short.

Scissor crossing

 

Did you see this polarity switching from DCC concepts thats another junction I am making but thats a straight forward relays to change ...

John


   
ReplyQuote
(@john40131)
Member
Joined: 5 years ago
Posts: 95
Topic starter  

@zeferby

I really appreciate your help and that looks a good idea on paper but for me to translate to a sketch would take me forever .... if sketches told you what you did wrong would make a lot easier but it only gives basic error finding I do have Atmel Studio which I beleive is better but never used so thats another learning curve...

I had an issue yesterday when I was doing the loop .. routefrog1 etc told me I had not defined in sketch so what did I do wrong ... was nothing to do with define it was a   " } " I had missed took me 2 hours to work that out..

John


   
ReplyQuote
(@zeferby)
Member
Joined: 5 years ago
Posts: 355
 

Hi @john40131

I played with the idea of frog locking/unlocking and came up with a sample0 sketch based on your code above, then tweaked it to add the concept of "locking owner" in sample1, and finally changed locking to be optional in sample2.

It is all bloatware, absolutely anti-DRY, but it should thus be understandable...I hope ?

 

Eric


   
ReplyQuote
(@john40131)
Member
Joined: 5 years ago
Posts: 95
Topic starter  

@zeferby

Thanks for help, its a bit late today but will ahve a look at those tomorrow...

Regards John


   
ReplyQuote
(@john40131)
Member
Joined: 5 years ago
Posts: 95
Topic starter  

@zeferby

WOW, just looked at your 3 sketches, this would have taken me years to write sketch and work out logic so if this works it will have saved my blood pressure and head scratching..

I will build up relays and input circuits while I wait for a Mega to arrive hopefully on Friday..

I really appreciate the time you have taken to do this...

Many Thanks

Regards John


   
ReplyQuote
Page 1 / 5