External crystal not working but internal clock worked normaly in PIC18F45K22

crystalmicrocontrolleroscillatorpic

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!?

Best Answer

Have you consulted the data sheet? Usually when it does not do anything it is a config problem.

I have absolutely no knowledge on this but from PIC18(L)F2X/4XK22 Data Sheet.

Note 1: Quartz crystal characteristics vary according to type, package and manufacturer. The user should consult the manufacturer data sheets for specifications and recommended application.

2: Always verify oscillator performance over the VDD and temperature range that is expected for the application.

3: For oscillator design assistance, refer to the following Microchip Application Notes:

• AN826, “Crystal Oscillator Basics and Crystal Selection for rfPIC® and PIC® Devices” (DS00826)

• AN849, “Basic PIC® Oscillator Design” (DS00849)

• AN943, “Practical PIC® Oscillator Analysis and Design” (DS00943)

• AN949, “Making Your Oscillator Work (DS00949)

Looks like oscillator problems are common. So I'd start there. I know you have a prototype working, but if the right bit is not set no magic happens.

And:

FIGURE 2-6: QUARTZ CRYSTAL OPERATION (LP, XT OR HS MODE)

Note 1: A series resistor (RS) may be required for quartz crystals with low drive level.

2: The value of RF varies with the Oscillator mode selected (typically between 2MΩ to 10MΩ.

Or:

FIGURE 2-7: CERAMIC RESONATOR OPERATION (XT OR HS MODE)

Note 1: A series resistor (RS) may be required for ceramic resonators with low drive level.

2: The value of RF varies with the Oscillator mode selected (typically between 2 MΩ to 10 MΩ).

3: An additional parallel feedback resistor (RP) may be required for proper ceramic resonator operation.

Also from Making Your Oscillator Work

Question: I am trying to use a 4 MHz resonator with VDD at 3V. The data sheet allows this, but the oscillator does not work. What am I doing wrong?

Answer: You may be using the XT mode oscillator. When VDD is raised, the oscillator may start working. Select the HS mode oscillator instead. This will allow the oscillator to work at a lower voltage, but will also draw additional current. Alternatively, change the resonator to a crystal, use XT mode as before and check the loading capacitor selection. When making such a change, retest the oscillator circuit to ensure that it will perform as expected.

Not sure if this applies, but it did make me smile.

I'd also check my programming software to see if it actually is setting the config word the way you want, because I've run into system defaults on PIC's which were not what I selected. Oscillator selected but running very slowly because RC timing was the systems default. (OK I have some knowledge, just enough to make me dangerous - Good luck SSR).

Related Topic