I have an STX-3790-5N 3.5mm stereo switching headphone jack in my circuit. http://www.kycon.com/Pub_Eng_Draw/STX-3790-5N.pdf
The intention is for the audio signal to flow from the ATmega328 pin 9 to the LM386 opamp and out to the speaker while the switch is closed. When a headphone cable is plugged into the jack, the switch should open, cutting off the audio signal from the LM386, while the audio signal continues out to the headphones.
This works fine in the open position. The audio plays through the speaker with no issues. Now...when I plug in a set of headphones to the STX3790 audio jack, the chip seems to reset or brown out or short out, the audio stops playing through the speaker and in the headphones I hear either a loud buzzing, nothing, or a very high pitched tone. When I remove the cable from the jack, the circuit remains in this stalled out state until I cycle the power. If I turn the power off, insert the headphone cable, then switch the power on, the result is the same.
Very strangely, if I plug in a plain stereo 3.5mm male-male cable that is not connected to headphones or anything else, the issue described above does not happen. The audio is still audible from the speaker, though just barely, very faint and quiet.
I've attached a snippet of my schematic here. The "audioout" signal here is coming directly from digital pin 9 on the ATmega328. Also the audio source is mono, I'm only using a stereo jack because this style of part seems more common and easier to source.
Thank you in advance!!
I can confirm that without the cable plugged in, pins 1-4 all have continuity with each other, which is what I want (given that this is mono audio), and all read an appropriate voltage. None have continuity with pin 5, which is ground/sleeve. When I plug in a phono cable, pins 1 and 4 still have continuity, which is good. Pins 2 and 3 have no continuity with any other pins, which is also good. This should cut off the signal to the opamp & speaker. HOWEVER, in this state, pins 1 and 4 now have continuity with pin 5 (gnd), which is not expected.
There are three of the same model headphone jacks on this board, the other two connect directly to 328 pins 2 and 10 respectively. I can confirm that one of them has the same shorting problem and the other does not. In the one that does not have this problem, the software pinmode is set to OUTPUT, whereas the other two are set to INPUT.
I can also confirm that if I switch the pinmode of the atmega328 pin connected to the other problematic headphone jack to INPUT instead of OUTPUT, it no longer shorts the board. But this breaks my functionality, so it's not a solution, just a clue.
ALSO if I leave the pinmode set to OUTPUT on that same pin WHILE the board is connected to my AVR programmer (which is connected to my desktop PC via USB) that secondary problem headphone jack DOES NOT cause the board to short when a headphone cable is plugged into it. Another clue. This has me thinking about grounding issues, but I'm not sure. Normally, the board is powered by 4 AA batteries, so not grounded on the Earth.