Model Railroad Application
BillH
Posts: 14
I've just purchased my first BS-2.· I hope to use it in a model railroad application.· Could someone give me some programming help?· I have extensive experience in building circuits but none in programming.· My railroad is built like a sound stage, 41 feet long, with a proscenium arch behind which are hidden 55 lights, seven speakers and 2 subwoffers.· I use a·diesel and a steam throttle, both of which have programmable sound effects.· The sound is attenuated by being directed to the overhead speakers through a set of seven pushbuttons attached to seven latching, 12 volt, 4PDT relays that draw 75ma.· The sound moves along with the train by pushing the buttons at the appropriate time.· It is a manual operation which I would like to automate using a BS-2.· I have installed an optical detection system which uses photo resistors mounted between the rails.· When a train shades a detector a commercially built comparator circuit provides a ground which can sink 250ma.· (If any of you are model railroaders, I use Sound Traxx throttles, and Circuitron DT-4 detectors.)· I have ordered a BS-2, a Super Carrier Board, and a ULN2803 Darlington array.· I would like to have the BS-2 perform as follows:· when a train shades the first detector the Stamp needs to see that and send a pulse to the first relay to energize and then ignore additional signals from that detector.· The problem is that there is a gap between each pair of cars that can allow light to cause the relays to chatter back and forth.· When the train shades the second relay the Stamp needs to signal the next relay to energize and so forth through all seven detectors and then loop back to the first detector and wait for the next train.· Also when power is initially turned on the Stamp·needs to energize the first relay.· Only one speaker relay is on at a time and they latch in both directions for manual control which is sometimes desirable.· Any programming hints would be greatly appreciated, or perhaps someone could direct me to a similar application.
·
·
Comments
·
The IR sensors are connectd to BS inputs and monitored by the program code in·the main·program loop. When a IR change is detected, the corresponding relay·connected to a BS output is·energized. A· program counter for the relay is also·set and is decremented in the main program loop. When·the program counter·reaches zero, the relay is de-energized. Each time an IR change occurs (the gap between the cars), the counter is again set to its starting value. In this way, the counter will not reach zero until a short time after the last car of the train passes the sensor.
The value for the relay counter depends on the main program loop execution rate. It needs to be large enough so that·the counter·won't reach zero on a car gap for your slowest moving train. The PAUSE statement can be used to slow down the main program loop so you don't·have to use·16 bit counters.
A single BS2 could easily control multiple relays. Each relay to be controlled needs a BS2 input for the sensor, a BS2 output to drive the relay, and an internal program counter. The rest of your functionality requirements can be handled by the program coding. Check your relay current requirements. I smoked a ULN2803 driver on a mislabeled surplus relay.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don Buczynski
http://www.geocities.com/donbuczynski
Post Edited (Don Buczynski) : 11/18/2004 4:08:12 PM GMT
Definitely check out his web-site. Good code, good construction details.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Knight Designs
324 West Main Street
P.O. Box 97
Montour Falls, NY 14865
(607) 535-6777
Business Page:·· http://www.knightdesigns.com
Personal Page:··· http://www.lightlink.com/dream/chris
Designs Page:··· http://www.lightlink.com/dream/designs
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don Buczynski
http://www.geocities.com/donbuczynski
Sorry OT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Knight Designs
324 West Main Street
P.O. Box 97
Montour Falls, NY 14865
(607) 535-6777
Business Page:·· http://www.knightdesigns.com
Personal Page:··· http://www.lightlink.com/dream/chris
Designs Page:··· http://www.lightlink.com/dream/designs
·
You really can't directly control a relay with a BS2 pin. Each BS2 pin can sink or source 20 mA max, and the entire BS2 should only source or sink 50 mA max. If you use the BS2 to control the ULN2803, which then controls the relay, you should be ok.
The BS2 will *try* to source more than 20 mA if you let it, and will burn out the pin driver (damage the chip) if you do. Putting at least a 220 ohm resistor in series with the I/O pin will limit the current from the BS2 if you think this might be a possibility.
One more thing. An 'unregulated' DC wall-wart rated at 9 volts will put out 12 volts or more with no load. It only puts out 9 volts under full load. If you are using a 'regulated' 13.5 V wall-wart, then it *should* put out 13.5 volts all the time. An unregulated 13.5 volt wall-wart would probably put out *more* than the 15 volts DC under a BS2 load -- thus the concern.
Check it with a volt meter, both under no-load and while driving the BS2 to find out which it is.
Instead of mechanicaly latching yor relays why not try an R/C holding circuit.
I just tried it using a +5 volt signal to turn a NPN darlington transistor on which turned on a 12 volt relay.
Using a 1000uF capacitor and a 1k0 series resistor I got turn off delays near 1 second.
You would have to invert your signal or perhaps use a PNP transistor.
You might then find a more challenging application for your Stamp.
Please let me know what you think, I'm a real novice when it comes to electronics but this should work.
pc size latching relays draw not power during usage except when changing state.
CHECK HOSFELT ELECTRONICS IN OHIO. GOOD SOURCE OF LATCHING RELAYS AND THEY ARE SMALL.
http://www.hosfelt.com/
45-512 @ $.99 AND 45-408 @ $.45 EA. FOR 5VDC
73
SPENCE
Bill H
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
4 digit serial LED
http://hometown.aol.com/newzed/index.html
·
The board is stamped 30 volts max because if you used a 25 volt DC un-regulated wall-wart, ITS open voltage would be huge -- 36 volts? THEN you would have a problem. Note, even then, the worst thing that would probably happen is the regulator on the BS2 would go into thermal shutdown.
BillH
Check pin 9 of the ULN2803. It should be connected to a common ground that includes the BS and relay power supply (if using a separate relay power supply). Pin 10 of the ULN2803 connects to the +12 volt side of your relay(s). ULN2803 output pins 11-18 connect to the other side of the relay(s).
According to the ULN2803 spec I have, the minimum "ON" input voltage·is 3.5 volts. Set the Basic Stamp pins connected to the ULN2803 inputs to "high" and measure the voltage on the UNL2803 inputs. I am driving relays with a·ULN2803 on my model railroad but I drive the ULN2803 inputs from TTL chips which are close to 5 volts when high.
Hope this helps.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don Buczynski
http://www.buczynski.com
Correction:· Pin 10 connects to the negative side of the relay.· The positive side of the relay goes to the relay supply voltage.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
4 digit serial LED
http://hometown.aol.com/newzed/index.html
·
Hmmm... I'm not sure I fully understand this. Each output pin of the ULN2803 already has a connection to its internal clamp diode. See attachments.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don Buczynski
http://www.buczynski.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
4 digit serial LED
http://hometown.aol.com/newzed/index.html
·
DO
IF (IN0 = 1) THEN
HIGH 9
ENDIF
IF (IN1 = 1) THEN
LOW 9
HIGH 10
ENDIF
IF (IN2 = 1) THEN
LOW 10
HIGH 11
LOOP
I am missing a basic link here. Do I need a subroutine to do this? The relays do energize but all stay energized and I only want one on at a time. Essentially I am trying to get them to act as if energized by a make before break rotary switch. Any ideas?
Bill Herbert
A TLC2543 will give you 11 channels of ADC inputs.· Very reliable method.
Notwithstanding all the above, I went to an IR detector·system.· I had four placed at strategic intervals around the track and they worked flawlessly.· With the IR all you have to do is detect the beam break - no data transmission problems to worry about.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
4 digit serial LED
http://hometown.aol.com/newzed/index.html
·
relays if you prefer.· I used 12 because the relays draw less current at that voltage.· All the relays plug into an 8-pin DIP socket, which makes replacement easy.· Also, each relay has an LED to indicate when it is being energized.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
4 digit serial LED
http://hometown.aol.com/newzed/index.html
·
DO
IF (IN2 = 1) THEN
LOW 9
LOW 10
HIGH 11
ELSEIF (IN1 = 1) THEN
LOW 9
HIGH 10
LOW 11
ELSEIF (IN0 = 1) THEN
HIGH 9
LOW 10
LOW 11
ELSE
LOW 9
LOW 10
LOW 11
ENDIF
LOOP
This logic would be susceptible to input sensor bounce causing the relays to chatter.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don Buczynski
http://www.buczynski.com
Post Edited (Don Buczynski) : 12/16/2004 4:03:38 PM GMT