Strange behavior comparator hysteresis - solved - Page 1
Forum section: electronics / projects

author: HendriXML
author_rank: Super Contributor
timestamp: July 29, 2020, 08:24:00 am
content: My circuit consists of 5 reflective optical sensors. One is used as a reference (reflects gray). 3 respond to signal tracks. 1 responds to a trigger track, triggering the processing of the signal sensors.I don't want the trigger to bounce, so I added some hysteresis via a mosfet.However the trigger output oscillates before settling. Which is shown on the scope.Channel 1 is probing the inverting input, channel 2 is probing the non inverting input, channel 3 is probing the drain (3) of the mosfet (thus the hysteresis offset), channel 4 is probing the trigger output.What I can't explain is why channel 3 seems first to rise (several times) when the mosfet starts conducting.The circuit at this pagehttps://www.maximintegrated.com/en/design/technical-documents/app-notes/3/3616.htmlwould use a p-mosfet on the lowside, which seems odd to me. So I'm probably misunderstanding something.. (But the eventual voltage drop is as I would expect.)

author: HendriXML
author_rank: Super Contributor
timestamp: July 29, 2020, 08:33:32 am
content: Could this be an effect of the gate drain capacitance of the mosfet?

author: OM222O
author_rank: Frequent Contributor
timestamp: July 29, 2020, 08:44:57 am
content: it just seems like a really odd way to add hysteresis ... you can make a schmitt trigger like so:or like this:depending on your application and desired waveform. I have not seen a mosfet used for adding hysteresis but it seems possible, however the schmitt circuit has always worked very well for me.Edit: a simpler solution would be using schmitt input inverters after the comparators. if you don't want inversion, just invert it twice

author: HendriXML
author_rank: Super Contributor
timestamp: July 29, 2020, 10:36:40 am
content: Quote from: OM222O on July 29, 2020, 08:44:57 amThe non inverting input is shared among 3 other comparators, so I did not want to disturb (load) that voltage. Hence this approach.

author: OM222O
author_rank: Frequent Contributor
timestamp: July 29, 2020, 10:55:24 am
content: Quote from: HendriXML on July 29, 2020, 10:36:40 amyou can eliminate the hysteresis there and use schmitt input inverters like I mentioned. cleans up the signal without interfering with anything or needing additional circuitry. a simple hex inverter allows you to clean up 6 signals at the same time but like I said, the downside is the inversion so if that matters, just invert it again to get the original signal

author: wraper
author_rank: Unknown
timestamp: July 29, 2020, 11:03:20 am
content: Is this fed into MCU? If yes, drop all of this and use ADC. These sensors have quite loose spec and using common reference level for all is not good IME.

author: HendriXML
author_rank: Super Contributor
timestamp: July 29, 2020, 11:38:41 am
content: The circuit is used to determine the position in a sliding "key". Because the large difference between dark and light, this can be done reliable using the reference.The encoding below is consists of start and stop rows, and rows that can be used tot determine the direction the key goes. On the other side of the key magnets are used to get the "data" of each row.

author: wraper
author_rank: Unknown
timestamp: July 29, 2020, 11:45:50 am
content: Quote from: HendriXML on July 29, 2020, 11:38:41 amThen I have no idea why you need "grey" reference sensor. And how it makes any good rather than breaks proper operation of the thing.

author: HendriXML
author_rank: Super Contributor
timestamp: July 29, 2020, 11:57:30 am
content: Quote from: wraper on July 29, 2020, 11:45:50 amIf anything changes due to aging, the reference changes too. It also gives a way to change the reference (different key). The idea is to use it in a diy escape box. (Let the user create the key). So eliminating one sensor has no real benefits.

author: wraper
author_rank: Unknown
timestamp: July 29, 2020, 12:38:50 pm
content: Quote from: HendriXML on July 29, 2020, 11:57:30 amHeck no, it's a completely dumb idea. First of all, if you look into datasheet, (in certain conditions) minimum output current is 3.3 times lower than typical, maximum is not specified at all. Each sensor is vastly different and you will base your reference on what might be an outlier, not average. Secondly what is your grey surface is not clear and it may become dirty and discolored over time, not to say it most likely will not represent optimal level for distinguishing light/dark surface. What you need is that even in worst case scenario sensors must act on light surface with a good margin but still do not act on dark surface. If dark surface is dark enough, using properly selected pull-down (or pull-up) resistor values and LED current should be enough for getting logic level outputs directly from sensors. If you want hysteresis, add something like 74HC14 of CD40106. If you need any more accurate level detection, then use MCU with ADC and individually calibrate inputs. If you still want to stay with comparators, throw out grey sensor and use variable resistor for setting voltage reference.

author: wraper
author_rank: Unknown
timestamp: July 29, 2020, 01:00:31 pm
content: To make it clear. One sensor may look at white surface, another sensor on grey surface and both have identical output current due to their parameter variations. So for reliable operation even grey of medium to high-ish darkness should be detected as light surface. But dark surface should be either really dark or the best would be just a hole with no reflection at all. Also what looks dark to an eye, quite likely might be very reflective at IR spectrum these sensors operate at.Quite a long time ago I had an issue with that on line following robot competition. Black line on white surface which organizers prepared was almost as reflective as white at IR spectrum. So more than half of robots had an issue following it, including mine since I did not implement individual adjustments for sensors. And even those which performed fine, did so only after fine adjustments.

author: David Hess
author_rank: Super Contributor
timestamp: July 29, 2020, 03:57:13 pm
content: I am confused about what circuit you are using but that MOSFET circuit will oscillate if the resistances are too high because of capacitive coupling between the output and inverting input. Add a little bit of AC hysteresis with a capacitor between the output and non-inverting input.

author: HendriXML
author_rank: Super Contributor
timestamp: July 29, 2020, 10:38:05 pm
content: Quote from: David Hess on July 29, 2020, 03:57:13 pmI've added a "decoupling" resistor and the capacitor. Which seems to do the trick. I think the gate drain capacitance of the mosfet was causing it. The situation before the fix, with enhanced sensitivity:Channel 1 is probing the inverting input, channel 2 is probing the non inverting input, channel 3 is probing the drain (3) of the mosfet (thus the hysteresis offset), channel 4 is probing the trigger output.After the fix:As can be seen the drain potential is lifted, when the gate is pulled up and still under the threshold.

author: HendriXML
author_rank: Super Contributor
timestamp: July 30, 2020, 09:20:38 pm
content: I lowered the capacitor to 47 pF. This is just enough, 100 pF would be better.Then I did a full scan of this (in reverse)The response is this:A more detailed Excel graph is below.This shows how the sensors react relative to each other. Important is that the trigger lies between the position encodings.Also the trigger signal should not be covering to much distance.SCAN CALCULATIONSRowDistance : 12,52 mmStartTriggerA : 415,02 msEndTriggerA : 425,84 msStartTriggerB : 477,78 msTimeBetweenTrigger : 62,76 msScanSpeed : 199,5 mm·s⁻¹ActiveTriggerTime : 10,82 msTriggerActiveDistance : 2,16 mmWhich is 2.2 mm, about the size of the trigger bar. This can be made smaller by using a darker reference.This is important to know because the sensing of the magnets on the other side of the key must overlap this size. So that the data is always sensed when the trigger is fired.What is also shown is that the sensors act about the same. The scanning was done while lifting the sensors a bit above the key. This influences the sensitivity of the sensor a lot, but using a reference sensor might mitigate the difference.For this application the results are good enough. The circuit however draws 160 mA which is a bit much (battery power wise).

author: HendriXML
author_rank: Super Contributor
timestamp: July 30, 2020, 09:37:59 pm
content: Quote from: wraper on July 29, 2020, 01:00:31 pmMy laserprinted drawings luckily give a good distinction between white and black. I think the sensor saturates in both instance. My application of them is quit controlled in terms of measuring distance, angle, environment light, which give me some confedence in that they can work in a reliable way.

author: David Hess
author_rank: Super Contributor
timestamp: July 31, 2020, 01:42:15 am
content: Quote from: HendriXML on July 30, 2020, 09:20:38 pmI usually does not take much more than the parasitic capacitance which is causing the problem.Comparators really need to be used with low impedance sources. You also might notice that many comparators use an alternative pinout which routes the output away from the inverting input and closer the non-inverting input which is the opposite of an operational amplifier.

author: HendriXML
author_rank: Super Contributor
timestamp: July 31, 2020, 08:35:34 am
content: Quote from: David Hess on July 31, 2020, 01:42:15 amNice info, I always wandered why the layout wasn't optimized for ease of routing.