MUFF WIGGLER Forum Index
 FAQ & Terms of UseFAQ & Terms Of Use   Wiggler RadioMW Radio   Muff Wiggler TwitterTwitter   Support the site @ PatreonPatreon 
 SearchSearch   RegisterSign up   Log inLog in 
WIGGLING 'LITE' IN GUEST MODE

Protecting microcontrollers inputs and outputs
MUFF WIGGLER Forum Index -> Music Tech DIY Goto page 1, 2  Next [all]
Author Protecting microcontrollers inputs and outputs
Nagasaki45
Hi DIYers!

Sorry in advance for the noobish question. I tried to search in the forum but couldn't find an answer.

I'm designig a module (see here) that is based on a microcontroller. The electronics part of it should be relatively easy I reckon. The only part I'm not sure about is how to protect the microcontroller inputs and outputs.

Inputs

From this article I think that something like this, but with a pull-down resistor instead of pull-up resistor, will do the job.



The Schottkey diods will limit the voltage range. The 1kΩ limits the current, and together with the capacitor they filter high frequencies. I will calculate the values to keep information that can be captured by the microcontroller (22kHz sample rate in my case). I'm not exactly sure what the 10Ω resistor is for and whether I really nead it.

How does it sound to you? A proper protection of the microcontroller input from eurorack signals?

Outputs

I have no idea what to do here. I couldn't find relevant information online (probably because I don't know how to search). The outputs from the microcontroller are digital 3.3V GPIOs and analog outputs (yes, DAC, not PWM) ranging 0 to 5 volts.

BTW, the "microcontroller" is a bela board. I believe that it's irrelevant to the question. Feel free to correct me if I'm wrong.

Any input will be much appreciated, unless exceeding the voltage/current limit :-)
Tom
megaohm
Nagasaki45 wrote:

The Schottkey diods will limit the voltage range. The 1kΩ limits the current, and together with the capacitor they filter high frequencies. I will calculate the values to keep information that can be captured by the microcontroller (22kHz sample rate in my case). I'm not exactly sure what the 10Ω resistor is for and whether I really nead it.




That 10R resistor is needed and it needs to be much larger in value.

From the Digikey article/link:
" Note that a small series resistor is used to protect the Schottky diodes from overcurrent. As these diodes are only on for a short time, a small resistor works well; something on the order of 10 Ω usually works fine. Alternatively, the 10 Ω resistor can be omitted if the Schottky diodes are beefy enough to handle short-duration, high current pulses."

That scheme is assuming the over voltages are very short in duration.
You have to design for a constant over/under voltage.
You should have as your max the power supply rails.
For instance, what happens if I plug a steady -15V or a steady +15V source to that input (+/-12V for euro, but use +/-15V anyway)?

What I would do is remove the rest of the circuit and only look at the input Voltage, 10R resistor, and the two schottky diodes. Also, ignore the diode drop of those schottky diodes for simplicity.

If you apply -15V to the input it is like putting -15V across 10R connected to ground. How much power is dissipated in that resistor?

If +15V is applied to the input it is like 10V being connected to ground across that 10R resistor (15V minus the 5V rail the schottky is connected to).

A 1K resistor would seem to be better. That would be just under 1/4W for the -15V scenario.

V squared divided by R = Power

so

With a 1K resistor
15 x 15 = 225
225/1000 = 0.225 (just under 1/4W)

with a 10R resistor -
225/10 = 22.5W

I do not work with micro controllers often so take what I say with a grain of salt. I'm also self/community taught so my knowledge tends to equal my ignorance (a surprisingly accurate equation!).
Hoping others will come in and confirm or refute what I wrote.
av500
or do it like every Mutable Instruments module out there:

digital inputs:

input -> 100k -> 2n3904 -> 10k pullup to 3.3V (or 5V) -> CPU input pin.

analog input:

MCP6002 or 6004 dual/quad opamps running at 3.3V, see e.g. MI Grids schematics for details

in both cases the relatively high input resistance on the input makes sure no significant current will flow..
NANO-Jorge
When I have a doubt, I watch the Mutable Instruments schematics hihi


av500 wrote:
or do it like every Mutable Instruments module out there:

digital inputs:

input -> 100k -> 2n3904 -> 10k pullup to 3.3V (or 5V) -> CPU input pin.

analog input:

MCP6002 or 6004 dual/quad opamps running at 3.3V, see e.g. MI Grids schematics for details

in both cases the relatively high input resistance on the input makes sure no significant current will flow..
Synthiq
Even if your board runs from +5V, the microprocessor on the Beagleboard Black is still a chip using +3.3V I/O voltages so make sure the diodes are terminated to the right positive supply voltage.

I agree with megaaohm that the input resistor should be increased from 10ohm to 1kohm (or even higher, say 10kohm). This not only protect the schottky diodes from excessive current, it also reduce the loading of the driving circuit when the signal is outside the range of the microprocessor. With a higher valued input resistor, the voltage drop over the schottky diodes will be low enough to prevent the standard diodes from ever turning on so they can be eliminated together with the 1kohm resistor before them. The 20Mohm resistor with, say, a 5pF input capacitance will limit the analog bandwidth to 1.6kHz so get rid of that resistor as well.

Isolating the inputs with a transistor as av500 suggests also works but be aware the circuit inverts the digital signal. Also add a 47kohm resistor or a diode between base and emitter to limit the maximum negative voltage to less than -5V for a -15V input signals so the base-emitter diode doesn't break down.
Nagasaki45
Thanks for the help!

@megaohm, your recommendation seems the easiest to implement. 1K resistor and 2 diods per input. That's it, right?

@av500, thanks for the suggestion! I downloaded eagle and I'm currently looking at the schematics for grids, and have some questions:

- All of the analog inputs also have a potentiometer, which I don't need. Which components should I remove with the potentiomenter?
- There is a "REF_-5" point in the schematic. Is it a -5 volt reference point? If so, I think that this design is too complicated for what I'm doing. Otherwise, what is this?

@Synthiq, sorry, but my knowledge of electronics is very basic to say the least. I understood only parts of what you wrote.

Synthiq wrote:
Even if your board runs from +5V, the microprocessor on the Beagleboard Black is still a chip using +3.3V I/O voltages so make sure the diodes are terminated to the right positive supply voltage.


Yes, I know, but thanks for the heads up!

Synthiq wrote:
With a higher valued input resistor, the voltage drop over the schottky diodes will be low enough to prevent the standard diodes from ever turning on so they can be eliminated together with the 1kohm resistor before them. The 20Mohm resistor with, say, a 5pF input capacitance will limit the analog bandwidth to 1.6kHz so get rid of that resistor as well.


Sorry, I'm not following. Should I remove the diods? The capacitor? Do you have a schematic?

Synthiq wrote:
Isolating the inputs with a transistor as av500 suggests also works but be aware the circuit inverts the digital signal.


Thanks for the note. I see myself freaking out not understanding the readings :-)

Synthiq wrote:
Also add a 47kohm resistor or a diode between base and emitter to limit the maximum negative voltage to less than -5V for a -15V input signals so the base-emitter diode doesn't break down.


Couldn't understand the reason but understood the required change.
Nagasaki45
Two more general question:

1. A friend suggested to use a zener diode regulator like the one bellow. It looks to me relatively similar to the schottkey design, but with one less component. What are the reason for not going with this simplified design?



2. What about the outputs? How do I protect them? I don't want to blow the microcontroller because I connected a VCO by mistake to a bare output.

Thanks again!
Tom
ucacjbs
That circuit assumes positive inputs, so won’t protect from negative overloads.
CLee
The Zener protection circuit is non-linear around the cutoff voltage. Input a triangle wave and you'll see a curved response around the clipping voltage.
Synthiq
The purpose of the input protection is to limit the input signal to the absolute maximum and minimum levels specified for the microprocessor. This normally is no more than Vdd+0.3V and no less than Vss-0.3V. That means that if you use diodes to Vss and Vdd, the forward voltage drop when the diode conducts must be less than 0.3V. Schottky diodes have lower voltage drop than a comparable standard diode but even a schottky diode will have voltage drop more than 0.3V if the current is high enough so that's why input resistor should higher to limit the current.

In the simulation result below, the input resistor was adjusted so the voltage drop over the schottky diode was 0.3V with a 15V input signal. The other output uses standard diodes and the voltage drop here is more than twice as high. You can use the circuit to the left with R1, D1 and D2. You can add a capacitor in parallel with D2 if you want but it isn't necessary. I would still increase R1 to at least 10kohm to reduce the current that will flow in R1 when the signal becomes higher than 3.3V or lower than 0V. Note also that this input cannot handle audio signals that are centered around ground. That was the reason for adding the -5V reference in the MI schematic to shift the ground level from 0V to Vdd/2.



Now to the digital input:
The maximum ratings for the ON Semiconductor 2N3904 limits the emitter-base voltage to 6V. The simulation below shows the results for the three cases with just a 100kohm input resistor, 100kohm and 47kohm resistors and 100kohm resistor and diode. With just an input resistor, the base voltage follows the input signal down to -15V (this is just a simulation, in real life the emitter-base diode will act as zener diode and limit the level to a lower maximum) and will violate the specifiaction. With the 47kohm resistor or the diode between emitter and base, the base voltage will be limited to -5V or -0.7V and no spec violations occur.
If you want the processor to react to an positive edge of the external signal,note that the collector signal goes low so the processor must then react to the negative edge instead.



I hope this clarifies some of questions.
mskala
ucacjbs wrote:
That circuit assumes positive inputs, so won’t protect from negative overloads.


It'll clip negative inputs to the forward voltage of the Zener diode, which may be good enough to protect the microcontroller.
megaohm
Nagasaki45 wrote:
Thanks for the help!

@megaohm, your recommendation seems the easiest to implement. 1K resistor and 2 diods per input. That's it, right?


Actually, use Synthiq's suggestion of 10K instead of 1K.
1K can get to almost 1/4W and that is a typical resistor maximum rating.
Ideally, you stay far away from that max rating.
X10 is a good rule of thumb so
1K x 10 = 10K
With 10K you are not even close to the max power rating so that is good.
Also, what Synthiq was saying is that if you are driving this input with a bipolar LFO, say +/-5V square, every time the LFO is at -5V it will be like it's output is being driven to ground across a 1K resistor. That is a heavy load for your LFO output to drive. If you had that LFO going to a mult and sent to other modules you may notice drooping or odd behavior.
10K is a much lighter load than 1K so your LFO output will have an easier time with it.


10K resistor -> schottky diodes -> micro input
One diode to 0V and the other to whatever +V powers the micro.

The other suggestions can be better but this is good especially for simply modding gear to work with modular levels and unpredictability.
Sometimes there isn't room for extra circuitry but the resistor and two diodes can usually be located at the jack in a pinch.
Nagasaki45
Thank you all for the help!

I will go with the schottkey and 10k resistor.

One more question, again: what about the outputs from the microcontroller? How do I protect them?
MrsWedge
If you really want to go ape use opto-isolators. They are particularly useful for connecting possibly dirty digital signals to more sensitive circuitry as the grounds can be isolated from each other.

For the outputs I think that what you need to look for is protecting the output against shorts to ground. For analog signals an op-amp follower and a current limiting resistor should work.for the digital outputs you'll want to use a buffer/driver of some kind.
CLee
Nagasaki45 wrote:
Thank you all for the help!

I will go with the schottkey and 10k resistor.


If the input is an analog source going to an ADC check the documentation. A 10k input impedance may cause sampling errors. You may be better off putting an op amp buffer on the input and driving the diodes/microcontroller with a 1k resistor. The op amp buffer will be able to swing to 3v with a 1k load but the module input will just see the load of the buffer so everything stays copacetic in the outside world.
Nagasaki45
Hi all,

Things start to fall into shape. I worked on the schematic today, and got this:



This is the first time that I'm working with eagle, or designing a circuit in general, so please be patient :-)

On the left there are 3 blocks, the upper two are inputs, one with attenuation, the other is normalized to an output from the microcontroller that alternate between 0 and 5 volts rapidly. It should trigger the sample and hold (in software) continuously when nothing is plugged into the jack. An attempt to explain the resistor and diode there will come later. Also, I used stereo jacks in the schematics because I couldn't find other 3.5mm jacks, so don't let this confuse you.

Now for the outputs. The mixer was copied from doepfer DIY page. I removed the output attenuator as I don't need it.

The gate outputs are probably the weakest part here. It was copied from look mum no computer. Will it work or is it really bad solution?
If it's a terrible idea I will be happy to get some help with buffering the output. I couldn't understand how it should be done.

You can notice that the diode and resistor in the normalization path to the sample and hold are the same as the ones on the gate outputs. This is my intuitive attempt to protect the microcontroller clock output in case it touches the eurorack clock when a plug breaks the normalization. Is this necessary? Is there a better solution?

Note that I'm going to use only the analog inputs and analog outputs of the Bela, which all work with 5 volts.

Any comment will be much appreciated!

Thanks again for all the help,
Tom
CLee
I'll post these here as ideas for you. They're the input and output circuits for an upcoming module (4U Euclidean Sequencer) that runs on an Arduino Nano (5 volts)

On the inputs you can ignore the TTL inverters. I needed them for MIDI out, so rather than leave 2/3 of the package unused I put them in the signal chain of the input. With them deleted the logic of the input is inverted.

The input uses LM393 Comparators. D3/R1 set the trigger voltage and R6 and R10 create hysteresis in the comparator. This way you get repeatable, glitch-free triggering at a level you can set with a voltage divider. The one on the right has an AC and DC input. I used a resistor and diode to set the trigger threshold so no part substitution is needed based on power supply voltage. The open collector output of the comparator allows you to translate down to 5v just by tying the output to the 5v supply with a resistor.

The outputs are low output impedance, fully buffered and compensate for fanning out to multiple modules.

With these in-outs there's no way to blow up your microcontroller by plugging the wrong thing into the wrong place.

EDIT: Forgot to add that the comparator chip runs of V+ and Ground, not +/-V



Synthiq
If you plug in a cable to the sample/hold input but leave the other end of the cable unconnected, the input will be floating and undefined so I would add a 100kohm resistor between the jack and ground to hold the input low in this case.

The LEDs D5-D8 must be reversed to turn them on. assuming outputs O0-O3 are positive. I'm also concerned that the LEDs and possibly the outputs with low impedance loads are too much of a load for the 47kohm potentiometers. If outputs J5-J8 are just gate outputs, I would assume you want fixed 5V gate signals. In this case they should be connected directly to OUT0-OUT3 instead of being attenuated by P2-P5.

I'm not sure diodes D9-D12 are really needed.

It seems to me like the the two output jacks J3 and J4 will generate the same signal so why not drive both outputs from the same amplifier? If these outputs are CV outputs that must be precise, they should be buffered by circuits similar to the ones suggested by CLee above. Otherwise a 1kohm resistor between the amplifier and the jack can be used for noncritical signals. Without any sort of isolation, the amplifiers may oscillate if they are loaded with too much capacitance from, for instance, long patch cables.
Nagasaki45
CLee wrote:
Nagasaki45 wrote:
Thank you all for the help!

I will go with the schottkey and 10k resistor.


If the input is an analog source going to an ADC check the documentation. A 10k input impedance may cause sampling errors. You may be better off putting an op amp buffer on the input and driving the diodes/microcontroller with a 1k resistor. The op amp buffer will be able to swing to 3v with a 1k load but the module input will just see the load of the buffer so everything stays copacetic in the outside world.


I don't mind having a sampling error too much so I guess it's fine.
Nagasaki45
I can't believe I uploaded a schematic with so many mistake. Really sorry...

Here's an updated one



Synthiq wrote:
If you plug in a cable to the sample/hold input but leave the other end of the cable unconnected, the input will be floating and undefined so I would add a 100kohm resistor between the jack and ground to hold the input low in this case.


Yeah, first mistake! I know that I need a pull-down resistor, just forgot it, now it's there.

Synthiq wrote:
The LEDs D5-D8 must be reversed to turn them on. assuming outputs O0-O3 are positive.


Oops... Now fixed.

Synthiq wrote:
I'm also concerned that the LEDs and possibly the outputs with low impedance loads are too much of a load for the 47kohm potentiometers. If outputs J5-J8 are just gate outputs, I would assume you want fixed 5V gate signals. In this case they should be connected directly to OUT0-OUT3 instead of being attenuated by P2-P5.


Yeah. I forgot 4 potentiometers and made a mess connecting things to the wrong places. The idea is pretty much a 2 channels pressure points, minus the pressure part, plus summing the columns and some fancy digital control over which column is on. Hope it makes more sense now.

Synthiq wrote:
I'm not sure diodes D9-D12 are really needed.


I think I'm starting to grasp this op-amp voltage follower idea. Are the new outputs better?

Synthiq wrote:
It seems to me like the the two output jacks J3 and J4 will generate the same signal so why not drive both outputs from the same amplifier?


Should be fixed now.

Synthiq wrote:
If these outputs are CV outputs that must be precise, they should be buffered by circuits similar to the ones suggested by CLee above. Otherwise a 1kohm resistor between the amplifier and the jack can be used for noncritical signals. Without any sort of isolation, the amplifiers may oscillate if they are loaded with too much capacitance from, for instance, long patch cables.


Nothing needs to be precise. I added the resistor as you suggested. They are also added to the gate outputs.

Thanks a lot for putting the time and effort to help me with this. Much appreciated!
Tom
av500
Nagasaki45 wrote:

@av500, thanks for the suggestion! I downloaded eagle and I'm currently looking at the schematics for grids, and have some questions:

- All of the analog inputs also have a potentiometer, which I don't need. Which components should I remove with the potentiomenter?
- There is a "REF_-5" point in the schematic. Is it a -5 volt reference point? If so, I think that this design is too complicated for what I'm doing. Otherwise, what is this?


- the pot value is added to the CV input value, so remove the pot and the summing resistor

- the opamp is in inverting configuration, so in order to shift from -5V / 5V to 0V / 5V (or 3.3V) you need to add a negative voltage. there is nothing complicated about a 25¢ lm4040 and a resistor.
av500
Synthiq wrote:

Now to the digital input:
The maximum ratings for the ON Semiconductor 2N3904 limits the emitter-base voltage to 6V....


in theory you are right. in practice it works just fine with thousands of Mutable modules (and many others). The 100k resistor limits the current to 15V/100k = 0.2mA
av500
megaohm wrote:

Actually, use Synthiq's suggestion of 10K instead of 1K.
...
Also, what Synthiq was saying is that if you are driving this input with a bipolar LFO, say +/-5V square, every time the LFO is at -5V it will be like it's output is being driven to ground across a 1K resistor. That is a heavy load for your LFO output to drive. If you had that LFO going to a mult and sent to other modules you may notice drooping or odd behavior.
10K is a much lighter load than 1K so your LFO output will have an easier time with it.


your typical Eurorack LFO with an 1k resistor at the output will have a hard time with either 1K or 10k:

with 1k, you get only half the voltage out, with 10k is 90% - in my opinion both are not acceptable. The general consensus is that Eurorack inputs have around 100k input impedance so you lose a max of 1% of the signal with the typical 1k at the output.
Synthiq
av500 wrote:

Synthiq wrote:
Now to the digital input:
The maximum ratings for the ON Semiconductor 2N3904 limits the emitter-base voltage to 6V....

in theory you are right. in practice it works just fine with thousands of Mutable modules (and many others). The 100k resistor limits the current to 15V/100k = 0.2mA

Yes, it will not break the transistor and when used as a noise source it will operate outside the maximum ratings for years. But that doesn't mean that it will not cause any long term changes to the transistor. So my advice to people who doesn't have a good understanding of semiconductor physics and understand the consequences of breaking a rule is still to stay inside the maximum ratings. After all, we are only talking about adding a 5 cent resistor...

av500 wrote:

megaohm wrote:


Actually, use Synthiq's suggestion of 10K instead of 1K.
...
Also, what Synthiq was saying is that if you are driving this input with a bipolar LFO, say +/-5V square, every time the LFO is at -5V it will be like it's output is being driven to ground across a 1K resistor. That is a heavy load for your LFO output to drive. If you had that LFO going to a mult and sent to other modules you may notice drooping or odd behavior.
10K is a much lighter load than 1K so your LFO output will have an easier time with it.


your typical Eurorack LFO with an 1k resistor at the output will have a hard time with either 1K or 10k:

with 1k, you get only half the voltage out, with 10k is 90% - in my opinion both are not acceptable. The general consensus is that Eurorack inputs have around 100k input impedance so you lose a max of 1% of the signal with the typical 1k at the output.


I don't disagree with you, but as mentioned earlier it can cause problems if the ADC sees a high source resistance. The 10-bit ADCs in Microchip's 8 bit controllers I have most experience with recommend no more than 10kohm but other controllers may have other requirements so the specs have to be read carefully.
emmaker
I don't think that U1G is going to work.

Looks like the power for U1G is between V+ and ground with the + input of the op-amps at ground. You either want to put the + inputs at virtual ground and rebias or run the op-amp with a bipolar (+/-) power supply.

Put the circuit into LTSpice to show what will happen. Note this is only the first op-amp so there will be another inversion after this.

Also the jack J2 is shown as a TRS (Tip, Ring, Sleeve) jack in the schematic. Don't know if you want a tip and sleeve jack with a switch there or not.


MUFF WIGGLER Forum Index -> Music Tech DIY Goto page 1, 2  Next [all]
Page 1 of 2
Powered by phpBB © phpBB Group