PDA

View Full Version : A logic gate chip with 1 ea XOR and 2 ea AND gates?



jellis00
- 25th June 2009, 20:28
I am using a PIC16F690 in an application which will control a valve solenoid. The solenoid requires reversing the polarity of the signal to latch open or latch closed the valve. I am using two output pins in the MCU to turn on or off two DPDT relays so that I can switch the polaritiy from a 9 v battery output to the solenoid: 1) MCU Pin1 turning on one relay that is Normally Open (NO) connects the +9 v to the redwire and GND to black wire of the solenoid...turning on the other relay that is NO connects the GND to the redwire and +9 v to the black wire.
The problem I need to solve is how to make sure as a fail safe that both relays are never activated at once by the MCU when it may be going thru powerup or register settings, which means I need a logic circuit connected to the two PIC output pins with the following logic outputs to the relays so that only one of the relays can ever be turned on:
Pin 1 Pin2 RL Output1 RL Output 2
0 0 0 0
1 0 1 0
0 1 0 1
1 1 0 0 'This state is the fail safe!
I have determined the logic circuit to do this is a 2-input XOR gate with its output wired to one of the inputs on each of 2 AND gates, and the individual inputs to the XOR gate also connected to the other input of each of the AND gates. My question is, where can I find a single DIP IC chip that contains at least one, 2-input XOR gate and two, 2-input AND gates, which I can then wire up per above on my MCU circuit board?? I tried to find a CMOS chip that combined these different types of logic gates with no success. Anyone know where I can find one and the part number?

aratti
- 25th June 2009, 21:27
jellis00, it is not clear how you have connected the two relays to the solenoid, but if you use the schematic attached you will have no fail safe problem.

Al.

Melanie
- 25th June 2009, 22:01
Most PICs power-up with the I/O's in Analog or Input Mode.

If your first commands set the Relay I/O's to whichever the Failsafe state is, followed by the TRIS for those I/O's, you should not experience any problems.

There is a gotcha here... that IF your I/O's are driving something like a ULN2004 or similar High-Current Driver, and you are using a Port with internal Global Pull-Up's (like PORTB on a 16F628), then the act of switching-ON the internal Pull-ups BEFORE you've set any I/O's to OUTPUT would be enough to flip them into an undesired state.

So the rule is... immediately on Power-Up...

1. Set your OUTPUTS to the desired High/Low state
2. Disable any ANALOG
3. Set appropriate TRIS for that PORT.

Worst case scenario, is that Relays take a few mS to react, and if you mess up you might pulse the Relays with a few uS in the wrong state... theoretically, it shouldn't affect things... anyone with a Pacemaker please step forward for an experiment...

jellis00
- 26th June 2009, 03:58
it is not clear how you have connected the two relays to the solenoid
Attached is a schematic as to how I am connecting the PIC outputs to the RELAYS to control the SOLENOID via its RED and BLACK wires. This shoulld permit switching of the polarity to the RED BLACK wires depending on which control pin is active??
I guess if I follow the steps from Melanie's email I can do this without inserting the 2XOR and Dual 2AND gates in between the two PIC control pins and the two relay coils??????

aratti
- 26th June 2009, 06:56
This picture should be more clear.

Al.

Edit: picture is too small to see details, I attach a zipped one

jellis00
- 26th June 2009, 07:35
aratti,
Thanks for the schematic. Yours is a better approach than mine because it only requires two SPDT relays instead of two DPDT relays...cheaper! However I am a little concerned about whether "nothing happens" in your circuit for the state where both Relay 1 and 2 coils are turned on and both the Red and Black wires are connected to +9vdc. I am not certain what the latching solenoid does that I am looking at when both wires are high.
Have your ever tested or used your circuit with an actual latching solenoid? If so what was your experience and can you refer me to the Part No. for the one you used??

aratti
- 26th June 2009, 08:27
Latching solenoid are just a normal solenoid with the addition of a permanent magnet. When you connect the coil (Red to + and Black to 0) the magnetic field attract the iron core and when the core is in contact with the permanet magnet it will be hold without the need of the magnetic field generated by the coil. So to activate it you just keep the coil connected for a very short while.

If you need to de-activate the solenoid, you will need to generate in the core a reverse magnectic field so that the core will be pushed away from the permanet magnet holding it. To obtain such a result you simply reverse the current flow into the coil, connecting the Red to 0 and the Black to + and hoops the solenoid has released the core.

If you connect both wire to zero volts or both wire to +9 volts nothing will happen, and when I say nothing I mean it (no current will circulate at all), and the solenoid will keep is position. This is the max I can say to assure you.

Have a nice day.

Al.

falingtrea
- 26th June 2009, 19:13
Instead of putting the battery terminals on the common of the relay, put the solenoid terminals on the common pins, and use a DPDT relay. Wire the N.O. pins with power and ground and wire the N.C. terminals opposite of the N.O. ones. With a DPDT relay you only need one control pin also.

jellis00
- 1st August 2009, 16:35
This picture should be more clear.

Al.

Edit: picture is too small to see details, I attach a zipped one

Anrati, I have designed the Relay Circuit for use with my 16F690 MCU as shown in the attached partial schematic. As you can see, pin RC2 controls one of the two SPDT relays and pin RC3 controls the other. I have purposely wired the ground from the battery rather than the positive terminal to the normally closed contacts on the two relays so that in case there is any leakage in the Solenoid_RED or Solenoid_BLACK wire circuits it won't drain the battery when the relays aren't actuated.

Do you think this circuit will work? One of my concerns is finding a SPDT relay that can be operated within the 25 mA limit of the MCU output pin. Any suggestions where I can get one?3558

Archangel
- 1st August 2009, 18:42
Hi John,
Why not just use an H Bridge to control your solenoid ?

aratti
- 2nd August 2009, 15:19
Do you think this circuit will work?

Yes.


One of my concerns is finding a SPDT relay that can be operated within the 25 mA limit of the MCU output pin. Any suggestions where I can get one

See at this link they have reed relay @ 5V 10 mA.

http://www.americanrelays.com/dip.pdf

Al.

Charles Linquis
- 2nd August 2009, 19:15
When I need a strange combination of logic gates that doesn't have to be exceedingly fast, I usually use a small PIC (12F series for example). Small, cheap and can be programmed to any function I need. The best part is that if I want to change something later, I can do it with programming instead of X-acto knives and little blue wires.

bogdan
- 2nd August 2009, 20:13
L293d

tle 5205-2

jellis00
- 2nd August 2009, 23:23
Yes.



See at this link they have reed relay @ 5V 10 mA.

http://www.americanrelays.com/dip.pdf

Al.

My 16F690 MCU is operating at 3.3 vdc. Therefore I need a relay (SPST or SPDT) whose coil voltage is 3.3 vdc with a coil resistance of 132 ohms or more, and a contact rating for 1 Amp when switching and 0.5 Amps when closed:
3.3 vdc/.025 ma = 132 ohms
Do you know of any sources? I have looked high and low with no success...most have coil resistances that require drive of 50 mA or more which is above 1-pin drive capabilty of the 16F690 and I didn't want to have to use more than one pin to trigger the relay.

I have read that many of the 5V reed relays will still operate at 3.3vdc. What do you know about this?

I appreciate your help. I am going to investigate the suggestion to use an "H-Bridge", but I know nothing about them. Can you point me to any good tutorials on H-Bridges for controlling solenoids that require more current than a PIC will provide?

bogdan
- 3rd August 2009, 00:14
what is the model # of your solenoid valve ?

Archangel
- 3rd August 2009, 06:21
I appreciate your help. I am going to investigate the suggestion to use an "H-Bridge", but I know nothing about them. Can you point me to any good tutorials on H-Bridges for controlling solenoids that require more current than a PIC will provide?
http://www.mcmanis.com/chuck/robotics/tutorial/h-bridge/bjt-circuit.html
http://www.cadvision.com/blanchas/hexfet/np-s.htm
http://www.4qdtec.com/h.html
The simplest 4 transistor h bridge:
http://library.solarbotics.net/circuits/driver_4varHbridge.html

jellis00
- 4th August 2009, 19:13
what is the model # of your solenoid valve ?

bogdan,
Our PIC microcontroller must control a latching valve solenoid, Model L 1/180 1/4"x1/4" as described at http://www.giplindia.com/pdf/water-valve-catalogue.pdf . Here is a description from this document and why we think it is the right choice for use with a microcontroller and battery operation. BTW, why do you ask?
"Brief Design Guide:
􀀹 Life of battery (1.5 V DC X 4 Nos. alkaline) is about 250 000 cycles (only valve
operations).
􀀹 Latching valve operates upto 5 V DC, 60 mS pulse. Hence cicuit should have cut off
voltage or battery low / replace battery indication sutabley.
􀀹 It is prefered to mount latching valve in coil up right position.
􀀹 As supply voltage goes higher pulse width decreases.
􀀹 40 mS pulse is optimum pulse width for valve operation from CLOSE to OPEN
position. For OPEN to CLOSE pisition, pulse width of 20 mS may be kept. This will
maximize battery life.
􀀹 Circuit employed in operation of valve should be of high quality and should have
minimum current consumption in stand by mode to maximise battery life.
􀀹 Test figures mentioned in this document is based on 6 V DC obtained using 1.5 V X 4
Nos. alkaline batteries."

jellis00
- 4th August 2009, 19:23
http://www.mcmanis.com/chuck/robotics/tutorial/h-bridge/bjt-circuit.html
http://www.cadvision.com/blanchas/hexfet/np-s.htm
http://www.4qdtec.com/h.html
The simplest 4 transistor h bridge:
http://library.solarbotics.net/circuits/driver_4varHbridge.html
Joe: I studied the H-Bridge circuit and I can see now why it is probably the preferred choice for microcontroller use with motor control, and I presume it can be applied in same manner for controller of latching solenoids. Therefore, I have redone our design as shown in the attached schematic, in which we propose to use a ROHM H-Bridge IC model BD6211 or BD6221, depending on what battery voltage we select for solenoid control (see http://www.rohm.com/products/databook/motor/pdf/bd622x_series-e.pdf for data sheet). This IC can be purchased for $1.50 USD at Mouser and greatly reduces the cost and simplifies the circuit layout as compared to using relays. What is your opinion of this schematic?....will it work to control the latching solenoid without fear of "shoot through" during startup of the MCU while it is being initialized and the MCU pin logics are not yet stabilized? At this point that is my only concern about using the H-bridge for latching solenoid control.
Thanks so much for this tip!

bogdan
- 5th August 2009, 00:22
..the clamp diodes are missing...

I think is easy with L293D (internal clamp diodes)...if you combine the channels you have Peak Output Current=1.2A (check the specs of the solenoid)

If you need more current use TLE 5205-2 (peak=6A)

Both of the items should be at mouser.com

...please check also this tutorial to understand better the h-bridge circuit http://www.robotroom.com/HBridge.html

jellis00
- 5th August 2009, 01:56
..the clamp diodes are missing...

I think is easy with L293D (internal clamp diodes)...if you combine the channels you have Peak Output Current=1.2A (check the specs of the solenoid)
]

Granted I forgot the external clamp diodes, but I can't see why you think using the L293D is an advantage over the Rohm BD62x1. Here are compairsons that appear to favor the BD62x1:

Operating range: BD62x1 will run with Vss 3 to 36 v; L293D is 4.5 to 36. This is important to me since my board supply is 3.95 vdc (3 ea AA NiMH batteries);

Quantity 1 price at Mouser: BD62x1 = $1.50; L293D = $5.12....even adding the 4 ea clamp diiodes (1N4001??) BD62x1 approach is a lot cheaper;

Low Stanby current: BD62x1 has standby mode = 10 microAmps; L293D has quiescent current total (Vss + Vx) of at least 18 milliAmps dey pending on logic setting.....this is too high for battery operation.

Based on above comparison I wouldl really appreciate your opinon as to why the L293D is preferable. ???

jellis00
- 5th August 2009, 02:14
Granted I forgot the external clamp diodes, but I can't see why you think using the L293D is an advantage over the Rohm BD62x1. Here are compairsons that appear to favor the BD62x1:

???

Taking a closer look at the Rohm data sheets for their BD622x chips, it appears they also have internal clamp diodes, making it a further advantage for the BD622x1 over the L293D. The chip diagram from data sheet is in the attached image. Am I mis-interpreting this image??

Archangel
- 5th August 2009, 05:29
Sorry for the delay, my ISP is sooooo lame!
Lots of HBridge chips out there, allegro makes a bunch of them, It trumps relays due to cost, reliability, size and they look better too ;) even discrete transistors are still cheaper, smaller, and more reliable, though mosfets might be better than junction types.