Millivolt level spikes when toggling an output pin

n9ds

Member
Below is my schematic. The idea is to route low-level audio with the relays. When in mute mode, I've programmed B.5 to toggle every 500ms. The problem is that is introducing a small (4-5mV) spike in the audio path (the first image is the scope trace.) The audio is microphone level, so 4mV is significant enough to cause an undesirable click. I've added 1uF and 220pF directly across pins 1 and 14 of the PICAXE and even disconnected the LEDs (meaning pin 8 is just floating) as well as tried replacing the LED with just a 180ohm resistor and I still get the spikes. When the problem occurs, none of the relays are being switched, and the audio path is electrically isolated from the rest of the circuit. The device is on a prototype PC board with numerous point-to-point wires (closer to a PC than a breadboard, but not either one.) Any ideas what's causing the problem and how to solve it?2023-01-23-PICAXE-Spikes.png
25982
 

piclt

Member
You say.... "I've programmed B.5 to toggle every 500ms". ..... does it toggle continuously all the time....?

Then you say, "When the problem occurs," ......so this indicates the problem is only some of the time that it is toggling.

So what changes when the spikes appear or dissappear..??

Is C0 and C1 your audio out...... Is the cable screened..... you could try screening.

Your scope trace indicates the spikes superimposed over the audio tone..??...... Does the the scope show system in "mute" mode or running normally.?

Also your programming connections........ The R10 22k resistor should be pointing to pin 2 of the Picaxe and the RS232 input from PC should be connected to the junction of the 22k and the 10k.........see the manual.

And where is "Real" GND in relation to the PC and the circuit..?
 
Last edited:

Buzby

Senior Member
I don't see any decoupling capacitors in that circuit.

Picaxe hardware rules ....

Rule 1 : Fit decoupling caps

Rule 2 : Don't ignore Rule 1

PicaxeShortedRelay.JPG

That relay coil is shorted. I would expect Q3 to get very hot very quickly !
 
Last edited:

inglewoodpete

Senior Member
I don't see any decoupling capacitors in that circuit.

Picaxe hardware rules ....

Rule 1 : Fit decoupling caps

Rule 2 : Don't ignore Rule 1
I second Buzby's message. Microcontrollers (and relays, even with protection diodes) create a lot of electrical noise on their supply lines, which can be harmful is not absorbed by capacitor/s. Refer to Manual 1 "Getting Started", from page 26 onwards - capacitors around the voltage regulator AND THE PICAXE (or any microcontroller) chip.
 

n9ds

Member
You say.... "I've programmed B.5 to toggle every 500ms". ..... does it toggle continuously all the time....?

Then you say, "When the problem occurs," ......so this indicates the problem is only some of the time that it is toggling.

So what changes when the spikes appear or dissappear..??

Is C0 and C1 your audio out...... Is the cable screened..... you could try screening.

Your scope trace indicates the spikes superimposed over the audio tone..??...... Does the the scope show system in "mute" mode or running normally.?

Also your programming connections........ The R10 22k resistor should be pointing to pin 2 of the Picaxe and the RS232 input from PC should be connected to the junction of the 22k and the 10k.........see the manual.

And where is "Real" GND in relation to the PC and the circuit..?
1) The pin toggles continuously every 500mS. I only see the spikes when the pin transitions from low to high or high to low. To make the spikes go away, I keep the pin high or low. (To be over-specific, when it switches from "mute" to "live", B.5 goes low and B.4 goes high. Both stay there until the user pushes one of the buttons.)

2) C.0 and C.1 are push button inputs. The audio comes in on J3 pins 1 and 3 and goes out on J4 pin 1 where I have the scope probe. (yes, that's the NO output of K4 which is open in this scenario.)

3) There is no audio, the trace is 500mS/div. I don't know what the mess is, I suspect RF. There's a wifi router under my bench and another across the room as well as fluorescent and LED lights on the desk. Those might be affecting it. But it's there whether I see spikes or not.

4) Thank you for pointing out the mixup on the resistors. They're on the schematic but not populated on this board. I'll fix it before I'm done.

"Rule 1: ..." "I've added 1uF and 220pF directly across pins 1 and 14" Doesn't that count as a bypass, or do I need more?

"Shorted relay coil" I think you're misreading that, R4 doesn't connect to the coil. It behaves the same as the other two relays, Q3 is fine.

"relays, even with protection diodes..." I don't disagree, but the relays aren't being actuated so unless they make noise sitting still, that's not the issue.

"Real ground..." The groundiest [sic] ground I have is the center pin of a coaxial DC connector. It goes straight from there to the ground pin of the 7805 and to the sleeves of the three audio jacks. From the 7805, it goes to a foil strip on the perf board itself (Radio Shack model 276-150). The ground of the scope connects to the sleeve of the output audio jack and the probe connects to the tip.
 

Buzby

Senior Member
Shorted relay coil, look in the circle I drew. There is a link directly across the relay coil. Nothing to do with R4. If K3 is switching properly then the drawing is wrong.

Decoupling caps are usually 0.1uF ceramic or plastic. Your 1uF is probably electrolytic, ( or worse still, tantalum ), which are not good for suppressing spikes. 220pF is a bit small, but better than nothing !.

I'm unclear about your grounding. In an audio routing device like this, the audio ground is usually totally seperate from the control ground. If a common ground has to be used, then the layout needs to be considered very carefully.

You say you are seeing spikes when no relays are attached, i.e. just the Picaxe toggling. The first thing to ensure is that the Picaxe is properly decoupled. I would use 10uF and 0.1uF. See https://picaxeforum.co.uk/threads/verification-error.33028/#post-345816

Unsuppressed chips cause large current spikes in both the power and ground traces. Disruptions to grounds cause audio disturbances because the audio signal is determined by the voltage relative to ground, and if the ground 'moves up' a few mV this is seen as a change in signal. Without special tools it is very difficult to measure exactly what is happening in ground traces, so best to design the problems out !.

The spikes can also be induced into cables. That's why it's essential to use screened cables for audio, with attention paid to where the screens are grounded, and to the routing of the cables. ( Don't run parallel to power cables is the first rule ! )
 

piclt

Member
Can You post your code to let us see what this thing does..?
I do not see J4 on your schematic...?
The relays are single pole changeover only one line of audio will get through.....where is the rest of the circuit........source and speaket etc.??
Your B5 and B4 are connected to J5...... so do not do anything until something is connected to J5...?
we need more info...?
 

n9ds

Member
Can You post your code to let us see what this thing does..?
I do not see J4 on your schematic...?
The relays are single pole changeover only one line of audio will get through.....where is the rest of the circuit........source and speaket etc.??
Your B5 and B4 are connected to J5...... so do not do anything until something is connected to J5...?
we need more info...?
I fixed the extra wire on K3, thank you. It was in the schematic but not the board.

My mistake, not J4, it's J2.

As far as J5 is concerned, the red anodes of the LEDs (there are 2 bicolor LEDs) are connected to pin 4. The cathode of LED 1 is connected to pin 3 and the cathode of LED 2 is connected to pin 2. (The anodes of the greens are connected to pin 1.) And before anyone asks, I already mentioned I see the spikes whether or not there is an LED attached.

"The relays are single pole changeover only one line of audio will get through" Yes, that's the whole point. This thing only routes audio. It doesn't generate or reproduce any sound. It's job is to route one of two mono inputs to one mono output and be able to prevent the sound from the selected source from getting through (a.k.a mute). But (IMHO) that's getting off the topic, since the relays aren't involved in the blinking process.

Here's the code. I include it for completeness, but the only part that's relevant to this question is subroutine flash.

I will try it without the sertxd() calls and report back later.

Code:
init:
sertxd("Init...")
symbol audioIn = b0
symbol mute = b1
symbol mutePin = b.1
symbol inputSelectPin = b.2
symbol cathodeSelectPin = b.3
symbol greenLED = b.4
symbol redLED = b.5
b2 = 1
b3 = 0

'b.5 Red
'b.4 Green
'b.3 Cathode select
'b.2 Input select
'b.1 mute
' Turn everything off
output b.1
output b.2
output b.3
output b.4
output b.5
low b.1
low b.2
low b.3
low b.4
low b.5
audioIn = 0
mute = 1
' Two pushbuttons
setint or %00000011, %00000011

main:
gosub flash
goto main

flash:
if mute = 1 then
    sertxd("Red",13,10)
    low mutePin
    low greenLED
        high redLED
        pause 500
        low redLED
        pause 500
else
    sertxd("Green",13,10)
    high mutePin
    low redLED
    high greenLED
end if
return

interrupt:
    sertxd("Interrupted", 13, 10)
    pause 100
    if pinC.0 = 1 then
        sertxd("Mute was ", #mute, 13, 10)
        mute = 1 - mute
        sertxd("Mute is now ", #mute, 13, 10)
        'Now wait for the input to go away
        do while pinC.0 = 1
        loop
        sertxd("pinC.1 is clear",13,10)
    end if
    if pinC.1 = 1 then
        audioIn = 1 - audioIn
        if audioIn = 1 then
            high inputSelectPin
            high cathodeSelectPin
        else
            low inputSelectPin
            low cathodeSelectPin
        end if
        sertxd("Waiting for pin to clear",13,10)
        'Now wait for the input to go away
        do while pinC.1 = 1
        loop
        ' Always mute on input change
        sertxd("pinC.1 is clear",13,10)
        mute  = 1
    end if
    sertxd("Set interrupt",13,10)
    setint or %00000011, %00000011
return
 

piclt

Member
If you disconnect your audio line from the picaxe circuit and switch off th picaxe circuit. Then hook the scope to the incoming audio line only.......do you get a clean audio signal on the scope..??.......no visible tone and no spikes as picaxe is off.
Your earlier post shows a tone on it and you say no audio..?

If you still get the visible tone on it then you need to screen the audio line or eliminate the tone.

Your unscreened audioline is acting like a receiving aerial..??
 

Buzby

Senior Member
I've looked closely at the audio switching part of your circuit.

If I understand correctly, two mono signals enter at J2-1 and J2-3. The first relay selects one of the two and sends it to the second relay, which then outputs the selected signal to either J3-1 or J3-3.

( Is this correct, as your description mentions a single output with a 'mute' function, but it doesn't look like that ? )

Also, I can't see where the grounds for these four signals are. Are they the middle pins on J2 and J3 ?

If that is the case, and your drawing is accurate, then the audio ground does not look to be connected the control ground in any way. This is a very Good Thing !.

Do a continuity test between audio ground and control ground. There should be no connection at all.

If this is the case, then we can rule out ground bounce, and if there is noise on the 5v or 0v rail, this will not reach the audio directly, so must be getting in somewhere else.

Some big suspects are the relays. If these are reed relays, then they are just a coil wrapped around a pair of contacts. These contacts are long compared to the coil, and in very close proximity to it. Any switching noise from the 5v will appear in the coil, even if the coil is off. This noise will induce further noise in the contacts. Even with no noise, there will be an induced signal when the relay is switched normally. You will always have a switching 'click'.

Even if you do manage to eliminate every source of switching noise, there is still a noise source beyond this circuit, i.e. your input signals !.

Imagine input A is at the top of a sine wave audio signal, and input B is at the bottom. If you then switch from A to B, or B to A, the amplifier will see a rapid change in level, which will sound like a click.

( This is why many audio routing devices use opamps or VCAs as selectors, so they can be ramped, which eliminates switching 'clicks' altogether. Another way of avoiding clicks is to mute the output, switch the relays, then unmute the output. If this is done with a soft-mute circuit then the results can be as good as an all solid state solution. )
 
Last edited:

n9ds

Member
I've looked closely at the audio switching part of your circuit.

If I understand correctly, two mono signals enter at J2-1 and J2-3. The first relay selects one of the two and sends it to the second relay, which then outputs the selected signal to either J3-1 or J3-3.

( Is this correct, as your description mentions a single output with a 'mute' function, but it doesn't look like that ? )

Also, I can't see where the grounds for these four signals are. Are they the middle pins on J2 and J3 ?

If that is the case, and your drawing is accurate, then the audio ground does not look to be connected the control ground in any way. This is a very Good Thing !.

Do a continuity test between audio ground and control ground. There should be no connection at all.

If this is the case, then we can rule out ground bounce, and if there is noise on the 5v or 0v rail, this will not reach the audio directly, so must be getting in somewhere else.

Some big suspects are the relays. If these are reed relays, then they are just a coil wrapped around a pair of contacts. These contacts are long compared to the coil, and in very close proximity to it. Any switching noise from the 5v will appear in the coil, even if the coil is off. This noise will induce further noise in the contacts. Even with no noise, there will be an induced signal when the relay is switched normally. You will always have a switching 'click'.

Even if you do manage to eliminate every source of switching noise, there is still a noise source beyond this circuit, i.e. your input signals !.

Imagine input A is at the top of a sine wave audio signal, and input B is at the bottom. If you then switch from A to B, or B to A, the amplifier will see a rapid change in level, which will sound like a click.

( This is why many audio routing devices use opamps or VCAs as selectors, so they can be ramped, which eliminates switching 'clicks' altogether. Another way of avoiding clicks is to mute the output, switch the relays, then unmute the output. If this is done with a soft-mute circuit then the results can be as good as an all solid state solution. )
You first sentence is completely correct. The "Mute" works by sending the audio signal into the ether.

I did add 22uF between the + and - rails that is not on the schematic. At one point I had added another small value (.01uF maybe?) in parallel with the 22uF, but that didn't solve the problem. I've since removed the small capacitor because it seemed useless and was in the way.

The audio jacks are 1/4" mono jacks. The sleeves are all point-to-point wired together. When I first assembled it, that's all I did, but it had 60Hz (plus harmonics of course) hum. When I added a wire from the sleeves to the center pin of the coaxial DC jack (DC ground,) the hum went away. Given that, I suppose ground bounce could be an issue. I wasn't sure how to diagnose or correct it.

A click when switching from A to B or B to A is acceptable. But the clicking I'm hearing isn't related to that. Again, blinking the LEDs is not done with relays. Unless what you're suggesting is the changing logic level of B.5 going through K3's contacts to a resistor to ground is inducing a current into K3's coil and into ground, I'm not sure I see how relay switching noise would explain what I'm seeing. But then, I'm not expert, that's why I'm here.

Below is the trace I get with the DC disconnect and no devices (except the scope itself) connected to any of the audio jacks. Horizontal is 500mS/div. Verical is 2mV/Div. The scope itself is a Diligent Analog Discovery 2 connected to the PC via USB.2023-01-23-PICAXE-No-Signals.png
 

Buzby

Senior Member
As you are learning, grounding in audio circuits is more of a black art than a definite science !.

Try instead of connecting the phono's sleeve ground to the DC jack ground with a wire, use a 0.1uF capacitor. This should cure the hum, without altering the DC level of the audio ground. It might not cure clicks, but it's a good thing anyway.

Your mute is not how a mute is usually done, just sending the signal into the ether. A mute usually provides a definite 'low signal' to the amp, not a floating pin. Floating pins attract noise !. ( Well not really attract, but that's what it seems like. )

Rewire the mute relay like this :

Code:
                                                          Play
From select relay -->------------------------------------+ \
                                                             \+----------------> To amp via J3
                                         ----------------+
                                         |                Mute
                                         |
                                       |   |  1k resistor
                                       |   |
                                         |
                                         -------------------------------- Audio gnd
When the mute relay is the the 'play' position, audio is routed to the amp.
When the relay is in the 'mute' position, the input to the amp is held low.

It is most imperative that the power rails are rock solid. Everything that could cause a power spike should be suppressed.
Put your scope across the 0v and 5v rails, AC coupled, 2mV per division, to see what that looks like before and after you add caps.

The 7805 regulator needs two 100uF and two 0.1uF as per the circuit shown in post #10. Similar 100uF + 0.1uF combinations should be across the rails at the Picaxe and at every relay. The 100uF capacitors provide a local reservoir of energy to prevent sag, and the 0.1uF suppress spikes and high frequencies. Do not skimp here.

Your scope traces posted here are at 500mS/div, which is too slow to show what the waveform is. That faint signal, 4mV to -10mV, is that 60Hz or some significantly higher frequency ?
 
Last edited:

piclt

Member
You could split your big problem into 2 little problems...?......see attached pic
n9ds..... I don't see where your circuit gives a mute condition to the audio....... Buzby circuit give mut to amp input.
K3 just switches the LEDs.....why do you need relay to switch LED..?
What is select relay..?
The bottom relay in the attached should be labelled K3.....
The attached is just a copy of n9ds circuit I didnt redesign it.
 

Attachments

Last edited:

n9ds

Member
Yes, muting isn't optimal. I'll worry about that later.
I'm using a relay to switch LEDs because it requires fewer pins.

I built an outboard regulator with a different 7805 with capacitors (2 220uF and 2 .05pf because that's what I had on hand...) I connected the output of that across 1 and 14 of the PICAXE, and the problem persists. So I put the scope on the rails (again, across 1 and 14.) Here are the results, 2mV/Div vertical, 100mS/Div horizontal...Blue is the rail, yellow is the audio output. I'm reminded of a friend of mine that worked extensively with NE555s back in the day and discovered one of their quirks was that they would short + to - briefly while switching sometimes causing mayhem downstream. Unfortunately that was 40+ years ago so I don't recall his remedy, but could this be a similar thing?

BTW, the "fuzzy" in the trace isn't audio, whatever it is it's closer to 500kHz.
I'll try putting the PICAXE in the breadboard by itself to see what it looks like there.
25988
 

piclt

Member
Your "fuzzy hum" is closer to 60 Hz ....... according to my count about 30 cycles in 500 ms equals about 60 cycles per second or 60 Hz.......mains hum or a mains inverter running somewhere...?
 

Buzby

Senior Member
220uF is a good value, but not 0.05pF, that's way too small.

Your NE555 story is exactly what is happening in the Picaxe, and the solution would have been the same, decoupling capacitors.
I can tell you stories about projects with not enough decoupling, and this will be yet another.

You said you built a 7805 circuit, then connected that to the Picaxe. How long were the wires to the Picaxe ?.

Decoupling needs to be as close to the chip as possible. You need caps at the 7805, and more caps at the Picaxe.

Values are not critical, within reason.

Between 10uF to 470uF is reasonable. I tend to use 100uF because I've got plenty on hand. This capacitor is there to provide a reservoir of power to stop the sag. You can see the blue trace takes over 100mS to recover, and that is bad. The 100uF is to reduce that.

For the spike suppressor use a ceramic or polyester device, 0.1uF is typical. These types have a much faster response time than an electrolytic, so are good for suppressing fast spikes.

I'm sure with proper decoupling you will get rid of the spikes, then we move on to the 'fuzz'.
( You might not be able hear the 'fuzz', but it will be doing something to the sound. )

Cheers,

Buzby
 

piclt

Member
I dont have a 14M2 but I ran your code in a 18M2. on a breadboard powered by a USB port of PC. I get similar waveforms, put in 100uf and 10 uf across the supply, didnt make much difference......but....
I think the problem you are seeing on scope is from pickup on the scope leads. Even itself I could see the spike and with 100mm jumper lead connected to it, open circuit I got the waveform as attached screen shot. If I hook on the supply pins or supply rails of the breadboard i get general noise but dont see the spikes as larger that anything else. The blue is the scope lead with 100 mm wire on acting like an aerial and the red trace is the voltage across the LED acts as a trigger. The high freq is mains hum etc.
Do you hear the clicks when the audio is playing through the router ...?? .. or only when the audioline is open circuit waiting on be connected. The audio amplifier could be picking up the interferrence vis the open ended audioline the same as the scope is doing. So only result may be to screen the cables well or seaerate boxes..??
 

Attachments

Buzby

Senior Member
I get similar waveforms, put in 100uf and 10 uf across the supply, didnt make much difference......
The only capacitors I can see on your breadboard are too far from the Picaxe to have any effect. Put 100uF and 0.1uF directly across the Picaxe power pins, right up close to the chip.

Your point about using screened cables is very valid. We are trying to eliminate a disturbance which is already lower than the noise being picked up from outside, so we need all the help we can get !.

If the OP tested with a real signal, not just open sockets, then I think the results will look much better. That Digilent box I think has a waveform generator built in, maybe that can be used.

The OP has also stated that muting is a low priority, but it's not. The existing 'mute' condition leaves the amplifier input floating, just like your 100mm floating scope cable does. A properly muted line will not pick up radiated noise, unless it is very powerful.

Cheers,

Buzby
 

piclt

Member
Tried 100uf and 0.1uf straddled over the supply pins on the breadboard....It reduced the pickup slightly but still being picked up by the open audioline.
Then switched on the signal generator on the scope and connected it to the end of the open line and spikes dissapeared and got a good signal trace.. I then unplugged the 100uf and the 0.1uf and still got same good clean signal. I varied the amplitude and freq or the signal generator and no spikes.
Attached is the trace with no capacitors on the breadboard and blue connected to sig gen. I tried both direct connection and also ac coupled via a capacitor. So the audioline should not be left open..??
And "Buzby"I tried your 1k to GND on the end of the line.......That works too, even with no caps....... Then clipped on the sig gen of the scope, the 1k attenuates the signal a bit but works..no spikes.
 

Attachments

Last edited:

n9ds

Member
Finally some progress. Thank you for all your suggestions, I have made a number of changes.
  • Rewired so that the muted output gets sent to a sink instead of into the ether
  • Added a destination for the Aux/Tuner output
  • All four LED anodes are now controlled directly by individual pins and not selected by a relay
  • Cleaned up the schematic
  • Added bypass capacitors
  • Fixed a bug in the code
With all the changes, the clicking is gone. To be honest, I think the real problem was in fact the code all along. When I said the LED wasn't switched on and off by the relay, that was indeed true. But if you look at the code I posted, in the Blink subroutine, after the LED is transitioned, I was also switching the relay. I don't know why, that was clearly an error (that has been fixed.) My one remaining problem is that there's hum during mute. My guess is that 220ohms is too high. The answer to that problem is beyond the scope of this question, so there's no need to comment. I'll do some experimenting and get that nailed down. I've attached the revised schematic just so you can see what I did. Thanks again to everyone.

26005
 

n9ds

Member
... My one remaining problem is that there's hum during mute. My guess is that 220ohms is too high. The answer to that problem is beyond the scope of this question, so there's no need to comment. I'll do some experimenting and get that nailed down. I've attached the revised schematic just so you can see what I did. Thanks again to everyone.
Update: The buzzing wasn't due to the 220Ohms. I replaced it with 0 Ohms and had the same problem. I tracked it down to the power supply. It was one of those switch mode wall warts. Even a more expensive "ultra quiet audiophile" one had the same issue (both work fine with the other guitar pedals.) When I replaced it with an old-school analog brick, it works beautifully.
 

papaof2

Senior Member
"old-school analog brick" - Some of those things just won't die.
I have one powering the 08M and the fan it controls in the A/V cabinet. It's been running since September 2006 - although the original 08M was replaced with an 08M2 just to see it there were any differences in the operation of something that's ON 24/7/365 and the fan has been replaced several times because they get noisy as they age ;-)
The DS18B20 detects the temperature above the hottest device in the cabinet (cable box/DVR) and turns the fan on when that location gets up to 86F/30C and off when it gets down to 82.4F/28C. That point above the cable box/DVR can easily exceed 100F/37.7C. This is in conditioned space so the ambient temperature should never be above 78F/25.5C. The fan blows the air through the cable box/DVR and then it goes up out of the cabinet by convection - there are two 3 inch/7.62cm holes at the top of the cabinet's back.
I was moved to add the fan when the shelf above the cable box/DVR was too warm to leave your hand on it for long. I'll guess that the cooling arrangement has greatly extended the life of the cable box as it's a few months older than the fan installation and I don't think many of them last 17+ years...
 
Top