Sending a digital signal with an RC circuit - Page 1
Forum section: electronics / beginners

author: Saimoun
author_rank: Frequent Contributor
timestamp: November 04, 2023, 06:17:01 pm
content: HiSay I have a simple circuit, no MCU. I want the circuit to send a simple signal over an open-drain UART at the press of a button.So all the circuit needs is to be low for a set amount of time, say 32us for example.Am I right that this could be done with a simple RC circuit (and a transistor to keep the edges sharp)?If not using an RC circuit, can I do this with a shift register 74HCx for example?Thank you

author: AG6QR
author_rank: Frequent Contributor
timestamp: November 04, 2023, 06:55:45 pm
content: Sounds like you're almost describing a 555 timer. That's one of the most popular ICs from long ago. It consists of a digital SR flip-flop, with the S(et) and R(eset) inputs driven by comparators. (A comparator is a device that compares two analog signals, and outputs a logic 1 or 0 depending on which of the analog signals has higher voltage). This chip is extremely versatile, but some of the most popular uses for it involve using RC circuits to generate timed logic pulses.Search the web for "555 timer IC" to find lots more info.

author: TimFox
author_rank: Super Contributor
timestamp: November 04, 2023, 07:28:23 pm
content: The original 555 is bipolar, and uses more power than the later CMOS versions (e.g., LMC555) for applications that don't need high output current.

author: Ian.M
author_rank: Super Contributor
timestamp: November 04, 2023, 07:45:30 pm
content: Quote from: Saimoun on November 04, 2023, 06:17:01 pmYou'll need at least two transistors and a handful of passives to keep the edges sharp. The complexity isn't worth it vs using an appropriate IC. Even a CMOS 555 is hard to justify vs using a low pin count MCU, unless its greater supply voltage range and higher output current capability lets you get away without using a line driver.A shift register will only be helpful if you've already got an appropriate clock, with a period that the desired pulse is a small integer multiple of.

author: Faranight
author_rank: Unknown
timestamp: November 04, 2023, 07:48:03 pm
content: Quote from: Saimoun on November 04, 2023, 06:17:01 pmJust checking... does the circuit have to output a logic low forexactly32us orat least32us? If the latter is true then you could do it with a RC and a pushbutton.

author: Ian.M
author_rank: Super Contributor
timestamp: November 04, 2023, 08:08:23 pm
content: ... or an old mechanical rotary phone dial mechanism, as it had a contact set to mute the speaker for the duration of its runback!https://en.wikipedia.org/wiki/File:Rotary_Dial,_Dialing_Back_with_LEDs.ogvhttps://www.ebay.com/itm/145406662537

author: Saimoun
author_rank: Frequent Contributor
timestamp: November 04, 2023, 09:07:22 pm
content: Wow, thank you all for all this info - brilliant!!I did not even think of the 555 timers ha ha (never used one - but I definitely heard about it).It sounds like this is the way to go - I'll investigate! Very happy I asked here!@Faranight: yes it has to be exactly 32us to fit the UART clock.@Ian: well the big difference in avoiding an MCU is to avoid the programming part of itMy next question: what if I have 4 LED's, which I want to light up every time the button is pressed?(i.e. LED 1 is on, when button is pressed, then LED 1 turns off and LED 2 turns on, when the button is pressed again LED 2 turns off and LED 3 turns on, etc. - and then it rotates back to LED 1)Can I do that with the 555 timer as well?

author: AG6QR
author_rank: Frequent Contributor
timestamp: November 04, 2023, 09:43:41 pm
content: Quote from: Saimoun on November 04, 2023, 09:07:22 pmNo. A 555 timer has only one digital output, driven by one single flip-flop. You could, in theory chain four of them together to accomplish what you're asking (a 556 chip helps somewhat -- it's essentially two 555 chips put into a single package), but when you chain a bunch of flip-flops together the way you describe, the common name for that is a "shift register", and there are many such chips available off the shelf. Or since you only need four bits, you could buy a quad flip-flop chip, like the CD40175B, and just string them together yourself, wiring the Q output of one flip-flop to the D input of the next one.But these days, I believe I'd seriously consider a small MCU rather than using a shift register or quad flip-flop The MCU is more flexible and versatile, so you can buy a few dozen of them and use them for all your future projects that need some simple digital logic. On the other hand, the shift register or quad flip flop doesn't require programming, might be cheaper, and might be able to directly source more current.Decisions, decisions...

author: Ian.M
author_rank: Super Contributor
timestamp: November 04, 2023, 09:45:48 pm
content: 4017 + something to debounce the button.

author: Terry Bites
author_rank: Super Contributor
timestamp: November 05, 2023, 06:24:58 pm
content: I'd use a SN74LVC1G17 or similar Schmitt trigger gate. It will do a great job of sharpening up your RC voltage and it will greatly reduce susceptibility to power rail noise.

author: David Hess
author_rank: Super Contributor
timestamp: November 06, 2023, 09:30:36 am
content: Quote from: Saimoun on November 04, 2023, 06:17:01 pmVarious forms of monostable multivibrator using a pair of transistors or pair of logic gates will do that in combination with an RC circuit.A set-reset flip-flop with the control signal driving the clock and the RC delay driving set or reset from one of the outputs would also work. Since the clock is edge triggered, this does not require AC coupling of the input, so I think this gets it down to three parts.

author: EPAIII
author_rank: Super Contributor
timestamp: November 06, 2023, 10:50:57 am
content: Can you do that with a 555 timer? Sure you can, if you use FOUR of them. The first one controls the first LED and the SECOND 555. The second 555 controls the second LED and the THIRD 555, etc. This has been done. And the 556 is a dual 555 - two 555s in one IC. And I believe there may even be a quad 555 package or used to be.BUT, a single Arduino or even a single, plain Jane PIC chip, which can be purchased for under one USD, can do the same thing with fewer components. Almost any of these devices can provide the needed current for LEDs without any extra parts.Also there are a multitude of logic chips that also provide the time delay function. Look for a CMOS monostable multivibrator. The CMOS family of devices are more likely to be able to handle the current that an LED needs.However, a simple RC or Resistor-Capacitor circuit, by itself, can NOT do what you want. You need an active device (transistor, IC, FET, etc.) to turn things on and off at the appropriate time. And jumping from one to four sequential LEDs is even more problematic so more active devices are going to be needed.And you mentioned a shift register. A shift register could also do it. But it is going to need a clock if you want to sequence several LEDs instead of just one. And a clock is another circuit that would be needed.For four LEDs in sequence, the single, PIC or Arduino or other micro processor is by far the better way to go. And the code isn't that hard to learn. You can probably find at least a partial program already written. And there are user groups for each and every one of these devices where you can easily get help. And YouTube videos. And tons more sources of help.PS: Do you expect to actually see an LED that flashes on for just 32us? That is 32 millionths of a second (32/1,000,000 s). I don't know if that is a good plan. You can probably find LEDs that will turn on and off that fast, but seeing that short of a pulse of light is quite another thing. Perhaps in a pitch black room. Perhaps, just perhaps.Quote from: AG6QR on November 04, 2023, 09:43:41 pm

author: Saimoun
author_rank: Frequent Contributor
timestamp: November 06, 2023, 11:33:49 am
content: Thanks all again for all those super useful replies!I know I can do this with an MCU - this way is a lot more funand as I said I want to avoid the programming stage (not because I cannot code it - from a manufacturing point of view).I did not mention this, but there will also be another circuit that needs to be cut for at least 2ms, and about 1ms before the 32us low pulse is sent. (so that the other part of the circuit does not interfere with the 32us pulse). This is the part ingreenin the diagram below.I attached my idea as a picture. I think I'm almost there, thanks to your answers. What I'm missing is the last part with the 4 LEDs, using a CD4017 with 10 outputs will not work, correct? AG6QR suggestd the CD40175B which has only 4, I'll try that. Or how to do this with a shift register?Thank you all againSimon

author: Ian.M
author_rank: Super Contributor
timestamp: November 06, 2023, 12:14:15 pm
content: Connect the fifth output of the CD4017 ("4") to its RESET pin and it will behave as a four state decoded counter, counting "0" "1" "2" "3" "0" "1" .... albeit with a very brief glitch going from "3" to "0" when none of the LEDS will be lit.There are however a couple of flies in the ointment - the simple circuit lacks a power on reset, and if it powers up in any state higher than "4" then up to five pulses could be required to get it back to "0" and light the first LED. If you want to fix this properly you'd use a seven input OR gate to combine all the unwanted outputs + an external RESET signal to reset it, but in practice its usually good enough to couple "4" to RESET through a resistor so a RC network + a diode can provide a power on reset pulse. The attached circuit shows how.N.B. R2 should be at least an order of magnitude greater than R1 to get valid logic levels, and the time constant of R2 with the junction capacitance of D1 does slow down the reset from "4" slightly, increasing the glitch duration. It wont be perceptible driving LEDs but you might need something better if you were sequencing some other fast acting circuit.

author: Saimoun
author_rank: Frequent Contributor
timestamp: November 06, 2023, 01:34:11 pm
content: Quote from: Ian.M on November 06, 2023, 12:14:15 pmThanks Ian that's amazing, I did not think of that! I'll make sure to add the reset circuit as you shown and I'll post the final circuit hereQuote from: Ian.M on November 06, 2023, 12:14:15 pmThat's never great innit

author: Saimoun
author_rank: Frequent Contributor
timestamp: November 08, 2023, 11:45:41 am
content: HiI'm struggling to generate the 32us pulse with the 555 timer. My problem is that if the input pulse is longer than 32us then the output stays low until the input pulse is finished (555 in monostable mode).So it sounds like what I need to detect is not an input pulse but rather just a falling edge, and then generate that 32us until the next falling edge (i.e. button released and then pressed again).Any ideas?Thank youSimonEDIT: ok actually found two great solutions for detecting edges in this video from Ben Eater:https://youtu.be/YW-_GkUguMM?t=635I like the second solution with the AC coupled cap, I think I need to add a diode to prevent the voltage to go below zero when the capacitor discharges. I'll post the full circuit here when I have it.

author: Saimoun
author_rank: Frequent Contributor
timestamp: November 08, 2023, 02:51:02 pm
content: Here is my circuit.My biggest problem is detecting the falling edge after the NAND gate A3. I am clearly cheating here considering all gates ideal.I have not worked with gates much before - can you simply connect inputs and outputs or should they have current limiting resistor in between (thinking the inputs are basically a Mosfet's gate?)?In the simulation the circuit works and does what I want it to do. No timing has to be precise except the 32us. All other timings can be anywhere around a few ms.Any thoughts on how that can go wrong once it goes to real life?Thanks

author: Saimoun
author_rank: Frequent Contributor
timestamp: November 26, 2023, 06:53:09 pm
content: Quote from: Ian.M on November 06, 2023, 12:14:15 pmJust wondering about this circuit - you wrote "if it powers up in any state higher than 4" - are you saying the 4017 powers up in a random state?

author: Ian.M
author_rank: Super Contributor
timestamp: November 26, 2023, 08:22:39 pm
content: Not exactly, as for a specific IC the powerup state typically isn't truly random.The usual implementation of a 4017 type decoded decade counter has five internal flipflops arranged as a Johnson (twisted) ring counter + logic to ensure that all invalid (non-decimal) states return to the valid state sequence within a small number of clock pulses. They don't include a built-in power-on reset circuit, though there is a reset pin allowing power-on reset to be applied externally, (re)setting the flipflops to the state decoded as '0'. The initial power on state of each flipflop depends on a number of factors including the exact performance of the transistors composing it, so a particular IC that has been unpowered for long enough, is likely to tend to have a favoured state immediately after powerup. Another IC of exactly the same type is likely to have a different favoured state, even if its from the same wafer.Therefore if you don't provide a reset pulse on powerup, your 4017 circuit can fail to operate as expected for a number of clock pulses e.g. NXP say their HEF4017 will "return to a proper counting mode within 11 clock pulses".

author: Saimoun
author_rank: Frequent Contributor
timestamp: November 26, 2023, 09:32:11 pm
content: I see - thanks for the explanationBut then with your circuit we do have a power-on reset since the reset pin is pulled high while C1 charges, right (for about 0.1ms)? And in this case after power-up the active output is the "0", correct?Moreover, I'm not sure I fully get the purpose of the diode - is it for when the capacitor discharges?Thank you

author: Ian.M
author_rank: Super Contributor
timestamp: November 26, 2023, 09:47:15 pm
content: Initially a power-on reset is applied via the diode. The capacitor charges via R1, ending the reset, and once charged the diode isolates the capacitor and R1 from the feedback signal (via R2) from the '4' output, allowing that to reset the counter.

author: shapirus
author_rank: Super Contributor
timestamp: November 26, 2023, 10:22:45 pm
content: Btw this raises a question of what is the rule of thumb for setting the duration of the power-on reset pulse for various ICs. What order of magnitude? Nanoseconds, microseconds, milliseconds? How fast do they generally power all their internal circuitry up and become ready to operate, at which point it's ok to release the reset signal?

author: David Hess
author_rank: Super Contributor
timestamp: November 27, 2023, 12:14:36 am
content: Crystal oscillators can take milliseconds or longer to start. Otherwise logic should be ready in 10s or 100s of nanoseconds. Very complex logic may have internal PLLs or DLLs which take time to lock.

author: Saimoun
author_rank: Frequent Contributor
timestamp: November 27, 2023, 08:41:26 am
content: Thank you all - all makes sense now, very useful info!