op amp knowledge

Dippy

Moderator
I think you minderstood Alband.
Steve said the sample and hold has to be held just before a hit.
I didn't notice a clairvoyancy routine in your code ;)

Anyway, I agree with BB that a suitable integrator could be used as your reference.

I really can't see the point of a lens as has been mentioned. I assume the range isn't so far that a cheapo laser diverges much.
And, I suggest everyone gets a cheapo laser-pointer and fires it through a large cheapo convex lens and sees what happens. No, it won't focus it down to a microdot. And a fresnel lens, esp cheapo floppy plastic things, are going to cause so much messy dispersion that it will be awful.
Don't believe me? Try it.
 

sghioto

Senior Member
Good! Using a seperate LDR was my origional idea in post #9, although you don't need to use a ADC input. Something like this should work. Correct, less wiring.

Steve G.
 

Attachments

sghioto

Senior Member
alband,

Yeah get the LM339s. Time to put this in action, would love to see the finished project.

Steve G.
 

alband

Senior Member
Right, they should be winging their way round to my house some time in the near future.
I also got a 0.5mm soldering iron bit because I was sick of having to use a broken bit which equates to about 5mm at the tip and some resistors :D.

"I now need to go light up an old fire" ;)
 

alband

Senior Member
The 10K's that are attached to the non-inverting inputs; can I just use one about where that arrow is?
They haven't arrived yet but I'm preparing the breadboard.
 

sghioto

Senior Member
alband,

I suppose you could use just one 10K resistor per LM339. Connect all four positive inputs on each chip together. Tie this connection to the bus through a 10K. Technically you don't need any. The reason for all the 10K resistors was to get some isolation. If you don't use any resistors and one of the positive inputs shorts out then you can't tell which chip is defective without removing all of them unless it was getting "warm" maybe.

Steve G.
 

moxhamj

New Member
Re
>And, I suggest everyone gets a cheapo laser-pointer and fires it through a large
>cheapo convex lens and sees what happens. No, it won't focus it down to a microdot.

No it won't. Unless the focal distance is a constant. But it is true that you can take a laser pointer and correct for the (inbuilt) divergence with a telescope in reverse. I saw this on the internet, didn't believe it and went and bought a cheap "monocular" (half a binocular) and tested it over 100 metres. You get a huge reduction in the light. But in return, you get a parallel beam that can be adjusted for virtually no divergence.

But this won't help with this particular problem as I understand it is short range. I still don't completely understand the design criteria. Apparently there is a half completed circuit that can't be change that needs to detect where on a 7x7 matrix a light pulse arrives. But at the same time, multiplexing is too slow.

So is the connundrum to find a way to detect where on a 7x7 matrix a pulse arrives but to do it with analog circuitry ie op amps?

If so, yes, there are all sorts of cunning circuits. We are getting into the realms of neural networks and weighted inputs and indeed, circuits that have weighting biased towards the centre and lesser weightings at the periphery are the core of the early processing of the retina. And they can be accurately replicated with op amp circuits or software simulations of neural networks.

But -you are going to need a lot of op amps (albeit LM324s at 30c each) and a lot more resistors and a huge circuit board. It *really* is a lot simpler to get those 49 values into a picaxe as soon as possible and do all the clever processing in the picaxe.

Sometimes it helps to think outside the square. And also be prepared to abandon half finished circuits...
 
Last edited:

alband

Senior Member
...Hang on hang on :confused:
I am very confused. :confused:
Er, hmm, right:

Gain of an op amp = R2/R1 yes?
No? Gain = -R2/R1

Dr. A's calculations assume the first so I'll stick with that for now but look:
This contradicts itself (I think) saying the formula is the first above, but then states that if R2 is 47K and R1 is 4K7, the gain will be 10. Surely it would be -10?
This explains the gain in its entirety but make the same mistake as the above site.
This (probably can't be trusted, but anyway...) gives the formula:
Gain = Rf/Rin
but then states this:
Gain = - Rf/Rin = - 4.7/1.0 = - 4.7
???

Is it just commonly accepted that it is an inverting amplifier and that the output will be inverted and so people miss out the -'s?

On another note, the stuff from Rapid has arrived, well some of it has. They sent four PIC16F627A's instead of my four LM339's and I got the wrong soldering iron tip. All of this is despite the fact that they sent the wrong items in the correctly labelled packets :confused::rolleyes:
I've emailed them and hopefully they'll sort it out and I might be able to keep those PIC's (hopefully they're PICAXE's but I'd better not try until they're mine).
 

BeanieBots

Moderator
Happy new year alband.

Now I'll depress you even more.
http://www.datasheetcatalog.org/datasheet/stmicroelectronics/2159.pdf

The LM339 is NOT an op-amp, so all bets are off for ANY op-amp circuits.
In particular, it has OPEN COLLECTOR outputs.
That makes it great for simply connecting all outputs together when used as a COMPARITOR but almost useless for ANY op-amp circuits utilising gains such as those you describe.
But then you knew that from reading the datasheet didn't you?

An op-amp can be used as comparitor but a comparitor cannot be used as an op-amp.

In a circuit such as
http://www.electronics-tutorials.ws/opamp/opamp_2.html

The output WILL BE NEGATIVE for a POSITIVE input.
You CANNOT use a LM339 in THAT circuit.
You can of course have +ve gains but with a different circuit.
 
Last edited:

alband

Senior Member
I need a comparator to compare the light level from an external LDR and the values coming from the target. See post 42.

Which formula is correct though?
-R2/R1
or
R2/R1
 

BeanieBots

Moderator
No Rs involved with a comparitor!!!!!!!!!!!!!!!!!!!!!!!!!!!
Vout = high if +Ve(in) > -Ve(in)

See post 50 for the answer to -R1/R2 or R1/R2 for an INVERTING op-amp circuit as shown in the link.
 
Last edited:

moxhamj

New Member
If it is an inverting amplifier, ie input into the - then the gain is the -R2/R1. If it is a non inverting amplifier then it is R2/R1.

But that assumes a reference of 0V and a dual supply, ie +5V and -5V.

So if you have a gain of 2 and an inverting amplifier you will get -4V out.

"Is it assumed that it is -100k/10k = -10?". Yes. Feed in 0.1V and you will get -1V out, assuming the + of the op amp is referenced to 0V and there is a dual supply. If there is a single supply ie 5V, you will get 0V.

But as explained in the tutes, it is a lot more convienient to have a single 5V supply and reference everything off 2.5V. Then the circuit is simpler but the maths is more complex. If you reference off 2.5V and have an inverting amp and 100k and 10k as you suggest and feed in 2.6V you will get 1.5V out.

There is absolutely nothing that beats playing with a real circuit. Get a LM324. Get some resistors. Feed in some voltages and see how they behave.

As for whether it will help with this particular circuit, I can't answer that. I must confess I don't understand the problem. If you have a 7x7 matrix and you want to know that any one LDR has been hit and what the value was, you can do that with a bunch of voltage followers and diodes. That will tell you the highest light value. But it will not tell you which one was hit.

If you want to know which one was hit, you have to scan all 49 of them over and over. And that involves a picaxe and 4051s and doesn't need op amps.

If you are going to scan all 49 that determines how long the pulse needs to be. You need to do some more experiments, because I think you might find that LDRs have a slow response time, and the laser is going to need to be on target for maybe half a second. If the laser is moving across the target, and you have devices with a slow response time, and your scan rate is slow, you will not get meaningful data. Then you might find that phototransistors are better.

Have you got a CRO? Can you pulse a laser say, 100x a second, and measure an LDR's response on the CRO?
 
Last edited:

alband

Senior Member
Thanks.

I have a 7x7 grid of LDR's arranged with diodes so that there are 14 outputs, each of which refer to a column or row. When an LDR is "hit", a row and column will go higher than the rest and which LDR it was can be determined by the grid reference.

The problem was ambient light, so it has now been decided to use the LM339 comparators to compare the 14 inputs with an external LDR which can measure ambient light. The comparator can then give a nice, clean, crisp digital outputs for the PICAXE to read. No scanning required, so the only thing dictating how long the laser pulse is, is how fast the LDR's and PICAXE can work together. I'd say about 0.1s but this can easily be adjusted.

Out of interest what is a CRO?
 

hippy

Ex-Staff (retired)
CRO - Cathode-Ray Oscilloscope

And apparently Cathode-Ray Oscillograph, but that seems to be a quite arcane usage.
 
Last edited:

sghioto

Senior Member
alband,

This circuit has been breadboarded and works. The op amp only needs to monitor row 4 and column 4 for ambient light. You won't need to add a seperate LDR. A simple capacitor ("Ch") provides all the "sample and hold" needed. The outputs were interfaced to a 08M. Using a red laser pointer the response time was well under .1 seconds. The op amp used was a AD822, this is a single supply rail to rail output type. I recommend this chip or one similiar.

Steve G.
 

Attachments

BeanieBots

Moderator
Looks hopeful.
You could dispense with the seperate LDR by using the existing LDR levels to drive the 'bus' voltage. Just add a lowish resistor in series with the 'bus' and use a highish value to pull it up slightly.
Or maybe just a diode drop on the +ve input.
 

sghioto

Senior Member
BeanieBots,

Can you draw that out? I don't see how that will keep the bus higher than the LDR array.
Where on the array would you connect to?

Steve G.
 

BeanieBots

Moderator
Feed the 'bus reference' from the 'regular' LDRs via diodes (which could be the ones fitted already). The 'bus' will then be just a bit too low which can be corrected with potential divider to a pullup (as apposed to 0v) or a diode step up.

Needs a series resistive element high enough to prevent an 'active' LDR from pulling the 'bus' higher than the trip point.
 
Last edited:

sghioto

Senior Member
BeanieBots,

I see it now. I'm using a LM393 comparator for testing because I don't have a LM339. The LM339 is the quad version so the internal circuit is the same. I just tried the circuit posted below and it works as is.
What's strange is when the laser is held on the LDR the output stays low even though the + input is higher then the - input. If I connect the + input to Vcc the output will still go low when the - input exceeds around 4 volts. It must have something to do with the particular values chosen in this circuit and the internal biasing of the comparator chip. Would have replied earlier but this required some investigation.

Steve G.
 

Attachments

alband

Senior Member
I can't see how that would work.
If you have two input coming from the same output LDR, they will stay the same relative to each other.

However, I didn't understand much of what's just been said, and I don't understand that diode arrangement...:confused:
 

sghioto

Senior Member
alband,
That is true unless the + input responds slower then the - input. What was happening before in my previous post was this: When the LDR was "hit" both the - input and the + input rose at the same rate and therefore the output would not go low until the - input exceeded 4 volts, and it stayed low as long as the - input was above 4 volts. This is kind of a fluke with this circuit. However by adding a capacitor to the reference bus we can delay the voltage rise on the + input. The .1uf cap gives about a .1 second delay which is plenty of time for this purpose. The LDR response is much faster when "hit". The output will stay low for about .1 second unless the resistance of the LDR is so low that the voltage rises above 4 volts on the - input. This is not a problem since the laser will only fire a 100ms "bullet" and once a hit is recorded it won't matter the state of the output. As BB suggested you will only need 1 additional diode, resistor and a capacitor. I chose row 4 in the schematic as an example since it runs across the middle of the array but you could choose any row or column.

Steve G.
 

Attachments

BeanieBots

Moderator
Don't understand why you are getting a 'low' when +ve > -ve.
The 10k pull-up is a bit high but should be OK. Worth dropping to say 1k just as a sanity check.
Try using an actual op-amp rather than a comparitor. LM324 would be my choice for low voltage single rail. If it still doesn't behave, try with proper dual rails of +/-15v at least until the circuit is proved.
 

moxhamj

New Member
I agree with BB, a LM324 will work just fine as a comparator or as an actual amplifier. Years ago I remember going crazy with the open collector thingy on the 339.

Play with the circuit on +/-15V to test things. But don't connect a picaxe while doing those tests. Once you prove the analog part, swap to 5V/0V supply.

The 324 swings to within 1.5V of the rails, so the useful range is 1.5 to 3.5V with a virtual earth of 2.5V and a 5V supply. It works fine within those limits but it is much easier to test things with a dual rail.

Do you have a dual rail power supply and a protoboard?
 

alband

Senior Member
I already bought the 339's.
I have got a breadboard, but its completely choccablock.

I understand the other threshold circuit now, but is there any advantage of using that as opposed to the separate LDR, or visa versa?
 

BeanieBots

Moderator
It saves an LDR for starters but possibly more important it uses the ACTUAL LDRs as the ambient reference. Hence, no need to worry about temp. ageing, dirt etc. etc.

The LM324 is actually MY favourite op-amp.
It's cheap & readily available. The datasheet (when compared to more specialised op-amps) does not read as the hottest op-amp ever but in practice, the amps perform much better than their very conservative specs.

With light loads (eg PICAXE ADC input) they go almost rail to rail.
Will work on single 5v rail. (can be pulled with just a simple resistor)
Very low input offset and bias current. (cf very expensive FET input varieties)
4 amps in one 14 package.
 

alband

Senior Member
Well, I have already bought the 339's so I try them first.
All I need is a comparator though and as previously discussed; a comparator only compares but is designed for the job specifically, and op amp can do many things including comparing making it more expensive (only 4p, but still). So the op amp is overkill really?
Is there anything wrong with the 339; what is this open collector thingy?
 

BeanieBots

Moderator
Open collector means the LM339 outputs can only SINK current.
This is a 'feature' of the LM339 as apposed to a difference between op-amps and comparitors.
You will NEED to fit a pull-up (as shown) on its outputs.
 

sghioto

Senior Member
BeanieBots,

Actually the LM324 behaved in the exact same way as the LM339. When the - input exceeds 4 volts the output is low even when the + input is connected to 5 volts Vcc. The reason they behave the same is because they have a similiar input circuit.
As long as the ambient light voltage on the array does not rise above 4 volts then the circuit works fine. This is easily accomplished by the value of Rx. Alband said the voltage on the LDRs varied about 1.5 volts depending on the ambient light level. Adjust Rx for around 3 volts on the - input under worst case condition.

http://i2c2p.twibright.com/datasheet/LM139.pdf

http://www.national.com/ds/LM/LM124.pdf

Steve G.
 

BeanieBots

Moderator
Indeed sghioto, getting too close to Vcc.

Should be fixeable by using "better" power rails.

I think alband may have a higher voltage available?? (pre-regulator?).
A negative rail is also easy to do using PWMout for a charge pump.

Anyway, keep with the limits you mention and all will be fine.
 

alband

Senior Member
Hazzar!

It works!

Well.. I have 3 LM339N's.
I ordered a soldering iron bit, some resistors, and 4x LM339's
I now have (after two parcels) some resistors, 5x PIC16F672A's, tree LM339N's and two soldering iron bit's - neither is right.

Because of this, I can't re-solder the target so that it fits the new board layout. So I just tested it with a couple of spare LDR's and it works.
Although, the third LM339 seems to short between the VDD and VSS -it took me ages to figure that out.

Anyway, rapid seem to have a fault in their system and also seem to be doing their best to resolve it, so at the moment they have slipped from my "good Book" and fallen into the pages of my "Slightly amusing" book. :rolleyes:
 

alband

Senior Member
Edit: Stop Reading! I hope I haven't wasted too much of your time. I made an incorrect assumption and then found it was incorrect from the datasheet; Sorry!

Hello again everyone, I'm at a bit of a loose end.

The LM339's stopped working completely. I tested them at more and more basic levels until I had two POT's for the inputs and an LED with no success. All the chips were in the same breadboard and so I assumed some kind of short or exotic voltage level had occurred (despite the 36V maximum rating) and so bought some more. However, the new ones don't work either, in that they are acting as if there is no supply voltage (however there is 5V across the correct pins).

This is the datasheet for them and it states that 5V should work, but it still doesn't.
The power supply is a wall charger. The output is designed to charge a 9.6V pack. The writing on the cover says "9.6V DC 70mA". IT is going through a 7805 to supply everything.

Does anyone have these exact chips working & if so, what set-up have they got.

Cheers.
David.
 
Last edited:
Top