Op Amp/Comparator with a Digipot

Thread Starter

spmaddox

Joined Nov 29, 2018
49
I've been busy the past few weeks working to better understand the basics of ohms law. I believe I properly comprehend it now as well as some aspects of the various components available to use to accomplish my objective here but I'm looking for some validation as well as guidance with respect to how the digipot actually works. Here I am using the ADCMP393 comparator and the AD5206 digipot, both from Analog Devices.

The circuits I'll need to build to the capability of monitoring will come in 7 different variations, the only variables between them is how many resistors (0, 1 or 2) are deployed along the circuit externally to my controller and what their resistance is. If there are 2 resistors they are always in series with one on the high side and the other "around" the load. If there is only 1 resistor it should always be "around" the load. By "around" the load I mean it is deployed such that it bridges the gap between the two sides of the reed switch, if the switch is open there is still current & voltage flowing back to the controller on the low side.

The 7 circuit configurations are;
  1. No resistors
  2. 1 1k ohm EOLR "around" the reed switch
  3. 1 2k ohm EOLR "around" the reed switch
  4. 1 5600 ohm EOLR "around" the reed switch
  5. 1 1k ohm on the high side + 1 1k ohm EOLR "around" the reed switch
  6. 1 2k ohm on the high side + 1 2k ohm EOLR "around" the reed switch
  7. 1 5600 ohm on the high side + 1 5600 ohm EOLR "around" the reed switch
In my calculations I've assumed that all resistors external to the controller (ie: those put in place by the installer) are 20% tolerance. I've also accounted for 20 ohms of resistance from the cabling between the controller to the reed switch and back to the controller and the reed switch itself; that is based on measurements I took on a 500' spool of stranded copper. Additionally my calculations take into account a temperature range of -50F to 120F. Given the circuit configurations above, cable/switch resistance and temperature range I've calculated the following voltage value/range for each circuit with the voltage measurement being taken on the high side of a 10 ohm .01% tolerance resistor at the low side of the circuit (ie: after the circuit returns to the controller);
  1. No resistor
    1. Open = 0V
    2. Closed = 497.81mV - 505.23mV
  2. 1 1k ohm EOLR
    1. Open = 16.1mV - 24.1mV
    2. Closed = 497.81mV - 505.23mV
  3. 1 2k ohm EOLR
    1. Open = 8.16mV - 12.32mV
    2. Closed = 497.81mV - 505.23mV
  4. 1 5600 ohm EOLR
    1. Open = 2.95mV - 4.47mV
    2. Closed = 497.81mV - 505.23mV
  5. 1 1k ohm on the high side + 1 1k ohm EOLR "around" the reed switch
    1. Open = 8.16mV - 12.32mV
    2. Closed = 16.06mV - 24.06mV
  6. 1 2k ohm on the high side + 1 2k ohm EOLR "around" the reed switch
    1. Open = 4.11mV - 6.24mV
    2. Closed = 8.16mV - 12.32mV
  7. 1 5600 ohm on the high side + 1 5600 ohm EOLR "around" the reed switch
    1. Open = 1.48mV - 2.25mV
    2. Closed = 2.95mV - 4.47mV
The intent is to use the comparator to signal high (>2.4V) when the circuit is closed and low (<0.7V) when the circuit is open. For circuits 1 - 4 that would seem to be pretty straight forward if I set the low side of the comparator to anything up to 497mV though I'd look to use 400mV. For circuits 5 - 7 it is more challenging, they are the reason i've included the digipot. The digipot is where things are getting less clear for me. I am not sure how to apply or calculate in the various terminal resistance options nor am I sure I am understanding the application of the resistance. I am looking specifically at the AD5206 which has terminal resistance of 10k ohms, 50k ohms and 100k ohms and 256 positions available to specify resistance levels; my interest in it is because I can specify resistance position for each channel independently. I would be using the AD5206 as a potentiometer

My thinking is I could supply the AD5206 A terminals with 400mV. For circuits 1 - 4 I would apply no resistance at the digipot resulting in 400mV being supplied to the low side of the comparator for that circuit; the result being the comparator output is high for a channel until high input falls below the 400mV. For circuits 5 - 7 I would need to apply resistance. if I am understanding the documentation properly with 400mV applied to terminal A each resistance position (ie: 1/256) equates to a voltage drop of 1.5625mV, is this correct? If correct then I would need to set the resistance position for circuits 5, 6 & 7 at;

5. 8, 9, 10 or 11 (8 on the low end, 11 on the high end) which would provide a low side comparator voltage of between 12.5mV and 17.1875mV which should trigger the comparator to swing from high to low output when its high side input falls below those values
6. 4, 5 or 6 (4 on the low end, 6 on the high end) which would provide a low side comparator voltage of between 6.25mV and 9.37mV which should trigger the comparator to swing from high to low output
7. 1 or 2 (1 on the low end, 2 on the high end) which would provide a low side comparator voltage between 1.5625mV and 3.125mV which should trigger the comparator to swing from high to low output

See the attached circuit diagram which illustrates the above. You'll find the same configuration on the top and the bottom of the diagram, the top shows and notates the situation with the reed switch open while the bottom shows and notates it with the reed switch closed.

I've also not designed this to address hysteresis, not sure if I should and would appreciate input/guidance there.

thx - sean

upload_2019-3-18_15-23-39.png
 

pmd34

Joined Feb 22, 2014
529
Hi spmaddox, its a little unclear what you are actually trying to achieve, and your circuit is rather small to see clearly.
So far the main question is.. why dont you use an analog to digital converter to get these many different voltages you refer to?
 

Thread Starter

spmaddox

Joined Nov 29, 2018
49
Hi pmd34 - apologies for the size, i've cropped it to show just a portion of the full image and included both the digipot and the comparator.

What I am trying to do is monitor the state change of the reed switch in the circuit. I've considered measuring volts, amps, volts+amps (allowing me to calculate ohms and watts) on both the high and low side and using the change in these as indicators of the reed switch status before settling on voltage on the low side as i've illustrated.

I also considered using an ADC, that is actually where I started. With the ADC approach I would either 1) need to constantly poll the ADC to detect change or 2) use an interrupt like mechanism to notify my program that a state change has been detected after which I would poll the ADC only for the specific channel (ie: circuit) on which the state change occured. With constant polling I will consume more CPU than is necessary as I loop through channels, I would need a fast ADC and I'd have some delay between the actual state change of the reed switch and its detection. The interrupt method resolves those issues with the comparator providing me what amounts to an interrupt by holding the output either high or low based on its input but if all I care about is detecting the actual state change and not the actual value of the voltage the ADC isn't necessary any longer so I've not included it.

The challenge is that each circuit can be 1 of the 7 types I defined previously; the difference between the 7 circuits is the amount of resistance and where that resistance exists. To address that variability I've included the digipot. At system setup the digipot will be "tuned" to the type of circuit detected; basically I will open and close the reed switch allowing my system to adjust the level of resistance for the circuit until it is able to detect both the open and the close events. This tuned value will be stored for each circuit and on system startup the digipot would be configured with this tuned value allowing the running system to detect the events.

Make sense?

My concern right now is whether or not I've comprehended the application of the digipot correctly. I'm unclear on the impact of the terminal resistance and its effect on the resistance applied to each of the digipots wipers.


Analog DAQ (OpAmp + Digipot Closed).png
 

pmd34

Joined Feb 22, 2014
529
Hi spmaddox,

I'm afraid its still a bit of a mystery to me! So you have 7 (?) read switches, and if one changes state you want to know about it?
You could just use the "change of state" interrupt pins on a microcontroller. (Something like an ATMEGA microcontroller has PCInterupt options for all its i/o pins.)

To use a few less interrupt (specific) data lines you could use something like an SN54148 (10 to 4 line encoder / 8 to 3 line encoder). Wait for a "change of state" on one of the pins, and then do a check on all the switches to see which one changed.

For your rather device gready of voltage system, are you not really just replicating a simple form of binary counting.. which you could just do with fixed resistors doubling in value for each "Bit".

Anyhow... for your actual question!
The only information I could find in the data sheet was this:
Capture.PNG

So, so long as you stay within these current limits when loading the digi-pot you should be ok.
 

danadak

Joined Mar 10, 2018
4,057
I also considered using an ADC, that is actually where I started. With the ADC approach I would either 1) need to constantly poll the ADC to detect change or 2) use an interrupt like mechanism to notify my program that a state change has been detected after which I would poll the ADC only for the specific channel (ie: circuit) on which the state change occured. With constant polling I will consume more CPU than is necessary as I loop through channels, I would need a fast ADC and I'd have some delay between the actual state change of the reed switch and its detection. The interrupt method resolves those issues with the comparator providing me what amounts to an interrupt by holding the output either high or low based on its input but if all I care about is detecting the actual state change and not the actual value of the voltage the ADC isn't necessary any longer so I've not included it.
There is a way of doing this in ARM. Use a scanning comparator -

upload_2019-3-20_8-40-56.png

This will scan, using either a common - input for ref or an individual channel value
as shown generated by a preset channel Vdac. You can bring each channel state
out to pins or use ISR to service each time a new channel compare is met. Up to
64 channels but that is dependent on package and other requirements you have
for the processor and rest of chip.

The scan rate using DAC is .5 Mhz max, using a common channel ref its 10 Mhz
max. Looking at datasheet AC performance of comparator, 50 mV overdrive,
response time is 110 nS. Point of this is 10 Mhz mode may be a little tongue
in cheek.....inconsistent. But is still pretty good for an onboard processor
resource.

This is an ARM based PSOC, component list attached. A component is an onchip
resource.

Or you could use the scanning 12 bit SAR that is onchip.

As you can see from screenshot this uses a fraction of available resources in part.
Part used is PSOC 5LP family, it may also be possible to do in PSOC 4 low end, I
did not check that out. Right hand window shows resources used. Note Vref is on
chip also.

upload_2019-3-20_8-51-13.png


Regards, Dana.
 

Attachments

Last edited:

Thread Starter

spmaddox

Joined Nov 29, 2018
49
Is this an existing alarm system?
Yes sir. I have a Honeywell Vista 21P and a handful of friends have similar boards from Honeywell, Tyco and Bosch which we'd like to replace with something a lot smarter. I mentioned my background in compute and networking in our prior correspondence so all of the smarts I need once I can get the signalling from the sensors isn't an issue. It's just a matter of figuring out the sensor notifications. The systems use 1k, 2k and 5600 ohm resistors though each system only uses 1 type. Rather than build 3 different boards I want to solve it with 1 board. Plus I like to learn new things.

Make sense?
 

Thread Starter

spmaddox

Joined Nov 29, 2018
49
I'd read just a bit about the Hall Effect sensors when I started investigating, i'll do more research on them. Are there specific reasons I should consider going that route vs. the comparator & digipot route? I presume the potential to calibrate in software is a major one.
 

Ya’akov

Joined Jan 27, 2019
10,234
I'd read just a bit about the Hall Effect sensors when I started investigating, i'll do more research on them. Are there specific reasons I should consider going that route vs. the comparator & digipot route? I presume the potential to calibrate in software is a major one.
The Hall Effect sensor is very simple, and the ones set up for current measurement have a lot of stuff built in. Look for “hall effect current sensor”. Some use pins on the package, some a trace on the PCB under the package, etc.
 

Thread Starter

spmaddox

Joined Nov 29, 2018
49
Ah, I "think" I get the thinking...the Hall Effect sensor will generate a proportional voltage based on the current measured.

To do the comparison between the value being measured and what was calibrated during setup as the value that represents "open" and the value that represents "close" in my software I still need to get the analog voltage values into digital form which I would think brings me back to the ADC. If I'm back to the ADC I believe I'm back to a scenario where my software needs to poll each circuit which is something I'd need to do 2 - 3 times per second per circuit to avoid a noticeable delay between the actual change in the circuit state and that change being recognized.

The table below shows my actual values and calculated expected value ranges. What isn't shown is the resistance for each resistor as well as the cable/switch itself. I did factor temperature impact into the cable/switch resistance. Thank you again for the input last week, it helped me figure these out more correctly.

The column highlighted in green is V at the high side of the 10ohm .01% on the circuits low side (R4 in the table but listed in my diagram above as R2, R4 & R6 simply because of their relative placement in the diagram). The table shows a slightly different V than the diagram, this is because I found an error in my prior calculations...I was applying the temperature variance to the total resistance instead of just to the cable/switch.

To my question earlier in my response given what is shown in the Current (I) columns I would think that the Hall Effect sensor requires the ADC and polling, correct?

upload_2019-3-20_10-50-22.png

thx - sean
 

Thread Starter

spmaddox

Joined Nov 29, 2018
49
I looked at doing the low end part, PSOC 4, looks also like it
would fit the bill.

Boards to use -

https://www.cypress.com/documentati...oc-5lp-prototyping-kit-onboard-programmer-and



or low end

https://www.cypress.com/documentati...s/cy8ckit-043-psoc-4-m-series-prototyping-kit




Board sizes shown not actual size.
Regards, Dana.
Hi Dana - thank you for the response, i'll look into these. I may come back with more questions but will research myself until i hit a roadblock.
 

Thread Starter

spmaddox

Joined Nov 29, 2018
49
I'm new to electronics and electrical circuit things such as this
So how come you don't just use multiple inputs and interrupts on a microcontroller?
I'm new to this type of stuff, my background is in data networking, compute, systems & software...hardware engineering like this isn't something i've done before. What I want is to raise visibility of the state change to my software which will be running under Linux on a SOC such as a Raspberry Pi CM3+ Lite.

I'm open to all advice, is there something you could point me to as a reference?
 

pmd34

Joined Feb 22, 2014
529
Ah ok, I just thought there was something I was missing about how it's all working!

I have not got into RPi myself, I usually use Atmel AVR microcontrollers. A typical example is the ATmega 88. It has 23 I/Os and you have the possibility of programming any number of them to produce an "interrupt request". This means if any of the pins changes state your code jumps from its routine operation to an interrupt routine. In the case of multiple interrupt lines, you would then get the MC to see exactly which one had triggered and whether it went high or low etc. and then respond accordingly. Its typically used for keyboard operations so you don't have to continuously scan the keys to look for an event.

I guess the RPi should have something very similar!
 
Top