Author Topic: Is my circuit correct?  (Read 4187 times)

0 Members and 1 Guest are viewing this topic.

Offline redgearTopic starter

  • Frequent Contributor
  • **
  • Posts: 286
  • Country: us
Is my circuit correct?
« on: August 25, 2020, 08:48:19 am »
I am trying to send the trigger signal to the ULN2003A only if the switch are closed and there is a trigger from microcontroller. I used a two input AND gate and connected the output from switch and micro to its input. I want to know if this is the correct way to do it or is there a better way?

Thanks
 

Offline george.b

  • Frequent Contributor
  • **
  • Posts: 383
  • Country: br
Re: Is my circuit correct?
« Reply #1 on: August 25, 2020, 01:08:13 pm »
You'd probably want to debounce those switches. Use a small capacitor between SWOUT and ground.
Also, unless you need the µC to know the state of SWOUT independently, you could connect those switches to TRIG instead of +5V, so you wouldn't need the AND gate.
 
The following users thanked this post: redgear

Offline Renate

  • Super Contributor
  • ***
  • Posts: 1460
  • Country: us
Re: Is my circuit correct?
« Reply #2 on: August 25, 2020, 01:29:27 pm »
You're doing an overall 3 input AND, two switches and this TRIG signal.
Depending on safety consideration and whether this is some fail safe, you could do this logic anywhere.
Me? I'd feed the two switches separately to the µP and do the logic there.
This would also give you the benefit of identifying switch failures.
OTOH, if this goes to a detonator you want to have the logic near the output.
You could put the two switches on the output of the ULN2003 or even after the relay.
 
The following users thanked this post: redgear

Offline Manul

  • Super Contributor
  • ***
  • Posts: 1147
  • Country: lt
Re: Is my circuit correct?
« Reply #3 on: August 25, 2020, 01:48:50 pm »
It is good to have debounce on a switch. Software or hardware. If you use software debouncing, then you do not need AND gate, you can write this logic in your code and just output signal to drive ULN2003A.

If this switch needs to act independently from code, then you need to add hardware debounce. But simple debounce like resistor and capacitor will produce slow edges, so you need to use a gate with schmitt trigger inputs.
 
The following users thanked this post: redgear

Offline redgearTopic starter

  • Frequent Contributor
  • **
  • Posts: 286
  • Country: us
Re: Is my circuit correct?
« Reply #4 on: August 26, 2020, 04:01:46 am »
The AND gate is a fail safe mechanism for the circuit. I want the power to the relays to be cut-off when the switches are opened. The micro checks if the switches are closed and then if the start button is pressed, turns on the relay. But in the case of the micro failing(stuck in the infinite loop, I use the internal WDT but still want to be safe) or something, I want to be able to cut-off the supply once the switches are opened. Thus, the AND gate. I'm open to suggestions and would like to if there is a better way to do it.

You'd probably want to debounce those switches. Use a small capacitor between SWOUT and ground.
Also, unless you need the µC to know the state of SWOUT independently, you could connect those switches to TRIG instead of +5V, so you wouldn't need the AND gate.

Thank You! Will a 0.1uF cap be enough? Yes, the microcontroller should be able to read the output from the switches.

You're doing an overall 3 input AND, two switches and this TRIG signal.
Depending on safety consideration and whether this is some fail safe, you could do this logic anywhere.
Me? I'd feed the two switches separately to the µP and do the logic there.
This would also give you the benefit of identifying switch failures.
OTOH, if this goes to a detonator you want to have the logic near the output.
You could put the two switches on the output of the ULN2003 or even after the relay.

Thank you. I have the micro controlling the logic already. This is a fail safe backup.

It is good to have debounce on a switch. Software or hardware. If you use software debouncing, then you do not need AND gate, you can write this logic in your code and just output signal to drive ULN2003A.

If this switch needs to act independently from code, then you need to add hardware debounce. But simple debounce like resistor and capacitor will produce slow edges, so you need to use a gate with schmitt trigger inputs.

Thank You. I will check out gates with schmitt trigger inputs.
 

Offline george.b

  • Frequent Contributor
  • **
  • Posts: 383
  • Country: br
Re: Is my circuit correct?
« Reply #5 on: August 26, 2020, 07:09:26 am »

Thank You! Will a 0.1uF cap be enough? Yes, the microcontroller should be able to read the output from the switches.

It should be enough. As Manul said, that simple solution does produce a slow edge - not that it has been a problem for me before, but if it's as safety-critical as you make it sound, then go for proper debouncing with hysteresis.
 
The following users thanked this post: redgear

Offline redgearTopic starter

  • Frequent Contributor
  • **
  • Posts: 286
  • Country: us
Re: Is my circuit correct?
« Reply #6 on: August 26, 2020, 01:10:58 pm »

Thank You! Will a 0.1uF cap be enough? Yes, the microcontroller should be able to read the output from the switches.

It should be enough. As Manul said, that simple solution does produce a slow edge - not that it has been a problem for me before, but if it's as safety-critical as you make it sound, then go for proper debouncing with hysteresis.

I am also thinking to connect the output from the switch to relay's 5v supply directly, that way the relay will be activated only if the switches are closed. Is it a reliable way to do it?
 

Offline Manul

  • Super Contributor
  • ***
  • Posts: 1147
  • Country: lt
Re: Is my circuit correct?
« Reply #7 on: August 26, 2020, 02:52:36 pm »
I am also thinking to connect the output from the switch to relay's 5v supply directly, that way the relay will be activated only if the switches are closed. Is it a reliable way to do it?

For sure could be a good way. This idea needs to be considered. The good thing is that it is a true cutoff and will work even if gate or relay driver fails horribly. Negative is increased contact wear because of more current and back emf if switch is operated while the driver is driving a relay.
 
The following users thanked this post: redgear

Offline redgearTopic starter

  • Frequent Contributor
  • **
  • Posts: 286
  • Country: us
Re: Is my circuit correct?
« Reply #8 on: August 27, 2020, 03:52:50 am »
I am also thinking to connect the output from the switch to relay's 5v supply directly, that way the relay will be activated only if the switches are closed. Is it a reliable way to do it?

For sure could be a good way. This idea needs to be considered. The good thing is that it is a true cutoff and will work even if gate or relay driver fails horribly. Negative is increased contact wear because of more current and back emf if switch is operated while the driver is driving a relay.

It is a safety cut-off switch, under normal conditions it should be operated only when the relay is OFF. But rarely, it can be operated when the relay is ON. Will a diode or something help reduce back-emf?
 

Offline george.b

  • Frequent Contributor
  • **
  • Posts: 383
  • Country: br
Re: Is my circuit correct?
« Reply #9 on: August 27, 2020, 01:11:02 pm »
I am also thinking to connect the output from the switch to relay's 5v supply directly, that way the relay will be activated only if the switches are closed. Is it a reliable way to do it?

For sure could be a good way. This idea needs to be considered. The good thing is that it is a true cutoff and will work even if gate or relay driver fails horribly. Negative is increased contact wear because of more current and back emf if switch is operated while the driver is driving a relay.

It is a safety cut-off switch, under normal conditions it should be operated only when the relay is OFF. But rarely, it can be operated when the relay is ON. Will a diode or something help reduce back-emf?

Well, there's nothing stopping you from using a transistor to drive the relay instead of driving it directly from the switches, in which case a flyback diode becomes a necessity.
 
The following users thanked this post: redgear

Offline redgearTopic starter

  • Frequent Contributor
  • **
  • Posts: 286
  • Country: us
Re: Is my circuit correct?
« Reply #10 on: August 29, 2020, 04:21:01 am »
Well, there's nothing stopping you from using a transistor to drive the relay instead of driving it directly from the switches, in which case a flyback diode becomes a necessity.

Driving the relay is not the problem, implementing a fail-safe is. Can the 5v from switches be used to power the relay directly?

Something like this:
« Last Edit: August 29, 2020, 04:22:44 am by redgear »
 

Offline george.b

  • Frequent Contributor
  • **
  • Posts: 383
  • Country: br
Re: Is my circuit correct?
« Reply #11 on: August 29, 2020, 06:40:37 pm »
I'm not entirely sure of what you're aiming to achieve, or how the relay fits in, it's not entirely clear to me from your last picture, but I gather you meant energizing the relay directly from the switches. I don't know what kind of switches or relay you're using and what their ratings are. I might be missing the point entirely, but I was thinking of something like in the attached picture.
 
The following users thanked this post: redgear

Offline redgearTopic starter

  • Frequent Contributor
  • **
  • Posts: 286
  • Country: us
Re: Is my circuit correct?
« Reply #12 on: August 30, 2020, 04:31:16 am »
I'm not entirely sure of what you're aiming to achieve, or how the relay fits in, it's not entirely clear to me from your last picture, but I gather you meant energizing the relay directly from the switches. I don't know what kind of switches or relay you're using and what their ratings are. I might be missing the point entirely, but I was thinking of something like in the attached picture.

Thank You!

The relay will energised by a ULN2003A driver. I am trying to provide the 5v supply for the relay directly from the switches. So even if micro fails, they relay's 5v supply is cut as soon as the switches are opened. Will removing the 5v supply while the relays coils are energized cause any problems?
 

Offline george.b

  • Frequent Contributor
  • **
  • Posts: 383
  • Country: br
Re: Is my circuit correct?
« Reply #13 on: August 30, 2020, 01:17:38 pm »
Thank You!

The relay will energised by a ULN2003A driver. I am trying to provide the 5v supply for the relay directly from the switches. So even if micro fails, they relay's 5v supply is cut as soon as the switches are opened. Will removing the 5v supply while the relays coils are energized cause any problems?

Depends on how you wire up the ULN2003's pin 9. If you keep it tied to the rail (as in your schematic), then you should add a flyback diode directly anti-parallel to the relay coil. By opening the switches to cut the +5V, you're disconnecting the ULN2003's internal flyback diodes also, and that could cause problems. Also adding snubber capacitors parallel to the switches wouldn't hurt. If you're tapping the signal from the switches/relay to the microcontroller, it might be wise to clamp the signal, just in case (e.g. with a 5.1V TVS or at least a zener).
 
The following users thanked this post: redgear

Offline redgearTopic starter

  • Frequent Contributor
  • **
  • Posts: 286
  • Country: us
Re: Is my circuit correct?
« Reply #14 on: August 30, 2020, 02:53:02 pm »
Thank You!

The relay will energised by a ULN2003A driver. I am trying to provide the 5v supply for the relay directly from the switches. So even if micro fails, they relay's 5v supply is cut as soon as the switches are opened. Will removing the 5v supply while the relays coils are energized cause any problems?

Depends on how you wire up the ULN2003's pin 9. If you keep it tied to the rail (as in your schematic), then you should add a flyback diode directly anti-parallel to the relay coil. By opening the switches to cut the +5V, you're disconnecting the ULN2003's internal flyback diodes also, and that could cause problems. Also adding snubber capacitors parallel to the switches wouldn't hurt. If you're tapping the signal from the switches/relay to the microcontroller, it might be wise to clamp the signal, just in case (e.g. with a 5.1V TVS or at least a zener).

This is what I have in mind. Will this work without any reliability or safety issues?
« Last Edit: August 30, 2020, 03:09:50 pm by redgear »
 

Offline george.b

  • Frequent Contributor
  • **
  • Posts: 383
  • Country: br
Re: Is my circuit correct?
« Reply #15 on: August 31, 2020, 06:18:52 pm »
This is what I have in mind. Will this work without any reliability or safety issues?

I'm afraid that's not going to work at all. 5V through a 10k resistor is 0.5mA, which is not enough to drive a relay. The TE PCH relay you're using requires 80 times that current. Check the ULN2003 datasheet - the drivers are common emitter. You won't get the 5V for the relay from the ULN2003. You should probably revert to the previous idea, with the caveats I've stated, and let the 5V for the relay come through the switches (and go to ground through the ULN2003).
 
The following users thanked this post: redgear

Offline redgearTopic starter

  • Frequent Contributor
  • **
  • Posts: 286
  • Country: us
Re: Is my circuit correct?
« Reply #16 on: September 01, 2020, 05:17:24 am »
I'm afraid that's not going to work at all. 5V through a 10k resistor is 0.5mA, which is not enough to drive a relay. The TE PCH relay you're using requires 80 times that current. Check the ULN2003 datasheet - the drivers are common emitter. You won't get the 5V for the relay from the ULN2003. You should probably revert to the previous idea, with the caveats I've stated, and let the 5V for the relay come through the switches (and go to ground through the ULN2003).

Thank You. If I wire the 5v from the switch directly to the relay, how can I detect the state of the switch with the microcontroller?


 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13034
Re: Is my circuit correct?
« Reply #17 on: September 01, 2020, 07:53:50 am »
Feed the top end of the relay coil from 5V through the switches.  Add a Schottky diode to ground, cathode positive to clamp the back EMF when the switches open.  Add a 1K pulldown resistor at the switched top end of the relay coil and use a 10K resistor from that point to your MCU input to sense the switch state.  DO NOT switch the 5V to the ULN2003 clamp diode pin.
 
The following users thanked this post: redgear

Offline redgearTopic starter

  • Frequent Contributor
  • **
  • Posts: 286
  • Country: us
Re: Is my circuit correct?
« Reply #18 on: September 01, 2020, 08:35:41 am »
Feed the top end of the relay coil from 5V through the switches.  Add a Schottky diode to ground, cathode positive to clamp the back EMF when the switches open.  Add a 1K pulldown resistor at the switched top end of the relay coil and use a 10K resistor from that point to your MCU input to sense the switch state.  DO NOT switch the 5V to the ULN2003 clamp diode pin.

Thank You!

Did I do it right?
1057816-0
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13034
Re: Is my circuit correct?
« Reply #19 on: September 01, 2020, 08:44:48 am »
Looks good.  I assume relay pin 1 is going off to your ULN2003, so doesn't need a separate clamp diode.
 
The following users thanked this post: redgear

Offline redgearTopic starter

  • Frequent Contributor
  • **
  • Posts: 286
  • Country: us
Re: Is my circuit correct?
« Reply #20 on: September 01, 2020, 08:54:41 am »
Looks good.  I assume relay pin 1 is going off to your ULN2003, so doesn't need a separate clamp diode.

Yes, relay pin 1 is connected to the output of ULN2003A.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13034
Re: Is my circuit correct?
« Reply #21 on: September 01, 2020, 08:59:47 am »
You'll probably want a smallish capacitor to ground at the MCU pin for debouncing, or at least to filter EMI.   

N.B. A buffer or MCU input following a RC filter for debouncing *MUST* have hysteresis (i.e. be a Schmitt trigger type input).

You should probably (re)read Jack Ganssle's excellent article on debouncing: http://www.ganssle.com/debouncing.htm
especially part 2 where he covers RC hardware debouncers.
 
The following users thanked this post: redgear

Offline redgearTopic starter

  • Frequent Contributor
  • **
  • Posts: 286
  • Country: us
Re: Is my circuit correct?
« Reply #22 on: September 01, 2020, 09:03:16 am »
You'll probably want a smallish capacitor to ground at the MCU pin for debouncing, or at least to filter EMI.   

N.B. A buffer or MCU input following a RC filter for debouncing *MUST* have hysteresis (i.e. be a Schmitt trigger type input).

You should probably (re)read Jack Ganssle's excellent article on debouncing: http://www.ganssle.com/debouncing.htm
especially part 2 where he covers RC hardware debouncers.

Thank you. I will read the article. But would I still need hardware debouncing if I debounce the presses on software?
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13034
Re: Is my circuit correct?
« Reply #23 on: September 01, 2020, 09:35:08 am »
No, but you probably do need some EMI filtering so the pin doesn't glitch when the relay switches or due to EMI pickup on the button wiring.. 
« Last Edit: September 01, 2020, 09:39:22 am by Ian.M »
 
The following users thanked this post: redgear

Offline redgearTopic starter

  • Frequent Contributor
  • **
  • Posts: 286
  • Country: us
Re: Is my circuit correct?
« Reply #24 on: September 01, 2020, 09:39:49 am »
No, but you probably do need some EMI filtering so the pin doesn't glitch when the relay switches.

I have 0.1uF and 4.7uF caps between all VCC and GND pins on the MCU. Is that enough? Do I need caps on the ULN2003A as well?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf