CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How to set an external oscillator

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
aroonkriss



Joined: 03 Dec 2012
Posts: 19
Location: kerala

View user's profile Send private message

How to set an external oscillator
PostPosted: Mon Oct 21, 2013 11:37 pm     Reply with quote

Hi,

I am using dspic30f3013 with ccs compiler. I need to set an ext. oscillator. I have connected a 20MHz crystal as required in the application.
I have used the following command for oscillator settings.
Code:

#FUSES EC_IO 
#use delay(clock=20M, crystal)

I have tried with other options like HS and EC other than EC_IO, but when I check the crystal output, there is no oscillation. Is there anything, I need to do, please respond. Any help would be appreciated.

Thank you
Aroon
_________________
I dream world peace
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Tue Oct 22, 2013 1:18 am     Reply with quote

You need to distinguish an external 'oscillator' from an external crystal....

A crystal is a piezoelectric device that exhibits resonance. Just like a bell, it 'rings'. However it is _not_ an oscillator. To make it 'oscillate', you have to take the output signal, and feed it back to the input (inverted), so that instead of the ringing dying away, it is continuously amplified and driven.

Now on PIC's there are a lot of different clock 'modes':

EC -= This requires an external _oscillator_. Something else generating the frequency required....

XT, HS. These are designed for use with a crystal (or any other resonant circuit, like a ceramic resonator). They enable a gate in the chip to generate the feedback required to keep a crystal oscillating. HS turns up the high frequency gain of the gate, allowing higher frequencies to be used. There is also sometimes 'LP' which turns the gain (and power) down even lower for very low frequency operation.

RC. This too generates oscillation, using a simple resistor/capacitor charge/discharge circuit. Very rarely used.

INTRC. Uses an internal oscillator in the chip (not all have this). Accuracy varies with the chip, with some types being quite good, while others are appalling....

There are also options on many chips to use different oscillators (primary/secondary etc..).

Now, looking at this, you will immediately see that 'EC' (and it's 'IO' cousin), will not work with a crystal, unless you add the external circuitry to make the crystal oscillate.
Then your 'CLOCK' setup disagrees with your fuse setup. One saying to use a crystal, the other to use an external oscillator.

So for a 20MHz crystal connected between OSC1, and OSC2, you need:

Code:

#FUSES HS,
#use delay(CLOCK=20M, CRYSTAL=20M)


Some comments then:

Why use a 20MHz crystal?. You can run the chip much faster using a slower crystal (under 10MHz), and the PLL. Up to 120MHz. With the 20MHz crystal, you are above the maximum frequency supported by the PLL, so are stuck at 20MHz....

Remember that the crystal needs suitable loading capacitors to give good accuracy. These are _not_ the 'loading capacitance' quoted for the crystal. The crystal sees the two lcapacitors, each 'paralleled' with the pin and track capacitances, _in series_ as it's 'load'. So a crystal requiring 20pF 'loading', with tracks and pins giving perhaps 7pF on each line, would need capacitors of (20*2)-7 = 33pF. Make sure your capacitors are right.

Then also remember that many crystals will be overdriven if connected directly to the PIC, and instead of 'ringing' will instead give the equivalent to a discordant clatter!. You may need a small series resistor to avoid this. Data sheet for the crystal....

Then the oscillator can sometimes fail to start. This depends on the gain of the particular crystal, and particularly on the rise time of the power supply. A large value resistor (1MR) across the crystal circuit (between OSC1 and OSC2), may be needed to ensure reliable starting.

Remember MCLR must be high (or turned off in the fuses) or the chip won't start.

I'd suspect you may have several problems.
Obviously your fuses being wrong to begin with but possibly a wiring or component error, which is why it doesn't start on HS. Something like accidentally picking 33nF capacitors instead of 33pF.

Start by proving the supply and MCLR connections are correct, and seeing if the chip will start with:
Code:

#FUSES FRC
#use delay (CLOCK=7.37M, INTERNAL)


Once you have verified that everything is working, then triple check the components round your crystal, and switch to trying this.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group