0
\$\begingroup\$

I have a working circuit and I'm looking for cues on how to improve it.

I'm building a device with a user controlled small stepper motor. Speed of the motor can be controlled by a pedal connected via audio-jack.

I need to properly recognise a type of the connected pedal and handle its value in the MCU.

There are 3 types of pedals that can be connected:

  • Type A - simple momentary switch, user can switch motor on or off.
  • Type B - pedal with a (10k) potentiometer, user can control speed with her foot.
  • "Type C" - nothing is connected, empty socket

I have a circuit that works using two ADC pins on atmega328p, A5 reads pedal type, A1 reads its value, combination of readings from both pins allows me to control connected motor.

Question: how I can improve, simplify or make it more resilient?

I would be very grateful for tips from more experienced colleagues.

enter image description here

\$\endgroup\$
5
  • \$\begingroup\$ Driving the input with a constant current source and measuring the input voltage can be a solution (Note that the current source should be designed so that the voltage at that node can be at a certain, non-zero level when nothing is connected). If a potentiometer or a resistor connected then there'll be a non-zero voltage at that node. If an NC (normally closed) type switch is connected then the measured voltage will be zero. \$\endgroup\$ Jul 29, 2020 at 17:27
  • \$\begingroup\$ A thought --- When a user is plugging in the 'audio jack', there usually will be a short-circuiting of the nodes. Make sure your circuit fails in a safe way when this happens. Also, it's not a bad idea to place a very small capacitor at A5-GND. This will keep your ADC stable when the pot is rotated. Pots wear out eventually and you'll get some level of noise as it's moved. You're seemingly not trying to read high-frequency AC signals so the capacitor won't have any negative impact on circuit function. (So long as you keep it small-ish... say 0.1uF or so) \$\endgroup\$
    – Kyle B
    Jul 29, 2020 at 17:29
  • \$\begingroup\$ Maybe also put a 100k resistor at the ADC input. Currently there is only 2k between a user-touchable node and the IC. The 100k would serve to prevent ESD from killing your microcontroller. Consider adding protection diodes also. LIke this: google.com/… \$\endgroup\$
    – Kyle B
    Jul 29, 2020 at 17:32
  • \$\begingroup\$ @RohatKılıç thx, didn't think about constant current source in this way, need to look into that, what could be improved by employing that? \$\endgroup\$
    – Jannki
    Jul 29, 2020 at 18:00
  • \$\begingroup\$ @KyleB thx! will try both capacitor and 100k at the A1. Regarding capacitor - it should be placed before 100k (on the ground side), right? (or after, between 100k and A5?) \$\endgroup\$
    – Jannki
    Jul 29, 2020 at 18:07

2 Answers 2

0
\$\begingroup\$
  1. If you know it is an active device, you test 1st with a DMM voltmeter.
  2. Since you know this is passive, you start with a DMM Ohmmeter which is 10uA to 1mA CC and measure voltage. An analog meter in Ohmmeter scale would be more responsive but less accurate.

How you implement this circuit is irrelevant unless you have tolerance specs for these options and may include 4) None of the above

Some audio drivers have this feature for Windows when enabled, that can auto-detect any audio port as having ;

  1. a speaker connected, by Low impedance to gnd,
  2. an electret microphone, by midscale DC voltage from external bias to V+
  3. or open circuit, detecting V+

Using the same approach you can define 3 states;

  1. A switch with a 9X resistor across it to get 90% of V+ when open and 10% V with 10% series R when the switch is closed.
  2. A slider pot with 20% series R's on either side that controls the V+ bias confined output voltage range with the chosen standard pot value that does not conflict the voltage in states 1. or 3. 15% V+ < Vx < 85% V+
  3. Open circuit V=V+ from external R bias.

schematic

simulate this circuit – Schematic created using CircuitLab

Something like this can detect the 3 states with voltage-current or by either sweeping with a DAC to detect a zero-crossing for the Voltage result or using an ADC to measure the voltage with V+ bias and series R.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ OP wants the system to auto-detect which input device the user has plugged in. \$\endgroup\$
    – Transistor
    Jul 29, 2020 at 20:10
  • \$\begingroup\$ @Transistor yes she wants a design using Ohm's Law and tertiary logic with analog controls for the middle state which in the digital world is "dont care" \$\endgroup\$ Jul 29, 2020 at 20:31
  • \$\begingroup\$ thx, either I'm not reading this correctly or I forgot to mention that I can't influence connected pedals construction (so R1, R2, R3, R4 need to be there or not for all the cases) But your answer gave me some ideas to try, I can probably compromise and treat closed switch as fully pressed potentiometer pedal and then one adc seems to be enough. \$\endgroup\$
    – Jannki
    Jul 30, 2020 at 16:15
  • \$\begingroup\$ Never forget to write down your assumptions. trust but verify. \$\endgroup\$ Jul 30, 2020 at 16:34
0
\$\begingroup\$

use an out-of-range signal for the button. use the AVR's internal pull-up to probe for a connected device.

schematic

simulate this circuit – Schematic created using CircuitLab

you can detect which is connected by enabling the internal pull-up on the analogue pin.

if nothing is connected the voltage will go high and stay there, the potentiometer voltage will change slightly, the button will go to a voltage mid-way somewhere. so turn the pull up off again after probing.

This will add software complexity: it becomes more important to re-probe to detect what's connected and to de-bounce the inputs, but for best reliability your original plan would have needed that too.

It also means that you can use 3-wire plugs which gives more options, especially if you only need to use commercial grade connectors.

\$\endgroup\$
3
  • \$\begingroup\$ thx, I get the idea but not sure if I understand how to distinguish between connected pot and closed switch. I forgot to specify that pedals are given, they're standard off the shelf components, I can only influence how receiving device is constructed (so R2 == R5, and R3==R4). So I'm pulling-up (A)nalog to probe and: nothing connected -> A=5V, switch connected -> A = ~2.5V (when switch closed ) or ~50mV (when open), pot connected -> A <0.5,4.5>V. How to distinguish between connected potentiometer and closed switch when R2==R5 and R3==R4 ? \$\endgroup\$
    – Jannki
    Jul 30, 2020 at 15:03
  • \$\begingroup\$ eg with VCC=5V a closed switch looks like 4.95V but the pot only goes to 4.6V, you have to test twice once with the pull-up off and once with it on. \$\endgroup\$ Jul 30, 2020 at 23:00
  • \$\begingroup\$ thx! need to test it once again then \$\endgroup\$
    – Jannki
    Aug 1, 2020 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.