Shop OBEX P1 Docs P2 Docs Learn Events
Model Railroad Application — Parallax Forums

Model Railroad Application

BillHBillH Posts: 14
edited 2005-01-29 21:11 in BASIC Stamp
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.

·
«1

Comments

  • m_fabio2m_fabio2 Posts: 49
    edited 2004-11-15 21:25
    as far as the gap between cars go, that isn't a problem. You could use a subroutine in the stamp with a pause statement, that should take care of those gaps. It sounds very similair to the "bounce" present in a switch. I know the stamp has some commands to deal with the bounce, that could be applied to this situation.

    ·
  • Don BuczynskiDon Buczynski Posts: 31
    edited 2004-11-18 16:00
    I have some experience with Basic Stamps and a model railroad. You can checkout my website for some ideas at: http://www.geocities.com/donbuczynski· I use IR sensors for some applications like grade crossings.·The way to·solve the gap between cars is to use·a piece of·BS code that functions as a retriggerable timer.

    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
  • BillHBillH Posts: 14
    edited 2004-11-18 16:42
    Thanks for this input. I may have more questions when I get more into the programming. BS-2 came in yesterday but have to leave town today for several days.
  • allanlane5allanlane5 Posts: 3,815
    edited 2004-11-18 18:21
    Don Buczynski is the king of BS2 RailRoad apps, as far as I know.
    Definitely check out his web-site. Good code, good construction details.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2004-11-18 21:03
    Gotta catch the site on a slow day though...I was juct checking it out and Geocities says it has exceeded it's daily traffic...Guess a lot of people check it out!



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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 BuczynskiDon Buczynski Posts: 31
    edited 2004-11-19 15:06
    Yeah, free Geocities accounts are limited. Most of the Geocities traffic limit warnings come from viewing the photos. I'm in the process of putting up a better mirror server for the site but progress is slow due to other priorities. The mirror server I've got running now is usually up daily from 4:00 pm to 10:00 pm PST.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don Buczynski

    http://www.geocities.com/donbuczynski
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2004-11-19 15:52
    Yep, I was checking the photos mostly...So Yahoo (Who owns Geocities) can give you 100MB of e-mail storage (Who needs that?), but they limit your Website bandwidth severely while still delivering the ADS!· Even when I could see your pages, I got lots of advertising...One of the reasons I was glad Parallax moved off Yahoo Groups.

    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
    ·
  • BillHBillH Posts: 14
    edited 2004-11-23 01:22
    I did get a chance to visit Don's web-site Friday night while in Houston visiting my son. Very impressive site and railroad. The programming is way over my head though, at this point. Bought Scott Edwards book and plan to work my way through it and then revisit Don's work. One basic question. All of Parallax specs for the stamps call for a power supply input of 5-15 volts DC. But when I ordered the stamp they told me 13.5 volts from the regulated power supplies that I am using was too high. Not sure I understand why.
  • allanlane5allanlane5 Posts: 3,815
    edited 2004-11-23 01:35
    The 'Vin' pin will work with voltages from 6 volts to 15 volts. The +5 volt pin of the BS2 can *only* take +5. So, you can put your 13.5 volts DC (it *must* be DC) into the Vin pin. However, you only get about 100 mA of regulation that way. If you want to drive anything else with +5 volts DC, you'll need to install a TO220 7805 regulator and a couple of capacitors. That will get you 1000 mA.
  • BillHBillH Posts: 14
    edited 2004-11-23 18:54
    OK, I think I understand. The man I talked to when I ordered the stamp said that input voltages above about 9 volts would shorten the life of one of the stamps components and that they really like to see inputs a little lower that what I am using. I will be using a ULN2803 to energize some relays that draw 75 ma so sounds like I would be OK with 9 V or 13.5 V input to the VIN pin.
  • allanlane5allanlane5 Posts: 3,815
    edited 2004-11-23 19:06
    Umm, 75 mA huh?

    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.
  • BillHBillH Posts: 14
    edited 2004-11-24 21:36
    The two power supplies that I have are Radio Shack table models rated at 13.5 volts and 2.5 amps. They pretty much power everything on the railroad except for track power. I may just buy a regulated 9 v supply just for the stamp. Waiting on a Jameco catalog to come in to decide which to buy.
  • allanlane5allanlane5 Posts: 3,815
    edited 2004-11-24 22:25
    All you really need is an 'unregulated' 9-volt DC supply (at like 100 mA to 300 mA) to power the BS2. The on-module regulator will add the 'regulation', you don't need the extra cost of a 'regulated' supply.
  • BillHBillH Posts: 14
    edited 2004-11-25 02:16
    Thanks. You have probably saved me a few bucks. I am going to start wiring the circuits next week and will have a bunch of new questions I'm sure. Hope you don't get tired of all these very basic questions. All very new to me.
  • tmatma Posts: 27
    edited 2004-11-27 22:05
    At the risk of being expelled from the forum I suggest that a simpler approach would solve your problem.

    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.
  • SPENCESPENCE Posts: 204
    edited 2004-11-27 22:44
    but think of the power you save if you use batterys even part time for power.

    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
  • BillHBillH Posts: 14
    edited 2004-11-30 02:01
    TMA, I'm not familiar with the R/C holding circuit and I have already built the latching relay system. Had it for several years and it works great, but manually. I also have a commercially built detection system which provides a ground when a train covers the photo resister. I was looking for a device to tie the two systems together and I think the stamp will do the trick. Spence, I don't use battery power anywhere on the layout but was glad to receive the info on the latching relays from Hosfelt Electronics for future projects. Got to go back to the soldering iron. Somehow today, while checking current flow with my VOM, I burned out one of the output transisters on one of the detector circuit boards. I'm learning, but slowly. Got in the game very late.
  • BillHBillH Posts: 14
    edited 2004-12-07 01:04
    I'm confused about a very basic question.· I have a Jameco Model DC906F52 "wall wart" power supply rated at 9V DC @ 600 ma.· Is this suitable for a BS2 mounted on a super carrier board?· Its unloded output is about 13.5 vDC.· It would seem that the load placed on it by the stamp would not be enough to draw it down to its rated 9 v.· And 9 v seems to be what everyone recommends as a max input to the stamp even though the board has input "6-30 vDC" printed near the barrel plug receptacle.· Am I just worrying too much?

    Bill H
  • NewzedNewzed Posts: 2,503
    edited 2004-12-07 01:12
    I think you are worrying too much.· The 9volt should be fine.· When you get it hooked up to the Stamp and Stamp is running, measure Vin and see what you get.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    4 digit serial LED

    http://hometown.aol.com/newzed/index.html
    ·
  • allanlane5allanlane5 Posts: 3,815
    edited 2004-12-07 15:02
    Yes, you are worrying too much. This would only be an issue if you were trying to drive Servo's with 'Vin' (the un-regulated voltage directly from the wall-wart). In that case you could STILL use this wall wart, but you'd need to add a 7805 to drive the servo's.

    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.
  • BillHBillH Posts: 14
    edited 2004-12-08 21:27
    Thanks, allanlanes5 and Sid Weaver.· I·was starting to solder all of this in place and wanted to make sure first.· I will quit worrying about this and go back to soldering and studying how to program my system. I am working my way through "What's a Microcontroller?"· and "Programming and Customizing the Basic Stamp Computer". I was really baffled when I started this project but am starting to feel a little bit less confused.· Both these books are great for the beginner.

    BillH
  • BillHBillH Posts: 14
    edited 2004-12-14 01:57
    I have yet to get one of my relays to be energized by the stamp via the ULN2803. I unhooked the carrier board from the railroad and have breadboarded a new spare relay with the stamp hooked up to my computer. I can't even get this breadboarded relay to energize. Gave up and tried an LED and it won't light up either. The ULN2803 is hooked up to 12 vDC and the polarity is correct to the two bottom pins. I must be missing something. Do they go bad easily? Is there a way to check to see if it is bad? The relays are Radio Shack 4PDT rated 12 vDC @75ma. The relay works fine when hooked up direct to 12 vDC. I removed the ULN2803 from its socket and the output pin then lighted an LED so I know the stamp is working. I could sure use some ideas.
  • Don BuczynskiDon Buczynski Posts: 31
    edited 2004-12-15 05:43
    Disconnect the Basic·Stamp and try manually energizing a··ULN2803 output pin by connecting its corresponding input pin to 12 volts through a 1K resistor.·If the relay does not energize, there·is likely a wiring error in the relay circuit or ULN2803 ground connection. Otherwise,·the ULN2803 is bad.

    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
  • NewzedNewzed Posts: 2,503
    edited 2004-12-15 13:36
    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).

    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
    ·
  • Don BuczynskiDon Buczynski Posts: 31
    edited 2004-12-15 15:32
    Correction:· Pin 10 connects to the negative side of the relay.· The positive side of the relay goes to the relay supply voltage.

    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
    512 x 384 - 16K
    512 x 384 - 10K
  • NewzedNewzed Posts: 2,503
    edited 2004-12-15 15:56
    The my post above is incorrect.· What I was trying to say is that the output pin of the 2803 goes to the negative side of your relay and the positive side of your relay goes to 12 volts.· Sorry about that - wasn't paying attention to the pin numbers.· Pin 10 goes to plus 12 volts.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    4 digit serial LED

    http://hometown.aol.com/newzed/index.html
    ·
  • BillHBillH Posts: 14
    edited 2004-12-16 02:11
    Don and Sid; you both solved that problem. It was the lack of a common ground between the stamp power and the relay power. I decided to breadboard the setup because I was hooking and unhooking the stamp carrier from the railroad, which is in an outbuilding, and bringing it to the computer in the house. Back and forth all day was getting tedius! Now I can energize a relay from the stamp while sitting at the computer. A major breakthrough! But I can't get them to sequence. I am trying to use IF - THEN. I have three relays set up as a prototype. I have three simulated photo-resistors (which would detect a moving train). I want the first detector to activate the first relay. Then the second detector should activate the second relay and deactivate the first relay. The third detector should activate the third relay and deactivate the second relay and then loop back and wait for the first detector to be activated again by a later train. I have been working with the following simple program most of the day and nothing seems to work:
    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
  • NewzedNewzed Posts: 2,503
    edited 2004-12-16 13:39
    Bill, one of the problems in using photo resistors to detect a train passing over it, is that to be precise, you have to use the PR as the bottom half of a voltage divider, then use an ADC to measure the voltage at the junction of the PR and the resistor.· When the train passes over the PR, the resistance goes up and so does the voltage at the junction.· You can now say if ADx is >Y then HIGH 9, or something like that.· Do you follow?
    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
    ·
  • NewzedNewzed Posts: 2,503
    edited 2004-12-16 13:56
    Bill, if you have ExpressPCB, I have a layout for the board I used in my stem that I can send you.· The board controls 4 track relays, plus one more relay for reversing the voltage to two of the tracks, and it controls four sets of track switches, eight in all.· The board requires 14 inputs from the Stamp BOE which were provided with two 595 shift registers.· The board also requires 12VDC input for the relays, although you could use 5
    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
    ·
  • Don BuczynskiDon Buczynski Posts: 31
    edited 2004-12-16 16:02
    How about some logic like the following. The CASE statement could also be used. Sorry, the forum software does not seem to let me indent parts of the code to make it easier to read.

    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
Sign In or Register to comment.