# Comparator or Microcontroller

#### atferrari

Joined Jan 6, 2004
4,235
Hola Francisco,

Your table in post #21 is still valid? Could you give an idea of how fast things could change? What is the window around both 45 degrees values where both need / could be off? Are we talking seconds or minutes?

If you could restate the problem from scratch I would be interested, more now that you went a long way in solving it. I you do not do it, it is still OK for me. Gracias.

#### ebeowulf17

Joined Aug 12, 2014
3,275
Hola Francisco,

Your table in post #21 is still valid? Could you give an idea of how fast things could change? What is the window around both 45 degrees values where both need / could be off? Are we talking seconds or minutes?

If you could restate the problem from scratch I would be interested, more now that you went a long way in solving it. I you do not do it, it is still OK for me. Gracias.
I'll let the thread starter answer the rest, but let me clarify one point from the table in post 21 that had thrown some people off: The deciding factor is the relationship between positions of sensor A and sensor B, not the relationship between either one and a fixed threshold.

So A>B or A<B matters, but A>45 is irrelevant.

#### ciscoasanchez

Joined Jan 26, 2016
32
I'll let the thread starter answer the rest, but let me clarify one point from the table in post 21 that had thrown some people off: The deciding factor is the relationship between positions of sensor A and sensor B, not the relationship between either one and a fixed threshold.

So A>B or A<B matters, but A>45 is irrelevant.
Thank you ebeowulf17 for clearing that up.
atferrari, time needs to be instant, the hydraulics move relatively fast, it takes less than 5 seconds to go from full open to full close.

My initial problem has been solved. The comparator circuit works great. I have setup two sensors, one is the "controller" and the other position sensor is reads the position of the hydraulics. I have it setup up on a test stand and it works flawlessly (so far). Now I would like to design some fail safe(s) into the circuit.

Each sensor works on 0.5V to 4.5V, but if one of them gets disconnected or shorts out, the hydraulics will continue to either open or close (trying to find equilibrium) until the hydraulic motor burns out or is powered off.

My new logic table is:
if A < B then FWD_RELAY ON & REV_RELAY OFF
if A > B then FWD_RELAY OFF & REV_RELAY ON
if A = B then FWD_RELAY OFF & REV_RELAY OFF
if A = 0VDC or 5VDC then FWD_RELAY OFF & REV_RELAY OFF
if B = 0VDC or 5VDC then FWD_RELAY OFF & REV_RELAY OFF

#### ciscoasanchez

Joined Jan 26, 2016
32
I think the best way to get what I want is to add a voltage window comparator circuit to this. Do you think that would work?

#### ebeowulf17

Joined Aug 12, 2014
3,275
I think the best way to get what I want is to add a voltage window comparator circuit to this. Do you think that would work?
Sounds right, although I think you'd need two; one for each input. The outputs from your added comparators could drive transistors that pass or block the signals from your original comparators.

I keep thinking there's probably a simpler way to approach this, but haven't thought of anything so far.

#### ciscoasanchez

Joined Jan 26, 2016
32

I am having an issue. The Sim shows this should work, however in practice Q4 and Q3 do not react to drop in voltage.

#### KL7AJ

Joined Nov 4, 2008
2,229
First off, I am a mechanical engineer, yet I am the most electrically minded at my company which does not have an electrical engineer. So I have become the unofficial electrical engineer.

I am working on redesigning a mechanical hydraulic controller. I want to use two position sensors (A and B) that operate on 0.5V to 4.5V

This is what I want to happen:
When A = B, Switch 1 and 2 are off. (I also want to have a tolerance here)
When A > B, Switch 1 is on.
When A < B, Switch 2 is on

I know how to program this into a arduino, I only know very little of Comparator Circuits so I am not sure how to even proceed with something like that. This will be a hydraulic controller that will be installed on fishing boats and work boats so it needs to be resilient.

If this is possible without using a microcontroller that would be ideal, but I need help.
Although I really like doing things with Arduino.....the technology makes it real tempting to drive a thumb tack with a sledge hammer. Comparators are wonderful things.
What you are looking for is a Comparator with some HYSTERESIS built in.
http://www.ti.com/lit/ug/tidu020a/tidu020a.pdf

I'm sure it will do JUST what you want...and nothing more.

#### ian field

Joined Oct 27, 2012
6,539
First off, I am a mechanical engineer, yet I am the most electrically minded at my company which does not have an electrical engineer. So I have become the unofficial electrical engineer.

I am working on redesigning a mechanical hydraulic controller. I want to use two position sensors (A and B) that operate on 0.5V to 4.5V

This is what I want to happen:
When A = B, Switch 1 and 2 are off. (I also want to have a tolerance here)
When A > B, Switch 1 is on.
When A < B, Switch 2 is on

I know how to program this into a arduino, I only know very little of Comparator Circuits so I am not sure how to even proceed with something like that. This will be a hydraulic controller that will be installed on fishing boats and work boats so it needs to be resilient.

If this is possible without using a microcontroller that would be ideal, but I need help.
A very simple solution is to use the window comparator in a 555 timer chip - but it can be tricky landing the threshold points just where you want them.

The input stage is a pair of comparators with reference points at 1/3 and 2/3 of Vcc. The pin marked CV on the datasheet gives access to one of those thresholds, so you can pull that off its set value with an external resistor. The only way of shifting the other threshold is by varying Vcc. The 2 comparators feed to a SR flip-flop, so you get good clean switching.

Years ago I used that trick to sense temperature on a temperature controlled Ni-Cd fast charger. The Vcc was supplied by a LM317 adjustable regulator and the CV pin had a preset pot. It was a little fiddly to set up but when done, it worked a treat.

#### ciscoasanchez

Joined Jan 26, 2016
32
I have realized I am ok with not having an upper limit, what I really want it for the system to not send signals to the relays when the voltage is less than 0.5VDC.

#### slackguy

Joined Feb 11, 2016
67
i would wonder why a fishing boaat needs a hydraulic controller

i'd next wonder what your plant are for protecting (transitors ) from shorting

why not a nice 3 pole switch?

#### ebeowulf17

Joined Aug 12, 2014
3,275
[Deleted this comment]
I think I misunderstood the previous comment when I last read it. Disregard my now-deleted comment.

Last edited:

#### ebeowulf17

Joined Aug 12, 2014
3,275
View attachment 100587
I am having an issue. The Sim shows this should work, however in practice Q4 and Q3 do not react to drop in voltage.
I'm confused on so many levels now:
1) It looks to me on your output graph like your outputs are disabled when either input is at 0V, so that appears to be working, at least partially.
2) I still can't wrap my head around how outputs on Q1 and Q5 are set up. There must be a connection I'm not seeing, or this is a configuration I'm not familiar with (I know there are a million clever ways to use BJTs, and I only understand a few of them.)
3) It appears that all of the output logic states are the opposite of what you want. You said before that your "amp" input is active low (turns the pump on when the input terminal is grounded) which means that you need your outputs to drop to 0V when you want them to be turning the pump on, and means that you can only allow one output at a time to be at 0V, or you'll effectively be telling the pump to go in both directions at once. As it stands, during what should be pump-off conditions, both outputs show 0V.

It looks like (maybe?) this whole thing is almost working perfectly, except that the output stages need to be reversed. Could you upload your .asc file (the LTspice sim file) so that I can understand the connections that are confusing me? There's still no guarantee that I can help, because this could very well be legitimate transistor applications that I'm not well versed in, but there's a chance that I can help after playing with the LTspice file.

#### ciscoasanchez

Joined Jan 26, 2016
32
So I have actually figured out how to get this working, I am actually going to use the comparators that sense a low voltage to open a reed relay. The reed relays are in series with each other and connect the npn transistors to ground. I actually ordered a couple of pcbs to start assembling this. The breadboard prototype works great, so here hoping I build the circuit correctly for a pcb.

#### ebeowulf17

Joined Aug 12, 2014
3,275
So I have actually figured out how to get this working, I am actually going to use the comparators that sense a low voltage to open a reed relay. The reed relays are in series with each other and connect the npn transistors to ground. I actually ordered a couple of pcbs to start assembling this. The breadboard prototype works great, so here hoping I build the circuit correctly for a pcb.
If you haven't already done so, you may want to put flyback diodes across the relay coils to protect your comparator outputs. I know reed relays use relatively small coils, so maybe the risk is lower than with typical relays, but I imagine the inductive kick could still be damaging.

Glad to hear you've got it working the way you want. Congrats!