Optical detector circuit of rotation - request for opinions - Page 1
Forum section: electronics / beginners

author: necromncr
author_rank: Newbie
timestamp: August 02, 2015, 09:31:01 pm
content: Hi everyone!First short introduction since this is my second post - and I apologize for my broken English (I am not a native speaker). I am an electronics enthusiast and even went to local high school for 4 years while later on in life switching to programming as a carer mostly by chance. I have always been interested in electronics since I can remember and I would like to somewhat return to this hidden "love". I also love hobby RC and I have decided to combine these to to create something new.I am working on a project that includes RPM (wait, don't stop reading) of a RC brushless motor. But to make things difficult (and interesting) I have limitations on what I can do:- measurement must be made with optical means- measurement must be at least 10mm away from the motor- motor surface supported can be either non-reflective (black), partially-reflective (silver matte) or reflective (silver glossy)- output must be 3.3V compatible- it must detect 300RPM to 5000RPM.I have been using STM32F103 for the task with ChibiOS and I am achieving an error of 1% which I am quite happy with. That was under controlled input.My PROBLEM lies in the detector circuit. I have never really dealt with analog circuits in my past - my experience is mostly with digital stuff. What I am targeting is single 5V supply with CNY70 detector with either reflective tape for non or partially reflective surfaces and black tape for reflective. After few iterations I have implemented and (breadboard) tested the following principle:The exact schematics and values are like such:I realize the LM358 is a problem and am waiting for some low-noise, rail-to-rail opamps use the "real stuff". So far it looks promising but I would be gratuitous for your feedback.Things that bother me are:1) At 10mm distance CNY70 is not showing it's strength - not even by a long shot. The second opamp does the uA detecting quite nicely but if I boost up the amplification by increasing R3 value the oscilloscope shows lots of oscillations in the 660kHz area at about 100mVpp. They are only picked up when current through CNY70 transistor drops below 10uA (measured by multimeter). I tried adding a bypass 1Mohm resistor to the transistor and it did not help. Only after addition of C1 the oscillations were gone and the value seems to be affecting the shape of the detected current. I understand that as this is AC. What worries me is I have no idea why this works, how does this limit the frequency of detection and after all - isn't RC circuit a simple oscillator? Any better ideas?2) Maybe too early to be thinking about this - in early iterations I had errors due to noise on input which I solved using simple 555 rigged as schmitt-trigger. Here I can not use it since the output floats in the middle and is quite low - around 1V per detection of the tape. I was thinking of two options: Monostable one-shot timer and a schmitt-trigger. First one would trigger the first rise and cover the imperfections in the tape but is rather complex to implement while the second is more easy to implement and requires much more strict input to prevent false triggerings.Again sorry for my english - as a further excuse it really late here and words are blurring for me.Thank you all in advance for you questions and suggestions and best regards,J.edit: modified subject

author: Fank1
author_rank: Regular Contributor
timestamp: August 02, 2015, 10:11:46 pm
content: You could try connecting the "right hand" side of the 10K resistor to Vref and not to the output of the opamp.It should then function as a comparator.I didn't try it, just an idea.

author: necromncr
author_rank: Newbie
timestamp: August 03, 2015, 06:34:34 am
content: @Fank1 - if I set it up like that I would get pulse-trains due to noise like I mentioned in my second question.

author: rs20
author_rank: Super Contributor
timestamp: August 03, 2015, 07:05:39 am
content: A few comments:-- The CNY70 is really not designed for this use case, the datasheet is centered around an expected distance-from-motor of 0.3mm. You'd ideally want to be emitting some sort of beam, not just using a broad light source like that.-- Capacitor C2 slows down the op-amp, calms it down, and thereby prevents oscillation. Look up "op amp lowpass filter", you'll basically see your circuit. RC does not oscillate, LC does.-- You have an AC signal of about 1 volt, and you want to convert this into high/low pulses, right? So you might want to use an RC filter to get a smoothed out version of your signal (the "average" / DC bias part), and then use a comparator to compare that against your original AC signal. Then, when your signal is "above average", it'll output high, when it's "below average", it'll output low. You can add some feedback to the non-inverting input to give a little bit of schmitt-trigger action, to prevent undesired oscillation. Google "LM358 schmitt trigger".It's also worth asking whether it's worthwhile carefully crafting a high-gain I-to-V converter like this, only to convert it to a pulse train. Why not just convert it directly to a pulse train? Having said that, I support experimentation!

author: necromncr
author_rank: Newbie
timestamp: August 09, 2015, 08:46:03 pm
content: I have totally forgot to thank you both Fank1 and rs20. Just to have an update - using new optosensor RPR-220 I have managed to create clean signal that I can use in my project.So without further ado - the revised schematics:I have been using TLV2782 for the breadboard tests but LMV324 should be good as well but I am still waiting for the samples to arrive. Thank god for samples!Like said output is a clean signal that works without problems. I do not feel daring (or smart) enough to give it a go using comparator alike circuit that would detect level changes and do it all with 1 or 2 opamps. Output:.Once again I apologize for any kind of errors - I have only between weekends some time for myself and my ideas and it's late. Tired.

author: rs20
author_rank: Super Contributor
timestamp: August 10, 2015, 12:33:30 am
content: Looks nice! Just a few optional comments/questions:-- Are R5 and R6 both actually 10k? That's quite a lot of hysteresis!-- Regarding reducing the number of op-amps, you can probably just get rid of IC1G1: The input of IC1G2 are high-impedance, so they're not going to load down the R1/R2 divider at all. So unless you have something loading down the V_REF connection (in which case I would consider moving IC1G1 to buffer just the V_REF output), you can just get rid of IC1G1.-- Just in case you're not aware, the combination of IC1G4, R5, and R6 is a Schmitt trigger circuit, a kind of comparator with hysteresis. The inputs to the comparator are OPTO_SIG and V_AVG. If you swap those inputs around, the OUT output will be inverted, but the number of pulses per second will be exactly the same. Now you might be wondering what the point of swapping the inputs is, but:-- If you swap the inputs of the IC1G4/R5/R6 schmitt trigger, then IC1G3's output will be connected only to the IC1G4 inverting input, which makes it unnecessary just like IC1G1 (again, assuming that nothing significant is connected to V_AVG). So you could remove IC1G3 too.So just with those minor transformations, you can go from 4 op-amps to 2 op amps.And I know I'm the one who suggested explicitly tracking the average voltage and comparing against it, but now that I see the circuit I don't know why I didn't suggest just using a high-pass filter to remove the DC average instead, rather than explicitly calculating the average and then subtracting it.But anyway, your circuit works fine so you may as well leave it the way it is! These are just thoughts for further experimentation if you want.

author: necromncr
author_rank: Newbie
timestamp: August 11, 2015, 11:05:25 am
content: Thanks for your reply rs20 - I woke up at midnight because I had to work on this problem - it wouldn't leave me alone!Regarding R5 and R6 - my mistake. R5 is 1k.I totally agree regarding IC1G1 - I knew there was something to be done there but could not see it. Voltage divider directly to IC1G2 is functioning normally.Regarding schmitt-trigger inverting: I tried connecting it and the detection rate went down dramatically. I don't understand completely what is going on but I think the feedback from the output leaks back into RC circuit into positive input and makes a havoc. Output is step on positive transition but negative just floats somewhere to around middle where it drops down to "0" again.High pass filter - ha. This was my first (miserable) attempt in detecting but since I have RPR-220 now I might give it another try. The spikes would be much easier to detect and filter with schmitt trigger I think but I need to test it all again and I have only two rail-to-rail single supply opampsLocal suppliers are not equipped with this kind of opamps and ordering from abroad somewhat expensive.. Also I am guessing that would require just one opamp (schmitt trigger), maybe an additional for Vref?

author: necromncr
author_rank: Newbie
timestamp: August 13, 2015, 09:52:28 am
content: Just an update: the more I think about it and try to wrap my head around this "problem" the more clear it is to me: if I want to support both detecting reflection on non-reflective surface and non-reflection on reflective surface and keep it without false triggers I will have to make it using low-pass filter. This design reacts to fast changing inputs either way and is not susceptible to noise - which was proven in breadboard tests. I think 4-opamp chip solution it is.

author: necromncr
author_rank: Newbie
timestamp: August 20, 2015, 06:44:54 am
content: Is it OK regarding forum rules to rant on with myself to keep this updates if anyone else ever needs it?

author: rs20
author_rank: Super Contributor
timestamp: August 20, 2015, 06:56:04 am
content: Quote from: necromncr on August 20, 2015, 06:44:54 amSounds fine to me, there are plenty of threads just like that.Quote from: necromncr on August 13, 2015, 09:52:28 amIt's worth noting that a circuit that generates a lowpass version of an input signal, and then subtracts that from the input;is just a highpass filter overall. Just a rather weird and expensive way of implementing it (and yes, I did suggest it in the first place!) So I'm pretty sure you could take your 4-opamp solution and convert it to a 3 or 2-opamp solution that behaves exactly identically.