Noise from crystal oscillator (LM386 audio amp)

Thread Starter

wafflemayp

Joined Aug 26, 2015
5
Hello all,

The project is a LM386 audio amp interfaced with a PIC16F877A microchip and LCD display. To shorten details:

*LM386 schematic is from datasheet
*Microcontroller LCD display is connected as per 'Example 4.12' on the mikroe website book (PIC Microcontrollers - Programming in C)
*Using adc to read the LM386 output (after biasing) via one wire

*The suggested 20pF~30pF are not connected with the crystal (4MHz)

Test wise the amplifier itself is working fine independently, same for the microcontroller & LCD setup.

When hooked up together, the issue is that the crystal is causing a buzzing noise to the amplifier speaker. I removed it quickly and the buzzing went away, put the crystal back in the the problem is back. I've checked the CLK pinouts and grounding and find no issue there.

Could it be the amplifier is sensitive to the crystal? I would love to hear any thoughts on how to rectify this. I've seen VU meter projects running well on youtube, so i'm at a loss.


Thanks all
 

GopherT

Joined Nov 23, 2012
8,009
Hello all,

The project is a LM386 audio amp interfaced with a PIC16F877A microchip and LCD display. To shorten details:

*LM386 schematic is from datasheet
*Microcontroller LCD display is connected as per 'Example 4.12' on the mikroe website book (PIC Microcontrollers - Programming in C)
*Using adc to read the LM386 output (after biasing) via one wire

*The suggested 20pF~30pF are not connected with the crystal (4MHz)

Test wise the amplifier itself is working fine independently, same for the microcontroller & LCD setup.

When hooked up together, the issue is that the crystal is causing a buzzing noise to the amplifier speaker. I removed it quickly and the buzzing went away, put the crystal back in the the problem is back. I've checked the CLK pinouts and grounding and find no issue there.

Could it be the amplifier is sensitive to the crystal? I would love to hear any thoughts on how to rectify this. I've seen VU meter projects running well on youtube, so i'm at a loss.


Thanks all
If you are going to ask a question about a circuit, please post the schematic. It takes much less brain power and clarifies all parts of the conversation. Also, please explain the need for a 4MHz crystal oscillator if there is an on-board 4MHz oscillator on the microcontroller? (accuracy - what are you measuring?, fun - what fun are you enjoying? add complexity - why can't your life be simple?). Also explain why you do not want to connect the crystal as suggested in the microchip datasheet (using the 20-30pF capacitors).
 

takao21203

Joined Apr 28, 2012
3,702
You just need a coil at the right place it will filter out the harmonics.

Sure controllers make noise depending on the frequency, and depending on the overall buffering.

Separating the rails helps but isnt always neccessary.
You can also try to keep the impedance low on the input side.

Coils are powerful components. The higher the frequency, the more a coil will act as a resistor.
They can store energy, andd act as filters too, and most are low cost.
Good idea to have common kinds available.

Ive solved a serious issue with PIC32 just with a plain 22uH small RF choke.
 

alfacliff

Joined Dec 13, 2013
2,458
harmonics of a 4 mhz crystal wont be heard in a speaker. 8,12,16 mhz and such. the lm386 will not amplify 4 mhz aolso. you are hearing digital noise which stops when the microprosser stops as the 4 mhz clock stops.
 

ronv

Joined Nov 12, 2008
3,770
Chances are the problem is actually with the 386.
Make sure the leads to the input are short and/or shielded and that you have good decoupling on all circuits.
 

Thread Starter

wafflemayp

Joined Aug 26, 2015
5
Apologies for skipping the schematic. The supply is stepped down via a power pack and/or 9V battery (with 100uF coupling and 10uF decoupling).
The PIC16F877A does not have an internal oscillator, hence the external crystal.

The reason why the 20uF~30uF are left out from the 4MHz crystal connection is because they weren't required for learning exercises that didn't involve the addition of the audio amp.

Thanks to all for the patience and early suggestions, hopefully this might provide a clearer idea of what is going on.

*Note: There is a 0.001uF capacitor between pin 3 of R7 and the LM386 input

LM386_proj.jpg
 

Thread Starter

wafflemayp

Joined Aug 26, 2015
5
You just need a coil at the right place it will filter out the harmonics.

Sure controllers make noise depending on the frequency, and depending on the overall buffering.

Separating the rails helps but isnt always neccessary.
You can also try to keep the impedance low on the input side.

Coils are powerful components. The higher the frequency, the more a coil will act as a resistor.
They can store energy, andd act as filters too, and most are low cost.
Good idea to have common kinds available.

Ive solved a serious issue with PIC32 just with a plain 22uH small RF choke.
I'll research that option, the buzzing only occurs once the PIC is hooked up.. (whereas no buzzing is heard even if the analogue in wire is detached and there is no audio input)


harmonics of a 4 mhz crystal wont be heard in a speaker. 8,12,16 mhz and such. the lm386 will not amplify 4 mhz aolso. you are hearing digital noise which stops when the microprosser stops as the 4 mhz clock stops.
Looks like i need to see about digital noise..


Chances are the problem is actually with the 386.
Make sure the leads to the input are short and/or shielded and that you have good decoupling on all circuits.
I have 100uF, 10uF and tried 0.1uF, 1uF and 0.01uF on the power rails (apart from the filtered regulator). The buzzing sounds different from a power hum (i've filtered that out prior to adding the microcontroller) it now sounds like an electric shaver with the PIC connected (sigh).
 

GopherT

Joined Nov 23, 2012
8,009
The pic sending signals to the LCD is likely happening at audio frequencies. Try disabling the LCD update functionality on the PIC but still have the power turned on to the pic (just run a NOP loop without turning on/off any output ports. See if you still have a buzz).

Try updating the LCD at half the rate if the current program to see if the buzz tone drops an octive.
 

recklessrog

Joined May 23, 2013
985
Chances are the problem is actually with the 386.
Make sure the leads to the input are short and/or shielded and that you have good decoupling on all circuits.

Ive been using 386's recently, and they can be VERY unstable unless the layout is carefully designed. Do decouple the supply adequately, keep wiring short, if unused, decouple pins 1 & 8 (gain control pins) with 1n capacitors, OR connect a 1-10mfd capacitor in series with a resistor from pin 1 to pin 4 (-ve) to control the gain, try with 100k preset and adjust until you have the required gain then replace with a fixed resistor.
Also be aware that some bench light use hf inverters to drive flourescent tubes and the 386 will pick any radiation up from its wiring and cause you nightmares! Especially the magnifier lamps sold by many component suppliers. I would advise when testing ANY new circuit, turn off anything that can cause interference, especially fluro lamps.
 

Thread Starter

wafflemayp

Joined Aug 26, 2015
5
The pic sending signals to the LCD is likely happening at audio frequencies. Try disabling the LCD update functionality on the PIC but still have the power turned on to the pic (just run a NOP loop without turning on/off any output ports. See if you still have a buzz).

Try updating the LCD at half the rate if the current program to see if the buzz tone drops an octive.

Ive been using 386's recently, and they can be VERY unstable unless the layout is carefully designed. Do decouple the supply adequately, keep wiring short, if unused, decouple pins 1 & 8 (gain control pins) with 1n capacitors, OR connect a 1-10mfd capacitor in series with a resistor from pin 1 to pin 4 (-ve) to control the gain, try with 100k preset and adjust until you have the required gain then replace with a fixed resistor.
Also be aware that some bench light use hf inverters to drive flourescent tubes and the 386 will pick any radiation up from its wiring and cause you nightmares! Especially the magnifier lamps sold by many component suppliers. I would advise when testing ANY new circuit, turn off anything that can cause interference, especially fluro lamps.

After playing around with trying to reduce/neutralise that noise with recklessrog's suggestion and then considering GopherT's suggestion about the LCD update functionality, it boiled down to layout on the breadboard.

I considered the possibility of the LCD's proximity to the LM386 chip (neighbouring in fact). I did some board reno and made some distance. The LM386 remains on a separate board, whereas the microcontroller and LCD are on another. Turns out the LM386 was picking up the buzz from the LCD (issue is gone, for now..)

Some additional playing around also lead to some discoveries (prior to the board reno):
  • Disconnecting power to the LCD (buzzing still there)
  • Removing the LCD altogether (buzzing still there)
  • Disconnecting GND to the LCD (buzzing stopped)
So at this point, either the LM386 was picking up frequencies from the microcontroller-to-LCD or something to do with the distance to GND. For now i've solved the buzzing, until i reach PCB stage for the final hurdle. At this stage programming my code to successfully read the audio out amplitudes for analogue-to-digital reading...

In the meantime thank you all for the above replies and thoughts, i will provide closure to this project when it's done (hopefully).
 
Top