Pelsea

The electrical switches you see most often on model railroads are toggles. It's no wonder, they do the job, they are easy to understand and connect, and they give a visual indication of layout status. However, some functions can be performed better with push button switches, particularly if you wish to control a function from two locations. The downside of pushbuttons is they can seldom do the job alone. They usually require an indicator light, and remote operation implies some sort of circuit that is being operated.

Now many are already reaching for their Arduino kits and have the IDE booted up by this paragraph. I am a great fan of Arduino and similar micro boards, and often use them for complex projects. However- that is serious overkill. A simple CMOS based button circuit can be built for $0.98 in parts (not counting the parts an Arduino would need also), and although an Arduino can handle many buttons, you will probably run out of pins right about the cost break even point. (Most of these circuits will handle two independent functions.)

The circuits presented here will mostly be based on one or two CMOS logic chips. CMOS logic is the Lego of electronics design. It consists of a set of basic function integrated circuits that can be connected together to build systems of unlimited complexity. I'm talking about everything from wristwatches to supercomputers. The typical use of CMOS is to design and prototype things with individual logic chips, then transfer the design to large scale integrated circuits-- the processor at the heart of the Arduino is an example. CMOS has a reputation for being finicky, but that is not really true-- there are just a few things you could get away with in other logic families that won't work with CMOS.

PB01a.jpg 

One thing you do need to think about is CMOS is a bit more sensitive to electrostatic discharge (ESD) than some other chips. If a pin is allowed to accumulate a high voltage static charge, a sudden discharge can damage the device. So if you live in a dry area, or have the sort of carpets and furnishings that give you occasional zaps when you touch stuff, you should take steps to protect the CMOS chips as you work. This is not complicated-- you can spray the floor and furniture in your work area with an anti-static spray (fabric softener), and you can work on an ESD safe work surface. An ESD safe work surface is slightly conductive-- enough so that if a charged item touches it, the charge will harmlessly dissipate. Of course some part of the ESD safe surface needs to be connected to earth, probably by way of the screw on a nearby outlet. You can buy ESD safe workbenches for multi$$, or just get a pad for $20. More elaborate schemes such as personal grounding straps can be put off until there is an obvious need. Another consideration is to keep the CMOS chips in the plastic carriers they arrived in until needed.

At the moment, I'm planning on showing two basic circuits-- a two button on and off setup and a single button toggle circuit. Then I will cover getting momentary pulses to drive something like an Atlas turnout, and a reversing drive for tortoises. If you have other things you want to connect, add a note.

pqe

 

Reply 0
Greg Williams GregW66

Watching with interest.

Would these be usable in the servo control circuit posted a few weeks ago instead of a toggle or slide switch?

Greg Williams
Superintendent - Eastern Canada Division - NMRA
Reply 0
Pelsea

Two button solution

I'll start with a circuit that has two buttons- one for on, and another for off. I prefer this to a single button toggle in most cases, because it is always obvious what to do. The heart of the circuit is a thing called a D-type flip-flop:

D%20FlipFlop 

A flip-flop is a memory. It is very limited, as it only remembers if it is on or off. (And only so long as the power is kept on.) In logic parlance, the on state (+V) is considered a 1 and the off state (ground) is considered a 0. Seems simple, but take a few billion of them and you have a computer. The D type flip-flop is the most basic. It has three main inputs: data, set and reset. There are two outputs on the version we'll use here. Q is 1 after a set and 0 after a reset. Not-Q (written as Q with a line over it) is the inversion of this logic- i.e. 0 and 1. The flip-flop also has a clock input- when this changes from low to high, the state of the data input is copied to Q. This clocking scheme allows vast armies of data to march through the system without losing a single bit.

Here's how I intend to put the flip-flop to use:

PBRS.png 

If the wiggly lines are unfamiliar to you, please look at my building simple circuits thread. Notice I have rearranged the inputs-- doing this helps make the schematic clear. When you look at the actual chip, you will have to figure out what is connected to which pin.

The operation of this is right out of the datasheet. Note that the push buttons are momentary contact type- this is the cheapest style, and the easiest to work with. (These are also known as N.O. or normally open.) The set action happens when the set pin is brought high. (Check datasheets when designing your own-- many chips have functions that depend on bringing an input low.) Closing the switch will connect the set pin to the +V line and turn Q on. When the switch is open, the 1k resistor pulls the input low. Incidentally, although the schematic says +5 volts, it will work on any voltage from 5 to 15, so this can be run from well regulated +12DC accessory power. The reset switch works exactly the same way, bringing Q to 0.

I'm not doing much with the output yet, just lighting an LED. This circuit will look familiar to many, as Arduino projects are littered with them. The NPN transistor will be turned on when the voltage at the base is raised above 0. Practically no current is required, so a 100k resistor can be used for the connection. (The main disadvantage of CMOS is it can't handle much current, so arrangements like this are mandatory to connect to anything but another CMOS chip.) The resistor is chosen to limit current through the LED as we have done in countless decoder installs.

What's with the junk on the (otherwise unused) clock input? Well one fault with this design is that the state of Q is random when the chip is turned on. That means your turnouts (for instance) would all be higgly-piggly at the start of a session. With the arrangement shown, the capacitor (it should be 1µf or bigger) will charge relatively slowly, and clock data to Q just once when the voltage gets high enough. The data pin is grounded, so this will  turn Q off. If you want Q on at the start, just connect data to +V.

Now we'll build one.

pqe

 

Reply 0
Pelsea

Can this be used with last weeks servo control?

Why yes it can, what a coincidence.

pqe

Reply 0
Pelsea

Building the two button circuit

This was a very quick build-- it ought to be considering it has a dozen parts, including the prototype board. I put it on vero board, so part of the process is breaking tracks on the back. The starting point is always the integrated circuit, in this case a CD4013 dual D-type flip-flop:

13pinout.png 

First of all, note that there are two completely independent circuits in this package. Not bad for 35 cents. Most members of the CMOS logic family come with four, six, or even eight devices in a package. In this case, each device has connections on one side-- not all ICs are so conveniently set up. The terms DIP, SOIC and SOP refer to mounting style for the packages. I like dual inline (DIP) which has pins that go through the board. The other two are surface mount, and rather difficult to work with. The right side of this diagram is the truth table, which describes the logic of the thing. It includes the result at Q and not Q for every possible input combination. The layout should be obvious from a picture of the completed board:

PB01b.jpg 

The two wires that run off the top are the power connections. The top track on the board is used as a ground buss, and the second as a +V. There is a 0.1 µf capacitor between the busses-- this helps manage noise on the power lines, both noise coming in and noise generated by this circuit going out. (Digital circuits are horrendous noise generators. just put your iPhone next to an AM radio to see how bad they can be.)  Everything else is wired to the IC. Here is a pin by pin connection rundown:

  1. (Upper left, by the notch) Q. Connected to the base of the transistor via a 100k resistor (set on end to save space). The emitter of the transistor is connected to ground and the collector is connected to the LED via a 1k resistor. The LED lead to connect is identified by a slight flat spot on the plastic rim. The other lead of the LED is connected to +V.
  2. Not Q. Unconnected at this time.
  3. Clock. Connected to a 10k resistor to +V and a 1µF capacitor to ground.
  4. Reset. Connected to the Off pushbutton and a 1k resistor to ground. I have used headers for the button connections so they can be mounted at a distance from the board. The top two pins on the header are On and the bottom two are Off. The free pins on the buttons are connected to +V.
  5. Data. Connected to ground.
  6. Set. Connected to the On pushbutton and a 1k resistor to ground.
  7. Ground. In the CMOS world, ground is called Vss for obscure reasons.

8-13 are not used-- I could use this board for two circuits by using headers for the LED connections and filling the right side with more or less what you see on the left.

Pin 14 is connected to +V. Also known as Vdd.

I basically treated the back as if this were a breadboard layout, just separating the the chip leads and the ends of the LED resistor. Here's the back:

PB01c.jpg 

It is flipped left to right.

A simple circuit, simple to build. Here it is in action:

 

I made a simple button board with the cheapest buttons I can find to test this, but this will work with most any push button. The only ones it won't work with are toggle push buttons or normally closed buttons. You can use as many buttons as you like in parallel for On or Off. There may be a practical limit to the length of wire, but it is probably quite long.

The LED is either on or off, but if you want a different color to light in the off state, simply connect it (with the associated transistor and resistor, of course) to not Q.

The working output of this will be Q. It can directly control the second version servo circuit presented here, or it can be boosted in various ways to control very large loads. I will discuss that in further posts.

Any questions? Anyone?

pqe

Reply 0
Pelsea

Toggle action

Sometimes we only need one button of the push-on, push-off style. This can be bought as a piece of hardware called a latching push button switch. Generally they are a bit more expensive than the momentary style, but the main problem is they cannot be remote controlled. Like the previous version, this circuit can be operated from as many buttons as you care to connect.

The heart of the circuit is again a D style flip-flop. The creative bit is the not Q* output is connected back to the data input. When the flip-flop is clocked, the not Q data is passed to Q, leading to an alternation of on, off, on, off. Otherwise the circuit is roughly the same:

[*Q is the output. Not Q is the inversion of Q, written with a bar over it or in code as !Q.]

Btoggle1.png 

Note that the functions have been rearranged from the two button version. The clock input is on the left and the set and reset are on the bottom. The clock input looks a little complex, and here's why:

There is a major problem with pushbutton switches called "bounce" (well, it's a problem with any switch, but seems more intrusive with pushbuttons.) The switch doesn't close cleanly-- there's a moment just as contact is being made when the current sputters. Here's an oscillograph from Wikipedia:

y_Switch.png 

This is a pretty bad switch, showing nearly three ms of garbage before it settles down. (Kind of like dirty track, really.) All of these spikes look like clock pulses to the flip-flop, so it will flip a dozen or so times. To the operator,  the switch doesn't work half of the time, because the output can come up heads or tails. The Arduino folks deal with this in software, basically looking at the input several ms after the first change is detected. Our job is to smooth out these ripples so they won't look like extra triggers. The 100nf capacitor connected to the clock input does this-- it charges instantly through the diode, but if there is a break in the switch current any discharge will be through the resistor, and the switch will have probably reconnected before there's much change.

There is often another burst of garbage when the switch is released, but the capacitor smoothes that over too. Incidentally, the amount of bounce in a switch is related to its price, but none are perfect, so the circuit is always necessary. If you get a cheap switch, a passive circuit like this may not work. In fact, once in a while you will probably get enough bounce to have to push the button again no matter what switch you use. Absolutely ironclad debouncing requires an active circuit, and I will return to the problem in a later post.

As before, we want the circuit to be in a known state when the power goes on. This is managed by connecting a capacitor from the reset pin to +V. That will be pulled high as the cap starts charging through the 100k resistor , but as the charge grows, the voltage goes to ground. (This part of the circuit may make more sense if you stand on your head.) If you prefer the device to power up in the on state, connect the cap and resistor to the set pin.

Here's the built circuit board:

PB02a.jpg 

I've left some space on the right side for the next lesson. The LED driver at the top is just like the previous circuit. The transistor connections are (from top)

  • Collector to LED via 1k resistor. The LED lead that connects to the resistor is identified by a flat spot on the side ridge. The other lead goes to +V.
  • Base to pin 1 (Q) of the IC via a 100k resistor turned on end.
  • Emitter to ground.

And the IC connections:

  1. Q. Via 100k resistor to transistor.
  2. Not Q. Connected to pin 5 with a yellow wire.
  3. Clock. White wire leads to debounce circuit.
  4. Reset. 100 nF (0.1F) capacitor to +V (trace is broken beneath cap), 100k resistor to ground at pin 7.
  5. Data. Connected to pin 2.
  6. Set. Connected to ground (Jumper to 7 barely visible under white wire.)
  7. Ground.

The second device is not used at this time. Pin 14 is +V, which can be anywhere from 5 to 15 volts.

The button will be connected to a header. This has a +V connection and leads to the debounce circuit. Look closely at the traces showing through the board. Three items connect to the button pin of the header: 

  • Diode to the white wire (trace just below the IC).
  • 10k resistor to the white wire.
  • 1k resistor to ground.

The capacitor is connected from the white wire to ground.

As per usual, black wires are ground and red ones are +V.

Here's the back:

PB02b.jpg 

And action!

Next step will be butting these toys to work. It may be a couple of days.

pqe

 

 

Reply 0
Kevin Rowbotham

Debouncing Demystified!

Watching and learning!

Regards,

~Kevin

Appreciating Modeling In All Scales but majoring in HO!

Not everybody likes me, luckily not everybody matters.

Reply 0
Pelsea

One push

The final button action I will look at turns a device on for a set time. This requires a monostable circuit, a term electronics fans might recognize from the good ol' 555. In fact, a 555 can be used for this function. However, I am going to use a somewhat newer chip, a CMOS CD4538. Let's see what is inside the chip:

538Block.png 

This block diagram is taken from the datasheet. The box represents most of the circuit, pretty much the same thing that is in a 555. Namely, threshold detectors and switches to take the capacitor Cx through a discharge/recharge cycle. The whole thing is arraigned so a low at A (which I would have labeled trigger) will initiate the cycle. CD is a clear that will interrupt the cycle if desired, bringing Q low immediately. The timing pins 1 and 2 are brought out of the package where you supply your own R and C. The time formula is simpler than the 555, just RC-- one farad times one ohm gives a one second cycle. (But remember, capacitors come in microfarads, so we usually need a lot of ohms to get noticeable times.) R must be at least 5k, so the practical range ot times is 5 milliseconds to all day.

The structure attached to the A (or trigger) point is interesting. That shield shape represents a logical OR gate. The essence of OR is that if any input is high, the output goes high. There's a whole course in ee that covers logic gates and theory. Four simple gates (OR, AND, NOT and XOR) are the basis of all of the data manipulation we do on our computers. In this case, the OR gate gives the 4538 two inputs. Note the little circle on pin 5. That indicates a logical inversion. So a low on pin 5 is equivalent to the second OR input going high. As a result the two inputs work differently-- pin 4 will trigger the circuit if it is brought high (and 5 is high) and pin 5 will trigger the output when it is brought low (and pin 4 is low.) This gives us a choice in how we hook up buttons.

The previous two circuits were triggered by bringing the input high, but the opposite action is more common in the electronics world. Most buttons and such activate when brought low.This simplifies wiring in most cases- a positive activation requires running +V lines to every button, whereas ground is often readily available.  Think of a car, where the chassis is ground, and your window activators, door latches and whatnot only have to connect a sense wire to the frame to work. I'm going toi use the active low trigger on this circuit, to show how it is done.

Here's the circuit:

nostable.png 

Parts of this are really looking familiar, aren't they? That's the nice thing about electronics-- most problems only need to be solved once. The circuit connected to Q is right out of our playbook, as is the circuit attached to Clear (pin 3)- that prevents the circuit from firing when the power is turned on. Pin 2 handles timing with a capacitor to ground and a resistor to +V. To use negative activation, pin 4 is grounded, and pin 5 goes to a button. Normally pin 5 is held high by a 10k resistor, but the button shorts this to ground and fires the circuit.

You could plug a 555 into this circuit and get much the same action, but there is one big difference: If you hold the button on a 555 circuit down longer than the on time, the 555 will cycle again. If you press the button a second time during the cycle, nothing at all will happen. The 4538 is triggered by the transition from high to low (or vice versa). You can hold the button as long as you like with no effect, and if you hit it twice, the time will be extended from the second hit.

In the other circuits I mentioned the debounce problem, but you will notice I didn't do anything special about that here. That's because an edge triggered monostable is inherently debounced. In fact, the best way to debounce any other circuit is to use one of these first.

Here's a board:

PB03aa.jpg 

As usual, the red wires are +V and the black ones are ground. The supply wires run off the top, and the +V and ground buss are bridged with a 100nf capacitor.  Looking at the chip first, here is a pin by pin connection list.

  1. (Upper left, by the notch) T1, connected to ground.
  2. T2. 47 µf cap connected to ground (note stripe marking negative polarity), and 100k resistor connected to +V. Change these to produce the on duration you desire.  T = RC
  3. Clear. 100k resistor to +V and 100nf cap to ground at pin 4. (It looks smaller than other 100 nF caps I've used- it is. I found a few 25v caps at the bottom of my supply drawer. Most of mine are 1000v cheapies I got in a grab bag.)
  4. Trigger A. Connected to ground.
  5. Trigger B. Connected by the white wire to the button and a 10k pull up resistor.
  6. Q. Connected to the base of the transistor by a 100k resistor.
  7. Not Q. Unconnected at this time.
  8. Ground. (There are 16 pins on this IC.)

9-15 are not connected, although it is a good idea to prevent accidental firing of the unused side by tying 15 and 12 to ground and 11 and 13 to +V.

Pin 16 is the power supply. I've forgotten this one on the last three builds. (Head slap)

Note that the transistor is turned from the position it has been in the other boards. The pins are (top to bottom)

  • Emitter to ground. 
  • Base to pin 6 via 100k resistor.
  • Collector to 1k resistor (brn black red). The other end of the resistor is connected to the LED (lead marked by flat) which is also connected to +V.

The button will connect to the header. One pin is grounded, the other is connected to the white wire and a 10k resistor to +V. You can connect as many buttons as you like between the pins.

Not much was done on the back except isolating the IC leads:

PB03b.jpg 

I am getting better at cutting tracks. I use a file to separate the ends-- this lets me test the board in a metal board holder. The other traces are cut with a lightweight grinder using a Dremel engraving bit.

And-- cue video:

 

What would you like to operate with buttons?

pqe

Reply 0
Pelsea

Turnout control

Probably the most common pushbutton job is turnout control. And probably the most difficult kind of switch machine to control is the Atlas snap-switch, since it will melt if current is not properly managed. (Do you know any other device that carries a warning about pressing the button for too long?). Safe operation of these puppies requires a pulse of 3 amps for no longer than half a second. That is exactly what the 4538 monostable circuit is designed to provide. Well, not 3 amps, but that is available with a little help. The help comes in the form of a TIP125 Darlington transistor:

TIP125.jpeg 

It's usually called a transistor, but it's really an integrated circuit, with two  transistors, a couple of resistors and a diode. The Darlington configuration is the the most popular output structure for transistor amplifiers. It combines an input transistor that provides sensitivity to small currents with a beefy brother to manage the watts we need for serious work. Darlingtons come in both PNP and NPN flavors. Audio amps use one of each, but for DC current switching, one will do. The choice depends on whether we want to switch on the +V side (PNP) or on the ground side (NPN) of the load. In case you are curious about the arrows in the circuit shown above, they indicate the flow of traditional (from + to -) current. The arrow is always the emitter of a transistor, and if it points in (PNP) the emitter is connected to +, whereas the outward arrow (NPN) connects to ground or negative. The arrow on the diode symbol is blocked, indicating current won't flow that way.

Here is the monostable circuit with a TIP125 helper:

nout1(1).png 

This is obviously two monostable circuits, one for each coil. Note that the TIP125 is connected to not Q. This pin is normally at +V and a PNP Darlington switches on when the base voltage is brought low during the cycle. These values for C and R will give a duration of 0.1 second, which is just enough to operate the turnout. Both circuits are the same, except on the normal side I have left out the capacitor on the clear pin that prevents any cycle on power-up. In fact, it would be nice if we got a cycle on power-up, because then the turnouts would start at a known state. (I'll discuss this more in the next post.) The coils are on the turnout of course. Normally when you control a coil (or motor) with a transistor, you need a reversed biased diode across the transistor to short out any back EMF the coil produces when it shuts off. In this case, There is already a diode in the TIP125.

The build:

PB04a.jpg 

Well, I've already built one of these-- I just needed to duplicate the circuit on the other side of the chip. The green things are 0.1 µf mylar capacitors. I used mylar here because the values are more accurate than the ceramic kind. The pin by pin rundown:

  1. T1. Ground.
  2. T2. 0.1 mF (100nf) capacitor to ground, 100k resistor to +V
  3. Clear. 100nf capacitor to ground (at pin 4) 100k resistor to +V.
  4. A input. Ground.
  5. B input. White wire to button. Also a 10k pull-up resistor to +V, at the button.
  6. Q. Not used.
  7. Not Q. 10k resistor (on end) to base (pin 1) of TIP125.
  8. Vss (chip ground). Ground.
  9. (lower right- the pins are counted clockwise) Not Q for device B. 10k to base of TIP125.
  10. Q. Unused.
  11. Input B for device B. White wire to other button. Also a 10k pull-up resistor to +V.
  12. A input. Ground.
  13. Clear. +V.
  14. T2. 0.1 mF (100nf) capacitor to ground, 100k resistor to +V.
  15. T1. Ground.
  16. +V for chip.

The TIP125s have three hefty pins, which don't show well. They can run warm, so you don't want them too close to other components. In fact, if you are really working them, you want to bolt them to something made of metal. Since the tab is also the collector (that's just the way this kind of package works) you would need to use a mica insulator and nylon hardware to mount it. Also a drop of special heat conducting sauce. Luckily, the Atlas turnout doesn't draw that much juice, so we can just leave the tab in the wind. The TIP pins are numbered from the top as you see it:

  1. Base. 10k resistor from not Q.
  2. Collector. Yellow wire to header for turnout.
  3. Emitter. +V. (Note red wire toward edge of board.)

The breaks in the tracks of the veloboard are pretty visible in this photo, so I won't bother with a shot of the back. The separation of the pins under the IC is extended down to separate the base and collectors of the TIPs. There are also breaks to separate  each button and the header, except for ground, which they share.

These videos are starting to get complicated:

You will see I made a little LED jig to test the output of the board. There are many possible mistakes that would send power to the turnout for longer than we should. Use of the LEDs during the debugging process can save the motor from damage. (In fact if you look closely at this turnout, you will see I forgot to use it once.)
 
I'm not finished with this yet-- in the next episode I'll add state indicators and a start-up circuit. Stay tuned.
pqe

 

Reply 0
Pelsea

The rest of the story...

I had thought I'd left space on the previous board to add another chip, but it turned out to be one column too narrow. So I wound up rebuilding the board. Ah well, this one is prettier.

The addition of indicator lights to the momentary action circuit is very easy-- all I needed was a D flip-flop with set and reset connected to the 4538 Q outputs. That is shown in the left half of this schematic:

ndicator.png 

When CMOS inputs and output are connected together there is no need for extra resistors.

The power on circuit is a little tricky. Since the B input is attached to the pushbutton, (and is normally high) we need to apply a falling trigger to A when the power comes on. So I used a trick we have already seen on the remaining flip-flop (remember, there are two per package). A capacitor to +V and a resistor to ground will cause the pin to be high at first, then fall to ground as the capacitor charges. (I left the values open for experiment, and finally settled on a 1µf capacitor and a 100k resistor.) But that's not the tricky part- I also connected the Q output to the reset input. It reminds me of Shannon's "most beautiful machine". That consists of a box with a switch on it-- when you turn the switch on, a hand comes out of the box and turns it off. On our flip-flop, once it is set, the high Q resets it immediately. That can also trigger one side of the 4538. This scope capture shows the sequence;

PB05d.jpg 

The yellow trace is the set input of the 4013 and the red trace is the Q output (and reset input). When both set and reset are high, Q is high. Once the set has fallen below "definitely high" reset can clear Q. Seems knind of hinky, but it works.

Here's the board with additions:

PB05b.jpg 

I've made the changes with thin wire so they will show clearly. Here's a pin by pin rundown of the 4013:

  1. Q of the indicator flip-flop. 100k resistor to a blue wire connected to the familiar transistor LED driver.
  2. Not Q. Likewise with an orange wire to the green LED.
  3. Clock. Not connected
  4. Reset. Orange wire from Q of the normal side of the 4538.
  5. Data. Not connected
  6. Set. Blue wire from Q of the diverging side of the 4538
  7. Chip ground.
  8. (lower right) Set of the power-up circuit. 100k resistor to ground and 1µf (tantalum) capacitor to +V.
  9. Data. Not connected.
  10. Reset. White wire to Q.
  11. Clock. Grounded (principally to provide a handy place to connect the 100 resistor).
  12. Not connected
  13. Q. White wires to reset and to trigger A of the 4538 "normal" side. This pin was grounded before, but I cut the trace.
  14. +V

Folks with sharp eyes will see I've added a (47nf) capacitor to ground to the B inputs on both sides of the 4538. This prevents some double triggers I was getting from the board mount buttons. Since the pulse is very short, the bounce on release of the button was firing the monostable again.

Here's a view of the back:

PB05c.jpg 

(The board is flipped left to right, so the new chip is on the left.) This shows a trick I have developed to help me keep my place on the back of the board. Some of the traces are used for ground and +V. I color them red and black, to give some obvious landmarks. I also color the cuts with a green pen-- I mark the cut as soon as it becomes obvious where they should be, but I don't cut them until everything is on the board. That way I don't have to repair cut traces when I change my mind.

And another video:

Next installment, Controlling a tortoise motor.

pqe

Reply 0
Pelsea

The final chapter.

Well that last circuit nearly jumped the shark, didn't it? It did not seem too complex as a schematic, but stuffed on a Veroboard it looks kind of intimidating. This is right at the edge where taking the project to Arduino makes sense. I can probably simplify the layout by building it on pinboard instead. I'll try it that way next time.

The final circuit goes back to the very first project: an RS controlled flip-flop with the ability to move a tortoise switch motor. That's probably my favorite circuit, because I use mostly Tortoises on my layout.

A Tortoise is undemanding as motors go- just pulling 20 ma at the worst of times. The bad news is it requires a reversal of current. This makes the output circuitry a bit more complex-- a PNP and NPN Darlington pair on each end (PNP to source current and NPN to sink). The schematic for this vaguely resembles the letter H, so it is called an H-driver. Luckily for us, the whole thing is available as an integrated circuit, so we only need connect inputs and outputs. The IC I'm using is an L293D:

93DBlock.png 

The driver sections are shown as simple triangles in this diagram. Each has an input (flat side of triangle), output (end of triangle), and an enable control. The package has four of them, but 1 and 2 and 3 and 4 share an enable each. You could use the enables to apply PWM to a motor, but normally we just tie them to +V. The logic of operation requires a high voltage applied to one amplifier and a low to the other. The motor will turn in the direction implied by the high input. (If both inputs are low, the motor will not turn.) We'll use the Q and not Q outputs  of a 4013 to supply the high and low.

This device has 2 Vcc inputs. The pin 16 power runs the internal logic-- this should match the CMOS or Arduino that is in control. The pin 8 connection provides the output power. This should have the muscle needed to move your motor. The two power sources need not be the same voltage, but logic shouldn't be above 7 volts. Since the tortoise will run from a 12 volt supply, we will need to generate a 5 volt logic power on the board.

Normally, when you run a motor (or any inductive load) you need some bypass diodes to protect the silicon from back EMF. (Whenever you cut off current to a coil, it gives some back, the wrong way). The L293D has these diodes built in. This is at the expense of a little less power, but there is still plenty available. If you get an L293 (no D, but possibly other letters) you will have to include the diodes yourself.

Here's the schematic for the entire circuit:

tortoise.png 

The RS circuit on the left side should be familiar by now. We only need half of the L293, but then again, we only need half of the 4013, so this board can easily control 2 tortoises. The L293D needs a bit of heat sink. This is provided by having 4 ground pins at the middle of the chip. Excess heat and ground current follow the same path away from the chip. (The L293 can manage half an amp. If you are pushing that much current around, connect the ground pins to big traces.) 

The 78L05 is a low power voltage regulator, used when the current requirement is less than 100mA. The capacitors connected to it smooth out any ripple on the power. The cap on the input should be .33 µf or so, and the output around 0.1µf.

8l05pins.png 

The LEDS shown in the schematic are hooked up in the traditional manner for tortoise indicators. Only one will conduct at a time, so they can share a resistor. (As always, adjust this resistor for the LEDs you have and the brightness you want.)

Here's the board:

PB06a.jpg 

The L293D is the upper chip. I think the connections are obvious enough that I'll skip the pin by pin description, but notice how the 70L05 is set up. Pin 3 (input) is the upper pin- that gets +12v from an aux power supply. Pin 1 (bottom) feeds +5v to the red buss lines on this board. The is another wire hidden on the back that runs from the input to pin 8 of the L293D;

PB06b.jpg 

And here's a video:

 
This is the final tutorial in this series. I hope you find these circuits useful, and watch for more simple circuits in the future.
 
pqe

 

Reply 0
Graeme Nitz OKGraeme

I have enjoyed this series...

...just like all yor posts they are very interesting.

One thing I would like to see which is an update of this circuit would be a circuit with only one PB, push the button and it changes state to the opposite. This would save on PBs and make panels simpler.

Good Work and great "lecturing" !

Graeme Nitz

An Aussie living in Owasso OK

K NO W Trains

K NO W Fun

 

There are 10 types of people in this world,

Those that understand Binary and those that Don't!

Reply 0
Pelsea

Thanks for the appreciation

This circuit can easily be made to toggle. Just copy the 4013 input connections from the second project (including connecting data to not Q). In fact, you could have three buttons connected at once-- set, reset, and change.

Thanks for following along.

pqe

Reply 0
Graeme Nitz OKGraeme

DOH!..

.. Of Couse! I should have one back to that.

Thanks

Graeme Nitz

An Aussie living in Owasso OK

K NO W Trains

K NO W Fun

 

There are 10 types of people in this world,

Those that understand Binary and those that Don't!

Reply 0
doc-in-ct

Would have made a great article

Thank you for taking time to post these, very useful.

This series would make a great article for the monthly ezine.

Alan T.

Alan T.
Co-Owner of the CT River Valley RR - a contemporary HO scale layout of Western & Northern CT, and Western Mass.  In the design stage; Waterbury CT.

Reply 0
Pelsea

You are welcome

I'm doing these to keep my writing chops up since retirement from teaching. I want to help keep analog awareness alive, but don't feel like connecting with the world of commercial publishing again.

Thanks for following along.

pqe

Reply 0
Kevin Rowbotham

Thanks Peter!

This is great, glad you are doing this here.  Thanks for sharing!

I don't blame you for not wishing to write the article.  I think these analog tutorial threads should be noted at press time so subscribers who are not forum regulars will be aware of the resource you have provided.

Thanks again.

Regards,

~Kevin

Appreciating Modeling In All Scales but majoring in HO!

Not everybody likes me, luckily not everybody matters.

Reply 0
Neil Erickson NeilEr

Drowning in parts

Pelsea:

This is all new to to me so have to figure out a way to organize all these components. Since my model space must be shared with kits, dcc and sound installation, switch building, sculpting and painting/weathering, it seems some small bins with labels would help me find led's, resistors, capacitors, buttons and switches, ic's, etc, etc, etc. 

Any sugestions?

Neil

Neil Erickson, Hawai’i 

My Blogs

Reply 0
Pelsea

Small bins...

Lots and lots of small bins....

bins14.jpg 

And some big ones too. The electronics are in the green tower and the upper part (not completely shown) on the second tower.

pqe

 

Reply 0
dnhouston

Nice Projects

Thanks for taking the time and sharing these circuits.

David Nation

Dusty Junction Railroad  http://www.djnrr.com

Reply 0
pschmidt700

Thanks, Pelsea

I think it would be great for all these topics you delve into to be archived somewhere for easy reference. This is good ol' basic digital electronics (well, sans the 555, which is analog) and you've made the application to easy model railroad projects attainable.
Reply 0
Neil Erickson NeilEr

@Paul

... And Pelsea. I have saved this thread as an icon on my iPhone / iPad to take me right to this thread. Good stuff is worth marking somehow. 

Thanks again. 

Neil

Neil Erickson, Hawai’i 

My Blogs

Reply 0
Kevin Rowbotham

@Paul - guys

Paul, I agree it would be good if these threads were archived for easy retrieval.  I've been bookmarking them for my own reference.

If these had been done as Blog posts they would all be part of Pelsea's blog, which would help.

I use plastic storage boxes like you will find at craft stores for storing beads etc.  I actually got most of mine from Lee Valley on a special buy offer.

The most static sensitive IC's I keep in anti static bags in the boxes, just in case.

I store resistors in plastic zip bags in old flip top 3.5 floppy disk file cases.

~Kevin

Appreciating Modeling In All Scales but majoring in HO!

Not everybody likes me, luckily not everybody matters.

Reply 0
Pelsea

Blog posts

Thanks for the nice comments, guys. As a matter of fact, they are blog posts, so they can be can be found by clicking on my username, then "view recent blog entries". 

The site search finds them if you enter the words pqe circuit. The more specific you get the better it will zero in. The only circuit that seems hard to find is my version of a campfire, because that was on an arduino thread. I'm thinking of posting a rerun, as soon as I have a chance to develop the idea a bit.

pqe

Reply 0
Kevin Rowbotham

Blog Posts

Quote:

As a matter of fact, they are blog posts, so they can be can be found by clicking on my username, then "view recent blog entries". 

Perfect!

I missed that, my bad.  Now I only need one bookmark.  Thanks again.

Regards,

~Kevin

Appreciating Modeling In All Scales but majoring in HO!

Not everybody likes me, luckily not everybody matters.

Reply 0
Reply