Electronic – Problems with using 20Mhz crystal withPIC18f2420

crystalfrequencypicpwm

I am using PIC18f2420 to generate PWM. I am using Timer 2 with 4MHZ crystal, which works perfectly by giving me PWM. I need to get 100KHZ of frequency for PWM, for which, 4MHZ crystal is not enough as it will reduce my resolution to an unacceptable level. I changed the 4MHZ crystal to 20MHZ without changing any of the configuration bits, hardware or program, as I do not know what do I have to change. Can you please give me advice what should I change? My crystal is connected to two 27pF capacitors, will they work fine for 20MHZ crystal too?

Current configiration bits:

#pragma config OSC = HS //HS oscillator 
#pragma config PWRT = ON, BOREN = OFF //power-up timer on, brown-out detect off 
#pragma config WDT = OFF //watchdog timer off 
#pragma config LVP = OFF //low voltage programming off 
#pragma config PBADEN = OFF //Configuration setting
  • Port B all digital I/O

Best Answer

Firstly, your crystal will work fine with 27pf capacitors if its is designed to work with 27pf capacitors. Please provide a link to the datasheet for the crystal so we can see what it requires (27pf sounds a little high to me).

Secondly, by your description, it sounds like the crystal may not be oscillating. Your configuration bits look fine for a 20MHz crystal.

Using your oscilloscope, set the probe to 10x impedance. Then probe the OSCI pin of the PIC18 to see if you get a 20MHz waveform. If you do, then obviously it's oscillating. If not, then it is unable to start the oscillations. This could be down to your load capacitors being too big (as I said, 27pf sounds a bit high, but we can't tell without knowing what crystal you're using).

The "random sinewave signal" is probably the pin being high impedance due to the chip not starting up, so you're picking up local noise from the mains.