Author Topic: Tear me apart: Relay Step Attenuator  (Read 734 times)

0 Members and 1 Guest are viewing this topic.

Offline BurnedResistor

  • Regular Contributor
  • *
  • Posts: 182
  • Country: at
Tear me apart: Relay Step Attenuator
« on: March 24, 2020, 09:25:39 pm »
Hey All!

As a first foray into the world of Audio (coming more from a digital/embedded background), I am working on an Audio Relay-Step-Attenuator and input switcher
In a few bullet points:
•   7 stage / 128 steps
•   0,5db step
•   “constant input impedance” design: Each divider represents an input load of 10k
•   Relay Mute
•   Fully passive, inputs isolated from each other
•   Switching between 4 inputs
I have attached the schematic.
I would be very grateful if someone could just look over my work and tear me a new one. I can handle it. I promise.
I also have a few questions:

1: Are the Omron G6K-2F-Y-3VDC a good choice here?
I mostly picked them based of the small smd footprint and the 3v coil voltage saving me a second power rail. I am really not sure if there are any specifications I should be paying attention to for audio stuff? 50’000’000 Mechanical operations should last me a while? Are there any shielding concerns?

2: How important is the order of the attenuation stages?
I have seen both the stage with highest and lowest attenuation first, and as far as I understand the circuit it theoretically should not matter: Each stage represents (almost) the same input load. Would it make sense to reverse the order so the highest attenuation would come last? That way the signal would be a higher amplitude longer, possibly bettering SNR? Would changing the order of the stages make the attenuator more susceptible to changes in what the actual load it sees are?

3: Output load correction
This attenuator type is designed to expect to see an output load of 10k. However, the devices I will most likely connect to the output all have an input impedance of around 20-45k. I thought I would include an (adjustable) resistor at the output to increase the load to closer to 10k. I ran some simple simulations in python (see attached plot), it seems that as long as the load the attenuator sees is greater than 10k, the performance is good enough for me (steps are no longer 0.5db, but the attenuation always increases, meaning that there would be no jumps of volume in the opposite direction when changing volume).

4: How necessary is it to keep the signal grounds isolated?
Right now I am switching both the signal and ground of each input, meaning the grounds of the various input signals are not connected together. I admit this “fully passive, don’t touch the signal at all” mostly comes from being afraid of doing anything that could reduce signal quality. Also I am scared of ground loops between phono preamps, dacs, headphone amps etc. I can swallow the cost of 3 extra relays as this design is only for me, but how necessary is this?

5: How should I be grounding the metal case/ground plane?
As a tag along to the previous question. I am on an isolated 9vAC supply. If I keep switching the signal grounds, what should I be tying the metal case and possible ground fills around the audio signals too? To whatever signal ground Is currently selected? The ground reference point of my digital circuitry? Tie the ground plane to whatever is selected and the case to digital ground? It seems a little strange to be switching the tie point of the metal case…

6: Muting when unconnected
A single button is used to cycle between the inputs (I can’t really get more inputs from the user). I would like to avoid large amounts of noise when cycling past an input that is currently unconnected/floating. For the 3.5mm inputs I was able to deal with that using the switch in the jack, but there are no such switches in the RCA plugs. I thought about adding a small jumper to ‘terminate’ those inputs? Maybe tie the signal to gnd using a 1M-10M resistor (that seems like a bad idea thought). Any thoughts? Maybe I just have the MCU keep the signal muted for a second or two when changing inputs…

I hope this did not get too wordy!

And again: I am really doing this to learn, so please tell me if everything I am doing is naïve, stupid, and pointless :P
Thank you!




 

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 1921
  • Country: ca
Re: Tear me apart: Relay Step Attenuator
« Reply #1 on: March 24, 2020, 11:18:52 pm »
Possibly some ideas here:
youtube.com/watch?v=no6lPPVh6Ec
https://www.diyaudio.com/forums/equipment-and-tools/310334-at2380v1-2-channels-digitally-controlled-stepped-attenuator.html

Maybe tie the signal to gnd using a 1M-10M resistor (that seems like a bad idea thought). Any thoughts? Maybe I just have the MCU keep the signal muted for a second or two when changing inputs…

Sounds reasonable to me, maybe 10-100k resistor. But you said your input divider has a constant load of 10k, so shouldn't that be enough to pull the signal down?
 

Offline BurnedResistor

  • Regular Contributor
  • *
  • Posts: 182
  • Country: at
Re: Tear me apart: Relay Step Attenuator
« Reply #2 on: March 25, 2020, 12:11:43 pm »

Sounds reasonable to me, maybe 10-100k resistor. But you said your input divider has a constant load of 10k, so shouldn't that be enough to pull the signal down?


Right... ofc... thank you :)  |O
 

Online Prehistoricman

  • Regular Contributor
  • *
  • Posts: 199
  • Country: gb
Re: Tear me apart: Relay Step Attenuator
« Reply #3 on: March 25, 2020, 12:32:57 pm »
Do the relays have consistent timing between each other?
What I'm thinking is that if you're switching from -32dB to -31.5dB that you may briefly have 0dB attenuation when K7 disconnects, but the other relays have yet to make contact.

I like how you have all the attenuation relays on the lower byte of a single port, so you can change the attenuation very easily in code.

Offline duak

  • Frequent Contributor
  • **
  • Posts: 835
  • Country: ca
Re: Tear me apart: Relay Step Attenuator
« Reply #4 on: March 25, 2020, 06:11:06 pm »
There could be a problem because the release time of the relays is extended by the flyback diodes across their coils.  If so, one of the ways to shorten the release time is to put a resistor in series with the flyback diode. Start with a value about the same as the series resistance of the coil.   

Apparently, Mark Levinson used relays to switch the attenuators in some of their products.  I haven't seen a schematic and some have said that ML used more relays than you would expect, probably to get around the 31.5 to 32 dB step problem.  BTW, this is known in the digital to analog converter field and occurs when a number of things have to switch simultaneously and perfectly.  Sometimes you can use a different binary code like the Gray code, but that won't work here.  I think it comes down to the weighting of the individual stages & switches and the only way around it is to use more switches so that any error or glitch is not so obvious.  However, that being said, it may not be a problem in the actual application.

I'm not sure these relays are the best choice for a low level application like this.  Looking at the data sheet I see that although the manufacturer says they are signal relays, the contacts are a silver alloy and they are rated for 2 A.  I'd consider this to be a dry circuit where the voltage is less than 1 V and the current is less than a few mA.  Silver is likely to tarnish over time causing an increased resistance.  Gold is generally used for contacts like this but I don't see a gold flashed version to be available.
 

Offline BurnedResistor

  • Regular Contributor
  • *
  • Posts: 182
  • Country: at
Re: Tear me apart: Relay Step Attenuator
« Reply #5 on: March 25, 2020, 08:02:47 pm »
I like how you have all the attenuation relays on the lower byte of a single port, so you can change the attenuation very easily in code.

I am a man of taste  ^-^

(Or "Spot the pcb made by the same guy writing the code  :-+")

Do the relays have consistent timing between each other?
What I'm thinking is that if you're switching from -32dB to -31.5dB that you may briefly have 0dB attenuation when K7 disconnects, but the other relays have yet to make contact.

My hope is that if all relays are switched in sync that the 2-3ms switching time the datasheet specifies should leave enough wiggle-room to ensure no relay re-connects before all are disconnected. If the relays are switching and not connected that is essentially a mute state.

Software engineering isn't my bottleneck here: If it really becomes an issue I can work out some smarts to prevent that. Maybe a 2 step update process where first any additional attenuation stage is engaged, before any stage is disengaged?
« Last Edit: March 25, 2020, 08:20:16 pm by BurnedResistor »
 

Offline BurnedResistor

  • Regular Contributor
  • *
  • Posts: 182
  • Country: at
Re: Tear me apart: Relay Step Attenuator
« Reply #6 on: March 25, 2020, 08:19:30 pm »
There could be a problem because the release time of the relays is extended by the flyback diodes across their coils.  If so, one of the ways to shorten the release time is to put a resistor in series with the flyback diode. Start with a value about the same as the series resistance of the coil.   

Thank you very much sir!  I really had not considered that - really new to anything analog related.
I will definitely put in resistors. Worst case I can jumper them with 0Rs
(Advantages of hobby projects.... No-one bats an eye at a few extra cents on the BOM  >:D)

Apparently, Mark Levinson used relays to switch the attenuators in some of their products.  I haven't seen a schematic and some have said that ML used more relays than you would expect, probably to get around the 31.5 to 32 dB step problem.  BTW, this is known in the digital to analog converter field and occurs when a number of things have to switch simultaneously and perfectly.  Sometimes you can use a different binary code like the Gray code, but that won't work here.  I think it comes down to the weighting of the individual stages & switches and the only way around it is to use more switches so that any error or glitch is not so obvious.  However, that being said, it may not be a problem in the actual application.

I read about it on some higher end audio stuff, and I am not sure I buy into it making a world of difference over a good quality pot. But let's be honest, I am here for the satisfying cascade of clicky sounds....

You might be on to something with the extra relays. See :
https://www.schiit.com/products/freya-s

Nice enough to include some PCB glamour shots..

Also has a stereo 7-step attenuator, but looks to have 7 dpdt relays per channel instead of my 7dpdt for both.... Hmm.... Worth investigating for sure, but I am tempted to see if this is enough and if some software smarts can do the trick.  :-/O I have seen audio step-attenuators with this layout online. (http://electronics-diy.com/audio-volume-control-attenuator-with-ir-control.php, http://www.twistedpearaudio.com/docs/control/jt/jt2_schematic.pdf)

(On a different note, taking a look at that pcb from Schiit: They must be cutting quite a margin! An RJ45 style port for programming what looks to be a very simple MCU? And that pcb has more free space than my workbench... Or am i misinterpreting that?)


I'm not sure these relays are the best choice for a low level application like this.  Looking at the data sheet I see that although the manufacturer says they are signal relays, the contacts are a silver alloy and they are rated for 2 A.  I'd consider this to be a dry circuit where the voltage is less than 1 V and the current is less than a few mA.  Silver is likely to tarnish over time causing an increased resistance.  Gold is generally used for contacts like this but I don't see a gold flashed version to be available.

I had not considered that... Hmm... I can get my hands on these fairly cheaply right now so I will give it a try, but I might start looking for alternatives...
 

Online Prehistoricman

  • Regular Contributor
  • *
  • Posts: 199
  • Country: gb
Re: Tear me apart: Relay Step Attenuator
« Reply #7 on: March 25, 2020, 08:41:25 pm »
There could be a problem because the release time of the relays is extended by the flyback diodes across their coils.  If so, one of the ways to shorten the release time is to put a resistor in series with the flyback diode. Start with a value about the same as the series resistance of the coil.   

Thank you very much sir!  I really had not considered that - really new to anything analog related.
I will definitely put in resistors. Worst case I can jumper them with 0Rs
(Advantages of hobby projects.... No-one bats an eye at a few extra cents on the BOM  >:D)
I love solving problems as much as the next guy, but isn't this actually in your favour?
My concern was that the sound would get unexpectedly loud when switching sometimes.
If the relays take a longer time to release, you're just going to get more attenuation before settling on the final correct amount of attenuation.

Online WattsThat

  • Regular Contributor
  • *
  • Posts: 65
  • Country: us
Re: Tear me apart: Relay Step Attenuator
« Reply #8 on: March 25, 2020, 09:33:03 pm »
Another factor that will affect relay turn on speed is your choice of switching transistor. The 2N7002 is an older part with a very high Rds and it wouldn’t be even my third or forth choice for a 3.3 volt application. Have a look at the data sheet and you’ll see the Rds is off the graph at 3 volts. Most times I’ve seen the 2N7000 series parts used is because they’re still available in through hole versions. Since you’re using surface mount, you have lots of options with hundreds of more modern, lower gate voltage parts.

Having a quick look at the DigiKey parametric search pops up the lowly BSS138 as an okay choice but not a lot of excess current capability, the DMN3730U looks better at .75 amp rating with lots more logic level one and two amp devices in the sot-23 footprint.
 

Offline imacgreg

  • Contributor
  • Posts: 7
  • Country: us
Re: Tear me apart: Relay Step Attenuator
« Reply #9 on: March 25, 2020, 11:16:46 pm »
I designed a commercial pro audio product that used a relay based attenuator similar to what you are describing. I would advise not relying on a hardware solution to the mis-match relay on/off time problem. It can very easily be handled in firmware and may require some tweaking, which is much easier in code.

For our application, every attenuation "transition" consisted of a few steps:
- Turn all relays off (maximum attenuation)
- Delay long enough for all of them to turn off
- Turn on all the relays needed for the new desired setting

As long as your delay time is longer than the worse case relay toff, then you'll never get loud blasts of audio between steps. During testing, I drove a handful of sample relays at low frequency (50-100Hz) with some DC across the contacts and was able to see what kind of toff variation we were getting.
 

Offline duak

  • Frequent Contributor
  • **
  • Posts: 835
  • Country: ca
Re: Tear me apart: Relay Step Attenuator
« Reply #10 on: March 26, 2020, 12:35:23 am »
I'm pretty sure that the open and close delays should be as identical as possible, especially for the relays with the greatest weighting ie. 32, 16 & 8 dB. If a relay takes longer to open, it may be an improvement when going from 31.5 to 32 dB, but when going from 32 to 31.5 it will be the opposite.  If nothing else, reducing the opening time shortens the time the output has to be muted during step changes as imacgreg suggests.

Just to think outside of the box, maybe there's another way to do this.  I built an audio attenuator with a bunch of precision resistors and a 24 position, 2 pole rotary switch.  The switch was make before break so it actually slid through a half step between positions so there was minimal disturbance when varying the attenuation. It would take 15 relays to replicate a 1 of 32 selector: consider a DPDT relay as a 4 to 2 selector.  The first bank needs 8 relays to reduce 32 lines to 16, the second bank needs 4 relays to reduce 16 lines to 8 and so on.  So 8 + 4 + 2 + 1 = 15.  The number of relays could be reduced by using 4PDT units, but the signal has to pass through 4 contacts.  When I think about what this configuration does, it's implementing a binary to 32 bit decoder and there's probably a theorem that says how many contacts are needed and after that it's a matter of selecting parts.  However, I've been wrong before.  Anyone have thoughts on this or other ideas?
« Last Edit: March 26, 2020, 12:40:09 am by duak »
 

Online Prehistoricman

  • Regular Contributor
  • *
  • Posts: 199
  • Country: gb
Re: Tear me apart: Relay Step Attenuator
« Reply #11 on: March 26, 2020, 02:02:15 am »
If a relay takes longer to open, it may be an improvement when going from 31.5 to 32 dB, but when going from 32 to 31.5 it will be the opposite. 

No?
Relay opening = less attenuation
If closing relays is faster, then (in any case), higher attenuation will occur before lower attenuation.

Consider your example:
32    = 01000000
to
31.5 = 00111111

The 6 1s in 31.5 will close first (if opening takes longer)
So briefly you will get this:
63.5 = 01111111

Then the 1 relay in 32 will open:
31.5 = 00111111

Offline floobydust

  • Super Contributor
  • ***
  • Posts: 3349
  • Country: ca
Re: Tear me apart: Relay Step Attenuator
« Reply #12 on: March 26, 2020, 04:31:47 am »
G6K relays are classified as "signal" type which seems to mean under 2A. I've used the Omron G6K-2P for low levels and they aren't so great, some have dirty contacts and need a beating to clean off the oxide. They also are problematic in reflow, the legs frequently haven't soldered well as the relay body seems to block heat. A few production runs ended up with dirty contacts after reflow which I guessed was due to off-gassing, as the relays are sealed. The relay is OK for switching power. Would not use for a step-attenuator.
You need a relay with AgPd contacts, and a minimum switching capacity specification that is uA, not A.
 

Offline duak

  • Frequent Contributor
  • **
  • Posts: 835
  • Country: ca
Re: Tear me apart: Relay Step Attenuator
« Reply #13 on: March 26, 2020, 05:45:36 am »
Prehistoricman,

It looks like I wasn't as clear as I should have been when I introduced the terms open vs closed for relays.  They really should refer to the state of a particular set of contacts.  I understand the relays as drawn on the schematic as being unenergized, with the magnetic gap and the N.O. contacts are open.  In this state the stage is attenuating.  When the relay is energized, the N.O. contacts close and the stage is bypassed.

If the release time is longer than the operate time (terms from the Omron data sheet) on the formerly energized relays, their N.O. contacts could still be closed when the formerly unenergized relays are operating and their N.O. contacts are closing. This means that on the -31.5 to -32 dB transition (and vice versa), all attenuators could be bypassed and pass a larger than expected signal to the output.  Do you agree with this analysis?

When I review what you highlighted in my reply, I have to say I can't remember what I was thinking of and I didn't make a note of it.  It was probably a fleeting thought that I can't explain.  Regardless, it's confusing and should be ignored.

One thing concerns me.  I don't have time to calculate the cummulative attenuation as the attenuator is advanced state by state.  It seems to me that each stage is loaded down by the cummulative input impedance of the following stages  This means that a stage's input impedance is determined by what state it is in and what states the following stages are in.  ie. the input impedance is not constant.  However, this may have been considered in the design but I 'm not sure.  Does anyone else see this?

Cheers,
« Last Edit: March 26, 2020, 05:47:59 am by duak »
 
The following users thanked this post: Prehistoricman

Offline BurnedResistor

  • Regular Contributor
  • *
  • Posts: 182
  • Country: at
Re: Tear me apart: Relay Step Attenuator
« Reply #14 on: March 26, 2020, 07:00:39 am »
One thing concerns me.  I don't have time to calculate the cummulative attenuation as the attenuator is advanced state by state.  It seems to me that each stage is loaded down by the cummulative input impedance of the following stages  This means that a stage's input impedance is determined by what state it is in and what states the following stages are in.  ie. the input impedance is not constant.  However, this may have been considered in the design but I 'm not sure.  Does anyone else see this?

The dividers are all designed to provide the desired amount of attenuation under 10k of output load and to present an input attenuation of 10k. So no matter what the attenuation selected is, any divider engaged will always see a load of 10k.

Hence the output load adjustment: If the audio device this is connected does not have a 10k input impedance, I have included the possibility for a resistor and pot to load down the output. (Only works if the output load is lower ofc..., but the stuff I wanted to connect it too seems to have an input impedance of around 20-40k)
 

Offline BurnedResistor

  • Regular Contributor
  • *
  • Posts: 182
  • Country: at
Re: Tear me apart: Relay Step Attenuator
« Reply #15 on: March 26, 2020, 07:27:33 am »
Adding on to the previous comment, some more stuff regarding resistor-choice and loading:

All attenuation stages are designed to operate with 10k of output load and present 10k of output load to the previous stage.

I did some python-tooling-around to get a feel for this.

Here is the attenuation this design provides at all steps (128 of them), into a 10k load:



I calculated this by actually solving the network at dc and seeing what kind of division it provided, so this is taking into account the small differences in load each of the stages will see due to imperfect resistor values.

so that gives the following absolute error in attenuation at all settings:



By itself, I calculated each stage to provide the following amounts of attenuation into a 10k load:
-0.5db stage:       -0.50201922 db
  -1db stage:        -1.01080154 db
  -2db stage:        -1.9471043   db
  -4db stage:        -3.86249197 db
  -8db stage:        -7.95564109 db
 16db stage:       -15.8991872  db
-32db stage:      -31.70163312 db


There is some error but I can live with it.. I actually don't really care that the attenuation provided is precise. I actually care much more that each consecutive attenuation stetting (so for example going from -31.5db (0111111) to -32db(1000000)) actually still represents a decrease in attenuation. I don't want to turn the volume down a notch and have it increase..... I can live with it not turning down exactly 0.5db though :)

This is the difference in attenuation in each setting going from 0 to full attenuation:



So increasing the attenuation one notch will always yield an increase in attenuation by between -0.45 and -0.65 db. That is good enough for me.

(This is not taking into consideration resistor tolerances yet, still working on that math/simulation...)

Lastly I also simulated the attenuator with different output loads:

956742-3

Like I said in my first post. It looks pretty rough, but as long as it sees 10k+ the 'step delta' (idk if that is the right word, 'difference in attenuation between steps') still seems to be at least all negative.

I feel pretty confident about the choice of resistors in 10k, but I am less sure of 10k as my value for my output load:

Like I said, I would rather have the resitance the device sees at it's output be higher than hat I designed for, and online I saw some designs using 10k, but I am not sure if it is a good move, hence the adjustment resitors at the output, to increase the load from say 40k to 12-20k.
 

Offline BurnedResistor

  • Regular Contributor
  • *
  • Posts: 182
  • Country: at
Re: Tear me apart: Relay Step Attenuator
« Reply #16 on: March 26, 2020, 07:39:44 am »
G6K relays are classified as "signal" type which seems to mean under 2A. I've used the Omron G6K-2P for low levels and they aren't so great, some have dirty contacts and need a beating to clean off the oxide. They also are problematic in reflow, the legs frequently haven't soldered well as the relay body seems to block heat. A few production runs ended up with dirty contacts after reflow which I guessed was due to off-gassing, as the relays are sealed. The relay is OK for switching power. Would not use for a step-attenuator.
You need a relay with AgPd contacts, and a minimum switching capacity specification that is uA, not A.

I see. Hmmm... So yeah, start looking for a different relay.

I designed a commercial pro audio product that used a relay based attenuator similar to what you are describing. I would advise not relying on a hardware solution to the mis-match relay on/off time problem. It can very easily be handled in firmware and may require some tweaking, which is much easier in code.

I think software is going to be my best bet here, yeah.
Do you remember/have access/can share what relays you used?
 

Offline BurnedResistor

  • Regular Contributor
  • *
  • Posts: 182
  • Country: at
Re: Tear me apart: Relay Step Attenuator
« Reply #17 on: March 26, 2020, 07:41:08 am »
Another factor that will affect relay turn on speed is your choice of switching transistor. The 2N7002 is an older part with a very high Rds and it wouldn’t be even my third or forth choice for a 3.3 volt application. Have a look at the data sheet and you’ll see the Rds is off the graph at 3 volts. Most times I’ve seen the 2N7000 series parts used is because they’re still available in through hole versions. Since you’re using surface mount, you have lots of options with hundreds of more modern, lower gate voltage parts.

Having a quick look at the DigiKey parametric search pops up the lowly BSS138 as an okay choice but not a lot of excess current capability, the DMN3730U looks better at .75 amp rating with lots more logic level one and two amp devices in the sot-23 footprint.

I know they arent great but I have a bunch at home from another project, so I thought i could use those ^-^
I will most likely try it with them, and if the switching speed really is an issue I can always change them...
Thank you thought.
 

Offline OldEE

  • Contributor
  • Posts: 13
Re: Tear me apart: Relay Step Attenuator
« Reply #18 on: March 26, 2020, 01:30:40 pm »
Since there will be no wetting current, and that's important, have a look at Panasonic Electric Works DS2E-S-DC3V relays.  They are designed for small signal work and have gold flashed silver contacts.

The yellow case stands out and can be seen in all sorts of low level switching applications.  AT one time they filled with argon but I see no mention of this in the data sheet.


To minimize magnetic coupling from the relay coil and it's traces into the signal traces, where possible, have them at 90 deg to each other.  Likewise the coil inside the relay should be oriented so that the end of the relay is 90 deg. to the signal traces.

On the 3V3 line for the relays consider using a much larger capacitor to handle the inrush current.  Also consider a separate regulator for the processor.
« Last Edit: March 26, 2020, 01:47:00 pm by OldEE »
 

Offline duak

  • Frequent Contributor
  • **
  • Posts: 835
  • Country: ca
Re: Tear me apart: Relay Step Attenuator
« Reply #19 on: March 26, 2020, 07:00:50 pm »
BurnedResistor,

Whew, good! Your explanation of the design algorithm and presentation was clear.  I was working on my reply late last night and could not get the numbers to agree.  Now, after some sleep, it all works.  Looking back, I now see that I took each stage in isolation and not seeing the minimum load, assumed an open circuit as the worst case.

This attenuator has 0.5 dB steps that are hard to discern by ear with real source material.  I expect that as long as the progression is monotonic, it will work well.
 
I have an idea for an optimization of imacgreg's recomendation to mute the output during stepping.  If it turns out that muting is noticable,  the firmware could mute only when the more significant stages change state. 

Cheers,
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf