LM339 Output & Toggle = Issue / Why?

praondevou

Joined Jul 9, 2011
2,942
Oops, I think I forget to mention the load resistor which you don't have. Please read the "comparator with hysteresis" section in AN-74.

Your breadbord looks good, but as mentioned, put bypass caps on the ICs and don't let unused IC inputs float.
 

t_n_k

Joined Mar 6, 2009
5,455
OK I bit the metaphorical bullet and dug into my parts box to find an IR pair.

I've used a IR emitter diode type SE5455-003 and IR photo-transistor type SD3443. The circuit is now essentially the same as yours with somewhat different values.

The circuit works well (i.e. toggles the 4013 when the IR beam is interrupted) with

R1=470Ω
R2=22k
R4=6.8k

I tried 100k for R2 (as you have) but the transistor leakage is probably too high and the emitter won't switch (from 12V) to a low enough voltage level when the IR beam is interrupted.

Pic of my layout attached. The currently disconnected 555 astable is to the left side of the image. You can see the IR pair facing off at the right.

I've got the pot R3 set to give a threshold of about 6V at the comparator..
 

Attachments

t_n_k

Joined Mar 6, 2009
5,455
An interesting observation is that the operation of the circuit I built is as expected but somewhat uncertain. Particularly if I slowly pass the obstructing opaque 'thing' [piece of card] between the IR diode and the transistor. Probably due to 'noise' around the transition point as the edge of the card passes through the zone where the receiver response is most sensitive.

So praondevou's suggestion of introducing hysteresis is quite important for a successful outcome. Depending on the physical nature of what you are doing with respect to the IR link, you may have to add some other level of sophistication to the design. A re-triggerable monostable between the comparator and the 4013 may be an option if hysteresis doesn't solve the problem completely.
 

Thread Starter

SiO

Joined Sep 12, 2011
22
An interesting observation is that the operation of the circuit I built is as expected but somewhat uncertain. Particularly if I slowly pass the obstructing opaque 'thing' [piece of card] between the IR diode and the transistor. Probably due to 'noise' around the transition point as the edge of the card passes through the zone where the receiver response is most sensitive.

So praondevou's suggestion of introducing hysteresis is quite important for a successful outcome. Depending on the physical nature of what you are doing with respect to the IR link, you may have to add some other level of sophistication to the design. A re-triggerable monostable between the comparator and the 4013 may be an option if hysteresis doesn't solve the problem completely.

Hi.
Thx for building this similar circuit. I wanna mention tought that I make it work the otherway around. Explanation: TX led dans RX IR transistor do not see each other and ar facing upword. This is a proximity detector. When IR light reflects on an object, then the RX activates. Does the same thing you did, exept the idle state is inverted from yours.
About the dark plastic, Ive read that black plastic is "transparent" to IR light. Weird stuff but your experiement tends to confirm.

Ill be back in a few, Il reading the Hysterisis doc.
If this can work, one on my last tasks will be to induce a known "power-on state' to the 4013.

Thx, BRB.

Question: Is a bypass Capacitor also needed on the LM339? If so, is it between pin 3 and 12 ?
 
Last edited:

Thread Starter

SiO

Joined Sep 12, 2011
22
OK I bit the metaphorical bullet and dug into my parts box to find an IR pair.

I've used a IR emitter diode type SE5455-003 and IR photo-transistor type SD3443. The circuit is now essentially the same as yours with somewhat different values.

The circuit works well (i.e. toggles the 4013 when the IR beam is interrupted) with

R1=470Ω
R2=22k
R4=6.8k

I tried 100k for R2 (as you have) but the transistor leakage is probably too high and the emitter won't switch (from 12V) to a low enough voltage level when the IR beam is interrupted.

Pic of my layout attached. The currently disconnected 555 astable is to the left side of the image. You can see the IR pair facing off at the right.

I've got the pot R3 set to give a threshold of about 6V at the comparator..

I can see on your circuit you didn't use any pull-up resistor on yours right? (on pin 2 of the LM339) Only a Load resistor to GND?
 

Thread Starter

SiO

Joined Sep 12, 2011
22
Hi all!
It is now working! Ill see if optimizing is needed, but following your suggestions, it is now working! Here's what ive done (see new Pix for updated circuit).

1) Added a Bypass Capacitor to 4013.
2) Replaced the Pull-Up by a lower value to accelerate rising time (from 83K to 5K)
3) Added a feed-back resistor to the LM339 as suggested (2 & 5)
4) I tried the LOAD resistor, at first with 2K. Not enough. Had to put 1M. Then it worked!
5) Grounded all unsued Inputs on 4013 (dawm... forgot to do the same on LM339... will do)

So I am really happy to be back on the right track. Thx to you.
Still got a few questions lefts, if you guys don't mind.

Q1) Do I need a bypass Capacitor somewhere around the LM339? Between 3 & 12?
Q2) Can a LOW level on a 4030 (XOR) drive a 12V relay, or the used of a NPN is recommended?
Q3) I will now start my research to find a way to make sure the 4013 Q output is always the same at power-up. I've heard this is pretty simple, but if you got any suggestions, shoot!
Q4) Last thing I need is to add a small delay to the LM339 input signal, in fact, Slow down the return to 0V (without affecting rising time). From what ive read, I guess I could tweek an Hysterisis for that right? Eg: Need 0.5V over Vref- to saturate output, but to De-saturate (get to 0V) Vref+ needs to drop to 0.25V. Is this feasable?

Thx alot all!
 

Attachments

Last edited:

Thread Starter

SiO

Joined Sep 12, 2011
22
I found my answer about the starting state. For those who are interested. Thx to SgtWookie !


"
Remove the ground from pin 4 (RESET input).
The cap needs to go from pin 4 to +12v instead of ground.
The 10k resistor needs to go from pin 4 to ground instead of +12v.

That way, the cap will pull the RESET input high by following the 12v supply when first powered on, and then the resistor will charge the capacitor, pulling the RESET input back to ground.

If it's still not starting off with the output low, then increase the resistor to 47k or 100k."
 
Last edited:

Thread Starter

SiO

Joined Sep 12, 2011
22
Looking great now.
But I just burned myself (again) on my emmiter 100Ω resistor... even tough its now a 1 Watt. The maths are simple:

- IR led Specs: 150mA
- 12V input.
- 12V/0.150 = 80Ω (So I used a 100Ω)

12V * 0.150A = 1.8Watt... If i'm correct here, I would need a 100Ω-2W resistor?
Am I right?
I really need MAX power the IR TX can provide.

-------------------------

On the other hand, for the delay I needed, Instead I will try the Hysterisis calculation to set a good enough Hi-Level detection, but a big Hysterisis so that the voltage on Vref+ will need to be pretty low to make the Output drop back to Zero.

For those interested I found a great Hysterisis calculator:
http://www.daycounter.com/Calculators/Comparator-Hystereses-Calculator.phtml

Enjoy.
Thx alot. Ill be trying that.
 

t_n_k

Joined Mar 6, 2009
5,455
I can see on your circuit you didn't use any pull-up resistor on yours right? (on pin 2 of the LM339) Only a Load resistor to GND?
It's all unimportant now given your success. Congratulations BTW.

But no - you misread my layout. It's actually a pull-up resistor. The inside power supply rails (top & bottom) are ground and the outside rails (top & bottom) are positive 12V. I find it's a convenient layout I always use, since one often needs links to both supply potentials on the same side of an IC.
 

t_n_k

Joined Mar 6, 2009
5,455
Hi.
Thx for building this similar circuit. I wanna mention tought that I make it work the otherway around. Explanation: TX led dans RX IR transistor do not see each other and ar facing upword. This is a proximity detector. When IR light reflects on an object, then the RX activates. Does the same thing you did, exept the idle state is inverted from yours.
Again it's probably academic but I understand your point.

I'd make a couple of observations concerning the design which may not be relevant if I have misinterpreted the concept.

Assuming the circuit is in an "idle" state with the 4013 Q output low....
Presumably the idea is that an object comes into the IR field and reflects the IR back onto the detector [Q1] side. The circuit would then go into a new state indicating that an object is detected. When the object subsequently leaves the detection zone the detector state changes and the circuit reverts to an "idle" state with the 4013 reset to its starting state.

I envisage this sequence ...

No object in detection zone - Q1 emitter low & 4013 Q output low.

Object comes into zone - Q1 emitter goes high
Q1 emitter goes high - LM339 output goes high
Low-to-high transition on 4013 clock input toggles the 4013 Q output high

Object leaves detection zone - Q1 emitter goes low
Q1 emitter goes low - LM339 output goes low
High-to-low transition on 4013 clock input should do nothing.
The 4013 Q output stays high indicating the object is still in the detection zone. (????)

Is this what you intended the design to do? If to the contrary, you expect the 4013 to be toggled back to the idle state when the object is removed from the detection zone, then it would appear the circuit works, but for reasons unanticipated in the design logic. A likely cause would be multiple (rather than single) transitions at the 4013 clock input. This could relate to the rise and / or fall time of the Q1 current and the 'knock-on' effect to the comparator.

Hopefully this makes some sense.
 

Thread Starter

SiO

Joined Sep 12, 2011
22
Again it's probably academic but I understand your point.

I'd make a couple of observations concerning the design which may not be relevant if I have misinterpreted the concept.

Assuming the circuit is in an "idle" state with the 4013 Q output low....
Presumably the idea is that an object comes into the IR field and reflects the IR back onto the detector [Q1] side. The circuit would then go into a new state indicating that an object is detected. When the object subsequently leaves the detection zone the detector state changes and the circuit reverts to an "idle" state with the 4013 reset to its starting state.

I envisage this sequence ...

No object in detection zone - Q1 emitter low & 4013 Q output low.

Object comes into zone - Q1 emitter goes high
Q1 emitter goes high - LM339 output goes high
Low-to-high transition on 4013 clock input toggles the 4013 Q output high

Object leaves detection zone - Q1 emitter goes low
Q1 emitter goes low - LM339 output goes low
High-to-low transition on 4013 clock input should do nothing.
The 4013 Q output stays high indicating the object is still in the detection zone. (????)

Is this what you intended the design to do? If to the contrary, you expect the 4013 to be toggled back to the idle state when the object is removed from the detection zone, then it would appear the circuit works, but for reasons unanticipated in the design logic. A likely cause would be multiple (rather than single) transitions at the 4013 clock input. This could relate to the rise and / or fall time of the Q1 current and the 'knock-on' effect to the comparator.

Hopefully this makes some sense.


Hi!
Thx for your interest. Infact, yes, this is meant to be.
Here's a quick explanation why.

This circuit is in fact doubled, and joined together by an XOR. This will be used to detect a model train going on a certain portion of the track (1 sensor at beging and one at the end of the section) So two of those circuits (so 2 sensors) will be placed under the track facing up, at about 2 meters apart. What happends is:

4013-1 initial "Q" State = 0
4013-2 initial "Q" State = 0

So 0 & 0 in XOR = 0 at XOR output.

When train trips the first sensor:

4013-1 "Q" turns to State = 1
4013-2 "Q" stays at State = 0

Since both Q ouputs are linked to a XOR gate:

1 & 0 = 1 at the XOR gate Output.

This Output trigers a RELAY that lights a RED LIGHT saying "this portion of the track is busy". Once the train trips the second sensor (exiting this track section) the 4013-2 Q passes from 0 to 1. This said:

1 & 1 in XOR = Output 0 = Relai off.
When the train comes back next time, same processs applies, inverse.
Make sense?

BTW, here are a few questions I got left that probably got lost in my sea of posts (sorry about that):

Q1) Do I need a bypass Capacitor somewhere around the LM339? Between 3 & 12?
Q2) Can a LOW level on a 4030 (XOR) drive a 12V relay, or the used of a NPN is recommended?
Q3) I found different specs for IR DEL TX... How can I make sure how many mA MAX it can drive? Seems to be between 100 & 150mA.
Q4) Has anyone ever experiences interferences on IR beam created by ambient lights or neons?

My main concern right now is the lack of sensitivity of the IR RX vs IR TX power.
I get best results when IR TX is operating a MAX force, 150mA (that why I need a 2W 100Ω resistor)
The angle of IR TX and IR RX is pretty touchy also. And distance between TX and RX.

I now need to calculate a good Hysterisis (thx for the crash course!) because I need to overcome a problem:
Between train WAGONs, there a GAP. MAX 1 inch. This is enough for the IR beam to pass between and loose detection, and screw my 4013 Q output....

So I got a few options. (which one is better you believe?)

1A) Calculate the Hysterisis on LM339 to: Trigger HI when Vref + is about 3V
1B) Calculate the Hysterisis on LM339 to: Trigger LOW when Vref + is about 0.5V
I made a graph, and I got this info out:
- When no object is in front: Vref+ = 0.33V
- When an object is at 2 inches = 3.00V
- when a object is at 1 inche = > 5.0V
- Vref- is currently ajusted to 1.25V
So I beleive that a good hysterisis would prevent issues when beaming between wagons.
2) Add a "delay" so that Vref+ voltage takes some sime to drop to zero when the object is not in front of sensor anymore.
3) Find a Logic way to set gates so that once gate one is triggered, only gate 2 will clear it, and vice vera (cause trains can go both ways)

Ill check option 3 later on... possibly the best one and simplest one. K.I.S.S.

Thx!
All suggestions and comments are welcomed !

Thx alot all!
Ill post final results, so you'll see the end result, hopefully working #1 !
 

Thread Starter

SiO

Joined Sep 12, 2011
22
Oops, I think I forget to mention the load resistor which you don't have.
This did complete my circuit fix. But can you explain what adding a Load resistor fixed my issue?

I've been looking for documentation on the role of a load resistor, with no luck.

I used to work alot with TTL. I never had to use a Load Resistor between two logical gates... so when do I need one here between LM339 and 3013?

Thx for the explanations!
 

t_n_k

Joined Mar 6, 2009
5,455
This may be of help - I'm not sure.

The modification including the re-triggerable monostable creates a non-retrigger interval depending upon the monostable interval - 3 seconds by way of example in this case.

Changing the monostable timing components gives a range of values up to many seconds. It could perhaps be used to cover the gaps between wagons or carriages. Unless the mono times out it is re-triggered to its nominal timeout value on receipt of a subsequent input logic transition cycle - such as would occur with a gap. The problem is how long one should extend the hold-off delay. Probably of no use if a train is ever stopped in the section.
 

Attachments

Thread Starter

SiO

Joined Sep 12, 2011
22
This may be of help - I'm not sure.

The modification including the re-triggerable monostable creates a non-retrigger interval depending upon the monostable interval - 3 seconds by way of example in this case.

Changing the monostable timing components gives a range of values up to many seconds. It could perhaps be used to cover the gaps between wagons or carriages. Unless the mono times out it is re-triggered to its nominal timeout value on receipt of a subsequent input logic transition cycle - such as would occur with a gap. The problem is how long one should extend the hold-off delay. Probably of no use if a train is ever stopped in the section.

Hi. Thx for the circuit.
But you guest right. The train does stop on this section unfortunetly.
There has to be a way to simply set a capacitor at the right place to slowly (in about 1 second) discharge towards Vref+ so that if Vref+ starts to loose voltage due to gap between wagons, the capacitor could fill in for a second... thats a theory for now.

My second idea was to create an hysterisis.
There is a gap between wagon, but they are still attached with a latch bewteen each other. When the gap will be on top of the sensors, for sure the Vref+ wil drop alot, but not completely (not equal to a completely clear view value).

Eg:

- No Obstruction: Vref+ = 4.0V
- Train Obstruction: Vref+ = 8.0V
- Gap (latch) Obstruction: Vref+ = 6.0V

I could set an Hysterisis on LM339 with the following caracteristics:

- Ouput sturated if Vref+ ­> Vref- (around 7.0V)
- Ouput drops ONLY if Vref+ < 5.0V

Hummm.. or mayby simply set Vref- to 5.0V would be simpler?

I believe this could work. What do you think?

Thx!
 
Top