Shop OBEX P1 Docs P2 Docs Learn Events
Basic Stamp Train Control — Parallax Forums

Basic Stamp Train Control

G McMurryG McMurry Posts: 134
edited 2017-10-06 14:56 in BASIC Stamp
This post references my previous post for implementing a cruise control on my 1/8 scale model train.



If you plow around my Youtube uploads, you can see several videos I have made about my train. I don't spend much time organizing them so sorry, you'll just have to browse.

The basic idea for the project was to operate a 1/8th scale train using all computer control. I started the project using the BS2 but soon wished I had gone with something more powerful. The result is that I have spent a good deal of time optimizing things so my CPU has the time to do everything I want. That's probably and ultimately a good thing.

The drive system for the train uses a 16hp gas motor that turns a 10kw alternator. Alternators are interesting because they generate no AC at low RPM. Therefore, I automatically have a transmission. Idle the engine and I sit still. Increase the RPM (throttle) and at about 30 volts AC I start getting some power. From then on, I just rev up the engine and I get more AC Volts and Power.

I take this voltage and feed it into a large bridge rectifier and I get DC that operates two surplus treadmill motors.

By selecting a good gear ratio, I have a pretty nice running motor control.

My alternator has two 120 volt outputs. I actually have two locomotives (A Unit and B Unit) so I can hook them together for more pulling power. Half the alternator feeds one, half the other.

Most of the time, I just run one Locomotive.

The first time I ran the engine, I used two hobby servos and a regular model airplane controller to run the train. One servo hooked to the throttle and one to the choke. After I ironed out the mechanics, etc. I started on my Stamp Control Portion.

My train also has classic Westinghouse Air Brakes. This is a long complicated topic but basically, you charge up a tank with air. The air pressure from the tank turns on the brakes. You turn OFF the brakes by maintaining the airpressure to the system. When you start lowering the air pressure, the differential between air in the tank and the control pressure, gives you a proportional control to the brakes themselves.

Pressure up, brakes off. Pressure down, brakes on. That way if the airline opens or cars separate, brakes automatically go on.

STAMP CONTROL

There is a control panel that has a bunch of switches and two pots. There is a pot for the throttle and one for the brakes. I use a single Stamp to sample these and create a SEROUT string that is a 7 byte protocol that I came up with. There are a couple of control bytes that give me 16 discrete bits for things like "ignition on", "horn", "lights on", etc. I have the only model train, for example, that has brake lights like an automobile.

SerString(0) = 255 'Start
SerString(1) = Throttle 'Direct Throttle Value
SerString(2) = 255 'Reserved for Speedo
SerString(3) = Brake 'Direct Brake Value
SerString(4) = ButLo 'Low Button Byte / Control1
SerString(5) = ButHi 'High Button Byte / Control2
SerString(6) = INA 'NemoAddr now available for anything


I am running 38.4k N,8,0 for all my serial commands. I am also using a variety of Stamp modules. BS2 for the simple things and BS2SX on some of the others.

There is a board with an SX on the engine that uses SERIN to receive the serial commands and convert them to useful things on the train. I am using the ServoPal to talk to the two hobby servos for Throttle and Choke. The rest of the stuff is using the 74C595 output shift registers that I learned to use on my first Stamp project in Stampworks almost 15 years ago.

I have 16 relay channels that I use for various things including headlights, starter, etc.

The control function just goes as fast as it can, timing is basically how long does the SERIN and SEROUT takes. I have a couple of LEDs on both the REMOTE and CONTROL boards that I TOGGLE during the cycle.

The Air Brakes operate with the PWM command into a little RC to create a DAC. I found a voltage controlled air regulator that takes 0-5 volts in and adjusts my brake air pressure from 0-100 PSI On board the Locomotive is a small air compressor used for Air Shocks.

MONITORING.

The most fun is reading out all sorts of data from the Locomotive.

There is a separate Basic Stamp on the Loco that has two ADC0838 ADCs so I can sample 16 Analog Voltages. I also have a few digital inputs.

I use COUNT to sample a pulse from the wheels to give me MPH and another COUNT input to show me engine RPM. Most all the other inputs are analog.

All this data is sent back to my system over SEROUT with 20 bytes of data.

20 BYTES OF SEND DATA. (New Nemo2)
' NemoString(00) START Always 255 as a Start Word
' NemoString(01) Throttle
' NemoString(02) Speedo Choke (as a Byte is changed to Speedo here)
' NemoString(03) Brake This is the digital command.
' NemoString(04) Control1 Controls 8 functions using 8 Bits
' NemoString(05) Control2 Controls 8 functions Unchanged from SerIn
' Nemostring(06) RPM X100
' NemoString(07) AAmps
' NemoString(08) AVolts
' NemoString(09) BAmps
' NemoString(10) BVolts
' NemoString(11) BattA
' NemoString(12) BattV
' NemoString(13) Oil PSI
' NemoString(14) Ent Temp
' NemoString(15) Air PSI
' NemoString(16) Brake PSI
' NemoString(17) Fuel
' NemoString(18) AirT
' NemoString(19) Gregs

Now, what do I do with all this stuff.

I have three types of display systems.
16X2 LCD
8 7 segment digits (2 rows of 4)
A Backpack video display (unfortunately Parallax stopped making these)

Through a variety of ways, I use Basic Stamp modules and the SERIN command to "listen" to the above 20 bytes and display whatever I want to see.

Mostly, on the Control Panel I drive with, I see MPH and the Brake Command. I use the nice LED 7-Segment displays here. I have a Thumbwheel switch that I can set so I can select other data that I want to see.

It has been interesting to sample other information from the engine. The most difficult to measure turned out to be the high voltage I am sending to the Traction Motors. I either have to measure 0 - 130 VAC or 0-160 VDC. None of these are nice to feed to my little basic stamp boards. They need to be isolated.

Right now, I am using a tiny step down transformer to convert the 0-130 VAC to 0- 6 VAC where I feed a little rectifier and then a voltage divider so I can scale the result to 0-5 VDC. Seems to work, though it is not perfectly linear. Its good enough. If anyone has a good suggestion for this, I would be interested.

There is a Youtube that shows the video display. If you can stand me droning on about my control system, take a look. The BACKPACK video display is shown at the end.



Well, thats enough of this. I told you it was boring.

I am happy to answer questions and share the code, even though I am sure it is poorly written. There is a lot of it since there are so many different modules, each requiring their own pBasic.

Thanks for Reading.

Greg

Comments

  • Greg, very nice project! That is a labor of love and what fun! If you ever get bored you can switch over to a Propeller and use just one uC.

    A phototransistor/led pair would give you an isolated output from your HV. Look up optoisolator.

  • I really like the node-based approach. If you ever do "upgrade" to the Propeller, you might consider an RS-485 network with address switches on your nodes.
  • So far, I have been doing OK with RS-232 using the MAX232 receiver/driver device. I don't think I need to address anything particularly, but I often think I would be better off using differential drivers / receivers My train keeps getting longer and longer. Noise on the data line will soon become a problem.

    Right now I have 2 Locomotives, an Engineers Riding car, a passenger riding car, a Boxcar and a Gondola. The serial data is available on all of them.

    Soon I will do a little video tour of the actual train.

    Greg
  • That is awesome, looking forward to the Train tour.

    Your "Brake Light" is legit,
    Any rolling stock at the back of any modern train gets an EOT (End Of Train) device.

    Keep up the good fun, and thanks for sharing.

    -Tommy
  • All the data is there for an EOT device... Its on my list.

    I just need to design something that can clamp on to the coupler and has a little space for a STAMP to decode its duties.

    Thanks for looking!

  • Neat! I am a train enthusiast as well and am looking to start an HO model layout in the future. I wanted to make a BS2 encoder for my locos but didn't think I would have room. I may be able to put the control system in the car behind the loco and connect the motors/lights/etc. externally.
Sign In or Register to comment.