| Electronics > Beginners |
| How do I Solve Race Conditions? |
| (1/2) > >> |
| bobleny:
Hi, I have the following circuit, and I am concerned about a race condition between Q8 and Q9. The purpose of this circuit is to only energize L1 only if VCC < ~14v DC. So, from a de-energized circuit, if VCC is connected to a 20v DC source, there is nothing to stop Q9 from activating before Q8. Thus, energizing L1 very briefly. So, the question is, is there a way to solve this issue? Am I looking at this wrong? Maybe there is a flaw in my thought process? Thanks! TMI: This is a simplified version of an overly complicated low battery cutout I designed, which does suffer from a race condition (I may have a problem). L1 represents the reset coil of a latching relay, which enables the low cutout circuit. So the relay has a tendency to "buzz" for a moment when the circuit is first energized. |
| fourfathom:
Add a capacitor from Q9 base to ground to delay the Q9 turn-on. Add a diode from Q9 base to VCC (cathode towards VCC) to quickly discharge the capacitor when power is removed. What is the purpose of R16? You might want to reduce the value of R12, to get a better-defined Q8 base drive. You might want to put a diode or RC snubber circuit across the relay coil, although in this circuit it's unlikely to be needed as the switching speeds are pretty slow. |
| Mechatrommer:
beside that, i think you need to reduce R15 a lot to something like 100 or 10R or eliminate entirely, there is a chance Q9 will never turned off due to leakage/divider from R13 to Q9's base, esp on very high VCC, and R15 will also slow down the capacitor discharge. |
| bobleny:
Thanks for the help. fourfathom, I don't know what R16 was for. I built the circuit first and then made the schematic from it (I often do this with simple circuits). When I went to upload it, I asked myself the same question, but I didn't have time to pull it out and test it, so I left it in there. Also, I was too lazy to add the flyback diode to the relay (or the relay for that matter), which I'm glad I didn't because I've never heard of an RC Snubber, so I will have to look into that. Mechatrommer, That's interesting. I didn't realize I built a voltage divider. That is probably the sort of thing someone with experience sees immediately... Now that you mention it though, like R16, I see no use for it. I also noticed, now that you pointed the one out, the voltage divider at the base of Q8. That one I am not worried about through. I wanted to test the race condition with and without the capacitor. So, I built the circuit shown in race-latching.png. As the name implies, I have it configured so if the relay is energized, it latches on so it is obvious if Q9 energized before Q8. First I tried it without the capacitor by setting VCC to 17.6v DC, then manually energized the circuit about 200 times. I also tried energizing the circuit about 200 times with R12 and R13 at 10k. So, in over 400 attempts, the relay never latched. That seems a bit odd to me. Is that just bad luck, or is this circuit just not as susceptible to a race condition as I thought? Are there other commonly used techniques(?) for dealing with potential race conditions? Is there a better way to design this circuit so there is no way for there to be a race condition? Thanks again for entertaining my ridiculous questions. P.S. I also tried this circuit without the latch and without the capacitor a couple hundred times with R12 and R13 at 100k and VCC set to 12v DC so I could make sure the circuit didn't have any unexpected issues. |
| fourfathom:
--- Quote from: bobleny on October 25, 2019, 05:42:08 am ---So, in over 400 attempts, the relay never latched. That seems a bit odd to me. Is that just bad luck, or is this circuit just not as susceptible to a race condition as I thought? --- End quote --- Probably the relay needs more than just a quick spike of current to latch, so even if the original circuit has a race condition it is too brief to activate the relay. |
| Navigation |
| Message Index |
| Next page |