Using a 556 to control RC servo speed

bertz

Joined Nov 11, 2013
327
Bertz, the more I beat my head against the wall, the better the picaxe looks. What do I need to get started, where to get it? And will my photoresistors or phototransistors do for the 'digital input' ? I sure hope the picaxe is noise resistant. I think I read where the alternating flashers and recorder can be included, too.
Everything you are trying to do with your circuit board can be done with a single PICAXE chip.
All PICAXE chips have A/D capability so your photoresistors and phototransistors should work.
Nothing electronic is completely noise resistant. You still need to separate track power from control power and use by-pass caps where required.
PICAXE was developed to teach school children programming. PICAXE BASIC is a very easy programming language, but it does have limitations. It doesn't handle floating point math very well and the BASIC interpreter tends to slow down the program execution. But for the model RR hobbyist these are not really issues to concern yourself with.
I would start by reading this and subsequent articles on this website.
Then go to the main PICAXE website where you will find links to a support forum, manuals, programming commands, buying info and much more.
 

Thread Starter

MikeK

Joined Apr 1, 2016
34
Yeah, I tried that,(moving the board) but when I connected the sensors to the board, troubles. So I'm looking at the picaxe you recommended earlier. Where is the best place to get everything I need? All I have is a computer. The prices seem to be all over the place. I'll want a couple of the 08M2 chips, and the stuff to program it. Then I'll need the program. I sure hope I don't have to type in all those lines, one typo and I'm sure it's trouble again.
 

bertz

Joined Nov 11, 2013
327
Yeah, I tried that,(moving the board) but when I connected the sensors to the board, troubles. So I'm looking at the picaxe you recommended earlier. Where is the best place to get everything I need? All I have is a computer. The prices seem to be all over the place. I'll want a couple of the 08M2 chips, and the stuff to program it. Then I'll need the program. I sure hope I don't have to type in all those lines, one typo and I'm sure it's trouble again.
OK
Probably the best place to order your gear from is RevEd. I gave you the link in a previous post.
I have attached several tutorials. You don't have to be an expert programmer, but you do need to be familiar with the fundamentals.
The bad news - yes, you do have to do a lot of typing when writing code.
The good news - I can do most of the heavy lifting, so all you have to do is go in and hack the code to do exactly what you want it to do.
If you are interested in pursuing this route, here's what you need to do:
Write out in detail exactly what devices (crossing gate, flashers, etc.) you want to control, what you want them to do and when you want them to do it. This is the first step in writing code.
Also describe in detail what kind of sensors you are using (part numbers if you have them). I would prefer digital inputs (less code) but analog inputs will also work.
In return I will draw up a schematic and give you a parts list to order. I'll also write the code based on what you tell me. Then all you have to do is cut and past it into the IDE.
Sound like a plan?
 

Attachments

Thread Starter

MikeK

Joined Apr 1, 2016
34
Thanks so much, that sounds really good to me. The photoresistors are 5mm GL5537. Also I have Phototransistors 900nm 5mm Radial Tops-050 which have good sensitivity (they are black)
What the crossing needs is a sensor three feet up the track from the crossing to start the cycle. This allows for time enough for the horn sequence, which can take up to 20 seconds. At the same time the gates driven by Tower Pro SG90 servos are to slowly lower, the alternating flashing lights begin, and a 5v greeting card recorder is powered. Once the last car has passed a second sensor near the crossing the cycle ends, the gates slowly rise, the flashers stop, and the recorder stops playing.
The alternating flashing lights are smd LEDs. I usually run three wires up the pole, connect the LEDs together pos to neg on one leg, and reverse polarity to alternate the flash. I can wire them with four wires if necessary.
The gates are driven by bell-cranks from the servos, I use full travel of the servo to stretch out the motion, to slow it down and be as smooth as possible
I ordered a starter kit from Robot Mesh, the other link is in the UK, shipping can be real slow from there.
Is your avatar a model plane? My dad did two-wire line control. I have built some sailboats of my own design, RC control. I don't have the co-ordination for a plane, it's all I can do to keep left-right oriented on the boats when they are coming or going.
 

bertz

Joined Nov 11, 2013
327
What the crossing needs is a sensor three feet up the track from the crossing to start the cycle. This allows for time enough for the horn sequence, which can take up to 20 seconds. At the same time the gates driven by Tower Pro SG90 servos are to slowly lower, the alternating flashing lights begin, and a 5v greeting card recorder is powered. Once the last car has passed a second sensor near the crossing the cycle ends, the gates slowly rise, the flashers stop, and the recorder stops playing.
Is the loco over the second sensor before the last car clears the first sensor?

Is your avatar a model plane? My dad did two-wire line control. I have built some sailboats of my own design, RC control. I don't have the co-ordination for a plane, it's all I can do to keep left-right oriented on the boats when they are coming or going.
I used to be a model railroader back in the 70's but they came out with proportional radio control and I was hooked. I fly aerobatic 50 cc class planes.

Still working out the logic for the uC. When I get it worked out I'll give you a shopping list.
 

Thread Starter

MikeK

Joined Apr 1, 2016
34
Yes, it's possible, but not likely that a train could be three foot long. I've seen some really long ones. That was the beauty of the 74ls123, it had one half triggered on a rising edge, the other triggered on a falling edge, and re-triggering the entrance had no effect until the exit had reset.
Basically, the exit sensor makes on light, the default setting, what the system sees with no trains around. Gates up, all off. The entrance sensor makes on dark, when the loco passes over it. The control then operates the gates, lights, recorder until the exit sensor sees light after seeing dark. The latching relay was convenient because the '123 only put out a pulse on the high output, with the way it was triggered.j
50cc, my first motorcycle was 50cc!
 

bertz

Joined Nov 11, 2013
327
Thanks so much, that sounds really good to me. The photoresistors are 5mm GL5537. Also I have Phototransistors 900nm 5mm Radial Tops-050 which have good sensitivity (they are black).
Which do you prefer? What have you had the best success with? My experience with photoresistors is they are very inaccurate and are susceptible to changes in room ambient lighting.

One of the problems with micro-computers is that they follow a fixed instruction set. What I wanted was for the crossing gate flashers to come on at the same time as the crossing gate started to come down. But since the computer has to execute each line of the program in sequence it would have had to wait until the gate was down before the flashers came on. The easy solution is to use two 08-M2s. One is the master which also flashes the LEDs and the other is the slave which drives the gate crossing servo. Using this approach we can even program in a delay between the time the flashers come on and when the gate comes down (very prototypical). The slave also has two extra outputs for sound effects and such.

Once we settle on the sensors I can finish the circuit and assemble a parts list.
 

bertz

Joined Nov 11, 2013
327
o_O Even if an instruction cycle can be only a fraction of a microsecond?
The gate may take a couple of seconds to come down, we are replicating scale. Prototype crossing gates come down veeeery slowly. Besides he can use the extra outputs.
 

Thread Starter

MikeK

Joined Apr 1, 2016
34
Yes, flashers before the gate, flashers stay on for the whole cycle while the gate is going down/wait for the last car/ going up. The slave might be a good idea, since I need the horn (and a bell in the same recording) operating along with the flashers. I would love to keep the board as simple as possible, but it takes what it takes.
The photoresistors go from 2k ohm (exposed) to 10k ohm (covered) in dim lite, 200 ohm to 2k ohm in brite lite. The black Tops-O50 photo transistors go from 400 to 4k in brite lite, 4k to 14k in dim lite. The metal phototransistors go from 7k to 15k in brite lite, 5k to 50k in dim lite. I like the photoresistors best, they are not polarity sensitive and seem well behaved.
Triggering on a changing edge seems like a good idea to me, it's not easy to meet a specific voltage or current requirement in this kind of work for me.
 

bertz

Joined Nov 11, 2013
327
I like the photoresistors best, they are not polarity sensitive and seem well behaved.
Triggering on a changing edge seems like a good idea to me, it's not easy to meet a specific voltage or current requirement in this kind of work for me.
Refer to the attached schematic. Please measure and record the voltage at the location marked TP when the PR is covered and uncovered. This is necessary to write the software for A/D conversion. This is the problem with photoresistors, the processor has to interpret an analog signal rather than processing a digital (0 or 1) signal. You cant trigger on an edge with an analog device since the output is a ramp.

photoresistor circuit.jpg
 

bertz

Joined Nov 11, 2013
327
What's the value of R2?
Hmm, I assumed you were already using these LDRs on your layout in which case there should be a series resistor.

At any rate I scrounged though my parts box and came up with an LDR to experiment with. When using a 10k series resistor I got 1.50 volts covered and 0.67 volts uncovered. When using a 4.7k series resistor I got 2.25 volts covered and 1.17 volts uncovered. Since these are not linear devices, the 4.7k resistor would seem to be more appropriate since there is a greater spread between covered and uncovered and it puts us roughly in the middle of the operating voltage range.

Based on this, I have come up with a schematic for your gate crossing controller. Only 6 components not counting the headers and terminal blocks. Can easily fit on a 2" x 2" board. I have left off the sound card because I don't know what triggers it, but there are plenty of outputs available for the sound card and other stuff you might have in mind. Very easy to add on.

The only note of caution I might add is depending on the distance separating the two phototransistors, you might need another sensor midway between the first and last. The reason for this is the program logic says that when both sensors are uncovered, it interprets this as the train having passed the crossing. We probably could get around this by introducing a delay after the first sensor becomes uncovered, but we can deal with that later. Study the schematic and let me have your thoughts.

Picaxe Crossing.jpg
 

bertz

Joined Nov 11, 2013
327
I've also attached a fritzing sketch showing the recently posted schematic wired up on a breadboard. You should always build a circuit on a breadboard for debugging before committing to final design. Also the breadboard is an easy way to program the chips, if you wish to proceed in this direction. Are you interested in looking at the code?

Picaxe Crossing_bb.jpg
 
Last edited:

Thread Starter

MikeK

Joined Apr 1, 2016
34
Looking good, bertz. I checked my schematics, no resistors between the photoresistors and the '123. I tested the PR I have, using the schematic you provided, and the PR did very poorly. Hardly any voltage change using 5.2 volts and 4.6kohm and 10kohm resistors. The black Tops-050 phototransistor did very well, going from 5.2 to 1.2 volts in room light using a 4.6kohm resistor. About the same using a 10kohm resistor. Maybe we start out using the phototransistors. My PICAXE startup package arrived, I'll start reading the manuals. The board you show looks good to me, not a whole lot of stuff on it. I'll learn the terms, get up to speed eventually.
I can be studying things while parts are on order, I see I'll need the other PICAXE chip. List what I need, and I'll get it ordered if I don't already have it.
What's your opinion of IC sockets for holding these chips? I have plenty of the usual ones, only contact on two sides, not with the nice bent legs to hold in the board for assembly. I like that little trick.
 

bertz

Joined Nov 11, 2013
327
Looking good, bertz. I checked my schematics, no resistors between the photoresistors and the '123. I tested the PR I have, using the schematic you provided, and the PR did very poorly. Hardly any voltage change using 5.2 volts and 4.6kohm and 10kohm resistors. The black Tops-050 phototransistor did very well, going from 5.2 to 1.2 volts in room light using a 4.6kohm resistor. About the same using a 10kohm resistor. Maybe we start out using the phototransistors.
So let it be written, so let it be done. I will change the schematics and software to reflect using the Tops-050 phototransistor.

It occurs to me that the phototransistor is either on or off (conducting or not conducting). That means we don't have to fool around with mapping and ADC conversion. We can treat the signal as a digital input.
 
Last edited:

bertz

Joined Nov 11, 2013
327
My PICAXE startup package arrived, I'll start reading the manuals. The board you show looks good to me, not a whole lot of stuff on it. I'll learn the terms, get up to speed eventually.
I can be studying things while parts are on order, I see I'll need the other PICAXE chip. List what I need, and I'll get it ordered if I don't already have it.
What did you get with your start-up package? The most important item is the programming cable. Let me know so I don't duplicate items in my shopping list.

Here is a really great deal on a breadboard package. You get the board, power supply, jumper wires and free shipping! You're going to be using the breadboard often for tweaking the software, adjusting the speed and throws of the servo, setting the rate for flashing the warning lights, etc., etc.
 

bertz

Joined Nov 11, 2013
327
What's your opinion of IC sockets for holding these chips? I have plenty of the usual ones, only contact on two sides, not with the nice bent legs to hold in the board for assembly. I like that little trick.
I prefer the machined sockets. They keep the pins on the IC's nice and straight, especially if you have to remove and replace them.

Here is the 8-pin socket and here is the 14-pin socket.
 

bertz

Joined Nov 11, 2013
327
So let it be written, so let it be done. I will change the schematics and software to reflect using the Tops-050 phototransistor.

It occurs to me that the phototransistor is either on or off (conducting or not conducting). That means we don't have to fool around with mapping and ADC conversion. We can treat the signal as a digital input.
OK Mike, here is the revised schematic. However it is by no means complete. We still have to deal with your sound effects and any other animation effects you want to include. So I'll need as much info as you can provide about the sound card you are using. Speaking of which, here is a really nifty little sound card I have used in other robotics projects. There are tons of sound effects you can download for free off the internet.

Picaxe Crossing.jpg
 

bertz

Joined Nov 11, 2013
327
So let it be written, so let it be done. I will change the schematics and software to reflect using the Tops-050 phototransistor.

It occurs to me that the phototransistor is either on or off (conducting or not conducting). That means we don't have to fool around with mapping and ADC conversion. We can treat the signal as a digital input.
And here is the fritzing image.

Picaxe Crossing_bb.jpg
 
Top