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

Ext Gate/clock IN to Gate OUT with microcontroller
MUFF WIGGLER Forum Index -> Music Tech DIY  
Author Ext Gate/clock IN to Gate OUT with microcontroller
ESSY
I wanted to get some of your valued opinions on this circuit I put together (***by ripping off circuits around the web like this). I feel I am using too many op-amps / components, and that it could be greatly simplified if I wasn't such a newbie with analog circuits.

The goal of this circuit is to take an external gate/clock signal IN, and either produce an identical/synced gate output OR (based on the toggle switch) activate the Gate Out via a micro-controller.



I am starting to think the MCP6002 buffer on the output isn't necessary. Or perhaps I can ditch the Gate IN op-amp entirely and just put the schottkey diodes after the toggle switch. I also feel like there is another way to light the LED when Gate is HIGH without using an additional op-amp or effecting the gate out voltage.

Ideally the external gate IN should be able to handle any signal you put in it - or at least avoid unwanted behaviour.

Apparently the Ext. Gate IN can all be done with a NPN transistor - but when I hook this circuit up all I get is a 1.78V rise.
Synthiq
If you only deal with logic levels you can avoid all the opamps. The circuit below will do the same thing as the original circuit and will select the external gate signal or the gate signal from the microprocessor and buffer the output and drive a LED. If you don't have clean logic input signals on EXT_GATE_IN pin, I would consider replacing the 4050 with two 40106 schmitt trigger inverters in series to ensure good logic levels at the output.

Graham Hinton
ESSY wrote:
I feel I am using too many op-amps / components, and that it could be greatly simplified if I wasn't such a newbie with analog circuits.

The goal of this circuit is to take an external gate/clock signal IN, and either produce an identical/synced gate output OR (based on the toggle switch) activate the Gate Out via a micro-controller.

Ideally the external gate IN should be able to handle any signal you put in it - or at least avoid unwanted behaviour.


You are falling into the traps that people who know a little about analogue circuitry usually do when they start trying to deal with logic circuitry.

For a start, your input stage has no noise filtering. This circuit is better and gets to 5V levels in one go using the output transistor as an emitter follower so it has better drive than an open collector:



This is a fast comparator, not an op amp, and uses positive feedback via R64 to create a hysteresis window to snap over noise. The ratio of R61 to R64 sets the noise margin, but the values shown will be optimum. R66/R67 sets the threshold voltage.

Your input stage will give a burst of oscillation if you feed it a slow rising edge, like an LFO, as it passes through the threshold voltage which would give false counts of a clock.

The other thing you are doing wrong is putting a logic signal through a mechanical switch. This will create more edges as the switch bounces. If you want to select logic signals use a logic multiplexer and if you have a manual switch debounce it first. In your case as you have a PIC involved all you need to do is put the input clock in to a pin, put the switch in to another, debounce them both and do the selecting in software.
ESSY
thanks for the replies Graham Hinton and Synthiq.

Both circuits seem to do what I am looking for. I happened to have a comparator chip on hand last night so I was able to test out Hintons circuit with success. I am going to give Synthiq a try perhaps this weekend. I also finally learned how a transistor works in this process which is awesome hyper

Since I happen to have an extra op-amp from my MCP6002 is it possible to create a comparator / schmitt trigger with an op-amp?

I'll post an update once I get time to hack through this.

Thanks again.
Graham Hinton
ESSY wrote:
Since I happen to have an extra op-amp from my MCP6002 is it possible to create a comparator / schmitt trigger with an op-amp?


Yes, but the output will swing between the analogue power rails less about 2V and you then have to convert to logic levels. Comparators like the LM393 and LM339 have an open transistor collector output, but the emitter is connected to the -ve rail. If this is powered between +ve and 0V it may be used with a pullup to the logic rail to get a 0-5V signal. You get a fast on when the transistor conducts, but a slower rise when it turns off determined by the pullup resistor and stray capacitance. To get the rise faster you have to use lower resistor values and then you are injecting higher currents in to your system 0V. The LM311 is unique in that both the collector and emitter are available and can be wired as an emitter follower as shown.

As you originally said that you wanted an identical signal (i.e. reshaped) be careful with circuits that introduce slight delays as these will limit your highest frequency clock. Or circuits that don't give clean switching edges which will cause counting errors.
Synthiq
ESSY wrote:
Since I happen to have an extra op-amp from my MCP6002 is it possible to create a comparator / schmitt trigger with an op-amp?

Yes, with some reservations.

Opamps are frequency compensated so they don't oscillate when you apply feedback, but this also makes them respond slower than a dedicated comparator. For slow or non-critical applications an opamp works fine, but if response time is critical you should use a real comparator.

Comparators are designed to handle large differential signals at the inputs but this is not always the case for opamps and some even have clamps between the inputs to limit the difference to a few volts. I have only seen this on bipolar input stages so jfet and cmos opamps are probably fine.

The MCP6002 is a low voltage opamp and would in this case be powered between ground and 5V. Since the input signal may be outside this range, you need to limit the input signal with diode clamps and this may load the source if you use 3.3kohm input resistor as in Graham Hinton's example above.

Graham is right about the problem with bouncing in the switch while clocks are applied to the inputs. Taking that into account, I modified my circuit and also added the remaining inverters in parallel to be able to drive the LED directly without the NPN transistor. Personally I would select a more efficient LED that doesn't need 10mA to be bright enough.

Graham Hinton
Synthiq wrote:

Graham is right about the problem with bouncing in the switch while clocks are applied to the inputs. Taking that into account, I modified my circuit and also added the remaining inverters in parallel to be able to drive the LED directly without the NPN transistor.


There is a better and easier way of debouncing with CMOS buffers--put 100k positive feedback across the 4050 or two 40106s. This can also be used to debounce a c/o switch or pushbutton that has 0V and +5V on its two poles. The buffer input is never floating as the switch changes over.

In general my advice is if you are going to do a digital circuit do a proper digital logic circuit and don't mix in analogue elements like diodes and capacitors all over the place. That is called MML, Mickey Mouse Logic. Once you have interfaced your signals to the digital domain, stay with digital techniques.
Synthiq
Graham Hinton wrote:
Synthiq wrote:


Graham is right about the problem with bouncing in the switch while clocks are applied to the inputs. Taking that into account, I modified my circuit and also added the remaining inverters in parallel to be able to drive the LED directly without the NPN transistor.


There is a better and easier way of debouncing with CMOS buffers--put 100k positive feedback across the 4050 or two 40106s. This can also be used to debounce a c/o switch or pushbutton that has 0V and +5V on its two poles. The buffer input is never floating as the switch changes over.

In general my advice is if you are going to do a digital circuit do a proper digital logic circuit and don't mix in analogue elements like diodes and capacitors all over the place. That is called MML, Mickey Mouse Logic. Once you have interfaced your signals to the digital domain, stay with digital techniques.

Why would it be easier to add a 100kohm resistor across the buffer than adding a capacitor at the input? A resistor may be better for very fast input signals but a capacitor, together with the input resistor, can also help filter out high frequency noise so the best alternative depends on the characteristics of the input signal.

The other problem here is that the input signal is for all practical purposes an analog signal and the switch is far from a digital circuit so there is no point in pretending we are working with logic signals. If 5V logic is used, the diodes and the resistor at the input are absolutely necessary to limit the input current if the signal goes outside the supply voltage. This is not Micky Mouse Logic, this is analog signal conditioning. Sure you can use an LM311 at the input and avoid the diodes, but if I have to choose between an LM311 that constantly burn >100mW or adding a couple of diodes and use a CMOS input stage with no static power consumption I go the low power route any day.
Graham Hinton
Synthiq wrote:

Why would it be easier to add a 100kohm resistor across the buffer than adding a capacitor at the input? A resistor may be better for very fast input signals but a capacitor, together with the input resistor, can also help filter out high frequency noise so the best alternative depends on the characteristics of the input signal.


An RC filter adds delay to the signal whereas a positive feedback latch changes on the first transition. Low frequency noise from switch bounce is a larger problem than high frequency noise, some switches take several ms to settle.

Quote:

The other problem here is that the input signal is for all practical purposes an analog signal and the switch is far from a digital circuit so there is no point in pretending we are working with logic signals.


Conversely, don't put signals that are already digital through analogue conditioning.

Quote:
If 5V logic is used, the diodes and the resistor at the input are absolutely necessary to limit the input current if the signal goes outside the supply voltage. This is not Micky Mouse Logic, this is analog signal conditioning.


I was referring to the main circuit functions, after the input processing.
Synthiq
Graham Hinton wrote:
Synthiq wrote:

Why would it be easier to add a 100kohm resistor across the buffer than adding a capacitor at the input? A resistor may be better for very fast input signals but a capacitor, together with the input resistor, can also help filter out high frequency noise so the best alternative depends on the characteristics of the input signal.

An RC filter adds delay to the signal whereas a positive feedback latch changes on the first transition. Low frequency noise from switch bounce is a larger problem than high frequency noise, some switches take several ms to settle.

With the components I used, the delay would be 100us and this shouldn't be an issue if the signal is a gate signal as the name implies. I tested with a 220pF capacitor and only saw some minor variations during the bouncing so think the capacitor can be reduced to 10pF if 100us is too long. As for the high frequency noise, I was referring to external noise, not from the switch bouncing. We don't know a lot about this external signal, so it's hard to say if this is relevant or not.
Quote:
Quote:

The other problem here is that the input signal is for all practical purposes an analog signal and the switch is far from a digital circuit so there is no point in pretending we are working with logic signals.

Conversely, don't put signals that are already digital through analogue conditioning.

If you are referring to sending the gate signal from the PIC through the lowpass filter, that may be true but I didn't find an easy way to do it with just one IC and besides the small delay there are no real downside with it except for principal reasons. But I tend to be pragmatic so I have no issue with it.
Quote:
Quote:

If 5V logic is used, the diodes and the resistor at the input are absolutely necessary to limit the input current if the signal goes outside the supply voltage. This is not Micky Mouse Logic, this is analog signal conditioning.

I was referring to the main circuit functions, after the input processing.

In my case, the resistor and diodes are the input processing.

In either case, by now I think ESSY has got a good idea of the pros and cons of the different alternatives so I leave it to ESSY to decide how to move forward.
ESSY
I am curious why an optocoupler has no been considered yet. When I started building this circuit I didn't really know what an optocoupler really did, but it seems like the ideal solution no? It decouples unwanted voltages levels from the micro-controller, while still generating the gate signal I want at a safe 0V-5V level.

Are there any drawbacks to using an optocoupler for this specific problem?

Here is the schematic I ended up using:

Synthiq
The input impedance is orders of magnitude lower than the other alternatives and not all outputs will be able to drive it, especially if the output has a 1kohm output resistance. You can most likely still trigger the optocoupler with a 1kohm output resistance, but the voltage at the input will drop so you may run into problem if it is also connected to other inputs in parallel.
ESSY
Synthiq wrote:
The input impedance is orders of magnitude lower than the other alternatives and not all outputs will be able to drive it, especially if the output has a 1kohm output resistance. You can most likely still trigger the optocoupler with a 1kohm output resistance, but the voltage at the input will drop so you may run into problem if it is also connected to other inputs in parallel.


Input Impedance is something I need to read up on, but I think what your saying is that if I feed my clock signal into this, everywhere else I use that clock signal will suffer?
Synthiq
ESSY wrote:
Input Impedance is something I need to read up on, but I think what your saying is that if I feed my clock signal into this, everywhere else I use that clock signal will suffer?

If the driver has a 1kohm series resistor as a current limiter in case the output is shorted, there will be a significant voltage drop if you load it with your circuit. With a 5V driver voltage and 1.7V across the diode in the optocoupler, the voltage after the 1kohm resistor would be 2.3V so you would loose more than half the signal. If this will affect other inputs driven by the same signal all depends on how high voltage they need to respond.

The main reason to use optocouplers is that you can have electrical isolation between the input side and the output side. In this case they are connected together and there is no advantage compared to a 2N3904 with a 100kohm base resistor driven by the input signal. Don't complicate things if you don't have to. Both the optocoupler and a 2N3904 stage are inverting the signal so in either case you would need to add another inverter to get the right polarity.
MUFF WIGGLER Forum Index -> Music Tech DIY  
Page 1 of 1
Powered by phpBB © phpBB Group