Author Topic: Is this right? Noise resistant-ish Pi-controlled 5V USB power switch?  (Read 991 times)

0 Members and 1 Guest are viewing this topic.

Offline jewelieTopic starter

  • Regular Contributor
  • *
  • Posts: 111
  • Country: gb
  • Everyone's gotta start somewhere
    • Personal website, of sorts, sometimes with a Pi-driven bird-feeder webcam (currently down but will be putting it up again in the near future with IR capability.)
For my Pi server, so I can use it to turn its USB 5V powered speakers on only when they're needed, such as to make audible status announcements, to avoid all audio background noise/interference issues when the speakers are not in use.

I think this is a more practical and pragmatic approach than what I was previously attempting, trying to make a new amp or filter the audio input or amp power etc to try to eliminate noise, as detailed in a previous post https://www.eevblog.com/forum/beginners/help!-pi-amplified-speaker-reducing-interferencenoise/#msg5515516

Uses opto isolation + turn on/off delay/filtering to try stop external noise sources turning it on accidentally (and also because I had never used an opto isolator before, I had some, and thought I should give them a go.)

Components chosen based on what I already had and ought to be suitable?

Scope traces at an unreasonably fast 10Hz to check the delay/filtering (note that the bottom trace, the output trace is inverted, cos I had the scope ground connected to the 5V and signal coming from the MOSFET drain.)

Constructed on breadboard and tested first, then drew the schematic afterwards. 

I've not actually tried driving it from a Pi yet though.

Does this look okay? 

Should I make any changes?
Anxious newbie to EEVblog.  Resuming an interest in basic electronics after a close shave with a joint EE/Computing degree decades ago
 

Online wraper

  • Supporter
  • ****
  • Posts: 17560
  • Country: lv
Disconnecting ground is a bad idea regardless if USB is used just for power (unless speaker is otherwise wireless) or it's an actual USB device. Also gradual powering that you call delay/filtering more likely will cause problems rather than help anything.
« Last Edit: June 04, 2024, 11:35:44 pm by wraper »
 

Offline radiolistener

  • Super Contributor
  • ***
  • Posts: 3925
  • Country: ua
I'm using Pi4 with 100 Watt 6Ω acoustic connected with CX31993 USB DAC and cheap AK-270 amplifier. And there is no noise. When sound is not played in software, there is almost impossible to detect if amplifier is powered or not. Of course there is some very low noise which can be detected with careful listening near speakers at max volume in total silence, but it is hard to listen it.
« Last Edit: June 05, 2024, 01:54:02 am by radiolistener »
 

Offline jwet

  • Frequent Contributor
  • **
  • Posts: 507
  • Country: us
I'm +1 with wraper- the overall idea is good and opto isn't bad but use a PMOS FET for the power switch and make a high side.  The difficulty with switching low side is that the amp will be kind of floating around on the high rail when "off".  Any capacitive coupling or leakage through low side switch could make its way into things.  Better to take away high rail.  Also might want to put a few K resistor across amp power input so it discharges bypass caps and doesn't sort of float around.
 
The following users thanked this post: tooki

Offline perieanuo

  • Frequent Contributor
  • **
  • Posts: 912
  • Country: fr
also a relay or a reed relay may work.
in your schematic led attach resistor seems too big imho, but maybe that opto can trigger...
 

Offline jewelieTopic starter

  • Regular Contributor
  • *
  • Posts: 111
  • Country: gb
  • Everyone's gotta start somewhere
    • Personal website, of sorts, sometimes with a Pi-driven bird-feeder webcam (currently down but will be putting it up again in the near future with IR capability.)
I'm using Pi4 with 100 Watt 6Ω acoustic connected with CX31993 USB DAC and cheap AK-270 amplifier. And there is no noise. When sound is not played in software, there is almost impossible to detect if amplifier is powered or not. Of course there is some very low noise which can be detected with careful listening near speakers at max volume in total silence, but it is hard to listen it.

Not enough space for an additional amp, plus the issue with noise is mainly from WiFi, DECT phone, other devices etc, plus it would mean rigging up an extra cable.  Good call on that CX31993, I have one of those.  That AK-270 amp keeps popping up as a suggestion on things too, so I will make a mental note should I need such a thing.  Thanks for your suggestions and ideas though!
Anxious newbie to EEVblog.  Resuming an interest in basic electronics after a close shave with a joint EE/Computing degree decades ago
 

Offline jewelieTopic starter

  • Regular Contributor
  • *
  • Posts: 111
  • Country: gb
  • Everyone's gotta start somewhere
    • Personal website, of sorts, sometimes with a Pi-driven bird-feeder webcam (currently down but will be putting it up again in the near future with IR capability.)
also a relay or a reed relay may work.
in your schematic led attach resistor seems too big imho, but maybe that opto can trigger...

I do have some relays, so could consider that an option too.

Do you mean the current limiting resistor from the Pi GPIO driving the LED of the Optoisolator?  If so, it would be around 2mA, which seems to be fairly typical in usage on the datasheets?  The current transfer ratio is at least 200% too.

https://www.mouser.co.uk/datasheet/2/143/EVER_S_A0008471837_1-2548735.pdf

Anxious newbie to EEVblog.  Resuming an interest in basic electronics after a close shave with a joint EE/Computing degree decades ago
 

Offline jewelieTopic starter

  • Regular Contributor
  • *
  • Posts: 111
  • Country: gb
  • Everyone's gotta start somewhere
    • Personal website, of sorts, sometimes with a Pi-driven bird-feeder webcam (currently down but will be putting it up again in the near future with IR capability.)
Disconnecting ground is a bad idea regardless if USB is used just for power (unless speaker is otherwise wireless) or it's an actual USB device. Also gradual powering that you call delay/filtering more likely will cause problems rather than help anything.

I'm +1 with wraper- the overall idea is good and opto isn't bad but use a PMOS FET for the power switch and make a high side.  The difficulty with switching low side is that the amp will be kind of floating around on the high rail when "off".  Any capacitive coupling or leakage through low side switch could make its way into things.  Better to take away high rail.  Also might want to put a few K resistor across amp power input so it discharges bypass caps and doesn't sort of float around.

Thank you both.

Yeah, after thinking about this longer and seeing a suggestion from someone else I tried a PMOS instead, I began to think of all the ways in which switching the ground for this was an awful idea, and did an alternative layout, attached below?

The only reason I didn't before is because the only PMOS I had is a SOT23 and my somewhat irrational fear of trusting small SMD things for anything power related, because my experience is mainly with thru-hole still.  Having said that, it has much lower threshold voltage so would probably be better for this anyway.

Should I drop the 1uF then do you think?  Particularly with the SOT23 I guess the risk of excess power dissipation during the slowed on transition of the PMOS would be even more serious.  Do you think just the inertia of needing to light the LED in the optoisolator, plus the need to charge the PMOS enough to reach the threshhold, would be enough to keep it from turning on through noise anyway?  I would also add 100k discharge resistor as suggested too.

What about feeding the signal from the Pi to the switching device, would it be enough to just lightly twist them, or would getting single core screened be a better idea?  (Actually, I'm bound to have some double core screened, no reason why I can't just use that I guess.)


Anxious newbie to EEVblog.  Resuming an interest in basic electronics after a close shave with a joint EE/Computing degree decades ago
 

Offline jewelieTopic starter

  • Regular Contributor
  • *
  • Posts: 111
  • Country: gb
  • Everyone's gotta start somewhere
    • Personal website, of sorts, sometimes with a Pi-driven bird-feeder webcam (currently down but will be putting it up again in the near future with IR capability.)
Anything I could do to limit the turn on speed of the the USB device being powered to reduce the click?

Obviously a bipass cap + that 100k resistor, but to slow the charging of the bypass cap(s) maybe even a fuse to add a tiny bit more resistance and provide overcurrent/fault protection indirectly too, given I wouldn't want to be running more than a few 100 mAs a little extra voltage drop shouldn't hurt e.g. the intended device, a small USB powered speaker?
Anxious newbie to EEVblog.  Resuming an interest in basic electronics after a close shave with a joint EE/Computing degree decades ago
 

Offline jwet

  • Frequent Contributor
  • **
  • Posts: 507
  • Country: us
Lose the 1 uF on the LED side.  LED's are current operated non linear devices, they don't respond slowly with a cap across the LED, it just delays a fast turn on.

The turn on time will be dominated by the 150 ohm emitter resistor.  You don't want to stay in active region too long but a mS or two shouldn't be bad, many FET data sheets will have a graph of pulse duration and amplitude- involves transient thermal, etc.  If you go too long you'll start dissipating real power in the PFET- poof.  The gate is a big capacitor.  Output Z of transistor is basically that emitter R (in parallel with collect load, but that is likely much larger).  Gate C is probably 3000 pF (didn't look it up, remember that C=Q/v if you only have charge spec- this is an approximation, its not linear).  Gate draws zero current after its pulled low (on), emitter R only matters in transition- will settle to gate at ground.  Breadboard it and play with it.  Click and pop can be tough.  Sometimes its just caused by bias circuits coming up and slowing Vcc rise down doesn't help.  Often just biasing up the input C causes a thump.  You might be able to put a high Z voltage divider on this node to keep bias on input C even when shutdown, so it doesn't get a big slug on power up.  You can reduce this C value too- these amps size input coupling for 20Hz, which depending on your app might not matter (toll grade voice is ~300 to 3400 Hz).   Does amp have mute input that is active on power up.  You could put an RC on this input so amp muted on slew.  If you have flexibility on amps, look at others- they vary widely

I've built a lot of audio players for ornithologists that play bird calls at certain times or on demand for various purposes.  Two gotchas are to watch grounds and how  ground current flows- don't let it contaminate your audio source- its common to get hum or digital noise in the audio.  The other is peak currents drawn by audio.  Bypass the amp well but don't have a FET driving a big low ESR cap directly (add an L), the current for a good cap can be really high with a fast step.

Good Luck.
« Last Edit: June 07, 2024, 03:53:58 pm by jwet »
 

Offline jewelieTopic starter

  • Regular Contributor
  • *
  • Posts: 111
  • Country: gb
  • Everyone's gotta start somewhere
    • Personal website, of sorts, sometimes with a Pi-driven bird-feeder webcam (currently down but will be putting it up again in the near future with IR capability.)
Re: Is this right? Noise resistant-ish Pi-controlled 5V USB power switch?
« Reply #10 on: June 07, 2024, 04:30:29 pm »
Lose the 1 uF on the LED side.  LED's are current operated non linear devices, they don't respond slowly with a cap across the LED, it just delays a fast turn on.

That's actually ideal for me then.  Ideally I want there to be some "inertia" of sorts to turning that LED on so that it's a bit electrical noise immune with reduced risk of accidental turn ons, whilst also still turning the PMOS on fairly quickly.

I've probably not been clear enough through this about my issues/concerns-

1. Electrical/RF noise immunity - to stop it accidentally turning due to WiFi, DECT etc, or impulse noise.  Hence the capacitor on the LED side.  Maybe keep the capacitor but reduce it's value?  Or just likely not needed or better way to do that?

2. General audio noise coming out of the 5V USB powered speaked.  This doesn't matter now, as it's only for doing voice announcements very occasionally.  99.99% of the time it's going to be unused.  Hence removing power, to make it proper quiet!

3. The switch on pop/click when the speaker powers up/down.  Would be nice to reduce this.

The turn on time will be dominated by the 150 ohm emitter resistor.

Will it though?  The current driving the LED is 2mA.  The CTR of the optoisolator is min 200%, probably around 300%.  So it's likely with 150ohm in series with the optocoupler transistor that it'll max at 4mA to 6mA ish, so it might not actually be saturated?  Do I need another transistor there maybe to drive the current into the PMOS to improve the transition?

You don't want to stay in active region too long but a mS or two shouldn't be bad, many FET data sheets will have a graph of pulse duration and amplitude- involves transient thermal, etc.  If you go too long you'll start dissipating real power in the PFET- poof.  The gate is a big capacitor.  Output Z of transistor is basically that emitter R (in parallel with collect load, but that is likely much larger).  Gate C is probably 3000 pF (didn't look it up, remember that C=Q/v if you only have charge spec- this is an approximation, its not linear).  Gate draws zero current after its pulled low (on), emitter R only matters in transition- will settle to gate at ground.  Breadboard it and play with it. 

Click and pop can be tough.  Sometimes its just caused by bias circuits coming up and slowing Vcc rise down doesn't help.  Often just biasing up the input C causes a thump.  You might be able to put a high Z voltage divider on this node to keep bias on input C even when shutdown, so it doesn't get a big slug on power up.  You can reduce this C value too- these amps size input coupling for 20Hz, which depending on your app might not matter (toll grade voice is ~300 to 3400 Hz).   Does amp have mute input that is active on power up.  You could put an RC on this input so amp muted on slew.  If you have flexibility on amps, look at others- they vary widely

I've built a lot of audio players for ornithologists that play bird calls at certain times or on demand for various purposes.  Two gotchas are to watch grounds and how  ground current flows- don't let it contaminate your audio source- its common to get hum or digital noise in the audio.  The other is peak currents drawn by audio.  Bypass the amp well but don't have a FET driving a big low ESR cap directly (add an L), the current for a good cap can be really high with a fast step.

Good Luck.

I'm thinking that maybe a fuse on the 5V might be a way to both limit the turn on current too (as it'll have some inherent resistance, especially if low enough current, e.g. 650mA), I feel more comfortable if there's a fuse in anything I make, lol.  The audio distortion aspect is neither here nor there really, as the speaker is only for doing voice announcements.

Anxious newbie to EEVblog.  Resuming an interest in basic electronics after a close shave with a joint EE/Computing degree decades ago
 

Online edavid

  • Super Contributor
  • ***
  • Posts: 3419
  • Country: us
Re: Is this right? Noise resistant-ish Pi-controlled 5V USB power switch?
« Reply #11 on: June 07, 2024, 04:43:29 pm »
OP, have you considered leaving the USB power on, and using relays to switch the actual speakers (drivers)?  That way you are guaranteed not to have speaker pops.  (Of course it assumes the relay clicks aren't equally annoying.)
 

Offline jwet

  • Frequent Contributor
  • **
  • Posts: 507
  • Country: us
Re: Is this right? Noise resistant-ish Pi-controlled 5V USB power switch?
« Reply #12 on: June 07, 2024, 05:40:56 pm »
The cap across the LED can stay- .1u would be plenty.  Subthreshold LED's have a high impedance and I can imagine being in a strong field, it could getting winked on.  The old industrial equipment quick test was to key a 5W VHF or UHF Handy Talky with the equipment door open.  This is actually a pretty common real world occurence for field maintenance techs.

Your other Q's, I recommend you test/try stuff.  Its a bummer to have a problem like this after its all together.  "I need to fix this but I can't change anything".  Click and Pop can be a pain- you don't want a big pop everytime you do a message.  See how amp reacts to turn on and slow rise.

The 150 ohm issue.  CTR is not a design spec really, its a minimum boundary value.  The transistor won't look like a current source all the way down- it will look like a bipolar with its base hammered high.  The start current is like to be something like the CTR x I LED, but it will leave active region and go into saturation when pulling down on that big gate C (a short).  The 150 ohms is important and will set the speed for most of the fall.

Last issue- fuses have a pretty low resistance depending on rating.  You might consider a poly fuse, sort of a self resetting fuse that is often used in USB apps.

Good Luck.
 

Offline radiolistener

  • Super Contributor
  • ***
  • Posts: 3925
  • Country: ua
Re: Is this right? Noise resistant-ish Pi-controlled 5V USB power switch?
« Reply #13 on: June 15, 2024, 07:22:42 am »
Not enough space for an additional amp

AK-270 is very tiny amplifier, its size is about 10.5x40.0x7.5 cm, it's size is almost the same as raspberry pi. It is very nice and low power consumption. The quality is not the best and you can hear some IMD, especially with high volume, but in combination with good acoustics it still much better than usual branded PC speakers.
« Last Edit: June 15, 2024, 09:07:12 am by radiolistener »
 

Offline jewelieTopic starter

  • Regular Contributor
  • *
  • Posts: 111
  • Country: gb
  • Everyone's gotta start somewhere
    • Personal website, of sorts, sometimes with a Pi-driven bird-feeder webcam (currently down but will be putting it up again in the near future with IR capability.)
Re: Is this right? Noise resistant-ish Pi-controlled 5V USB power switch?
« Reply #14 on: July 02, 2024, 12:14:22 am »
The finished device. 

Left the 1uF cap on the input to the optocoupler as it didn't hurt. 

Used the PMOS as switch with 2K pullup and 150R drive.  You can see the waveform running at an unrealistic 1KHz fetching a 10ohm load.  With the approx 1ohm fuse, it drops 0.5V as expected.

The pop and click was minimal in the end and pretty irrelevant in use.

Image + audio of actual use.

The Pi itself is running-

1. DLNA server (providing media kept on a shared drive.)
2. ADS-B plane signal uploads to FlightRadar and PlaneFinder.
3. IR Remote control to change volume, reboot etc.
4. Voice announces reboots, when network issues have been detected (scheduling automatic reboots), when the mains power grid is at its greenest, and has code for other things (generic sensor-based alarm alerts.)
5. A small webserver for miscellaneous functions (checking the status of the Pi, firing off wake on LAN requests, etc.)

It acts as a general purpose server for extra "nice to have" functions for the home network etc that nothing else covers.
Anxious newbie to EEVblog.  Resuming an interest in basic electronics after a close shave with a joint EE/Computing degree decades ago
 

Offline jewelieTopic starter

  • Regular Contributor
  • *
  • Posts: 111
  • Country: gb
  • Everyone's gotta start somewhere
    • Personal website, of sorts, sometimes with a Pi-driven bird-feeder webcam (currently down but will be putting it up again in the near future with IR capability.)
Re: Is this right? Noise resistant-ish Pi-controlled 5V USB power switch?
« Reply #15 on: July 02, 2024, 12:20:04 am »
(Please pretend you didn't see the resistor underneath. That's the first time I've ever done that! I realised I'd miscounted the number of lines of holes left and decided that was the least worst bodge.)
Anxious newbie to EEVblog.  Resuming an interest in basic electronics after a close shave with a joint EE/Computing degree decades ago
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf