PWM compressor

GroupDIY Audio Forum

Help Support GroupDIY Audio Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.
zamproject said:
Hi

Maybe it's because ppl (like me?!?) reading Ian asking "what about a uControled PWM compressor ? " think that you have a plan to work on it  :-X

best
Zam

I hope it's not inadequate to bump this old topic, but I just started building a PWM based VCA .
The circuit is based on the schematic from Rod Elliot: http://sound.whsites.net/articles/vca-techniques.html#s10
I'm using an Arduino Uno to generate the PWM, a 74hct4066 for switching, a cd40106 as inverter and a sallen-key filter on the output (built around a TL072).
At a first glance it's working better than expected, but of course the arduino's 8bit PWM and the maximum PWM frequency of 62khz are a limiting factor. I'll swap the Uno for an STM32F4 and will see, how the circuit handles faster PWM speeds. Besides that, the rest is basically just a detector circuit (which is just a buffered analog input on the MCU) and C-code (lots of it!), to turn this into a full compressor.  :)
I'll keep you posted and if it works out, I'll upload some Code & Schematics on Github.
 
As I said a few years ago in this thread, VCAs are not the hard part for dynamics processing.

===

In my drum tuners I make passable sine waves using a micro PWM... (good enough to get the drum heads wiggling).

Now decent CODECs are cheap, why not use a microprocessor multiplier to perform the dynamic gain changes?

JR
 
krabbencutter said:
I hope it's not inadequate to bump this old topic, but I just started building a PWM based VCA .

Not at all. 8 bits is a little small for a VCA but for a compressor it is probably plenty. Presumably the Arduino 8 bit  PWM frequency is limited to 16MHz/256? There are so many variants available now there must be one that can easily do better.

Cheers

Ian
 
ruffrecords said:
Not at all. 8 bits is a little small for a VCA but for a compressor it is probably plenty. Presumably the Arduino 8 bit  PWM frequency is limited to 16MHz/256? There are so many variants available now there must be one that can easily do better.

Cheers

Ian

I got an STM32F4, which is based on an ARM Cortex M4. The timers are 16bit and having the system clock at 168MHz I can get 10bits PWM at 164KHz, which is quite an improvement compared to the Uno.
Going forward I'll still use the Uno for testing, because it's just so convenient to program. But this whole project should be device-agnostic anyway, so I can easily swap it for the STM32 anytime.

Regarding the PWM circuit as a whole, I'm still a bit unsure what I need to pay attention to in regards of logic levels, bias voltages etc. So here's what's currently going on on my bench:
- I have a linear regulated +/-12V PSU
- the PWM signal ranges from 0 - 5V (or 3.3V in case of the STM32 but I could use a logic level shifter?)
- to power the CMOS chips I regulate +12v down to +5V with an LM317 (do I need to buffer it afterwards, like with a LM358?)
- the CD74HCT4066 is operating at +5V
- the CD40106 is operating at +5V
- a simple RC Lowpass on the signal input should prevent any potential interference with the PWM (?)
- using a voltage divider coming from +5V I bias the input signal around +2.5V, so I can run it into the CMOS chips
- the MCU is currently powered from USB, but at some point it would be powered from +5V, too
- the active filter is operating at +/- 12V (currently a sallen-key built around a TL072)

Now for the detector input: If I want to use a feed forward topology, I would simply buffer the biased input signal and run it into one of the ADCs on the MCU, right? In case of the STM32 the ADCs are 12bit and I can easily clock them at 48KHz or higher.
After that, it's basically "just" code, math and headaches to get a "working concept" up and running, I guess?

And I really need to stress the "working concept". My current goal is to build a basic circuit that other people can improve on  :)
 
krabbencutter said:
- to power the CMOS chips I regulate +12v down to +5V with an LM317 (do I need to buffer it afterwards, like with a LM358?)
LM317 is capable of 1.5A, so you don't need to buffer it.

- a simple RC Lowpass on the signal input should prevent any potential interference with the PWM (?)
Typical sampling theory applies there: any frequency above the Nyquist frequency gets folded down in the audible range, with identical amplitude. These frequencies are "naturally" attenuated by the frequency response of the microphone and mic preamp, so the additional LP filter may be quite simple. 

Now for the detector input: If I want to use a feed forward topology, I would simply buffer the biased input signal and run it into one of the ADCs on the MCU, right?
Whatever the topology, you want to scale and low-pass the signal to the ADC. The constraints on the LP filter would be more stringent than that for the PWM signal path.
 
JohnRoberts said:
As I said a few years ago in this thread, VCAs are not the hard part for dynamics processing.

===

In my drum tuners I make passable sine waves using a micro PWM... (good enough to get the drum heads wiggling).

Now decent CODECs are cheap, why not use a microprocessor multiplier to perform the dynamic gain changes?

JR
Feel free to tell me about the hard parts, preferrably with links to some articles, resources, etc  :)

About codecs:
1. they're digital.
So you'd be building a digitally controlled compressor with a digital gain element, do I get that correctly? In that case it's pretty much an embedded VST plugin and that's not what I'm currently interested in (because what's it to do with PWM?)
2. they're SMD.
I'm here for quick ideas and the fun of it. I like getting excited and playing around on the breadboard without any need for preparation. Now with SMD I'd have to carefully plan the whole project, simulate the hell out of it, prepare some PCBs, order those PCBs which would all take at least a couple of weeks until I can even start building the whole thing. Might be cool for some people, but at the moment that's definitely not the part of this hobby that gets me excited  ;D

Why my interest in PWM compression? It's easy to build, potentially pretty clean, parts are easily available and most importantly it's not been done that much.
 
krabbencutter said:
Feel free to tell me about the hard parts, preferrably with links to some articles, resources, etc  :)
::) It has been a few decades since I did any dynamic design but back in the day (70s/80s?) AES preprint/white papers published by DBX explained their variant compressor design approaches (DBX is the company that THAT corp spun out of).

The "hard part" that I allude to is dynamically manipulating the gain in ways that don't generate audible artifacts or distortion. The last compressor I designed was in the late 80s, an inexpensive -10 dBV unit for bedroom recording market (AMR/Peavey). I did get a patent for the VCA I designed for that SKU, but a few years later DBX/THAT started sharing their VCAs with other manufacturers so I directed a junior engineer in my group to use their chip set and connect the dots in a later design. 
About codecs:
1. they're digital.
Codecs are combination analog to digital and digital to analog convertors, so mixed analog and digital.
So you'd be building a digitally controlled compressor with a digital gain element, do I get that correctly? In that case it's pretty much an embedded VST plugin and that's not what I'm currently interested in (because what's it to do with PWM?)
I'm suggesting that if you are already generating the side chain gain control inside a digital processor it would be more straight forward to just use a digital multiplier to manipulate gain inside the digital domain.

I guess you could generate PWM using completely analog circuitry, and forget about doing anything digital... 8)
2. they're SMD.
these days most modern parts are...
I'm here for quick ideas and the fun of it. I like getting excited and playing around on the breadboard without any need for preparation. Now with SMD I'd have to carefully plan the whole project, simulate the hell out of it, prepare some PCBs, order those PCBs which would all take at least a couple of weeks until I can even start building the whole thing. Might be cool for some people, but at the moment that's definitely not the part of this hobby that gets me excited  ;D

Why my interest in PWM compression? It's easy to build, potentially pretty clean, parts are easily available and most importantly it's not been done that much.
My first experiments with PWM was to throw together a crude couple watt PWM amplifier on my bench... It worked but trashed radio reception for the entire building.  :eek:  Thinking that a PWM gain element is clean, ignores the switching artifacts. If you want clean a digital multiplication is as clean as it gets.

Do whatever floats your boat... Using PWM to generate variable effective resistances has been discussed here before.  Have fun..

JR
 
krabbencutter said:
I just started building a PWM based VCA .
The circuit is based on the schematic from Rod Elliot: http://sound.whsites.net/articles/vca-techniques.html#s10
I'm using an Arduino Uno to generate the PWM, a 74hct4066 for switching, a cd40106 as inverter and a sallen-key filter on the output (built around a TL072).
At a first glance it's working better than expected, but of course the arduino's 8bit PWM and the maximum PWM frequency of 62khz are a limiting factor. I'll swap the Uno for an STM32F4 and will see, how the circuit handles faster PWM speeds. Besides that, the rest is basically just a detector circuit (which is just a buffered analog input on the MCU) and C-code (lots of it!), to turn this into a full compressor.  :)
I like it. But you could improve the parts a LOT. A regular ol' 74H cmos chip is going to give you distortion. Something high voltage with low on resistance (Ron) and good on resistance flatness would be better. Like MAX4600 (and with that particular chip you wouldn't need an inverter because it's dual SPST with one NO and and one NC). With low Ron and +-15V circuit you could get the noise and distortion very low. You could also use an LCL filter to get a 3 pole filter, keep the characteristic impedance low and use small passive parts. The PWM at 60kHz could be fine but any jitter in the PWM could be an issue. It might be worth while using a high speed PWM IC and run a 600kHz. If you do all of those things, it could perform very well. But of course when pushing the envelope with parts like I suggest you will run into unexpected problems. For example, the gate capacitance of the MAX4600 is very high at over 500pF. In theory it should not matter in this particular case (might even be good) but it is high.
 
@JR thanks for the insight, I'll take a look at that!

JohnRoberts said:
I'm suggesting that if you are already generating the side chain gain control inside a digital processor it would be more straight forward to just use a digital multiplier to manipulate gain inside the digital domain.

I guess you could generate PWM using completely analog circuitry, and forget about doing anything digital... 8)
And that's what I am looking to avoid. I don't want to manipulate the source signal within the digital domain. (read = right now with this current project idea!). But in no way is that supposed to be some statement about DSP. PWM got me curious and now I want to explore it. Or to say it another way: Yeah, apples are great, but right now I got a craving for oranges  ;D

JohnRoberts said:
My first experiments with PWM was to throw together a crude couple watt PWM amplifier on my bench... It worked but trashed radio reception for the entire building.  :eek:  Thinking that a PWM gain element is clean, ignores the switching artifacts. If you want clean a digital multiplication is as clean as it gets.
Thank god I grew up in the internet age. Unless I go to 2,4G our WiFi should be fine  ;D
By "potentially clean" I didn't want to deny any switching artifacts. Or to quote Dave Hill: "It should be noted that all electronic devices will add some distortion to the audio path."
But unless you start building your suggested codec-compressor, we will probably never know if the AD/DA distortion of your circuit will outweigh the switching artifacts of mine  :p
 
Converting to digital and back would add a significant delay. It would also be completely overkill.

Using PWM will have no effect on radios or anything else. JR was making a bit of self-deprecating humor in admitting that he once designed a bad circuit (ha ha). If you keep traces carrying PWM as short as possible over an unbroken ground plane and keep high impedance / high gain amplifiers far away from any PWM / digital, noise will be totally undetectable.

In general, the more I think about it, the more I like PWM level control because it should be possible to make it very low noise and low distortion but it also scales well. Meaning you could make a module with 4 or 8 elements and then you are 90% of the way to making a high performance, cheap digitally controlled analog mixer that has level control, mute, PFL and compression that can be controlled remotely and automated.
 
I dabbed with PWM in the 80's, looking for an alternative to VCA chips. The main weakness was at producing large (>60dB) attenuation. In order to minimize Nyquist issues, one has to choose a rather high switching frequency, at least 100kHz i.e. a period of 10us. For 60dB attenuation, the conduction time must be 10ns, which includes the rise and fall time of the comparator and whatever propagation delay to the switches. Phase noise of the reference oscillator is a a major issue since it translates into amplitude modulation of the signal. Indeed any unwanted signal coupling results in degraded performance.
This and actual improvements in VCA chips made me abandon this direction.
 
squarewave said:
Converting to digital and back would add a significant delay. It would also be completely overkill.
:'(
Using PWM will have no effect on radios or anything else.
My experience with switching circuits especially back in the 70s involved lots of interference with radio and broadcast TV (anybody remember them?).  Even in the 80s and 90s I recall issues with digital products interfering with wireless mics used for sound reinforcement.  Products need to pass FCC emissions standards.
JR was making a bit of self-deprecating humor in admitting that he once designed a bad circuit (ha ha). If you keep traces carrying PWM as short as possible over an unbroken ground plane and keep high impedance / high gain amplifiers far away from any PWM / digital, noise will be totally undetectable.
I make no claims for my thrown together class D amp as a technician on my bench back in the early 70s... I thought it was remarkable that I even got it to make sound come out of a speaker...  No output filter, the speaker was the LP filter. The speaker wires were my antenna.  ::) 

Over the decades times have changed and I am currently using a class D SMD IC to drive speakers in my battery powered drum tuner while only sipping current from the batteries. I included LC filters on the output from that puppy before connecting to the speaker wires. 
In general, the more I think about it, the more I like PWM level control because it should be possible to make it very low noise and low distortion but it also scales well.
not to burst any bubbles, and Abbey has already shared some of the issues. If you use an analog PWM, the ein of the comparator input pair is a source of in band audio noise.  Not unlike with class D amps, the PS quality is also a contributor to output, unless the topology includes that within a feedback loop, possible in NF amps not so much for open loop PWM (did I mention I like Hypex amp design).
Meaning you could make a module with 4 or 8 elements and then you are 90% of the way to making a high performance, cheap digitally controlled analog mixer that has level control, mute, PFL and compression that can be controlled remotely and automated.
Good luck and have fun...

Like Abbey, I melted plenty of solder back in the 70s/80s looking for alternatives to the relatively expensive and performance limiting VCA technology back then. I never came up with something better, and IMO only the last generation VCAs from THAT  deliver close to no compromise audio quality...  ironic perhaps only to be eclipsed by inexpensive digital technology.  8)

JR
 
abbey road d enfer said:
For 60dB attenuation, the conduction time must be 10ns, which includes the rise and fall time of the comparator and whatever propagation delay to the switches.
I don't understand this. Please explain. 10ns at 50% duty = 20ns period = 50 MHz. Why would it need to be anywhere near that fast?
 
JohnRoberts said:
Like Abbey, I melted plenty of solder back in the 70s/80s looking for alternatives to the relatively expensive and performance limiting VCA technology back then. I never came up with something better, and IMO only the last generation VCAs from THAT  deliver close to no compromise audio quality...  ironic perhaps only to be eclipsed by inexpensive digital technology.  8)
Ok. Well I haven't built anything like this and I'm not about to (I should be writing code right now but apparently I have some kind of emotional insecurity that causes me to retreat to the comfort of groupdiy) so maybe I'll quit here but they didn't have fast 1 ohm high voltage analog switches in the 80's so maybe this could work with the right parts.
 
squarewave said:
I don't understand this. Please explain. 10ns at 50% duty = 20ns period = 50 MHz. Why would it need to be anywhere near that fast?
For 60dB attenuation, you need a conduction time of 1/1000th the period. 100kHz switching frequency=> 10us period, so conduction time must be 10ns.
I must check but Drawmer had a PWM compressor. IIRC, they used two cascaded cells, probably for the same reason.
 
abbey road d enfer said:
For 60dB attenuation, you need a conduction time of 1/1000th the period.
I see. So the cell has to be "open" 1/1000th the period to allow 1/1000th of the signal through (-60dB). Yeah, that's a problem. Analog switches are ~100ns. Some are a little quicker but the Ron tends to go up accordingly.
 
squarewave said:
I see. So the cell has to be "open" 1/1000th the period to allow 1/1000th of the signal through (-60dB). Yeah, that's a problem. Analog switches are ~100ns. Some are a little quicker but the Ron tends to go up accordingly.

Who need a 60dB compression ?
20 dB is enough, 1/10 duty cycle for PWM switching

Best
Zam
 
zamproject said:
Who need a 60dB compression ?
20 dB is enough, 1/10 duty cycle for PWM switching

Best
Zam
True. And if you need more than 20dB compression you're either doing something wrong, or you need an 1176  ;D

But I guess the -60dB came up, because you could also use PWM for a mixer circuit. But besides the switching speedm clock speed would be another constraint. As PWM resolution decreases drastically the lower you go -40dB already equals 1% Pulse Width. So to get 100KHz switching speed with 16bit PWM resolution would a require a 6,5GHZ clock, if I'm not mistaken.
 
zamproject said:
Who need a 60dB compression ?
20 dB is enough, 1/10 duty cycle for PWM switching

Best
Zam
A) I mentioned VCA, not specifically for a comppressor. Actually my interest was in remote gain control.
B) I often use 40+dB of compression; why? Because I can. Check the piano at the end of "A day in the life".
 

Latest posts

Back
Top