Adruino PWM and Sallen Key third order

From circuitbending to homebrew stompboxes & synths, keep the DIY spirit alive!

Moderators: Kent, luketeaford, lisa, Joe.

Post Reply
Quinie
Learning to Wiggle
Posts: 36
Joined: Thu Jul 09, 2015 3:14 pm
Location: Netherlands

Adruino PWM and Sallen Key third order

Post by Quinie » Mon Sep 14, 2020 6:43 am

Ok I am in over my head.

I working on a Arduino project where the PWM pin goed into a sallen key filter (third order with amplification).
Attached image of schematic.
Sallenkey.PNG
I not sure what values to use for the resistors/caicitors. I just don't have the knowlege to understand the calculation. Is anyone able to explain this in normal english?

Then my second question.

Arduino is able to output multiple PWM's on different pins. These can be combined with each other to provide (what I understand) better quality. The mozzi libary specificy this as "hifi mode". There isn't a example of how to do this with 2 sallan key filter (3th order with amp). Is it possible to connect both pins after the sallen key filters ? And how to calaculate the filters (question one)
You do not have the required permissions to view the files attached to this post.

User avatar
devinw1
Super Deluxe Wiggler
Posts: 1576
Joined: Tue Aug 07, 2018 11:20 am
Location: Portland, OR
Contact:

Re: Adruino PWM and Sallen Key third order

Post by devinw1 » Mon Sep 14, 2020 10:40 am

This site has some very nice calculators for active and passive filters. Here is exactly your case:

http://sim.okawa-denshi.jp/en/Sallenkey3Lowkeisan.htm

Plug-n-play!

jorg
Ultra Wiggler
Posts: 791
Joined: Fri Apr 03, 2015 9:38 am
Location: East Coast USA

Re: Adruino PWM and Sallen Key third order

Post by jorg » Mon Sep 14, 2020 11:01 am

I don't know the sample rate of the PWM you're using, or whether you are outputting audio, CV, or what, and can't comment on how the Arduino might combine multiple PWMs. However, if you want to send two inputs into the filter, you could double the value of the first resistor and use two resistors, both connected to the first capacitor.

Scale all your capacitors to set the cutoff frequency to something much less than the PWM sample rate. The filter as shown has a cutoff frequency (-3dB point) of about 59Hz; so it would be suitable for slow CV. If you use 1nF capacitors, you get 590Hz; 100pF would give 5900Hz; 47pF would give around 12KHz cutoff. Your op amp may become a significant factor if you want a high audio cutoff; you could consider something faster such as OPA1679. The DC gain is 2, or 6.02dB. Attenuation slope is 18dB/Octave.

User avatar
MikeDB
Common Wiggler
Posts: 130
Joined: Fri Feb 08, 2019 8:28 am
Location: UK

Re: Adruino PWM and Sallen Key third order

Post by MikeDB » Mon Sep 14, 2020 11:03 am

I was just typing that you have the capacitors connected wrongly when I noticed the link from devinw1 above. Make sure you connect them properly or you won't get the response you are after.
Personally I hate cats !

User avatar
guest
Super Deluxe Wiggler
Posts: 4519
Joined: Mon Aug 19, 2013 11:49 am

Re: Adruino PWM and Sallen Key third order

Post by guest » Mon Sep 14, 2020 2:27 pm

for my stompshield i used a 3rd order MFB filter (can give the same response if the right values are chosen). it also uses a mix of 2 PWMs to get higher resolution. you can find the schematic image on the page below. the filter is the part around U1G$3. the values are for a much higher PWM rate than the standard analogWrite() does, so may need to be changed.

http://wiki.openmusiclabs.com/wiki/StompShield
openmusiclabs.com

Synthiq
Veteran Wiggler
Posts: 590
Joined: Mon Feb 06, 2017 3:10 pm
Location: California

Re: Adruino PWM and Sallen Key third order

Post by Synthiq » Mon Sep 14, 2020 2:41 pm

devinw1 wrote:
Mon Sep 14, 2020 10:40 am
This site has some very nice calculators for active and passive filters. Here is exactly your case:

http://sim.okawa-denshi.jp/en/Sallenkey3Lowkeisan.htm

Plug-n-play!
This simplifies things. Note, however, that these calculations assumes a gain of 1 in the amplifier. Higher gain will result in more peaking at the corner frequency unless the feedback capacitor is reduced. Using the calculator and then divide the feedback capacitor with the gain removes the peaking but I still see a shift in corner frequency. A gain of 2 results in about 25% higher corner frequency that should be compensated for.

jorg
Ultra Wiggler
Posts: 791
Joined: Fri Apr 03, 2015 9:38 am
Location: East Coast USA

Re: Adruino PWM and Sallen Key third order

Post by jorg » Mon Sep 14, 2020 10:41 pm

MikeDB wrote:
Mon Sep 14, 2020 11:03 am
I was just typing that you have the capacitors connected wrongly when I noticed the link from devinw1 above. Make sure you connect them properly or you won't get the response you are after.
I simulated this circuit in Tina TI and it looked perfectly fine.

Synthiq
Veteran Wiggler
Posts: 590
Joined: Mon Feb 06, 2017 3:10 pm
Location: California

Re: Adruino PWM and Sallen Key third order

Post by Synthiq » Tue Sep 15, 2020 12:17 am

jorg wrote:
Mon Sep 14, 2020 10:41 pm
MikeDB wrote:
Mon Sep 14, 2020 11:03 am
I was just typing that you have the capacitors connected wrongly when I noticed the link from devinw1 above. Make sure you connect them properly or you won't get the response you are after.
I simulated this circuit in Tina TI and it looked perfectly fine.
It looks fine in an ac simulation but did you try a transient simulation? C9 adds positive feedback making the circuit unstable.

[Edit] The ac simulation looks weird, though. The phase shift goes from 0deg to -90deg for a third order filter!

jorg
Ultra Wiggler
Posts: 791
Joined: Fri Apr 03, 2015 9:38 am
Location: East Coast USA

Re: Adruino PWM and Sallen Key third order

Post by jorg » Tue Sep 15, 2020 10:44 am

Synthiq wrote:
Tue Sep 15, 2020 12:17 am
jorg wrote:
Mon Sep 14, 2020 10:41 pm
MikeDB wrote:
Mon Sep 14, 2020 11:03 am
I was just typing that you have the capacitors connected wrongly when I noticed the link from devinw1 above. Make sure you connect them properly or you won't get the response you are after.
I simulated this circuit in Tina TI and it looked perfectly fine.
It looks fine in an ac simulation but did you try a transient simulation? C9 adds positive feedback making the circuit unstable.

[Edit] The ac simulation looks weird, though. The phase shift goes from 0deg to -90deg for a third order filter!
Aw crap! You're right. The circuit is incorrect.

erroneousbosh
Learning to Wiggle
Posts: 12
Joined: Wed Jul 22, 2020 3:47 pm
Location: Glasgow

Re: Adruino PWM and Sallen Key third order

Post by erroneousbosh » Tue Sep 15, 2020 5:01 pm

Quick and dirty way is to work out that the cap from the opamp input to ground needs to be half the value of the feedback cap to give a Q of (very roughly) 0.707 for a Butterworth response, if both resistors are the same. Making both the same simplifies calculating Q to 1 / 2*(sqrt(c1*c2)) so for 1n and 470pF you'd have 1/ 2 * sqrt(1*.47) = 0.729, not far off. Plugging in 22k resistors to the calculator site above along with the cap values gives a pretty respectable cutoff of 10kHz which ought to be okay, or 15k will give you 15.5kHz which might let some more PWM whine bleed through.

Forget the three-pole filter, just follow it up with a notch filter at your chosen PWM frequency - if you've gone for phase-correct PWM at a 16MHz clock crystal, this will be 31370Hz.

Quinie
Learning to Wiggle
Posts: 36
Joined: Thu Jul 09, 2015 3:14 pm
Location: Netherlands

Re: Adruino PWM and Sallen Key third order

Post by Quinie » Wed Sep 16, 2020 5:54 am

Thank you all for the input. I been reading the respondes, and I still got a lot of googling to do.

The idea behind this project is to make a PCB with two PWM output's, jumper select to output pure pwm or thru a filter, and a jumper if you want to combine the filters for dual pwm. Two jacks on the front panel so the "builder/programmer" can choose the usage with jumpers without have to rebuild the module.

For me there a lot of information here i'm trying to proces.

"It looks fine in an ac simulation but did you try a transient simulation? C9 adds positive feedback making the circuit unstable."

Thanks for pointing the mistake out. Will update the schematic's. But I don't realy understand what happening with a unstable circuit and why you would use or test for transient. Man I got a lot of reading to do ;)

User avatar
Neutron7
Oldschool bleeper
Posts: 1965
Joined: Sun May 23, 2010 12:24 pm

Re: Adruino PWM and Sallen Key third order

Post by Neutron7 » Wed Sep 16, 2020 6:52 am

I could be wrong but i think that doing a Mozzi type pwm mixer putting it after the filters will not work as expected.
both filters would be working on different parts of the signal, which are at different frequencies. (on a saw wave, the LSB side would be 7 octaves higher.) filters have a phase response which changes over frequency, and the 2 sides would become separated in time. when you put them back together it will not "mesh"

also the mozzi mixer needs low tolerance resistors, the differences between at least some of the components in the 2 filters comes in to play.

if you used a dual op amp, the other one (besides the filter) could do the mozzi mix, (and dc offset if its needed) before the main filter.

Synthiq
Veteran Wiggler
Posts: 590
Joined: Mon Feb 06, 2017 3:10 pm
Location: California

Re: Adruino PWM and Sallen Key third order

Post by Synthiq » Thu Sep 17, 2020 12:16 am

Quinie wrote:
Wed Sep 16, 2020 5:54 am
"It looks fine in an ac simulation but did you try a transient simulation? C9 adds positive feedback making the circuit unstable."

... But I don't realy understand what happening with a unstable circuit and why you would use or test for transient. Man I got a lot of reading to do ;)
As an example why positive feedback is bad, consider an amplifier with a gain of 2 and with a 1mV input signal. The output signal would be 2mV so if that is fed back to the positive input without attenuation it would again be amplified by 2 to 4mV and then 8mV and so on until the output is saturated at the positive supply rail. Now, a TL074 has not a gain of 2 but >100,000 so it will be even worse.

I'm not sure why this instability didn't show up in the ac simulation as peak with infinite gain, but it is possible it happens at a frequency outside the simulated frequency range or, if the peak is very narrow, it occur between two simulated frequency points. Anyway, I have seen this happen before, so when I see an unexpected simulation result I double check by doing a different type of simulation to verify the result. Don't assume the circuit simulator never makes an error.

Neutron7, if the two filters really were identical, it wouldn't matter if the two PWM signals were first summed and then filtered or first filtered and then summed as long as the system is linear. In this case you can look at each frequency component separately and it is clear that the output would be the same if it passes through filter A or filter B as they behave exactly the same. But I totally agree that the two filters will not be identical due to component tolerances so in practice the best option is to sum the the two PWM signals before the filter. This will also save one opamp and some passive components. The summation can be done passively with just the 3.9kohm and 499kohm resistors as in the Mozzi circuit and it can be connected directly to the 100kohm resistor at the input of the filter. To be precise, the 100kohm resistor should be reduced by output resistance of the summing resistors (3.9kohm//499kohm.)

Post Reply

Return to “Music Tech DIY”