View previous topic :: View next topic |
Author |
Message |
Johannes
Joined: 05 Dec 2003 Posts: 10 Location: Port Elizabeth, South Africa
|
How do I test PIC external Oscillator with scope? |
Posted: Tue Dec 09, 2003 1:15 am |
|
|
Hi All,
I am trying to test the oscillator of a PIC16F877 with my digital oscilloscope. The pic is configured with a 20MHz x-tal and two 33pf capacitors. As soon as I connect my scope to the oscillator inputs of the PIC, the Oscillator stops running. I gues that the scope is loading the oscillator to much. How should I connect the scope to the PIC to verify the oscillator speed without disturbing the PIC's operation?
Thanking you,
Johannes |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Dec 09, 2003 2:34 am |
|
|
Which oscillator pin are you putting the probe on ?
Try putting it on the OSC2 pin. On a 40-pin DIP, that
would be pin 14. That pin is the output driver of the
oscillator.
If you do this, does it still shut off ? If so, try these things:
1. Are you using a 10x probe or a 1x ? You should use a 10x.
2. Are you certain that you're using HS mode ?
I don't know if a 20 MHz crystal would oscillate at XT mode,
since I've never tried it. But, I know that XT mode has much
less drive than HS mode. It's much easier to load down the
oscillator pins in XT mode, and shut down the oscillator.
If you're using XT mode, change it to HS.
3. Possibly, you should reduce the capacitor size to 22 pf, at
least as a test. I know that if you follow the formula for
calculating the load capacitor size, it will say to use either
27 pf or 33 pf caps. But I typically use 22 pf, perhaps just
out of habit. Anyway, it's worth a try. |
|
|
Johannes
Joined: 05 Dec 2003 Posts: 10 Location: Port Elizabeth, South Africa
|
|
Posted: Tue Dec 09, 2003 5:02 am |
|
|
Thanks for the info, the PIC is not shutting off anymore. I am not sure what caused the circuit to shut off before.
However I still don't get the right frequency.
I have the scope on 10x and measure from OSC2 and the scope GND on the the PIC Vss.
The PIC is configured to run in HS mode.
According to the scope the period for one oscillator cycle is 240 us that is 4.1667 kHz.
Could this be that I don't connect the scope right to the PIC. Surely the period for one cycle should be 50ns (20MHz). |
|
|
Ttelmah Guest
|
|
Posted: Tue Dec 09, 2003 6:17 am |
|
|
Johannes wrote: | Thanks for the info, the PIC is not shutting off anymore. I am not sure what caused the circuit to shut off before.
However I still don't get the right frequency.
I have the scope on 10x and measure from OSC2 and the scope GND on the the PIC Vss.
The PIC is configured to run in HS mode.
According to the scope the period for one oscillator cycle is 240 us that is 4.1667 kHz.
Could this be that I don't connect the scope right to the PIC. Surely the period for one cycle should be 50ns (20MHz). |
The amount you are 'off', is massive. I have seen the oscillator run at a sub frequency (but normally only perhaps 2.5MHz), where the crystal is overdriven, and slightly overdamped. A series resistor to the crystal, may prevent this. However your amount is so far out, as to be silly. Are you dead sure the capacitors are 33pF?. You might expect something like this, if a 33nF was fitted instead!. 33pF, is a slightly large value for most 20MHz crystals. You should check the specification of the crystal you have fitted. Generally, the larger types, may require 30pF, but some of the small HC49U types only require 12pF. Remember also, this is the total 'load' capacitance, so your capacitor is paralleled with the pin capacitance, and that of any local tracks. This is why 27pF, is a common value to use for crystals requiring 30pF load.
The crystal is seen as a simple 'filter' network, with the highest 'pass', at it's fundamental frequency. Normally the crystals used, are 'overtone' crystals, so unless the rest of the circuit is right, there can be a tendency to oscillate on the fundamental, rather than at the required overtone. Your frequency though is so low, that you have to think in terms of something massively reducing the gain at higher frequencies. Hence the comment about the capacitors. Given the low gain that may be occuring, the oscillator may not be reliable (which could explain the tendency to stop when the scope probe is added).
For 'test' purposes, try programming one of the CTC outputs to run at a known divider, and output this for a frequency test (avoids the need to load the oscillator).
A low oscillation frequency like this, might also be seen if the crystal had been damaged by soldering, and is behaving just as a high value resistor. Combined with the input capacitor, this could give frequencies like this.
Best Wishes |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Dec 09, 2003 7:06 am |
|
|
Quote: |
I don't know if a 20 MHz crystal would oscillate at XT mode,
since I've never tried it.
|
I've done that before with resonators. A 20MHz won't work with the XT nor will a 4MHz work with HS. In one of the cases, a touch of the circuit seemed to get it going. |
|
|
Johannes
Joined: 05 Dec 2003 Posts: 10 Location: Port Elizabeth, South Africa
|
|
Posted: Tue Dec 09, 2003 7:24 am |
|
|
Ok, I took out my PICdem 2 Plus Demo Board and tested the same thing. The only difference is that now I use a 4MHz x-tal module. I measure with the scope between OSC2 & GND, eureka. The cycle time is exactly 250ns ( 1/250ns = 4MHz).
The other board runs perfect. I don't have any problems with it. I just wanted to test the oscillator speed as a matter of interest. It obviously is loaded too much when I try to connect the scope giving me false readings. I must still try to use 27pf caps. |
|
|
chas Guest
|
Possible aliasing |
Posted: Tue Dec 09, 2003 9:20 am |
|
|
Which digital scope are you using? What is the sampling rate of the scope? Is there a chance that you are experiencing some sort of under sampling aliasing? Your scope must sample at least 2x the frequency of interest, and preferrably higher. Some scopes with lower sampling rates play tricks by shifting the sampling clock on repetative waveforms to sort of build up the waveform. |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Tue Dec 09, 2003 10:19 am |
|
|
Johannes,
I guess that if you are checking your xtal frequency is because something wrong. Did you check your #fuse configuration to be sure NOLVP is present ? Some time ago I spent half a day to realize that !
Code: |
#fuses HS,NOWDT,PUT,BROWNOUT,NOPROTECT,NOLVP,NOCPD,NOWRT
|
Regards,
Humberto |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
Re: Possible aliasing |
Posted: Tue Dec 09, 2003 1:27 pm |
|
|
chas wrote: | Which digital scope are you using? What is the sampling rate of the scope? Is there a chance that you are experiencing some sort of under sampling aliasing? Your scope must sample at least 2x the frequency of interest, and preferrably higher. Some scopes with lower sampling rates play tricks by shifting the sampling clock on repetative waveforms to sort of build up the waveform. |
If you have a slow scope you could write a little program to generate a low frequency square wave using the PIC's hardware counters, and measure the resulting square wave to be sure the xtal is running OK. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
Johannes
Joined: 05 Dec 2003 Posts: 10 Location: Port Elizabeth, South Africa
|
|
Posted: Wed Dec 10, 2003 11:26 pm |
|
|
Thanks all for the info, the problem seems to be my scope. I took my board to a friend of mine and we tested it on a 100MHz scope. All measured as expected. Now I will have to budget for a new scope. Any ideas which scopes are fairly well priced for embedded work? |
|
|
martin gordon
Joined: 15 Sep 2003 Posts: 6 Location: Edinburgh
|
Scope |
Posted: Thu Dec 11, 2003 3:47 am |
|
|
Can recommend an Agilent 54622D, 100MHz analogue 2 channels plus 16 channels digital. It has very long memory 2,000,000 samples so can capture odd pulse sequences.
Problem not low cost
Becarefull look at single shot bandwidth, many units quote large bandwidth or repititive triggers and are useless on infrequent events
Martin |
|
|
Guest
|
|
Posted: Thu Dec 11, 2003 4:11 am |
|
|
I would reccomend an 100 Mhz Agilent digital scope too.
For embedded work it would be a good idea to choose one of the Agilent Scopes with built in Logic Analyzer. This way you both have two analog inputs and 16 digital inputs. |
|
|
Guest
|
|
Posted: Thu Dec 11, 2003 4:15 am |
|
|
|
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Dec 11, 2003 7:30 am |
|
|
I also agree! I have the 54645D. The "MegaZoom" feature comes in real handy when looking at signals over a long time period. Great for debugging communications! |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Thu Dec 11, 2003 9:42 am |
|
|
If you are hobbiest without the budget for a new scope check out used gear on EBAY. I picked up an HP 1631A logic analyzer which has 2 analog channels and many digital channels real cheap. That and my old analog scope cover all my uP needs. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
|