Connect with us

Circuit to activate the uC interrupt

Discussion in 'General Electronics Discussion' started by Ban84, Dec 28, 2013.

  1. Ban84

    Ban84

    7
    0
    Dec 28, 2013
    I need a circuit that detects changes from a photoresistor. The output of the circuit will be fed into a microcontroller in order to bring it back from power down mode to active mode by activateing an interrupt. So far i have come up with this circuit:

    circuit.jpg

    So, my question is: should i proceed with calculating the values,getting the parts and building the circuit or it has some functional error that i cant see with my limited knoledge on circuits? If its no good, can u show me a circuit that can do the job and hasn't to many or to fancy(i.e gates etc..)components? In addition, if the circuit is good, i have available some lm741 op amps, are they suitable for the circuit?

    A little description for the circuit:
    The main idea is that the comparator is going to compare the currrent voltage value provided by the voltage divider (Photoresistor and R5) with the previous voltage level stored in C0 cap.
     
    Last edited: Dec 28, 2013
  2. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,186
    2,692
    Jan 21, 2010
    I think I see what you're trying to do.

    It looks like you want to cause the output to be low whenever the light intensity is a little higher than the average of what it was in the preceding period.

    Let me show you a simpler way before I tell you why it may not do exactly what you want it to.

    [​IMG]

    This circuit creates a voltage on the inverting input that continually varies with light intensity.

    Rx and Cx cause a voltage to appear on the non-inverting input that is essentially an average of the intensity over the past several RC time constants.

    When the current intensity is above the average, the output is low, when the light intensity is below it, the output is high.

    However the drawbacks of doing this are that the circuit is incredibly sensitive and will likely result in continuous transitions as the light intensity rises and falls by minute amounts.

    There are ways and means of reducing the sensitivity of the circuit. Typically you bias the inputs so that they are at slightly different voltages. The circuit will then change state once the light intensity starts to increase (or decrease, but not both) beyond a certain rate.

    You probably need to be more specific in what you want the trigger conditions to be and what you want the output to do in these cases.
     

    Attached Files:

  3. Ban84

    Ban84

    7
    0
    Dec 28, 2013
    Steve, first of all really thank you for your help.

    The scope of the circuit is that the output of the comparator will go high (3V+) when i stand close to the LDR or wave my hand close to it therefore altering the illumination on the LDR,No need for it to stay
    high, a simple pulse is enough.

    But i don't want it to go high all the time by minor variations of the voltage comming out from the voltage divider.

    In addition i dont wan't to compare that voltage to e fixed voltage because then it would be useles when it would be darker than a certain point(so the use of the capacitor).

    You think adding a gain and maye a Schmit triger on the output could solve the problem you mentioned?
     
    Last edited: Dec 29, 2013
  4. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,186
    2,692
    Jan 21, 2010
    So you want a reduction in light to cause the output to go high?

    Yep, I kinda figured that.

    [/quote]You think adding a gain and maybe a Schmit triger on the output could solve the problem you mentioned?[/QUOTE]

    Not in this case. Neither would do a great deal to achieve your goal (at least initially).

    [​IMG]

    Excuse the slightly funky drawing.

    In this case there are 2 Rx's and these are to cancel out the effect of input bias current. (although it's probably not such a big deal). Rx should be large with respect to R2 and R3 -- at least 10 times their sum.

    R2 should be small, and possibly variable -- how small is a matter for experimentation. Start with (say) 1k for R2 and 4k7 for R3 (and say 100k for Rx).

    Cx provides your time constant, let's say you pick 1 second, so Cx is 0.1uF

    In operation, with constant light levels, the voltage on Cx is the voltage across R3, and the voltage at the inverting input is higher, the voltage at the top of R2. In this case the output is low.

    If the illumination gets stronger, this difference increases (until Cx charges) and the output remains in the same state.

    If the illumination decreases very slightly (or very slowly) the voltage at the inverting input remains higher than at the non-inverting input , and still the output is low.

    If the level of illumination falls sufficiently quickly, the voltage at the non-inverting input will exceed that of the inverting input and the output voltage will go high.

    The output will still be noisy, but only during periods where the illumination is dropping, or for a brief time during the recovery. If you're monitoring this with a microcontroller, you should be able to handle this in software.

    If you need to operate the comparator at a higher voltage than the uC, then depending on the output, you can use a pull-up to the uC's supply voltage or a divider to produce an appropriate output.

    Note that you'll need to be careful in your choice of comparator that it can have its inputs close to the supply rails and that it can drive the output very close to ground. The 741 probably won't meet those requirements.
     

    Attached Files:

  5. Arouse1973

    Arouse1973 Adam

    5,164
    1,078
    Dec 18, 2013
    Just be aware that the circuit will pick up the mains frequency from indoor lighting. What effect this will have if any is somthing your going to have to test.
    Thanks Adam
     
  6. Ban84

    Ban84

    7
    0
    Dec 28, 2013
    Well, my initial thought was that any significant sudden change of the light level should bring the output high, but your aproach that only significant sudden drops of light level is better since my presence close to it won't make the place brighter. At least literaly :)

    I dont mind the output to be noisy for quite some time after the 1st high state of the output(that will trigger the uC interrupt).I will disable that interrupt for about 10-15secs till the uC reenables that interrupt and goes back to power down mode and waits for the next interrupt.

    The uC will operate on 5V, an input is considered high by my uC as long as input(in V)>=0.6Vcc. So any output below 3V wont triger it.

    I dug out this A6393S http://pdf1.alldatasheet.com/datasheet-pdf/view/40207/SANYO/LA6393S.html Looks close to the specs you mentioned.

    Good point Adam, the lighting bullbs in my house work at 50Hz, i guess a 1nF cap should stop the inverting input varying because of that. Right?

    Scan-131229-0002.jpg
     
    Last edited: Dec 29, 2013
  7. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,186
    2,692
    Jan 21, 2010
    It doesn't look bad. But notice that the common mode range only goes up to Vcc - 1.5V.

    What is your power supply? Do you have a higher voltage rail to run the comparator from? Both the output load resistor and the LDR can be tied to +5V which should give you the correct voltage swing and keep the inputs happy.

    I suggested 100nF would give a time constant of 1 sec, so a 1nF would give a time constant of 10 mS, that's probably not good enough to eliminate mains hum. I'd perhaps go 4.7nF.

    That means you'd have the 100nF (0.1uF) cap Cx from the non-inverting input to ground, and a 4.7nF C2 from the inverting input to ground (as you've shown).

    It would give a poor-,man's band-pass filter which should detect relatively fast things like a hand being waved over the LDR, but be less sensitive to both high frequency (in this case 50Hz is high frequency) and very low frequency signals (such as the sun setting). If the device can see daylight, a cloud passing over the sun might be detected...
     
  8. Ban84

    Ban84

    7
    0
    Dec 28, 2013
    My power source will probably 6 AA batteries (9V) since i use a 7805(2V dropout voltage) to get the 5V for the uC
     
  9. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,186
    2,692
    Jan 21, 2010
    An LM393 would probably do the job well and do it while operating from a 5V rail.
     
  10. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,186
    2,692
    Jan 21, 2010
    OK, you could operate the comparator you've chosen from the unregulated input voltage and that would keep the inputs within the range required for correct operation.
     
  11. Arouse1973

    Arouse1973 Adam

    5,164
    1,078
    Dec 18, 2013
    Hi Steve
    4.7nF is way too low, with say 50mV of noise coming in this will only reduce to about 48mV. You will need something like 1uF to give you about 3mV. But this still could trigger the circuit. Why not try a capacitor across the inputs so both inputs will see the same signal. I do this as part of an EMI filter for front end op-amp circuits. You might need to add some series resistance to both pins after the cap to increase your phase margin.
    Thanks
    Adam
     
  12. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,186
    2,692
    Jan 21, 2010
    1uF is used on the other input to give a time constant of 1 second. -- Except I shouldn't do math in my head. Cx should be 10uF, and C2 0.47uF (and that's pretty close to your estimate of 1uF.

    A 1V input signal at 50Hz will be attenuated to about 70mV. I wouldn't expect you'd see a 1V signal in most cases, and you should have at least that 70mV of margin except possibly at very low light levels.

    Thanks Arouse1973 for effectively checking my math!

    So, Ban84, Cx 10uF, C2 0.47uF
     
  13. Arouse1973

    Arouse1973 Adam

    5,164
    1,078
    Dec 18, 2013
    No probs Steve. One other thing to mention is that the output stage of most comparrators are open drivers. They will need a pull up resistor unless you use one with push pull output.
    Thanks Adam
     
  14. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,186
    2,692
    Jan 21, 2010
    Yeah, I think I mentioned that a few times, but it's worth mentioning again because it's an easy one to forget!
     
  15. Ban84

    Ban84

    7
    0
    Dec 28, 2013
    Hey guys, I did some tests yesterday. After wasteing about 1 hour trying to find out what was the wrong with my 1st circuit useing the A6393 I found out that none op amps of the package was working, i went for the only other available op amp I have right now, the 741 (the Lm393 might take some time to come).

    I removed the caps and i set the 2 potentiometers so that the circuit had the desired sensitivity. I found the values as they are shown in the scematic below. I skipped the second cap for now since i was doing all the tests eather in daylight or with battery powered light.
    So by that time the led was on when the light level was low and of when light level was high.
    Scan-1.jpg

    The problem is that whatever cap(even big ones) i tried in Cx place it seemed to have no effect .The circuit continued to respond just like the way it did without the cap. Shouldn't be there only a pulse when the light levels dropped,or if that pulse was to short to see with bare eyes, shouldnt it just look off all the time?

    You mean that the circuit should be like this?
    Scan-131229-0002a.jpg
     
    Last edited: Dec 31, 2013
  16. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,186
    2,692
    Jan 21, 2010
    Both of your circuits are the same, but the pull-up on the output is correct as shown.

    However if you used a pull-up, you would never use a load like you have there.

    What response are you getting? Without Cx, there should never be a response (practically, there might be because weird things happen when you use the inputs out of their appropriate range, and you possibly are for a 741. (OK, for a 741, the inputs should not go closer than 3 volts from the supply)

    Once you have the correct device, the behaviour you should see is that when you interrupt the light, you will see the output go high for a while, then it will go off. The length of time is proportional to both Cx and the difference in light levels.

    Did you kill the LA6393? Without a pull-up resistor, it might appear broken. The other option is to place the output LED (and resistor) between the output and Vcc. This will appear the opposite to what you want (it will be on when the output is off), but that's not too hard to interpret. The problem with the LA6393 is the inability to take the inputs near the +ve rail. If you wire the inputs as you have here (LDR to +5V) then you should be fine.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-