AVR 16MHz external Crystal prone to Electrical noise

Go To Last Post
20 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am using AVR ATMEGA-16A. while testing the code, if I use internal 8MHz oscillator it works fine. but when I use 16MHz external oscillator then any electrical noise like rapidly switch ON and OFF other appliances(FAN, Tubelight) on same switchboard where the AVR power supply connected then AVR hangs or works undesirable like LCD character shifts or hangs.

I tested various times to find the problem and this problem only occurs when I use 16MHz external oscillator. 

 

note: I have to use external 16MHz oscillator for the accuracy. I am using Timer Interrupt for accurate 1 sec overflow. External Osc. is connected as given in the datasheet using 22pf cap to both pins and grounded also very close to XTAL pins. 

 

Please help me out.

Thanks for everyone for attention.

This topic has a solution.
Last Edited: Fri. Jan 3, 2020 - 08:32 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Does your PCB have a gnd plane or are you using traces for your gnd?

Show your PCB layout (photo or cad drawing) please.

 

Jim

 

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for replying Jim

Here I am attaching PCB layout CAD file with some details.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2


As I suspected, no ground plane, long thin gnd trace, no vcc bypass caps near VCC/GND pins, and AC input located next to xtal!!!

 

 

Use a double sided pcb, make the bottom the gnd plane, add 100nf cap to VCC/GND pin pair as close a possible to the pins.

Move AC input away from the xtal, see if that helps.

Jim

 

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1


 

Note that's just a crystal - not an oscillator: See Tip #4 (in my signature, below; may not be visible on mobile)

 

If all else fails, using an oscillator - rather than just  a crystal - should help ...

 

Also see Tip #1 for how to get the image visible in the post like this.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Mega16A?  Does that have a "full swing option?  What clock fuses are you using?

 

Still, your symptoms indicate a situation where it may be very difficult to get robust operation.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for suggestion.

I have a AVR Development board where I have tested this same Circuit after this noise issue. On development board AC input is far from crystal (I have attached a photo of the Board). but the same issue occurs on development board also. It has thick ground traces on it.

I am attaching Development board photo and also 12vac to 5vdc power supply circuit.

I am not getting about where to add 100nF Cap?

Nishad

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1


Nishadkharade wrote:
I am not getting about where to add 100nF Cap?

Here:

I think you have the two on the right side now, but need one on the left side as well.

Jim

 

 

 

 

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 3

Sorry, but it seems you missed answering 'theusch' about the fuse setting concerning rail-to-rail mode.

This is from datasheet:

 

When CKOPT is programmed, the Oscillator output will oscillate a full rail-to-rail swing on the output. This mode is suitable when operating in a very noisy environment...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Try to connect the house of the crystal to GND.

 

Your GND plane is way to weak! 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

sparrow2 wrote:
 connect the house of the crystal to GND

Previously, on AVRFreaks:  https://www.avrfreaks.net/forum/why-ground-crystal-case

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

 works undesirable like LCD character shifts or hangs.

I tested various times to find the problem and this problem only occurs when I use 16MHz external oscillator. 

Be careful...have you considered any software timing issues (8 MHz vs 16 MHz), especially with slow LCD's ?    You could try an 8 MHz crystal (rather than 16)...do you still see the failure?  If so, then it def has to do with going to external crystal.  If 8 MHz internal vs external makes no difference, look elsewhere.  Note even then it is not 100% proof since an 8 MHz vs 16MHz external might react very slightly differently to noise & layout (& the slight diff could be THE issue).

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Nishadkharade wrote:

... but when I use 16MHz external oscillator then any electrical noise like rapidly switch ON and OFF other appliances(FAN, Tubelight) on same switchboard where the AVR power supply connected then AVR hangs or works undesirable like LCD character shifts or hangs.

Nishadkharade wrote:

I have a AVR Development board where I have tested this same Circuit after this noise issue. On development board AC input is far from crystal (I have attached a photo of the Board). but the same issue occurs on development board also.

Items like FAN, Tubelight will generate high dV/dT noise and that can couple almost anywhere, as it is more like RF than 50/60Hz mains.  Getting 100% immunity can be difficult. (power Drills with brush motors are also nasty)

 

Narrow spikes field coupled into XTAL pins, (and other pins) can propagate runt clock pulses that can disturb MCU operation.

Ground planes can help, as can very short leads / compact loops.

 

You could wire in an Oscillator module (as suggested above) to both your test PCB's, and check again, to see if that is enough of a fix. (after you have added the Vcc/Gnd caps as above, SMD ones are easy to add, and SMD xtal caps can place underneath the board, for shortest leads. )

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

 

prob need to see the schematic...may help diagnose.

Also you have a nice opto but then seem to violate it---why?  There is plenty of room, so why crowd opposing wires together?

 

 

If that red line indicates copper, things are even worse!

 

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Thu. Jan 2, 2020 - 10:59 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Creepage clearance on that pcb is minimal. The optos on the relays are a waste of time - apart from the tracks running underneath them, the supply is common. As well, clearance around the relay contacts is minimal. Hopefully they don’t switch mains. If they do switch mains, choose a relay that makes the layout easier - omron g2r or similar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello everyone,

 

I have gone through all suggestions you all gave me. I decided to make changes as per the posts. I was thinking which posts I took first. so I decided to take the post which was easy to make change in my test board then one by one go for critical changes like in pcb layout change or adding caps etc.

 

So I took the post of "fuse setting concerning rail-to-rail mode" which is easy to change fuse bits. I tested it, and the noise problem is gone !!! on very first try I got the solution. I found that it is a CKOPT bit. I prgrammed the CKOPT bit  so that the Oscillator output will oscillate a full rail-to-rail swing with stable crytal working.

 

After this solution I tested it by switching ON and OFF the switches vigorously to test for 100% robust working. There is very minute issue that is only LCD character shifts one or two places on vigorous switching. no MCU hang or any other issue that I had earlier. Now I will test it for timer overflow accuracy in noisy environment.Now I am going to make changes like connecting decoupling caps, connecting the house of the crystal to GND, shifting ac input, making strong ground plane for 100% robust working.

 

This is my really first thread on any forum and I got so much help and response.

 

Thank you everyone. Wish you all a very HAPPY NEW YEAR 2020 !!!laughsmiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

 

If that red line indicates copper, things are even worse!

 

It is not copper, I have just bordered the HV area :)

Last Edited: Fri. Jan 3, 2020 - 08:25 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
The optos on the relays are a waste of time

 

Actually there is electrically very noisy working environment and also high AC voltages on PCB board and on relay contacts. So for MCU safety/noise from Output side ,I have connected OPTOs instead of transistors. what do you think about this?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My point exactly - what are the optos on the relay doing? Nothing - you have a common power rail to the relays, so the optos cannot do what they are supposed to do. As well, you violate the required clearances, so your circuit is not electrically safe. Any sniff of a transient will get coupled into your circuit.

 

What optos are you using that can switch the relay current? Transistors would've been much easier and ensuring you have adequate clearance on your pcb along with slots to increase the creepage distance would go a long way to helping.

 

The circuit in the top left of the pcb just seems to be detecting mains - surely you could just use an opto, diode and a couple of resistors? I don't think you need a reactive dropper power supply.

 

 

Last Edited: Fri. Jan 3, 2020 - 10:07 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Post your schematic before you make your next move.  Then you can be assured all issues are taken care of & your board will hum along first try!

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!