I have designed a PCB based on the PIC18F45K22 microcontroller. I want to use an external crystal (4Mhz crystal with two 22pF capacitors). I can successfully program the code but the PIC won't run. When changing the oscillator mode in the config settings to use the internal clock, it works fine.
The code that I'm trying to test is a simple blink LED code.
note that when the microcontroller didn't run, i couldn't enter to debug mode.
I have tried various values of caps but that didn't help. I noticed that bad soldering actually added some stray capacitance between the OSC1/OSC2 pins and the ground (measured using an RLC meter) so I tried lowering the value of the capacitors to 15pF.
I have tried various crystal (replaced the 4MHz, then tried a 16MHz crystal) but that didn't help. I also replaced the microcontroller but nothing changed.
I have tried to make the exact same connection on a bread board and it worked normally using external crystal mode. I only poppulated MCLR, VSS, VDD, PGD, PGC and an LED with a series resistance.
I have redesigned the layout of the board, thinking its a layout problem with the crystal but that didn't help.
I have searched about similar problem but i can't find any helpful answer
part number of crystal: ATS040B-E datasheet of crystal: http://www.mouser.com/ds/2/96/008-0309-0-32667.pdf
I just managed to make this board work... The ground plane that connects the capacitors of the crystal is connected to GND at one point as recommended by many application note... but there is a capacitor 100nF between this plane and +5V for decoupling... this was a mistake by the layout designer. I removed this capacitor and it worked. There is another one between GND and +5V near the PIC's pins as it should be.
still I can't understand why did this solve the problem...
I did test earlier to check if there is any AC voltage between this plane and GND of the PIC... and the AC voltage between this plane and +5V of at the micocontroller. It was about 5mV so I guessed it was OK...
Now the question is how the hell did this 100nF cap messed up the oscillator circuit to prevent it from oscillating!?