Go Down

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

polymorph

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

karl101

Hello,

If anyone is interested, here is what I ended up making:



This is it on a stripboard:


The Attiny85 allows me to add in a couple of LED's that are set to pulse when a coin passes by, a well as output a 5v pulse for an Arduino to look out for.

Attiny85 code:
Code: [Select]

/*
* coin detector for attiny85 microcontroller
* detects a change pulse on pin0, makes a couple of LED's on pins 1 and 2
* flash and makes pin3 go high for about 120ms.
*
*  * v1,0 October 2013
*
* pin change interupt code taken from; http://www.insidegadgets.com/
*/

#include <avr/sleep.h>

const int ledA = 1;
const int ledB = 2;
const int pinIn = 0;
const int pinOut = 4;
volatile int state = HIGH;
volatile int lastState = state;

#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

#define PTIME 30
void pulse(int times) {
 
  int k = times - 2;
  // for a pulse:  p = (PTIME * 2) * x
  // (30*2)*2 = 120ms
  // (30*2)*3 = 180ms
  digitalWrite(pinOut, HIGH);
  do {
    digitalWrite(ledA, HIGH);
    digitalWrite(ledB, HIGH);
   
    delay(PTIME);
    digitalWrite(ledA, LOW);
    digitalWrite(ledB, LOW);
    delay(PTIME);
   
    if (times < k) {
      digitalWrite(pinOut, LOW);   
    }
   
  }
  while (times--);
}

void setup(){
  pinMode(ledA, OUTPUT);
  pinMode(ledB, OUTPUT);
  pinMode(pinOut, OUTPUT);
  pinMode(pinIn,INPUT);
 
  sbi(GIMSK,PCIE);    // Turn on Pin Change interrupt
  sbi(PCMSK,PCINT0);  // Which pins are affected by the interrupt
 
  digitalWrite(pinOut, LOW);
  delay(1000);
}

void loop() {

  if (state != lastState) {
    pulse(20);
    lastState = state;
  }   
  digitalWrite(ledA, HIGH);
  digitalWrite(ledB, HIGH);     

  system_sleep();
  //delay(5);
}

// From http://interface.khm.de/index.php/lab/experiments/sleep_watchdog_battery/
void system_sleep() {
  cbi(ADCSRA,ADEN); // Switch Analog to Digital converter OFF
  set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Set sleep mode
  sleep_mode(); // System sleeps here
  sbi(ADCSRA,ADEN);  // Switch Analog to Digital converter ON
  state = !state;
}

ISR(PCINT0_vect) {
}


Karl.


polymorph

I'm curious as to what waveforms you get.
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

jremington

#33
Oct 23, 2013, 11:12 pm Last Edit: Oct 23, 2013, 11:18 pm by jremington Reason: 1
The photodiode D2 is backwards in your schematic. It should normally be reverse-biased. But then, the op amp isn't properly biased, either, with Vin+ connected to +5 V. If the circuit works, fine, but I wouldn't recommend it to others.

karl101


I'm curious as to what waveforms you get.


Output from opamp:


Output from attiny85:


Karl.

karl101


The photodiode D2 is backwards in your schematic. It should normally be reverse-biased. But then, the op amp isn't properly biased, either, with Vin+ connected to +5 V. If the circuit works, fine, but I wouldn't recommend it to others.


Thanks, I'll update the diagram at some point. The datasheet http://www.vishay.com/docs/81522/bpw41n.pdf isn't clear which way is which, I just wired it up so it worked.

After trying to connect the opamp various ways, what I ended up with is what I found worked.

Karl.

polymorph

It is working, but it may not continue to work. In those shots, is your scope set on AC input?

I don't know what is going on there. Can you put the scope on the lead of the photodiode that is connected to the Op Amp?

I suspect that if you were to insert a different Op Amp in there, it might stop working.
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

cjdelphi

I'm curious about c1...

I thought it's function was to be a high pass filter? Is it needed?

2ndly, i want to recreate this circuit but using a transistor instead of an op-amp.


Docedison

@ Cjdelphi... Good Luck in the contest.. The one thing apparent is that you have no direct knowledge of Photodiode operation.
The output current is in the order of uA.. If that part was a phototransistor a second transistor might work... Not however with a photodiode.... The capacitor typically is in the order of 10 to 100 pF.. It's used to compensate for the photodiode junction capacity.

@OP 
Quote
No results were found for your search term 'AD283'.
from both Datasheets. http://www.datasheetcatalog.com/datasheets_pdf/1/N/5/4/1N5406.shtml and the Analog Devices web site where I captured that quote.
The photodiode is reversed and that it works at all is a wonder.. For two reasons, with the + and - inputs biased as they are that Op-Amp should be hard against one rail... At a minimum the + input should go to a 10K pot to set the comparator threshold.
However there is no data sheet for the Op-Amp.. which is all the more reason to suspect a phototransistor.. There are many IR phototransistors available. Notice I didn't say IR Detector.. The three leaded type? they are two completely different devices..
For all this is worth a "Regular" Phototransistor... would in all probability work as well as that kludge you've wired up.
The old National Semiconductor analog app notes books have a great section on the why's and wherefore's of using Photodiodes properly...
BTW for Really Fast pulses it isn't unusual to see 100 or more volts on the cathode of the photodiode.. The high voltage is used to increase the avalanche current for fast particles, which because of their speed don't cause much avalanche current to flow..

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

cjdelphi

I forgot to put "s" on the end of "transistor"


karl101

Quote

@OP 
Quote
No results were found for your search term 'AD283'.
from both Datasheets. http://www.datasheetcatalog.com/datasheets_pdf/1/N/5/4/1N5406.shtml and the Analog Devices web site where I captured that quote.
The photodiode is reversed and that it works at all is a wonder.. For two reasons, with the + and - inputs biased as they are that Op-Amp should be hard against one rail... At a minimum the + input should go to a 10K pot to set the comparator threshold


It might help if I had put the op-amp part numbers in the right order AD823, not AD283...
http://www.analog.com/static/imported-files/data_sheets/AD823.pdf

As  jremington has pointed out, the photodiode is the wrong way round in the diagram. It may be correct on the board.

I'll stick a 10k resistor between the + in and 5v and see what happens.

Karl.

jremington

The voltage at Vin+ should be somewhere between 0 and +5 V. As someone else suggested, the best approach would be to use a 10K potentiometer (outer pins to 0 and +5, central wiper pin to Vin+). That way you can have an adjustable trigger level.

karl101

Hello.
Here is, hopefully, the final build of the IR coin detector. The addition of a 10K variable has made the output much more square



On stripboard:


Opamp output:


Thanks for all the help everyone
Karl

polymorph

Would you mind humoring me, and get a reading from the (-) input of the Op Amp? I'm curious as to how much voltage there is there, and the waveform.

Yes, the output certainly looks a lot cleaner, now. I suspect that the signal you got before was from the trailing edge of the coin pass and highly dependent on the precise characteristics of the Op Amp. The new circuit should be much more repeatable.
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

karl101


Would you mind humoring me, and get a reading from the (-) input of the Op Amp? I'm curious as to how much voltage there is there, and the waveform.


Here you go. Looking at this it makes me think the op-amp is unnecessary for providing a trigger signal to the attiny :-). Unless the resistor across the - input and output is adding something?

Go Up