I’m writing this after having read this Hack A Day post. The post is about a Youtuber named GreatScott! (which I already knew for its well made electronics videos) attempting a second build of a coilgun driving circuit, this time using logic integrated circuits instead of an Arduino. The video I’m referring to is this one.
Up until now everything seemed fine. It’s actually cool to show that “there’s more than one way to do it” in electronics. However, after watching the video, I was quite disappointed. The video seems – to me, at least – more like a way to prove the point that using an Arduino was a good idea in the first place, rather than an attempt at giving a fair comparison between logic design and microcontrollers. Why, you may ask? Because the author made no attempt at actually optimizing the circuit! Not putting any effort in optimization, unsurprisingly, leads to an overcomplicated design.
Here’s a list of the missed optimization points (which might make sense to you only after you watch the video):
1) Use of inverters to match the pushbutton to the flip-flop. A pushbutton can close to the positive rail and have a pulldown resistor, or close to the negative rail and have a pullup resistor. When using a microcontroller, the choice of pushbutton configuration gives you no advantage (unless you want to use the microcontroller’s internal pullups), but when using logic you can take advantage of this to avoid needless inverters.
2) Unnecessary use of opamps. The use of RC circuits to provide timing in logic is well known, but so is the fact that CMOS logic happily accepts the slowly rising voltage of a capacitor without the need for an opamp used as a comparator. Schoolbook examples such as the NOR monostable prove this. Even in tricky situations, the availability of CMOS gates with schmitt triggered inputs means you can get away without opamps.
3) Use of discrete gates where wired logic is sufficient. Wired logic is a common way to optimize a design, eliminating the need for discrete gates. The infrared sensors he used (CNY70) are even natively open collector, which simplifies the schematic even further.
4) Missed opportunity for simplification of the original schematic. The original design using an Arduino requires IRS2001 MOSFET driving ICs because an Arduino works at 5V or 3.3V, and that voltage may not be high enough to drive a high power MOSFET. However, CMOS ICs happily operate at up to 15V, so they can be operated at the same voltage used for the coils, and drive the MOSFETS directly, actually reducing the IC count compared to the Arduino schematic!
As I don’t think it would be fair to state all this without proving it at least with a schematic, here’s my solution to the coilgun driving problem using logic (download it in Eagle format here).
We’ll start describing the schematic from the top left. The button is used to fire the device. It closes to ground, so no inverter is needed. The use of C1 and R2 is to prevent the first coil from being permanently energized if the user keeps the button pressed, an issue that the author stated the Arduino version does, but his logic solution doesn’t do. A CD4093 4 NAND gates with schmitt trigger inputs is the only IC in the circuit. Half of it is used to make the first flip-flop. R4 and C2 provide the safety timeout circuit to de-energize the coil if something goes wrong. D1 quickly discharges the capacitor. The light sensor, and the RC circuit are wire ANDed together to reset the first flip-flop and start the next one. The bottom circuit is just a simple repetition of the first one, which incidentally makes extending the circuit to a coilgun with more than two stages very easy.
The component count is just one IC, a CD4093, two transistors and two MOSFETS. Compared to three ICs and two MOSFETS in the Arduino version, the solution is simpler and cheaper. But this does not mean that it couldn’t be optimized even further. The schematic I’m proposing is just the first option that occurred to me, and is using common logic gates such as NANDs. After designing the schematic I realized that maybe replacing the CD4093 with a dedicated double monostable chip such as a CD4098 with the light sensor connected to the monostable reset lines could remove even the need for the two transistors.
However, to be honest, I still think my post is a bit unfair. That’s because the author of the video actually built the circuit, while I’m only providing an untested schematic without component values. The issue is, I’m on holiday (yes, I follow Hack A Day even while on holiday), so unfortunately I can’t build the circuit to test it. I hope I haven’t made any major mistake 😀
To end this post, I’ll add just a small note. Even though I am not exactly a fan of Arduino (which I like to think of as a good learning tool an engineer should grow out of at some point), I am definitely not against the use of microcontrollers in general. I even wrote an operating system for microcontrollers, Miosix. There are good reasons for using a microcontroller: data logging, a menu based user interface, PC interfacing come to mind. Even too complex application logic is a good reason for using a microcontroller. It’s just that I recognize that certain tasks are still better solved using logic, and two flip-flop with a timeout definitely falls in this category.