Go Down

Topic: Extend Pulse from Op-Amp/Photodiode combo? (Read 14623 times) previous topic - next topic

karl101

Hello
I have built an IR LED to photo-diode object (a coin) detector, it uses an op-amp to amplify the signal and connects to analog 0 on the Arduino. Its for a box that puts on a light show when a coin is pushed through the slot.Here is the circuit diagram:

The NE5532P op-amp was the only 5v one I had in the bits box.

Below is the code on the Arduino, it shows a voltage of around 4.08v, and when a coin goes past a drop to 3.40v. While this works it only detects a coin that's moving relatively slowly, one that's freely dropping past is not picked up by the Arduino. I can see a negative pulse on the oscilloscope, obviously this pulse is not lasting long enough to be picked up in the loop which checks every 100 milliseconds. I don't want to reduce this as I'll also be having the Ardunio control lots of coloured LED's and a small TFT screen.

So, is there a small and compact way to pick up this short duration pulse, so I can have the Arduino check once every 300 or 400 milliseconds?

Code: [Select]

#define inPin0 0
unsigned long milliTime;
boolean coinOn = false;
void setup() {
  Serial.begin(9600);
   
}

void loop() {
  milliTime = millis();
 
  if (milliTime % 100 == 0 && coinOn == false) {
    // check for a coin
    int pinRead0 = analogRead(inPin0); 
    float pVolt0 = pinRead0 / 1024.0 * 5.0;
    Serial.println(pVolt0);
 
    if (pVolt0 < 3.9) {
      coinOn = true;
    }
  }
 
  if (milliTime % 1000 == 0) { 
    // do somthing once a second
    Serial.println("once a second");
  }
 
  if (coinOn == true) {
    // coin detected - do things
    Serial.println("***** coin *****");
    coinOn = false;
  }
  delay(1); // this stops everything being done twice per loop
}


Thanks
Karl

Grumpy_Mike

Two ways to do this:-
1) Use an NE555 timer as a monostable and stretch the pulse that way.

2) Use the negative pulse to trigger an interrupt and have the interrupt service routine set a Boolean variable to true. Then in the loop look for the state of the variable and if it is true make it false and do your thing.

nickgammon

Code: [Select]

if (milliTime % 1000 == 0) { 


That is fraught, if you happen to miss the exact moment when it is evenly divisible by 1000. Better of saving the start time and looking for current time - start time >= 1000.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

karl101

Thanks for the replies.
I didn't know about the interrupts, a test shows it works rather well and saves me having to add a 555 timer

I'll bear the millitime % 1000 thing, in mind, I probably wouldn't off seen that as being a problem until the program got more complicated.

Karl.


Grumpy_Mike

Quote
I probably wouldn't off seen that as being a problem until the program got more complicated.

Better to fix it now while you can still remember.

MarkT

Your circuit seems odd - you haven't provided a bias current path to the +input of the
opamp.

But more importantly the NE5532 isn't 5V, it is designed for a minimum supply of 10V.
For instance +/-5V split supplies, so running it from +5 and ground won't work as you
think.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

cjdelphi

Another way might be to use a dalington transistor pair or 2 transistors biased to amplify the signal then feed it through a schmitt trigger to clean the waveform up .

Oh yes of course using a capacitor to "extend" your pulses ill design a circuit should be simple.

Grumpy_Mike


Another way might be to use a dalington transistor pair or 2 transistors biased to amplify the signal then feed it through a schmitt trigger to clean the waveform up .

Sigh! - No it would not.

cjdelphi



Another way might be to use a dalington transistor pair or 2 transistors biased to amplify the signal then feed it through a schmitt trigger to clean the waveform up .

Sigh! - No it would not.


if biased properly so the sits off via the voltage divider, it will amplify the signal, why not? passed that 5v high (not low side of the transistor) to a not gate, or simply a buffer, and it will give a low and high edge or bypass it completey and design the  schmitt trigger..

mike, point is you read what I say as literal, I do not mean Literal if i did i'd be listing components, they're just thoughts and yes it's possible to use just transistors to extend a pull... never made one, have you? so don't rule it out.

runaway_pancake


mike, point is you read what I say as literal, I do not mean Literal if i did i'd be listing components, they're just thoughts and yes it's possible to use just transistors to extend a pull... never made one, have you? so don't rule it out.


You ought to present your "concept" with a circuit sketch, not verbally.
"Who is like unto the beast? who is able to make war with him?"
When all else fails, check your wiring!

cjdelphi



mike, point is you read what I say as literal, I do not mean Literal if i did i'd be listing components, they're just thoughts and yes it's possible to use just transistors to extend a pull... never made one, have you? so don't rule it out.


You ought to present your "concept" with a circuit sketch, not verbally.



I shall then.....I amplify the signal, clean it and extend the pulse, which gets fed into the IC... yup i'll have a think about it and design a circuit,

Grumpy_Mike

Quote
f biased properly so the sits off via the voltage divider, it will amplify the signal,

Yes it would, unfortunately this is not what the OP wanted.

Quote
mike, point is you read what I say as literal, I do not mean Literal if i did i'd be listing components, they're just thoughts and yes it's possible to use just transistors to extend a pull

I only have words to go off and your words as usual are rubbish and show a staggering ignorance of anything approaching electronic design. Maybe a schematic would show that either your words do not match your thoughts or your thoughts are wrong.

Quote
passed that 5v high (not low side of the transistor) to a not gate, or simply a buffer, and it will give a low and high edge or bypass it completey and design the  schmitt trigger..

Yes I am taking these words to literally mean you are speaking in English, all the words are there, sadly they are jumbled up nonsense.

Quote
... never made one, have you?

Yes.
Quote
so don't rule it out.

Why not? As presented the idea you have will not extend the pulse which is what the OP wanted.

Of course according to your logic the OP is not to be taken literally so when he says he wants to extend a pulse then maybe he really wants to bake a cake and we should be telling him about that, but not in a literal sort of way.

Better to keep your mouth shut and be thought a fool as open it and remove all possible doubt - as someone famous once said.

Docedison

I wonder Cjdelphi... If you have ANY IDEA of the photodiode current available in that circuit or the gain of the Op-Amp?.
Stretching the pulse is trivial.. A half monostable from a 40106 or a 4584 will serve nicely..
It is possible too, to use a 4069UB to do all of it with 3 sections connected as a linear amplifier 40 DB of gain can be easily realized and the remaining 3 sections can clean up and delay the pulse. The down side is that the 4069 isn't very fast because it is unbuffered..
I would suggest that in the future you supply schematics to back up your rather unusual? claims.

Doc
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

polymorph

A photodiode is not what I would choose to use in this circuit. It takes a fair amount of gain after it, in a circuit a bit different than the one presented. There are problems with it, as pointed out by MarkT in post 5.

You could probably use a phototransistor without the use of an Op Amp. As long as the LED and phototransistor are well-shielded from outside light. With the proper amount of LED current, aiming correctly, and the proper selection of a collector resistor, you should be able to get less than 1V unblocked, and nearly 5V as the coin passes.

Take to heart everything up to and including post 5. As suggested, fix millitime now, you -will- run into a problem. It'll be intermittent at first, and again as suggested by then you may have forgotten.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

polymorph

Stretching a pulse is -so- easy with a 555 timer...
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

Go Up