PWM fader experiment

I wanted to experiment with an audio fader based on the use of 2 analog switches. The switches are used to either choose the signal from source 1 or the signal from source 2 and connect it to a buffering op-amp. Have a look at the diagram:

The switches are switched on alternating with a high frequency. The duration a switch is ON determines the net amount of signal you hear from the connected source. By using pulse width modulation the duration can be changed and one can e.g. fade from one source to the other depending on the duty cycle setting of the control signal. I used an arduino nano and a logic inverter to control the switches. The PWM frequency is about 64kHz.

The code that does the fading looks something like this:

void fade(byte switch_control_port) {
  for (int duty_cycle = 0; duty_cycle < 256; pwm++) {
      cd4066.setSwitch(switch_control_port, duty_cycle);
      delay(SHORT_DELAY_TIME);    
  }
}

I made a video clip which shows the circuit on a breadboard and the signal traces of the pwm signal controlling the 2 switches on an oscilloscope.

In the background you can hear the audio fading from one signal source to the other and back while the PWM signal is varied repeatedly.

Note, if you lower the PWM frequency and use only one input signal, you basically have constructed something that sounds like a ring modulator. The switching of the CD4066 can be seen as the modulating frequency and the input signal as the carrier. So … if you want to make a ring modulator, this is one route you could take.

B.t.w. in the video at one point you can hear me sniff. That is not because I was emotionally moved that the circuit was working as well as I had hoped. It is simply because I had a cold at that time ;-).

10 Likes

Oh, oh, oh, after having another look at my original post I noticed a mistake in the code example I posted. If you make a loop with the variable duty_cycle as the controlling variable and check it against an upper limit, here 256, then obviously you also have to increment it now and then via cycle++ and not increment some variable pwm which is not used in the example at all. So here is a better version of the example code:

@Jos I like the idea of this!

However, It might be a good idea to put a lowpass filter at the output to remove the HF PWM, this will prevent the high frequency signal from potentially interfering with subsequent modules or interacting with the sample clock of a digital recording device or the bias oscillator in an analogue tape recorder.

Correct, I didn’t go that far in this experiment. But that would be a good follow up step.

1 Like