Control a servo from a potentiometer, WITHOUT a microcontroller? - Page 1
Forum section: electronics / projects

author: I wanted a rude username
author_rank: Frequent Contributor
timestamp: December 04, 2019, 03:41:22 am
content: You may have heard ofcode golf, which is trying to solve a problem in the fewest lines of code.Using a microcontroller to read a potentiometer and PWM a servo accordingly is a favourite Arduino task, and can probably be done in a few lines of code.But can it be done inzero lines of code? Is there a non-microcontroller solution to this problem? I have one in mind, but it uses a bunch of discrete components.Presentingelectronics golf: solve this problem to minimise Σ(electronic components, lines of code)!

author: oPossum
author_rank: Super Contributor
timestamp: December 04, 2019, 03:44:01 am
content: Something other than this?https://www.google.com/search?q=555+servo+tester

author: I wanted a rude username
author_rank: Frequent Contributor
timestamp: December 04, 2019, 03:48:02 am
content: Yeah, I have a hunch it can be done with fewer parts, but lack the electronics background to improve on that solution. Also it's an interesting exercise.

author: ebclr
author_rank: Super Contributor
timestamp: December 04, 2019, 08:04:09 am
content: 74HC14 1 capacitor, 2 resistors, 2 diodes, the pot is everything you need, to make a variable duty cycle oscillator, who will drive the servo position

author: Ian.M
author_rank: Super Contributor
timestamp: December 04, 2019, 09:41:20 am
content: That's more complex (and has more pins to solder) than a CMOS 555 (so you can gamble on no decoupling) + a resistor , a capacitor, a pot and a diode. Add an extra resistor in series with the pot to limit the minimum pulse width.It can't really be simplified any further in the analog electronic domain - you need two RC time constants to set the timing so that's four components straight off, even if you cheat and use a mechanical stop for the pot knob to set the minimum pulse width.An electromechanical solution could be simpler - imagine a tiny bimetallic strip with a heating element wrapped round it and a pair of NC contacts as a thermal oscillator controlled by a set-screw bending the base of the strip towards the fixed contact to increas the on time. Tap off the output across the heating element.

author: leeatljs
author_rank: Contributor
timestamp: December 04, 2019, 10:26:29 am
content: Are we allowed to modify the servo?

author: Wolfram
author_rank: Frequent Contributor
timestamp: December 04, 2019, 11:48:43 am
content: How about a relaxation oscillator built around a neon lamp? A variable resistor between the neon lamp and the capacitor would allow the pulse width to be adjusted. It might not win on the lowest overall part count, but it's hard to beat it on the number of active components!If ICs count as one component, then an LT6992, a resistor and a potentiometer would do.

author: Ian.M
author_rank: Super Contributor
timestamp: December 04, 2019, 02:14:16 pm
content: I presume output would be across a 4.7V Zener in series with the lamp?

author: dferyance
author_rank: Regular Contributor
timestamp: December 04, 2019, 02:30:35 pm
content: It sounds like the goal is to avoid code and not so much avoid micro-controllers. This might be possible with a PSoC via schematic entry. It has analog blocks and digital blocks that can be wired together.Another possibility is a FPGA. If verilog or VHDL qualifies as code, it is still possible to do via schematic entry.Not saying those are good solutions, but just solutions you shouldn't rule out in your quest to not have code.To me it seems to defy the point to have 0 lines of code. The challenge is to optimize an algorithm to be as simple and small to solve a problem. You are going down the path of having no algorithm -- so you aren't optimizing anything. As soon as you go the route of no computation, you could introduce solutions such as a person manually turning a servo in response to a nob. Being outside the world of Turing computers is a totally different kind of problem to solve.

author: Wolfram
author_rank: Frequent Contributor
timestamp: December 04, 2019, 03:10:11 pm
content: Quote from: Ian.M on December 04, 2019, 02:14:16 pmThat's the simplest way to ensure solid logic levels on the output. I'd maybe add a resistor in parallel with the zener as well, to get a well defined logic low output value. Given that the output pulse length only needs to change by a factor of 2:1, it might be possible to skip the zener and take the output across a resistor in series with the lamp, depending on the valid logic input levels of the servo.

author: SiliconWizard
author_rank: Super Contributor
timestamp: December 04, 2019, 03:23:32 pm
content: Quote from: I wanted a rude username on December 04, 2019, 03:41:22 amThere's a slight contradiction between your title "without a microcontroller" and the last line "minimise Σ(electronic components, lines of code)".I guess here, the goal is to do without an MCU, so no lines of code at all. (Or maybe you were thinking about a CPLD/FPGA?)Any programmable component, such as an MCU or FPGA, may actually hide a lot of "lines of code" via libraries (/respectively ready-made IPs), so generally speaking, "code golf" contests have to be strictly defined, otherwise they don't mean much. You could be using a crapton of external libraries and make your own code only a 1-liner, is that a valid approach? Is the goal about designing something with the least amount of code/components overall, or is it about doing it with the least amount of effort? The two can be almost completely opposite and contradictory.Anyway here, assuming 1/ you said NO MCU and 2/ you didn't say "only with discrete parts", one of the simplest solutions in terms of both design effort and number of parts would be to use, for instance, an LTC6992. It would only require 1 resistor to set the period, and it has a control input for the duty cycle. Then to do it "right" (design it such that the output pulse width is settable in the standard range for a servo, which is often 1ms to 2ms, with 1.5ms being neutral), you'd need two additional resistors (at each end of the pot), along with the pot. Then pot wiper to the MOD input. Add a decoupling cap for good measure on the power supply. That's 1 IC, 3 resistors, 1 cap, zero code or configuration, and you'll get something relatively stable.

author: m98
author_rank: Frequent Contributor
timestamp: December 04, 2019, 04:23:55 pm
content: Another solution: One GreenPAK

author: SiliconWizard
author_rank: Super Contributor
timestamp: December 04, 2019, 05:27:08 pm
content: Quote from: m98 on December 04, 2019, 04:23:55 pmNice devices. But they are "programmable", aren't they? So requiring some "lines" of "code". Or I don't know exactly how you configure them.Which raises the question: if we want to minimize both part count AND "lines of code", how are we going to "normalize" both measures?If one solution requires 5 components but zero line of code, is it better or worse than one requiring only 1 component and using 5, 10, 100 lines of code? How can we compare hardware and "software"?

author: Etesla
author_rank: Regular Contributor
timestamp: December 04, 2019, 05:35:52 pm
content: Here's one solution:

author: tggzzz
author_rank: Super Contributor
timestamp: December 04, 2019, 05:39:37 pm
content: Quote from: I wanted a rude username on December 04, 2019, 03:41:22 amHow do you think servos were controlled when computers were the size of rooms and cost 1000 times your annual salary?It does require a basic understanding of analogue electronics, control theory, particularly PID loops and backlash - but that's equally true for a software control loop.Alternatively look at and understand the concepts in analogue computers.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: December 04, 2019, 06:06:47 pm
content: No need for an oscillating solution. A couple transistors and their supporting resistors (and maybe an R+C or two for compensation) will do it. Mechanical setup, probably a pot on the servo shaft to indicate position, and the error amp controls the servo to match input voltage to position.Tim

author: m98
author_rank: Frequent Contributor
timestamp: December 04, 2019, 06:40:27 pm
content: Quote from: SiliconWizard on December 04, 2019, 05:27:08 pmThey have a schematic entry tool, so no "lines of code" required. In fact, as far as I know, that's the only official way to configure them.But this boils down to the question if programmable hardware is permitted by the rules the OP had in mind, really.One could even make the case that a PCB created by a CAD-tool contains "code", since it is stored in markup language and "programmed" in the manufacturing process.

author: m98
author_rank: Frequent Contributor
timestamp: December 04, 2019, 06:45:38 pm
content: Quote from: T3sl4co1l on December 04, 2019, 06:06:47 pmThere is, unless re-specifying the used servo was allowed. In that case, he could simply use one that takes analog input off-the-shelf...

author: Benta
author_rank: Super Contributor
timestamp: December 04, 2019, 07:49:02 pm
content: Quote from: T3sl4co1l on December 04, 2019, 06:06:47 pmMy reading of the OP is that he's talking about RC servos.These need a 0...4.8 V input amplitude, 20 ms period, 1...2 ms pulse input; 1.5 ms being neutral position. I don't see a solution without an oscillator.

author: I wanted a rude username
author_rank: Frequent Contributor
timestamp: December 04, 2019, 09:04:57 pm
content: What have I started?It's best if the set of rules emerges organically. If you want clarification, then personally I would make the number of components/lines of code follow the complexity of the solution in some way.Programmable devices like FPGAs and PLCs may need to count as having some number of "function points", even if they're programmed via a 4GL, Node-RED style Web interface, etc. ... otherwise of course you could build pretty much any solution in an FPGA and hope the decoupling caps don't push you over someone else's solution.Existinglibraries are OK, because they're just other building block. But the library should exist publicly when the challenge is put forward ... noMyLibrary.solveTheProblem().Anyway, those are just suggested rules. And yes, I was thinking of a generic, unmodified PWM servo, but it's also fun to consider hacking it.