ESP32 DAC Envelope Generator – Part 2

Following on the back of my ESP32 DAC Envelope Generator and in particular my note at the start that it was essentially the code algorithm and none of the electronics that might make it useful, I started to try to find the simplest possible circuit that Just Might Work as a voltage controlled amplifier (VCA) for demonstration purposes. It turned out to be quite a “rabbit hole”. This post details where I ended up.

But first, just to be clear, I’ll repeat my warning from last time – don’t hook this up to anything else unless you really know what you are doing (unlike me). This is my fumbling around with a little knowledge, largely being “dangerous”, based on random circuits I’ve found online. If that isn’t enough to scare you off, I’m not sure what is…

Warning! I strongly recommend using old or second hand equipment for your experiments.  I am not responsible for any damage to expensive instruments!

If you are new to electronics and microcontrollers, see the Getting Started pages.

Introduction

I’m after a voltage-controlled amplifier (VCA) that can be controlled with my 0-3V3 signal and that could be used to shape an audio signal. This can be thought of as a “black box” with an audio input and output and a control voltage.

But of course there are a large number of considerations if one is to do this properly.

So naturally I threw all that out the window and started searching online for “simple VCA circuit” to see what comes back.

I’m not after any specific quality of VCA, I just want to see the art of the possible with regards to fewest components, simplest design, and useful demonstration of the envelope generator working.

The designs I’ve found can be categorised largely as follows:

  • Opto-electronic based designs – e.g. optoisolators, vacrols or similar.
  • Transistor based designs – often paired with diodes.
  • Op-amp and amplifier based designs – these are starting to get more complex, but seem to produce some pretty usable designs from what I can see.
  • Dedicated chips – e.g. the AS3330, AS3360 and compatible devices.

I’d suggest that I’ve probably listed these in order of simplicity (simplest first) which also seems to be inversely proportional to quality of output (that is, the best is last).

Opto-electronic Based Designs

These had instant appeal to me as they appear to be pretty simple on the face of things. Essentially the control voltage modulates the light emitting side of an optoelectronic device such as an LED; which in turn modulates a light sensing side which controls the level of an audio signal.

Here is one of the simplest designs I found using an optoisolator: https://www.reddit.com/r/synthdiy/comments/lreytp/simple_vca_in_eurorack_format_on_stripboard/
This includes a circuit for an LED to indicate activity, which I wasn’t so bothered about, so I’ve simplified it further to the following:

This is about the simplest thing I’ve found and it does kind of work to a degree. I found myself with some cheap optoisolators so used those. The key points to consider for this:

  • The resistor on the CV input has to limit the current through the optoisolator’s LED.
  • The optoisolator’s LED will only start conducting when the CV input reaches the LED’s forward voltage.

I used a PC817 and PC814. The only difference as far as I can see is that the 814 allows for AC operation, incorporating two diodes in the input side.

For both, the forward voltage of the LED is nominally 1.2-1.4V, which is almost half the CV level! This means that attempting to use the envelope generator “as is” significantly reduces the effectiveness of the levels.

There might be a way to bias the input signal, but I’ve not found a simple way in electronics to do this. Ideally, the voltage range for the input would end up in the region of 1.2-4.5V (i.e. up to 3V3+1.2V), but I don’t know how to do that myself for a slow changing voltage like this – at least not without getting more complicated (and probably involving OpAmps) I must admit to being seriously tempted to give this idea a go as suggested by “Chip” on Mastodon as a very crude possibility, but I’m not sure how the DAC would like that…

Another option might be some simple amplification so that the voltage drop across the LED is a smaller fraction of the whole range.

One simple way to avoid the additional electronics is to introduce an offset in the code so that the output of the DAC is in the range 1.2-3.3V, so that is what I’ve done for now and that seems to work pretty well.

On the oscilloscope trace below, I have the output to a 8Ω speaker. We can see that it is ridiculously noisy… but it does work! It sounds a lot better than it looks and there is no filtering or processing going on other than what is shown in the circuit above.

Using a minimum ATTACK_LEVEL of 70 seems to ensure there is little audio leaking, but it is possible to hear where the voltage drops below the forward voltage of the LED – there is a slight blip. In the photo below it is clear to see the non-linearity of the response (top) compared to the control voltage (bottom), especially in the rising ATTACK stage.

The audio in this case is the ESP32 generating a 440Hz tone using the Arduino tone() function, so it is a 0-3V3 square wave being generated.

Most designs using optoelectronics tend to use a VACTROL. This is effectively an LED glued to a LDR in a sealed enclosure. They can be bought or made (apparently VACTROL is a brand name, but that is what everyone calls them).

Here are some circuits and tutorials using a VACTROL as a VCA that look quite interesting and probably worth following up:

  • Kirstian Blastol’s Modular in a Week video “Vactrol VCAs and CV Attenuators”. This video shows how to build your own vactrols using a variety of methods. His “Schematic_Vactrol” is essentially the same circuit as shown above for the optoisolator…
  • Benjie Jiao’s “Passive Vactrol VCA” which is a very similar circuit again, described as a “low pass gate”.
  • “Voltage to resistance” from thesquarewaveparade (search for thesquarewaveparade VtoR.jpg) has a range of increasingly complex, but still relatively straightforward to understand circuits for a voltage-controlled resistance.

But the best discussion on how to make best use of a Vactrol, and hence by inference (by me) probably also an optoisolator can be found here:

I just used exactly the same circuit as for my optoisolator, but the Vactrol I’m using seems to have a larger forward voltage. It is marked VTL5C9, but I’m not sure it’s an “official” Xvive one – but if it is, then the datasheet states a forward voltage of 2.5V which is rather a lot when my control voltage tops out at 3.3V!

To be any use at all, I’ve had to set the minimum ATTACK_LEVEL to 110 which has essentially halved the resolution. But once again, it does work for some definition of “work”.

The longer lead is the anode for the LED side – then I’ve just used it in place of the optoisolator.

Transistor Based Designs

A number of simple VCA designs use a single transistor or a transistor and a diode. I found this one being discussed online so gave that a go:

As far as I can see this is sort of “reversed” in the sense that rather than the control voltage controlling the audio, to me it looks like the audio is controlling the control voltage signal… the end result is still audio only when the control voltage enables it though.

I didn’t have a BC549B transistor, which I believe is a common low-noise NPN transistor, so I used a 2N3904 instead. Note that the pin assignments are different between the two!

One of the advantages of this design appears to be good tracking of the envelope as can be seen below. The actual output level isn’t very high though – the blue scale is 200mV compared to the yellow’s 1V below. I suspect that is a result of attempting to drive the 8Ω speaker directly. I guess this would need to go into some kind of buffer or amplifier stage with some sensible impedance matching at the very least, to be particularly useful.

There is some discussion of this circuit here: https://www.modwiggler.com/forum/viewtopic.php?t=168810. I believe it is only working in the simple case shown above as the audio signal is biased to a 0-3.3V signal rather than a +/- signal.

A bit further down in the linked thread there is an example of how to cope with an unbiased input audio signal by adding a DC bias to the transistor base, so I tried a variant of that as follows:

As I’m using a 3V3 control voltage, I’ve used 680kΩ and 100kΩ to bias the transistor at around 420mV. A coupling capacitor removes any existing DC bias to the audio signal prior to feeding it in.

The final signal at the loudspeaker is pretty low as before, but if I take the output from just before C1 it is looking pretty good to me although we can see the output is still positive only.

Once again, the trick now would be to buffer or set up the load on this signal to preserve it as an actual audio out.

This is pretty crude, but then the discussions implied nothing less. But for a handful of largely passive components, this does seem to show some promise.

For a proper discussion on the workings of transistor based VCAs, I can recommend:

OpAmp Output Buffer

For completeness I briefly experimented with adding a LM358 OpAmp based buffer (or “voltage follower”) circuit as follows:

This is connected instead of the speaker in the previous circuit so the input is coming from the right hand side of the 100nF capacitor, so the input is unbiased. But the OpAmp is running from 5V and there are two resistors on the input which adds a 2.5V bias.

The output is pretty good, but I can see the top of the envelope being clipped in the positive direction. I’m not entirely sure why – I thought powering it from 5V (rather than 3V3) would give enough headroom for a decent signal, but maybe not.

Also my limited electronics knowledge is failing me in understanding how the signal shown above (measured at the collector output for the transistor) becomes the signal shown below (measured after the final capacitor in the buffer circuit).
Once again it is probably something to do with my lack of understanding of output impedance and related topics.

It might work better with a LMV358 rather than a LM358 as apparently the LMV version runs better at lower voltages with output much closer to the power rails (“rail to rail”). It might also be possible to adjust the bias resistors and re-align the signals somehow…

Other Transistor Circuits

I also found a couple of circuits where the control voltage is fed into the base of the transistor to control the audio passing through it in a more “traditional” (or at least, “expected” by me) manner. But I wasn’t really able to get them working, so I didn’t take those any further. One I never actually tried as the LMNC “painfully simple VCA” which is essentially just a diode and transistor.

I also found a circuit describing a “swing VCA” but again my initial experiments didn’t seem to give me anything useful, so I’ve largely ignored those too.

OpAmps and Amplifier Based Designs

In one of the discussions I found talk of a TDA7052A in use as a VCA. It was posted by elektrouwe in the discussion here: https://electro-music.com/forum/topic-63383.html&postorder=asc. Further on in the discussion was another circuit, posted by Hammer.

The original TDA7052 is a 1W mono audio amplifier apparently designed for battery led operations and to be powered by 3-18V. The TDA7052A is an upgrade that adds DC voltage volume control, but I believe the power requirements have increased slightly to requiring a 4.5-18V source.

A good discussion for how to use them can be found here: https://electro-dan.co.uk/electronics/tda7052.aspx.

In particular, note that elektrouwe states:

“TDA7052A has a gain of ~ 56x, which means Vin should be in the 100mV range, otherwise you need an input voltage divider. You MUST use an input coupling cap., because the chip generates an internal DC bias voltage.

Pretty much every other example circuit I’ve seen shows the two outputs (pin 5 and 8) connected directly to a 8Ω loudspeaker, but the design above is only using one of the outputs. The two outputs apparently provide an inverting and non-inverting output option.

Here are some key points that might be relevant to its use as a VCA (from the “TDA7052A/AT: 1 W BTL mono audio amplifier with DC volume control” datasheet, dated July 1994, sometimes braded Philips, sometimes NXP):

  • “The maximum gain of the amplifier is fixed at 35.5 dB.”
  • “The DC volume control stage has a logarithmic control characteristic.”
  • “The total gain can be controlled from 35.5 dB to −44 dB.”
  • “If the DC volume control voltage is below 0.3 V, the device switches to the mute mode.”
  • Positive supply voltage range: 4.5V to 18V.

From the graphs in the datasheet (shown below), the response appears pretty linear when the DC volume control voltage is between 0.4 and 1.2V.

So I think the summary is that to use this as a VCA then the control voltage needs scaling to the 0.4-1.2V range (or thereabouts) and the input signal needs to allow for a maximum 35.5dB gain at the high end of that range. The article I linked to earlier describes the original TDA7052’s 39dB gain as equivalent to a voltage gain of 90 times, so to keep within the 0-5V presumed output range, that would require an input audio signal in the 50-100mV range.

I took an approach that largely used elements of each circuit. From here, we are told:

“The DC volume control is at pin 4. The TDA7052A produces a voltage of around +1.125V at this pin, as well using the current at this pin as a volume reference.”

So I thought the approach of using a PNP transistor to modulate that according to the control voltage was probably the way to go.

To get my CV (which is in the 0-3.3V range) down to 0-1.2V I used a voltage divider of a 2MΩ and 1MΩ resistor dropping the range down to approx 0-1.2V. To keep the audio signal within a sensible range to allow for the full gain, I used another voltage divider, this time using a 1MΩ and 100kΩ resistor dropping my 0-3.3V test signal down to around 0-300mV, which is perhaps still a little high, but it was fine for a test. Any final circuit may have to account for a line-level audio input (probably) so will need to be adjusted accordingly.

Note, from my experiments, the audio input (pin 2) seems to be internally biased at around 2.6V. This was with either a 3V3 VCC or 5V VCC.

So here are the components used:

  • 1x TDA5072A
  • 1x BC557 PNP transistor
  • 1x 1KΩ resistor
  • 2x 1MΩ resistors
  • 1x 2MΩ resistor
  • 2x 1uF electrolytic capacitors
  • 1x 10uF electrolytic capacitor

The circuit is designed for a 0-3.3V CV input and is powered from a 0-5V supply.

And here is my test circuit:

And this seems to work fairly well. In the following trace (I’ve swapped the traces over – blue is now the CV and yellow the output), we can see the effect of both the logarithmic response of the DC volume control of the TDA5072A and possibly some maxing out of the volume when at full (I’m not sure tbh).

But it certainly sounds convincing to me and is perhaps the most promising solution so far.

The LM13700 Transconductance Amplifier

The LM13700 appears to be a massively useful circuit in synthesizer designs! I’ve found it used in at least three designs online and it has a chapter of its own in “Make: Analog Synthesizers” by Ray Wilson.

I’ve not got any at the moment, but here are links to the designs and some further discussions about it:

This will be one to come back to.

Closing Thoughts

This was a bit of a diversion, and really I was after the cheapest, simplest, VCA I could manage to build.

I really like the simplicity of the optoisolator/vactrol approach, and for higher signal voltages I can see that it would work well, but for 0-3.3V signals the non-linearity from the use of the LED is just too great. If I can find a simple way to add ~1.5V to the signal then this would probably work pretty well.

The transistor designs were very encouraging, but I suspect I’d really need a little more electronics knowledge to be able to sensibly use them in a circuit.

The TDA7052 is the easiest for me to understand at present, but I would like to return to the topic if I managed to get hold of some LM13700 equivalent devices at some point.

One group I never mentioned is dedicated VCA/EG chips, like the AS3330/33360 or the CEM2164. Again this is probably a subject to return to at some point, but I’m getting quite well past simple, cheap, lo-fi at that point – these are used in proper modular synth designs.

Just a reminder – none of these circuits have any input protection, there is no buffering, and no thoughts of impedance – they are literally the bare bones that might have a hope of kind of working (if at all). They are just part of me learning how some of these things work.

They are not intended for any real use and certainly not for use with any equipment that isn’t disposable.

Kevin

Leave a comment