PWM Phaser Questions

Started by Epameinondask, November 15, 2016, 05:05:33 PM

Previous topic - Next topic

Epameinondask

Hi there,

So, I've been trying to design a PWM phaser using a CD40106BE and a CD4066CN. I'm also using a TL074 for an integrator, amplifier and comparator as shown here: http://www.pcsilencioso.com/cpemma/pwm_erg.html (i've made some mods to this circuit so it can co-op with the oscillator). The idea is to have a phaser controlled by an LFO or an expression pedal (something like the EHX Bad Stone auto/manual shift). The oscillator coming from the CD40106 is running at around 100khz, then fed to the integrator-amplifier-comparator. I am able to get a 0-100% duty cycle (although I suspect that something like a 10%-90% cycle is more useful).  As I'm trying to keep things simple for a start, in order to focus on the circuit design, I'm using only the pot from the comparator as the "manual shift" mode.

So my questions are:
- What is the variable resistance needed to move the notches in the phase shifting stages? Is there something like a rule of thumb? For example in the MXR Phase 90, 100Ω-22kΩ are needed to move the notches.
- What is this variable resistance depended on? Some of my observations using my oscilloscope and DMM were that the slower the oscillator is running the bigger the resistance from the CD4066 swithces (to Vr). Also the bigger the resistor connecting a switch pin to Vr the bigger the resistance. For example without a resistor to Vr, the CD4066 switching at 100khz can get from around 150Ω up to 3.3KΩ. With a 2.2k resistor to Vr, it can get from 2.2k to 23kΩ.

I don't know if i make any sense  :icon_lol: :icon_lol: . I'm kinda new to circuit design, so I'm having trouble trying to wrap my head around the PWM phasing. I tried using the MXR Phase 90 circuit with PWM resistors but i got nothing but a heavily distorted signal (which makes sense as I am pretty ignorant as far as PWM and phase shifting is concerned  :icon_razz: )

P.s. I've used the search function, but I didn't find much info answering these questions/problems. If I missed something, please post the links that can help.

Cheers  :icon_smile: :icon_smile:


Rixen


Epameinondask

#3
Thank you guys for the replies!

Quote from: Rixen on November 16, 2016, 04:39:42 AM
here's an example of an excellent PWM based phaser:

http://www.parasitstudio.se/building-blog/parasite-phaser


I've seen this phaser before and put it on the breadboard to study it. Very good circuit but I decided that I want to do somethings in a different way e.g. the integrator and the comparator. Read Freppo's thread about his parasite phaser but it seems there is no info about the characteristics of the variable resistance.

Quote from: robthequiet on November 15, 2016, 06:15:57 PM
MXR Phase 45/90 and the function of it's LFO
The better question is what's the usable range of resistances that makes for an audible change of phase on the phase shift circuit? In this case, the answer lies in the way the phase shift circuit works. The phase shift is done by varying the "R" in the R*C circuit on the + inputs. The cap on the input has an impedance which varies with frequency, as Xc = 1/(2*pi*f*C). The effect of the resistor in controlling the output phase starts one decade below the RC crossover of the R*C network and extends to one decade above it. So if the crossover frequency of the cap and JFET resistance is 1000 Hz, the lowest frequency that shows any noticeable effect is 100Hz and the highest is 10000Hz. In practice, only about an octave above and below makes any difference, so the noticeable range for RC=>1000Hz is 500 to 2000. As you change the R by varying the JFET resistance, this two-octave phase change region moves around, following the R*C frequency.

All that is a preamble to saying: it depends on the capacitance value. The JFET *can* vary over a hugely bigger range than you need. It's most sensitive in the 1K - 100K region. You pick the frequency range by selecting the cap value to put the sensitive phase change regions in the middle of the human hearing sensitivity region for the biggest audible effect. Call it 500Hz to 1kHz. And put in enough wobble to wave it completely through the region, then season to taste.

I believe you're referring to this. This pretty much answers both of my questions. So the distortion I got when i plugged my guitar(or my function generator) is irrelevant to the resistance coming from the CD4066 switches, right? Because I think with the 2.2k to 23k resistance they output I should see on the scope or hear with my guitar some kind of a more limited phase shifting of a Phase 90. Just to be clear about it, I am not trying to mod a phase 90 to get it to work with PWM resistors. I just use it like a reference in order to understand how these resistors from the PWM switching are working and what affects them. I couldn't quite understand R.G. is talking about but I think he's saying that the capacitor in the RC network of the variable resistance and the cap in the non inverting input is what affects the variable resistance values or maybe it's the starting point to figure out what variable resistance is needed to move notches. I'll do more research in this new info. I'd be really glad if someone could break it down  :icon_biggrin: :icon_biggrin:

antonis

Quote from: Epameinondask on November 15, 2016, 05:05:33 PM
For example without a resistor to Vr, the CD4066 switching at 100khz can get from around 150Ω up to 3.3KΩ.
My dear Theban general & statesman, 100kHz is far away from any frequnecy of audible interest...
"I'm getting older while being taught all the time" Solon the Athenian..
"I don't mind  being taught all the time but I do mind a lot getting old" Antonis the Thessalonian..

Epameinondask

Quote from: antonis on November 16, 2016, 08:27:07 AM
Quote from: Epameinondask on November 15, 2016, 05:05:33 PM
For example without a resistor to Vr, the CD4066 switching at 100khz can get from around 150Ω up to 3.3KΩ.
My dear Theban general & statesman, 100kHz is far away from any frequnecy of audible interest...

Hello Antonis. Theban general hahaha good one  :icon_biggrin: :icon_biggrin:. The oscillator is running at 100khz to prevent any noise coming from the CD4066 switching. There is no particular reason for it to be 100khz, but I read that it has to be over 20khz so that most us can hear any switching noise.A rule of thumb is to have it running twice the highest audible frequency range of the human ear. I've tried running it at 50khz but the was little difference in the variable resistance that the switches could output. Freppo's parasite phaser PWM is running at around 89-90khz (I had a look at it in my scope)

anotherjim

Just to be clear, the PWM speed isn't the modulation (LFO) speed. In theory, about 12Khz PWM would be fine for guitar bandwidth -  but that means a pretty steep anti-alias filter to stop you hearing the 12Khz and stop intermodulation with the guitar signal. If it can do 100kHZ, well you don't really need much filtering with that.

Find the sweep range by trial & error. You could have a trimmer to put a DC offset into the pwm comparator to range it. Also consider fixed resistors in parallel with or in series with the switches if necessary to range it.

Don't forget to make sure equal DC voltage across the switches by bias connections, just like JFET modulators do.

Epameinondask

Thanks for the heads up Jim.  :icon_biggrin:

Quote from: anotherjim on November 16, 2016, 11:32:41 AM
Don't forget to make sure equal DC voltage across the switches by bias connections, just like JFET modulators do.

Could you please explain how to do this? Something like the Vbias trimmer on the phase 90 LFO? A trimmer between Vr and gnd? or V+?

anotherjim

In this one...

... The issue is solved by the parallel range resistors across the JFET's. The sources are tied to Vref and the 22k puts Vref on the drain. 0.05 caps and the high impedance of the op-amps + input means Vref at the drain isn't changed by the rest of the circuit. The 22k means that's the largest resistance in the control, even if the JFET is off.
If you don't need a range resistor, you can still fit a large enough value that has negligible effect, 1M if necessary, purely to carry Vref to the drain. For a 4066, you can consider either end of a switch to be equivalent to source or drain - chose whichever makes board layout easier.

The 4066 switch works best if the signal in/out pins are biased mid-way between supply rails. 4.5v in a typical pedal, which is also the usual Vref for op-amps, so you can use the same Vref for the switches. Because JFET's need the source voltage set relative to gate control range, Vref is set to match, which may not be mid-way.



Epameinondask

So, I'm having quite some trouble getting these resistors to work.  :icon_frown:

First things first. I have a scope and a function generator, so i can hookup a sinewave simulating the guitar in the input of the circuit. If I use only the first phasing stage, shouldn't that be enough for me to see (if the Cd4066 resistor work properly) a sinewave (attenuated maybe?) moving back and forth? If not, what should I see in the scope? Are more phasing stages  are required to see the modulation of the phasing?

One thing I tried was to have a 4.7kohm resistor to Vr. With the PWM at 100khz, the resistance I get from a 10%-90% duty cycle in this configuration is 4.7k to around 20k+. Should that be enough to hear some phasing?

Quote from: anotherjim on November 16, 2016, 05:20:45 PM
If you don't need a range resistor, you can still fit a large enough value that has negligible effect, 1M if necessary, purely to carry Vref to the drain. For a 4066, you can consider either end of a switch to be equivalent to source or drain - chose whichever makes board layout easier.
The 4066 switch works best if the signal in/out pins are biased mid-way between supply rails. 4.5v in a typical pedal, which is also the usual Vref for op-amps, so you can use the same Vref for the switches.

You are talking about the pins 1 or 2, right?
https://upload.wikimedia.org/wikipedia/commons/thumb/b/b1/4066_Pinout.svg/220px-4066_Pinout.svg.png

I can't quite figure out what I'm doing wrong here.

P.S. Thank you all very much for taking some of your time to help me out here  :icon_biggrin:


Epameinondask

Well, I got it to work with the Phase 90 circuit. I just had to use the same 5.1 volts Vref for every Vr connection.It worked even with 4.5 at  one of the pins of the switch (as Vr), but the phasing was better at 5.1 volts as Vr.

ElectricDruid

I spent a bit of time on this same problem: "What resistance does a PWM switch make at X% duty cycle?".

I had to make a fair number of assumptions to arrive at an answer, so bear with me. And do please correct me if you think I'm barking up the wrong tree.

1) We have a series resistor inline with our PWM switch called Rs. Rs=0 if you're not using it.
2) We have a parallel resistor across our PWM switch called Rp. Rp=infinity if you're not using it.
3) Our switch has an on resistance with is measurable. Call it Ron. Example value 100ohms. Check the value from your chosen switch's datasheet.
4) Similarly for the off resistance. Call it Roff. Example value 10MOhms.

Now, when the switch is on, we've got the combined total of Rs+Ron in parallel with Rp.
When it's off, we've got the combined total of Rs+Roff in parallel with Rp.

We know (or can easily look up) that for parallel resistors R1 and R2, the equivalent resistance is (R1xR2) / (R1+R2).

So in our case we've got (Rp x (Rsw+Rs)) / (Rp + Rsw + Rs), where Rsw is the switch resistance, either Ron or Roff.

I assumed that varying the duty cycle interpolates linearly between these two values. So if you're at 10%/90% On/Off duty cycle, you get (0.1 x the on value) + (0.9x the off value).

This gave me enough to write a little PHP script to work some stuff out for me. Really, you only need the end points - the fully on value and the fully off value. With those, you can work out the extremes of the frequency range and get it somewhere you need it.

Hope it helps. Can't guarantee any of it is true - it was only my best guess.

Tom

anotherjim

Makes sense Tom. I'm thinking R(on) is so low compared to R(off), we could also say that 50% duty cycle is practically half of R(off)?
Now, I'd have though that adding scaling resistors, to whatever control element, would change the response curve to the LFO or envelope. Like a log resistor hack to a pot? Funnily enough though, if that is happening, it usually seems to suit the effect.

I've not yet designed a PWM further than the modulator to switches. What I did for experiment was to use 2x of a 4066 switches wired across the supply as a potential divider, fed anti-phase PWM control pulses, you should see the LFO wave reproduced at the output of the switched divider. Also put 4k7 resistors in the +9v and 0v connections so there isn't a short straight thru if both switches got turned on!
Anyway, that let me check the response between the LFO wave and the PWM duty cycle.

ElectricDruid

Quote from: anotherjim on November 18, 2016, 07:11:35 AM
I'm thinking R(on) is so low compared to R(off), we could also say that 50% duty cycle is practically half of R(off)?
Yeah, at least to a reasonable approximation.

Quote
Now, I'd have though that adding scaling resistors, to whatever control element, would change the response curve to the LFO or envelope. Like a log resistor hack to a pot? Funnily enough though, if that is happening, it usually seems to suit the effect.
Well spotted. That's exactly what I learned from my PHP script. The scaling resistor bends the curve much closer to a exponential. Here's my result:



The red line is an octave-based exponential curve (e.g. musically 'linear'), and the green line is what you get from the PWM. So it's not far wrong, and definitely "bent in the right way".

Quote
I've not yet designed a PWM further than the modulator to switches. What I did for experiment was to use 2x of a 4066 switches wired across the supply as a potential divider, fed anti-phase PWM control pulses, you should see the LFO wave reproduced at the output of the switched divider. Also put 4k7 resistors in the +9v and 0v connections so there isn't a short straight thru if both switches got turned on!
Anyway, that let me check the response between the LFO wave and the PWM duty cycle.
Very cunning!

Tom

Epameinondask

#14
I've been experimenting around with this PWM resistor circuit the past couple of days and I found out that scaling resistors (in parallel or in series or both) cannot give you the resistances you might need for the phasing. For example, at 100 khz, you get a 250 ohm up to 2.5 kohm resistance, from the switch alone. If you put a resistor in series with the switch, you can get all kinds of resistance. If you put a 100k resistor in series (to Vr) you get a resistance from around 100k (when the switch is at 90% = almost on all the time) up to 3.6 Mohms (at 10%). The thing is that if you put a resistor in parallel to this setup you can never scale it to a desired resistance range, because a parallel resistor to the in-series-with-the-switch setup will (obviously) affect both ends of the resistance range. So practically it's "impossible" to scale down the resistance to what suits your phasing circuit.

So the question now is: How is it possible to get any range of variable resistors with the PWM method? Well, from what I saw while experimenting, the frequency off PWM is affecting the resistance you can get from the switches, more than anything else (resistors, Vr Voltage). At around 3khz, it is possible to get a resistance from 200 ohm (90%) to 22-23 kohms (10%). The thing is that you have to filter out the noise that the switches create at this frequency. I haven't got the chance listen to the circuit at this frequency just yet, but I believe that there is a change that noise filtering  will be needed. How can this noise filtering be done?

Next question that comes to mind is: is there any way to figure out what resistance is needed to achieve phasing in any given phase circuit? Something like a formula? Maybe an in depth reading session of the Mxr Phase 90 analysis will probably answer this question.

anotherjim

It sounds like you are not actually getting a proper pwm pulse on the control of your switches. Frequency alone should not alter the resistance, only the duty cycle should do that. As you were trying for 100Khz, are you sure you have a good, sharp control pulse? If the slew rate (edge rise & fall) of the pulse is too slow, it may only appear to be work at a low frequency.
Looking back at the link in the first post -  are you using an LM324? That chip is a little too slow I think. It might help to  change to 50Khz and use a comparator chip for U1d, that at least will give faster edges to the pulse.

I don't think you could make pwm at 3Khz work, you can't filter it out without also filtering your audio.

Epameinondask

Quote from: anotherjim on November 20, 2016, 05:18:10 PM
It sounds like you are not actually getting a proper pwm pulse on the control of your switches. Frequency alone should not alter the resistance, only the duty cycle should do that. As you were trying for 100Khz, are you sure you have a good, sharp control pulse? If the slew rate (edge rise & fall) of the pulse is too slow, it may only appear to be work at a low frequency.
Looking back at the link in the first post -  are you using an LM324? That chip is a little too slow I think. It might help to  change to 50Khz and use a comparator chip for U1d, that at least will give faster edges to the pulse.

I don't think you could make pwm at 3Khz work, you can't filter it out without also filtering your audio.


I'm using the TL074. Well, the pulse is not exactly sharp but nothing extreme. It still looks like a PWM but the fall and rise of the PWM are visible, but very little. It has a rise of around 320 ns. I'll try and find the best non distorting frequency tomorrow. The currenct PWM edges that I use can definitely be improved. Can you name some fast chips? Or it's the fact that 100khz is too much for most of the op amps?

The thing with the frequency and that it should not affect the resistance is what puzzles me, because the slower the frequency the more time the switch stays off, leading to more resistance,right? Why would the edges of the PWM matter? I will have a look tomorrow, using my function generator. It can create a PWM with 20ns rise/fall. This should tell me more about the edges of the PWM.

anotherjim

The PWM frequency itself only has to be at least x2 the highest audio frequency so that it can be made inaudible. The ratio between the switches on & off states determines the average resistance.

Ok, PWM = Pulse Width Modulation.
A key word is Modulation.
If I were God, I'd change Modulation for Encoding, but telecom & broadcast engineers liked Modulation better. They started it with AM & FM and also gave us PCM. They are all methods of changing something (signal) into something else (carrier). They like "Signal" better than "Information", which is what signal basically is.

PWM encodes a value (signal) in the pulse width. We also call it Duty Cycle (percentage of the high/on state compared to the low/off state in a single cycle period) or even Mark-Space (echoes of Morse code there and ancient teleprinter transmission).
Anyway, with PWM, the carrier is the pulse wave frequency, but the important thing it encodes is represented by the pulse width.

As a control element, you are after using a switch which has only 2 states, on or off. Now, by changing the ratio of the time it is on versus off, the switch now appears to be in some other state between on & off, if you do it fast enough that it's a blur to the signal passing through the switch. That "fast enough" is over x2 the highest signal frequency - thank you Mr Nyquist.

Maybe it's easier to visualize what's happening by using PWM to produce an analogue voltage from a digital output.
Then, the output feeds an integrator formed by a resistor in series to a capacitor to ground.  Voltage across the capacitor is the analogue output voltage.
Switched high, the capacitor charges to the high voltage.
Switched low, the capacitor discharges to the low voltage.
Pulsed with 50% duty cycle, the capacitor charges to 50% of high voltage.
Pulsed with 25% duty cycle, the charge changes to to 25% of high voltage.

The most common trick of PWM the student is introduced to is changing brightness of an LED. You can throw away the integrator, persistence of vision does the job. And the brightness does indeed vary, despite the control only actually being on or off.

Now, the resistor/capacitor is integrating the pulses over time to give a useful DC average. If the integration time is too long, the DC  out will lag behind the intended value - may never reach it if the duty cycle keeps changing sooner.
If the integration time is too short, you get the pulses directly reaching the output - there is ripple.

To the practical, most op-amps have a slow response compared to digital components, which the 4066 really is. Being digital, it turns off when the input is close to 0v and turns on when it's close to the + supply v. If the input spends too long somewhere between those logical states, its insides can "jitter", flapping in the breeze. So it needs a quick switch between 1 & 0. Also, the job of PWM is time sensitive, the pulse width you intend can be changed if the states change too slowly.

Freppo, as the Parasit studio boss calls himself here, found a faster op-amp for the PWM comparator job, the TLE2074.
To eliminate the need for a "special" amp chip, I came up with the following, as well as keeping the CMOS theme of Parisit designs.
This uses a comparator chip to replace the "special" op-amp. 2 were used because the effect is sweeping 2 filter frequencies in opposite directions, so the 2nd comparator inverts the PWM simply by swapping the + & - inputs.



Epameinondask

I grabbed myself a couple of LM393's today and tried them out. First of all, the PWM has indeed a much better shape with these comparator chips. But the "problem" is the same. I get the same resistance range. So, at 53khz with the CD4069 oscillators, with an even bigger duty cycle of 5% to 95%, I can now get 250 ohms to 16-17 kohms, a range that I could get with the not so well shaped PWM. It seems that the shape of the PWM is a minor factor of the overall resistance you can get. So, if the PWM can get from a couple hundred ohms to about 20 kohms in a very big duty cycle, is it safe to assume that the PWM is very limited method of variable resistance? Because if the phasing stages require a variable resistance of 200 ohms to 100k, it seems that the pwm duty cycle would have to reach to even lower percentages, an area where few millivolts make a huge difference in the maximum resistance. Is there any way that we could get any range of variable resistance we want from a PWM resistor? A more "logical' range, a range that can be used in these kind of circuits.
Then again I think that I'm barking up the wrong tree here, because even though the variable resistance plays a very big role in phasing circuits, the frequencies that notches occur and move are not only related to the resistance. Reading the Mxr P90 analysis, I noticed that the frequencies that the notches occur can be calculated from the following formula: f= [tan(φ/2)]/2πRC, where the R is the variable resistance. Then again the C in the formula is a very small number, changing it shouldn't make a huge difference.  I don't know if I'm missing out something here, I'm self taught so I might be unaware of some tricks or methods around PWM and resistance.  :icon_lol:

ElectricDruid

Quote from: Epameinondask on November 20, 2016, 03:45:54 PM
For example, at 100 khz, you get a 250 ohm up to 2.5 kohm resistance, from the switch alone.

This alone should set some alarm bells ringing that something's not right. How is it possible that a switch which when open has a resistance of some many megohms can only give you a 2.5Kohm resistance? Doesn't make sense. Something is squiffy.

How are you measuring the resistance? Are you sure the measurement method will work ok with a PWM signal? Remember you need something that will integrate the pulses back into something sensible, or your readings will be way out, like happens trying to read a PWM output as a DC level.

Tom