Tear me apart: Relay Step Attenuator - Page 1
Forum section: electronics / projects

author: BurnedResistor
author_rank: Regular Contributor
timestamp: March 24, 2020, 09:25:39 pm
content: 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 switcherIn 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 inputsI 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 correctionThis 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 unconnectedA 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 pointlessThank you!

author: thm_w
author_rank: Super Contributor
timestamp: March 24, 2020, 11:18:52 pm
content: Possibly some ideas here:youtube.com/watch?v=no6lPPVh6Echttps://www.diyaudio.com/forums/equipment-and-tools/310334-at2380v1-2-channels-digitally-controlled-stepped-attenuator.htmlQuote from: BurnedResistor on March 24, 2020, 09:25:39 pmSounds 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?

author: BurnedResistor
author_rank: Regular Contributor
timestamp: March 25, 2020, 12:11:43 pm
content: Quote from: thm_w on March 24, 2020, 11:18:52 pmRight... ofc... thank you

author: Prehistoricman
author_rank: Regular Contributor
timestamp: March 25, 2020, 12:32:57 pm
content: 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.

author: duak
author_rank: Super Contributor
timestamp: March 25, 2020, 06:11:06 pm
content: 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.

author: BurnedResistor
author_rank: Regular Contributor
timestamp: March 25, 2020, 08:02:47 pm
content: Quote from: Prehistoricman on March 25, 2020, 12:32:57 pmI am a man of taste(Or "Spot the pcb made by the same guy writing the code")Quote from: Prehistoricman on March 25, 2020, 12:32:57 pmMy 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?

author: BurnedResistor
author_rank: Regular Contributor
timestamp: March 25, 2020, 08:19:30 pm
content: Quote from: duak on March 25, 2020, 06:11:06 pmThank 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)Quote from: duak on March 25, 2020, 06:11:06 pmI 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-sNice 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.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?)Quote from: duak on March 25, 2020, 06:11:06 pmI 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...

author: Prehistoricman
author_rank: Regular Contributor
timestamp: March 25, 2020, 08:41:25 pm
content: Quote from: BurnedResistor on March 25, 2020, 08:19:30 pmI 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.

author: WattsThat
author_rank: Frequent Contributor
timestamp: March 25, 2020, 09:33:03 pm
content: 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.

author: imacgreg
author_rank: Contributor
timestamp: March 25, 2020, 11:16:46 pm
content: 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 settingAs 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.

author: duak
author_rank: Super Contributor
timestamp: March 26, 2020, 12:35:23 am
content: 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?

author: Prehistoricman
author_rank: Regular Contributor
timestamp: March 26, 2020, 02:02:15 am
content: Quote from: duak on March 26, 2020, 12:35:23 amNo?Relay opening = less attenuationIf closing relays is faster, then (in any case), higher attenuation will occur before lower attenuation.Consider your example:32 = 01000000to31.5 = 00111111The 6 1s in 31.5 will close first (if opening takes longer)So briefly you will get this:63.5 = 01111111Then the 1 relay in 32 will open:31.5 = 00111111

author: floobydust
author_rank: Super Contributor
timestamp: March 26, 2020, 04:31:47 am
content: G6K relays are classified as "signal" type which seems to mean under 2A. I've used the OmronG6K-2Pfor 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.

author: duak
author_rank: Super Contributor
timestamp: March 26, 2020, 05:45:36 am
content: 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,

author: BurnedResistor
author_rank: Regular Contributor
timestamp: March 26, 2020, 07:00:39 am
content: Quote from: duak on March 26, 2020, 05:45:36 amThe 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)

author: BurnedResistor
author_rank: Regular Contributor
timestamp: March 26, 2020, 07:27:33 am
content: 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 db16db stage: -15.8991872 db-32db stage: -31.70163312 dbThere 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 thoughThis 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: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.

author: BurnedResistor
author_rank: Regular Contributor
timestamp: March 26, 2020, 07:39:44 am
content: Quote from: floobydust on March 26, 2020, 04:31:47 amI see. Hmmm... So yeah, start looking for a different relay.Quote from: imacgreg on March 25, 2020, 11:16:46 pmI think software is going to be my best bet here, yeah.Do you remember/have access/can share what relays you used?

author: BurnedResistor
author_rank: Regular Contributor
timestamp: March 26, 2020, 07:41:08 am
content: Quote from: WattsThat on March 25, 2020, 09:33:03 pmI know they arent great but I have a bunch at home from another project, so I thought i could use thoseI will most likely try it with them, and if the switching speed really is an issue I can always change them...Thank you thought.

author: OldEE
author_rank: Contributor
timestamp: March 26, 2020, 01:30:40 pm
content: 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.

author: duak
author_rank: Super Contributor
timestamp: March 26, 2020, 07:00:50 pm
content: 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,

author: BurnedResistor
author_rank: Regular Contributor
timestamp: April 07, 2020, 09:24:19 am
content: Ouff. Busy with some school stuff but finally had some time again to start working on the things that actually matterQuote from: OldEE on March 26, 2020, 01:30:40 pmGood call. I will add a second 5V line for the realys.I did some looking around regarding what relay to pick.Quote from: OldEE on March 26, 2020, 01:30:40 pmThose look very fancy, but I am a little size constraint and I dont see those available in a smaller packageQuote from: floobydust on March 26, 2020, 04:31:47 amBut after some digging the Panasonic TQ2SA-5V seem like a good bet:10 µA 10 mV DC minimum switching capacityAu-clad AgNi type contactsRelatively small smd packagePlus I saw some reports online that they are used in some high-end analog mixing boards, which gives me some confidence.Is there any other spec I should be looking at?One last question:The TQ2 Series Datasheet mentions " In case of 5 V transistor drive circuit, it is recommended to use 4.5 V type relay." so If I have them on a 5V rail with low side mosfet switching I guess I really should pick the TQ2SA-4.5? Or what else would they mean by "5v transistor drive circuit"?https://www.mouser.at/datasheet/2/315/mech_eng_tqsmd-1304769.pdf

author: max_torque
author_rank: Super Contributor
timestamp: April 07, 2020, 01:10:28 pm
content: One "trick" i do with driving, especially turning on, high inductive loads (in my case, automotive fuel injectors) is to overdrive them for a short period, ie to apply significantly more than their rated voltage to kick them into movement, and as they start to move, their inductance increases which further slows their transition. Now obvs, this is a compromise and if overdone could shorten the life of the devices, bu tan effective "peak and hold" driver can be doen very easily, especially if your load is fixed, which yours is (it's a known relay that doesn't change.There are various circuits to achieve peak and hold, depending on how efficienct you want the driver to be, in your case, you probably don't care too much, because overall power levels are low?You might get away with a series resistor up stream of the relay, feeding into the relay coil + and in parallel, a capacity of a few uF. Then, when you switch the low side to ground, initally, there is more voltage (and current) to at first drive the relay open, but once the boosting cap is "empty" then the supply current is limited by the resistor in series (which of course also has to waste power when the relay in on) On the turn off side, simply use a high voltage fet/transistor, and put a suitablly high rated diode around the relay coil to break down just before your driver does. There are various schemes using various cunning architectures to achieve this voltate boosting without significant losses. especially for loads that dont' actually switch much, so don't actually consume much power during the switch event!(my fave is the one used for high voltage (~100V) direct injectors on modern DI engines, where the inductance of the injector itself is used as the boost element in a boost converter, and in the injector off period, the injector is driven on/off at too high a frequency to actually open the injector (ie within its dead time) but that can act to charge a HV holding capacitor, ready for next time the injector needs to be opened (and that cap also is arranged to re-capture the inductive energy on injector closing too!of course, you need to be careful, because too much voltage and current in an audio application might actually be worse than slowly switching or mis-switching your attenuation......