Jump to content
 

Train detection... ...DIY IR-DOT


ShinyShoe

Recommended Posts

Circuits are complicated and that’s why all electronics engineers always prefer to build prototypes before committing to a production run. (You just can’t think of everything at the beginning!)

 

Circuit design is very complicated and circuit elements, and components, interact with each other all the time and sometimes in some quite unexpected ways – and that’s before you get into the logic of the circuit and its interaction with the real world. (The real world tends to have a habit of not quite behaving in the way you first thought it did!)

 

All this can ‘put you off’ electronics.

But don’t worry, there is a way that “lets you off”, “gets you out of jail” and allows you to build prototypes quickly and cover up any initial lack of thought.

This “magical” device is the micro-controller.

 

There is a reason why these “little computers” have become so popular!

 

Cheap ‘Starter’ kits are now made at almost throw away prices and the micros now cost the same as one logic chip.

 

I recommend that you look at the PIC12F675 (8 pins) or the PIC16F88 (18 pins).

Changing the whole way that your circuit works now is only a few lines of code away – (and quite a lot of thought as well though!). Changes are made with a keyboard and not with a soldering iron!

 

Shinyshoe, At the beginning of this topic I recommended my IRD circuit to you and you was originally aghast at its complexity.

Take another look. Is it more complex than your recent designs?

 

The circuit will do what you want, and I am still here to guide you – whichever way you go.

The IRD circuits greatest advantage is that it is programmable.

(Plus the software is free! ;-)

 

Kev.

 

I agree. I was only using the outdate PIC16F84 as a throwaway example. Obviously the 12FXXX would be the PIC of choice when only a couple of inputs and outputs are required for one sensor, as in your example. I have been using the PIC16F1827 in a few of my studies of late. I haven't really got into the complexities of 12F devices yet. At the moment I am studying assembler code and working towards using PIC C and PC assembler and C sharp. Still doing basic stuff at the moment, but I do like PIC BASIC, having used Proton and also looked at your MikroElectronica basic program.

Link to post
Share on other sites

I completely understand what you are saying about using a PIC. I'm a bit of computer geek and so its strange that its not turning me on to want to play with a PIC to do it.

 

But I'd still need to process the signal into the PIC so the bits that present the challenges around flickering signals may still present a challenge for a PIC albiet that you can process some of the issues out.

 

The interesting thing is the NAND gate you recommended can be used as an invertor so I think I now have less components than my previous attempt.

 

I've made quite a few changes:

 

Firstly the sensor swapped places with the resistor. Will that work to make the signal normally low and go high when the transistor opens? Or will it pull power from the LED and so be high anyway?

 

You'll notice I added a diode to the capacitor to stop it discharging "backwards" . If the emiter is high I forsee that capacitor rapidly charging up and then when the emitor goes low the cap feeding the NAND gate for just over a second. The NAND gate you suggested will hold for a bit longer too because its the Schmidt Type. Its effectively just acting as an invertor.

 

I moved manual occupy to the second feed on the latch. Does it need a resistor to protect the latch?

 

Is the reset OK there? Will it short pin Q4 and Q7 and would that matter? If so would it be better as a momentary break on the existing reset that connects to Pin 14 of IC1D

 

IC2A and IC2B don't need the schmidt but the chip is there so making use of it rather than adding an extra.

 

post-10683-0-14230100-1326068071_thumb.png

 

Its only 10 different components (9 if the switches are actually the same design wired differently). I can buy them all (exlcuding the strip board, wire and solder for £5.27 (including 2 IR sensors) and thats taking into account that resistors come in packs of 50! (20 parts in total). Kev-s circuit which I realise is infinately more adapatable because of the PIC has more parts than mine (till I get told I missed bits) and if I was to put the nice neat terminal blocks on would cost as much for the terminal blocks alone as I can't nip down to the Chineese electrical market!!

 

Many thanks for everyones continuing input into this.

Link to post
Share on other sites

  • RMweb Gold

ShinyShoe, have a look at the “PIC-Ready 1” on this page:-

 

http://www.mikroe.com/eng/categories/view/6/pic-development-tools/

 

For $29 it will be your interface, between the real world, and the PC – USB built in!

It will also ‘do’ most of the logic processing for your circuit – delays, de-bounce, memory, direction, impossibly complicated logic combinations, etc, etc. ;-)

 

You don’t even need a programmer and free programming software, (hi-level language compilers), are available, (again see:- http://www.mikroe.com/).

Lots of starter examples illustrate virtually every aspect of this board.

It's reprogrammable - via the USB port - upto 100,000 times. So plenty of scope for experimenting!

 

I’m using this for my signalling interface, but other than that, not connection with the company.

The UK distributers website is:-

 

http://www.mcustore.com/

 

 

I will have another look at your circuit later today but, as you already suspect, I’m not going to like the switch shorting the two inputs of the Nand gate together!

 

Kev.

Link to post
Share on other sites

  • RMweb Gold

Updates and further thoughts…

 

Took a longer look at your circuit today and I am impressed.

 

However, (I but you hate me saying that – sorry), when I suggested changing from logic family a-CMOS to logic family b-TTL(LS) I would automatically change mindset from a-problems/advantages for CMOS to PROs/CONs for TTL. Hmm I’ll think further, but this should not trouble you as you only need to concentrate on the logic of the block occupancy.

 

Well done for spotting that the NAND can be changed into a NOT gate, but it goes further, it can also make ORs, NORs, ANDs, XOR (or is it XNOR – I can’t remember) but these use more gates. Another chip to consider, (instead of the quad 2-input NAND gate IC 74LS132), would be the 74LS232 – Quad 2 input NOR gates. Changing the spare gates into inverters would be the same but if you need a OR gate instead of an AND gate then just swap chips!

(Changing to HCT might be something to consider too.)

 

The good news is that the delay circuits are not needed. Let the SR circuit do its job – ie remember, it doesn’t matter that the input (S) is chattering up and down the SR output (Q) will still be high. As long as you don’t try to reset the SR (ie the train exits the block) during this time.

 

The manual reset switch will need to be changed. (can’t short the two SRs outputs together if one is high and the other is low - (TTL low would probably win, CMOS don’t know!).

 

The receiving transistor, (of the TCRT5000), may work connected directly to Vcc, and its emitter floating above the resister, I don’t know. This needs to be tried first before committing. I would, as a matter of course, have the emitter connected to ground and the collect pulled up to Vcc. This does, however, invert its output.

 

I’ve printed out your latest circuit and scribbled my – random – thoughts on it.

The amount of scribble in no way reflects the basic logic, which is what you need to provide, but just the detail that electronics engineers always have to consider, give up, and then build a prototype!

 

 

The next bit I am not sure about.

Is this circuit for the main line and bi-directional? (I am assuming it is.) Or is it for the main line Uni-directional? (It can’t be for the sidings!!)

 

I will continue to assume that it is for bi directional running.

In which case please consider the following, (others please join in here!):-

 

Noise – setting the circuit,

Noise – resetting the circuit,

Train enters block but loses the tail end in the block,

Train enters the block and deliberately detaches some wagons in the section,

Shunting enters the section but leaves the way it came (either clipping or clearing the entry sensor),

Train fails in section,

Rescue loco enters section from rear,

Rescure loco enters section from in front,

Two trains enter at the same time!!!,

Manual override with the above,

Track cleaning,

Hand of God,

Ambient lighting,

And, no doubt, many more.

 

 

The answer to the above could be:- don’t care, won’t happen, I’ll press reset, I want that to happen, must handle it, etc, etc.

But whatever, you must consider them at this stage. Try and add a few yourself and then answer them all, at this stage it doesn’t matter what the answer is as long as the scenario is not forgotten.

 

 

Kev. (trying desperately not to put you off!)

post-12815-0-78846000-1326148268_thumb.jpg

Link to post
Share on other sites

  • RMweb Gold

Baby Deltic,

 

I've looked at the 16F1827, (I missed it), but I went for the 18F1320 instead.

Mainly because the compiler needed a 18F series chip in order to be able connect SD cards - another project..

The 16F1827 chip does have a more sensible pin-out though!

 

 

ShinyShoe,

 

In a a previous post i said that the charging was through a 10k + 1k, this is clearly wrong as only one resister was in the charging circuit.

 

 

Kev.

Link to post
Share on other sites

ShinyShoe, have a look at the “PIC-Ready 1” on this page:-

 

http://www.mikroe.co...elopment-tools/

 

For $29 it will be your interface, between the real world, and the PC – USB built in!

Oooh.... tempting me now... But I guess I'd struggle to take 10 IR sensors and 7 points settings onto that board or am I failing to grasp something basic.

 

But you are appealing to my programming geek! I can see fathoming the logic for the signalling once the block occupancy is known could well be a challenge on logic chips, and I can see that expansion onto new layouts that connect in will be even harder. So I could well be thinking of using that to manage the signalling... taking feeds from the IR Circuits to identify occupancy.

 

And is it just me or was th $99 touch screen very tempting to save having all those switches on a control panel !!!!! ;-)

 

No pun intended? ;)

Ooops! None was!

 

The schmitt triggers are a good idea on the inputs.

Thank you to Kev for the hint.

Link to post
Share on other sites

  • RMweb Gold

I should really try and answer the questions!

 

"I moved manual occupy to the second feed on the latch. Does it need a resistor to protect the latch?"

Yes, with TTL a 10K pull-up is fine, (check logic). TTL really dosn't like pull downs because of the input sourcing current.

 

 

(I might have to dig out my 'Texas Instruments' Bible soon at this rate!!)

 

Kev.

Link to post
Share on other sites

Well done for spotting that the NAND can be changed into a NOT gate, but it goes further, it can also make ORs, NORs, ANDs, XOR (or is it XNOR – I can’t remember) but these use more gates. Another chip to consider, (instead of the quad 2-input NAND gate IC 74LS132), would be the 74LS232 – Quad 2 input NOR gates. Changing the spare gates into inverters would be the same but if you need a OR gate instead of an AND gate then just swap chips!

(Changing to HCT might be something to consider too.)

Pretty sure I need an AND (or NAND) i.e. to determine when the entry and exit have both been sensed.

 

The good news is that the delay circuits are not needed.

For once I can disagree! For detecting occupancy I totally agree the latch should latch at the first sign of the train. However, when exiting the exit will be detected on the first sign of the train leaving. That triggers the NAND (both IRs are latched HI) and the reset into both latches. As the train is still exiting the exit latch will have SR both LO and Q will stay HI. However, the gap between wagons needs the time delay or the latch will be reset on the first gap.

 

The manual reset switch will need to be changed. (can’t short the two SRs outputs together if one is high and the other is low

I just knew you'd say that but it made the symetry of the design nice!! I'll just move it to be a NC Switch on the reset feed.

 

I’ve printed out your latest circuit and scribbled my – random – thoughts on it.

Did you mean to provide that?

 

The next bit I am not sure about.

Is this circuit for the main line and bi-directional? (I am assuming it is.) Or is it for the main line Uni-directional? (It can’t be for the sidings!!)

Its the bidirectional main line, but would work unidirectional just probably has more circuits than it needs.

 

Noise – setting the circuit,

Noise – resetting the circuit,

I'll only operate in a sound proof room ;-) ==> until a build is present and I can see how often it gets accidentally tripped I can't be sure. If its over sensitive then some resistor trickery could fix it. I actually suspect the issue will be lack of detection rather than over detection. Its only supposed to have a 15mm range and thats not huge!

 

Train enters block but loses the tail end in the block,
I will be in close control so an unplanned drop of wagons will be dealt with.
Train enters the block and deliberately detaches some wagons in the section,
Will happen to run round. Manual occupancy switch will be set. (Vehcile on Line I think was the term you used)
Shunting enters the section but leaves the way it came (either clipping or clearing the entry sensor),

A train leaving by its point of entry will require the block to be manually reset using the reset switch. Leaving via the entry route will not trigger a second IR sensor and so no AND status is reached.

Train fails in section,
tut tut - my trains are all well maintained and never fail!
Rescue loco enters section from rear,
having passed a red signal with permission from signal box presumably. Passing the IR will make no difference as its already latched.
Rescure loco enters section from in front,
Would still have to pass a red danger signal and get permission from signal box. But signal box would need to mark the block occupied manually.
Two trains enter at the same time!!!,
One will cancel the other's block protection. Both will collide, then be hit by a third train because the block is not marked occupied...
Manual override with the above,
?
Track cleaning, Hand of God,
Suspect I'll manuall reset if hand of god has been in if needed...
Ambient lighting,
sensor has a filter fitted so its supposed to be OK.
Link to post
Share on other sites

  • RMweb Gold

ShinyShoe, you were right to disagree with me. The delays are needed in this circuit, just not both at the same time.

Because the line is bi-directional the sensors are either entry or exit sensors. Only the exit sensor needs to be ‘smoothed’ with a delay.

 

You need two ‘manual occupy’ pushbuttons to simulate the virtual direction that the occupancy is coming from. Wait bare with me! But because the line is bi-directional the ‘manual occupy” push button, at the other exit end, then becomes the ‘manual block release’ push button.

In the same way that the entry/exit sensor, at one end of the section, automatically dictates that the other sensor becomes the exit/entry sensor.

Thus, you don’t need a reset PB elsewhere.

But you will need to indicate which direction is active.

 

 

OK, suggested mods to the circuit:-

 

Add another Push-to-Make switch to the SR latch at the bottom of the circuit. (Use the other 3-input SR latch here.)

This Push Button will then need to pull down, to 0volts, the input to the latch S2. A resister, 10k, will pull up the input when the PB is not pressed.

 

Remove S1 reset switch.

 

You now need an indication circuit that tells you which ‘direction’ the line is being occupied from. (So you then know which occupy/reset PB to press if you need to manually release the line.)

There are a number of ways in which you can do this.

1/ Have a LED on the output of the two 3-input SR latches, either pulled up to Vcc or pulled down to 0v via a 330 Ohms resister.

2/ Have one bi-directional Green/Red LED, plus a 330 Ohm resistor in series with it, between the Q outputs of the two 3-input SR latches.

Orientate the LED so that Green means ‘line occupied in normal’ direction and Red means ‘line occupied in reverse’ (“Bang Road!”) direction.

 

 

I will look at the delay circuit values later.

I will also look at the reset circuit again, (final SR latch), as I think it won’t reset the exit sensors latch! (Maybe another delay-off circuit is needed here!!)

 

Kev.

 

Edited because i'm stupid!

Link to post
Share on other sites

All good stuff, thank you so much. And please do thank your wife (I saw your status the other day).

 

Hadn't thought of using a second manual occupy to de-occupy. Hadn't realised direction indication was that close. I didn't want directions (if a block is occupied its occupied the signals need to block access. However I knew that expansion down the line in future would benefit from direction and if I go the PIC route for signalling that becomes much more amangable than trying to also factor that into the signalling by logic gates. For pretty much no effort its already there.

 

I'm 99.9% convinced the reset will work on the exit latch if you need me to explain what I think is happening I can...

Link to post
Share on other sites

  • RMweb Gold

Ok, one last chance to convince you of the merits of a micro-controller in this application.

 

“Circuit Ideas 1†is an attempt, (without a prototype), of a Hard-Wired circuit to fulfil you criteria. (It may be possible to remove one NAND gate chip if the reset delay doesn’t need a ‘Schmitt’ following it.)

Advantages – (allegedly) simple and easy to follow! No programmer needed. No software needed.

Disadvantages – Big BIG chance that the circuit is wrong. Big BIG chance that the logic is wrong. Can not change easily.

 

“Circuit Ideas 2†is a good first shot, (ready for prototyping), of what you need.

Advantages – Cheaper. Quicker to build. Can be changed within a minute. Flexible. Featurs can be added at a later date.

Disadvantages – Needs a programmer. Needs some programming ability (Not much, can be learned quickly). Looks more complicated!!! The circuit can be reduced further, (R2 and R4 may not be needed and the optional components can be deleted.)!

 

Both circuits need a 5 volt supply. “Circuit Ideas 1†may benefit from CMOS or HC logic instead.

Don’t forget, a wire link is usually more time consuming and difficult to fit than a component!

 

Kev.

CircuitIdeas1.pdf

CircuitIdeas2.pdf

Link to post
Share on other sites

A few observations regarding 'Circuit Idea 1' as currently presented...(bearing in mind it is a first-off).

 

The contacts of the push-button switches are likely to suffer badly if you connect 470uF capacitors directly across them as shown. A series limiting resistor, even a few tens of ohms, would be sufficient to protect them without affecting the button operation. That's unless they are intended to be 470nF instead, which would be more usual.

 

The value of the pull-down resistor on the 'Wired-OR' arrangement is somewhat low at 330R. I would expect to see this in the low k's range, probably 4k7 or 10k. Struggling to see how the notion of a reduction to 220R for this would be necessary or desirable.

This particular feature would also benefit from the use of HC logic rather than LS TTL, because it's output can source current equally well as sinking it - and it has rail-to-rail voltage swing, which will ensure a reasonably good logic level at the diode junction.

 

I would fully concur that the microcontroller version of this (Idea 2) would be a lot more efficient in many ways, not least of which is sheer component count (and associated build complexity).

Link to post
Share on other sites

  • RMweb Gold

Hello Gordon H and welcome,

 

I agree entirely.

 

The 470uF is large enough to dump enough energy to cause damage. (Might even need to de-couple the supplies!)

The value, at the moment, is somewhat arbitrary as its value is determined by the logic family used, and the time thats need to be used and, more importantly, what works in the prototype.

A large value was just a ‘cover all’ for TTL (LS) and to demonstrate how inflexible the circuit is. I’m still not convinced the logic is correct!

 

As for the Wired-OR, well I haven’t used one of those for decades and that was with standard 7400 parts then!

 

I feel the need to re-iterate the title on drawing “Circuit Ideas 1†and that is:-

 

DON’T TRY THIS AT HOME!

 

 

Sorry for 'shouting' to all those of a delicate disposition.

 

 

ShinyShoe, “Circuit Ideas 1â€, or any such similar circuit, will cause too much frustration and will probably never work as intended. Where as “Circuit Ideas 2†is much cheaper and, once working for your mainline sections, will probably work for your sidings too – even if it is just with software delays. (You could use the two IR sensors as a quadrature counter with the micro counting up, for trains entering the siding, and counting down, for trains exiting the siding. 0 = no train in siding! (Not sure about wagons dropped off though!))

 

Kev.

Link to post
Share on other sites

OK, well SHMBO say the circuit diagrams and said circuit 2 looked simpler. She knows nowt about owt so that decides it - I'm building it with valves and switches!

 

Seriously, I do understand where you are coming from with the PIC. Presumably I wouldn't use 5 of those $20 boards to build them? Not really sounding cheap, but can I prototype on that board and then unplug the chip and 'solder'? it to a strip board? (or solder a chip holder).

 

On a serious note the time has come to start melting some lead. So the basic design of sensor section stays much the same throughout give or take a capacitor. I need to build one or two of those and actually see what it can "see". And since the cost of a couple of logic chips is less than the cost of a trip to starbucks I'm thinking "why not" just grab them stick them on a bread board and see if any of this works. And if it doesn't after half an hour of banging my head on a wall I'll chuck em in the bin and come back looking for PIC advice...

 

Calum

Link to post
Share on other sites

  • RMweb Gold

You really should be building it in relay logic - and not with valves!

 

Seriously,

The bread board answer is the most sensible.

As you say 'try it'. I'm certain bits will work well and others, well, not so.

 

The PICready2 board would 'do' several sections at once, but its main attraction would be in just using 6 IO pins and simulating a circuit in "Circuit Ideas 2". You will quickly realise its potential.

 

Kev.

Link to post
Share on other sites

Couple of curiousities with the first circuit...

 

U1.2 and U1.3 what purpose do they serve? they seem to feed the same circuit as U2.2 and 2.4

 

U4.4 would presumably be better replaced with a NPN configured as a NOT gate that would have a better current handling...

 

I don't think the time delay C3 R5 is needed is it? You already have a delay for couplings and if a train is over the sensor the reset can't happen - can it? Maybe I'm missing why people would want to add a delay.

 

Could U4.4 not take its feeds from the direction indicaton LEDs

Link to post
Share on other sites

  • RMweb Gold

Presumably, you mean U1.1 and U1.2.

The wired-OR output needs to show occupied from the instant a train enters to the last detection (+ a bit) of the train leaving.

The reset circuit will reset on the beginning, or leading edge, of the train leaving the section and NOT the tail end.

 

U4.4 can be replaced by a transistor, (open collector output). I would use a ZTX651 but I’m old! (And I’ve got a bag full of the E-Line little devils.)

 

C3*R5 is needed to ensure that the circuit resets ‘a little bit’ after the last vehicle has left the section and needs to be timed accordingly.

 

Re – U4.4. Don’t they already?

But the direction LEDs don’t include the final Reset delay(s) and the final output should either be fully “clear†or “section occupiedâ€.

 

 

Still probably got some logic problems though – keep looking.

(And that isn’t a hint I’m afraid!)

 

 

Kev.

Link to post
Share on other sites

Hi there. Parts arrived today.

 

Have built sensor on proto board. Will "work" hi or low but the voltage change is SMALL

 

Resting voltage 0.05v with ambient light etc.

 

Goes to about 0.7v if it catches a rivot at the right angle. But generally its about 0.2-0.3v with train above. That's with

a 20k resistor in to pull down... when I have 10k in its half that and when I have 1k in its 0v resting but 0.02-0.03v.

 

should I be trying a 100k or even a 1M ..? Does reducing current matter?

 

 

Will try and post a couple of pics.

post-10683-0-60985000-1326497532_thumb.jpg

post-10683-0-76683500-1326497576_thumb.jpg

post-10683-0-19348300-1326497623_thumb.jpg

Link to post
Share on other sites

  • RMweb Gold

Could do with the circuit your using.

(Too many circuit ideas have been shown here!)

 

Specifically, what voltage are you using and what value is the series resister in line with the IR LED?

Is the supply voltage smoothed or is it regulated?

 

Check that you’re getting IR light. – Use a mobile camera phone to ‘look’ at the transmitter. (Should show up, dimly, depending on phone.)

Use different materials, as test reflectors, until the circuit works. Then change circuit values to widen the range and the sensitivity of the transceiver.

(Paper, finger, black plastic, foam, metal, mirror, etc.)

 

Here are a couple of links to other websites that have used the TCRT5000 device:-

 

http://extremeelectronics.co.in/avr-projects/avr-project-atmega8-based-rpm-meter/

 

http://theclickteamrobot.siam2web.com/?cid=425553

 

http://pe2bz.philpem.me.uk/pdf%20on%20typenumber/A-C/ANT014.pdf

 

Kev.

Link to post
Share on other sites

Shinyshoe

Is photo of circuit as your post #13

No, its half that circuit... kind of..to test what the sensor throws out... but the volts are probably on the low side to throw the NPN that then opens the relay. But its also only a 5v circuit

 

Could do with the circuit your using.

(Too many circuit ideas have been shown here!)

 

I ll scribble something real quick.

 

Its 5v regulated 5.2 on my meter.

330ohm on the LEDside

 

Circuit does work just voltage change is tens of mV

 

Link to post
Share on other sites

  • RMweb Gold

Looking at the Data sheet, the TCRT5000 has the IR LED and the Photo Transister, are carefuly 'aligned' to deliberately limit the sensing distance. (I know thats what you want eventually but it may not be helping now.)

Use the different test subjects I sujested earlier.

Also, don't use the track and wagon yet. This can be done later, but for now, distance is critical.

 

Try, as you already have, different value resisters on the transister receiver side.

Don't worry about the value, (at first), "if it works" is all that matters at the moment.

 

The data sheet also uses 'high reflective' test pieces and not black plastic.

 

You could try increasing the power to the IR LED by reducing the resistance from 330 Ohms down to, say 165 Ohms.

Doubling the current throught the LED. Just use two 330 Ohm resisters in parallel.

 

Also, use your TV zapper to fire the circuit.

The TV zappers IR LEDs are high power for distance working.

(I found this a particularly useful trick when not much else was happening!)

 

Kev.

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...