Author Topic: Strange behavior comparator hysteresis - solved  (Read 2301 times)

0 Members and 5 Guests are viewing this topic.

Offline HendriXMLTopic starter

  • Super Contributor
  • ***
  • Posts: 1085
  • Country: nl
    • KiCad-BOM-reporter
Strange behavior comparator hysteresis - solved
« on: July 29, 2020, 08:24:00 am »
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 page https://www.maximintegrated.com/en/design/technical-documents/app-notes/3/3616.html would 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.)
« Last Edit: July 30, 2020, 08:58:35 pm by HendriXML »
“I ‘d like to reincarnate as a dung beetle, ‘cause there’s nothing wrong with a shitty life, real misery comes from high expectations”
 

Offline HendriXMLTopic starter

  • Super Contributor
  • ***
  • Posts: 1085
  • Country: nl
    • KiCad-BOM-reporter
Re: Strange behavior comparator hysteresis
« Reply #1 on: July 29, 2020, 08:33:32 am »
Could this be an effect of the gate drain capacitance of the mosfet?
“I ‘d like to reincarnate as a dung beetle, ‘cause there’s nothing wrong with a shitty life, real misery comes from high expectations”
 

Offline OM222O

  • Frequent Contributor
  • **
  • Posts: 768
  • Country: gb
Re: Strange behavior comparator hysteresis
« Reply #2 on: July 29, 2020, 08:44:57 am »
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 :D
« Last Edit: July 29, 2020, 08:53:54 am by OM222O »
 

Offline HendriXMLTopic starter

  • Super Contributor
  • ***
  • Posts: 1085
  • Country: nl
    • KiCad-BOM-reporter
Re: Strange behavior comparator hysteresis
« Reply #3 on: July 29, 2020, 10:36:40 am »
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.
The non inverting input is shared among 3 other comparators, so I did not want to disturb (load) that voltage. Hence this approach.
« Last Edit: July 29, 2020, 10:44:21 am by HendriXML »
“I ‘d like to reincarnate as a dung beetle, ‘cause there’s nothing wrong with a shitty life, real misery comes from high expectations”
 

Offline OM222O

  • Frequent Contributor
  • **
  • Posts: 768
  • Country: gb
Re: Strange behavior comparator hysteresis
« Reply #4 on: July 29, 2020, 10:55:24 am »
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.
The non inverting input is shared among 3 other comparators, so I did not want to disturb (load) that voltage. Hence this approach.

you 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  :-+
 

Online wraper

  • Supporter
  • ****
  • Posts: 17314
  • Country: lv
Re: Strange behavior comparator hysteresis
« Reply #5 on: July 29, 2020, 11:03:20 am »
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.
« Last Edit: July 29, 2020, 11:07:17 am by wraper »
 

Offline HendriXMLTopic starter

  • Super Contributor
  • ***
  • Posts: 1085
  • Country: nl
    • KiCad-BOM-reporter
Re: Strange behavior comparator hysteresis
« Reply #6 on: July 29, 2020, 11:38:41 am »
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.
“I ‘d like to reincarnate as a dung beetle, ‘cause there’s nothing wrong with a shitty life, real misery comes from high expectations”
 

Online wraper

  • Supporter
  • ****
  • Posts: 17314
  • Country: lv
Re: Strange behavior comparator hysteresis
« Reply #7 on: July 29, 2020, 11:45:50 am »
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.
Then I have no idea why you need "grey" reference sensor. And how it makes any good rather than breaks proper operation of the thing.
 

Offline HendriXMLTopic starter

  • Super Contributor
  • ***
  • Posts: 1085
  • Country: nl
    • KiCad-BOM-reporter
Re: Strange behavior comparator hysteresis
« Reply #8 on: July 29, 2020, 11:57:30 am »
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.
Then I have no idea why you need "grey" reference sensor. And how it makes any good rather than breaks proper operation of the thing.
If 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.
“I ‘d like to reincarnate as a dung beetle, ‘cause there’s nothing wrong with a shitty life, real misery comes from high expectations”
 

Online wraper

  • Supporter
  • ****
  • Posts: 17314
  • Country: lv
Re: Strange behavior comparator hysteresis
« Reply #9 on: July 29, 2020, 12:38:50 pm »
If 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.
Heck 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.
« Last Edit: July 29, 2020, 12:42:39 pm by wraper »
 

Online wraper

  • Supporter
  • ****
  • Posts: 17314
  • Country: lv
Re: Strange behavior comparator hysteresis
« Reply #10 on: July 29, 2020, 01:00:31 pm »
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.
 

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 16898
  • Country: us
  • DavidH
Re: Strange behavior comparator hysteresis
« Reply #11 on: July 29, 2020, 03:57:13 pm »
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.
 
The following users thanked this post: HendriXML

Offline HendriXMLTopic starter

  • Super Contributor
  • ***
  • Posts: 1085
  • Country: nl
    • KiCad-BOM-reporter
Re: Strange behavior comparator hysteresis
« Reply #12 on: July 29, 2020, 10:38:05 pm »
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.

I'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.
« Last Edit: July 30, 2020, 01:35:33 pm by HendriXML »
“I ‘d like to reincarnate as a dung beetle, ‘cause there’s nothing wrong with a shitty life, real misery comes from high expectations”
 

Offline HendriXMLTopic starter

  • Super Contributor
  • ***
  • Posts: 1085
  • Country: nl
    • KiCad-BOM-reporter
Re: Strange behavior comparator hysteresis - solved
« Reply #13 on: July 30, 2020, 09:20:38 pm »
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 CALCULATIONS
  RowDistance                             : 12,52 mm
  StartTriggerA                           : 415,02 ms
  EndTriggerA                             : 425,84 ms
  StartTriggerB                           : 477,78 ms
  TimeBetweenTrigger                      : 62,76 ms
  ScanSpeed                               : 199,5 mm·s⁻¹
  ActiveTriggerTime                       : 10,82 ms
  TriggerActiveDistance                   : 2,16 mm


Which 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).
« Last Edit: July 30, 2020, 09:47:35 pm by HendriXML »
“I ‘d like to reincarnate as a dung beetle, ‘cause there’s nothing wrong with a shitty life, real misery comes from high expectations”
 

Offline HendriXMLTopic starter

  • Super Contributor
  • ***
  • Posts: 1085
  • Country: nl
    • KiCad-BOM-reporter
Re: Strange behavior comparator hysteresis
« Reply #14 on: July 30, 2020, 09:37:59 pm »
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.
My 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.
“I ‘d like to reincarnate as a dung beetle, ‘cause there’s nothing wrong with a shitty life, real misery comes from high expectations”
 

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 16898
  • Country: us
  • DavidH
Re: Strange behavior comparator hysteresis - solved
« Reply #15 on: July 31, 2020, 01:42:15 am »
I lowered the capacitor to 47 pF. This is just enough, 100 pF would be better.

I 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.
 
The following users thanked this post: HendriXML

Offline HendriXMLTopic starter

  • Super Contributor
  • ***
  • Posts: 1085
  • Country: nl
    • KiCad-BOM-reporter
Re: Strange behavior comparator hysteresis - solved
« Reply #16 on: July 31, 2020, 08:35:34 am »
I lowered the capacitor to 47 pF. This is just enough, 100 pF would be better.

I 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.

Nice info, I always wandered why the layout wasn't optimized for ease of routing.
“I ‘d like to reincarnate as a dung beetle, ‘cause there’s nothing wrong with a shitty life, real misery comes from high expectations”
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf