View previous topic :: View next topic |
Author |
Message |
winson
Joined: 03 Dec 2008 Posts: 24
|
External Oscillator with PIC MCU |
Posted: Tue Dec 23, 2008 5:50 am |
|
|
Hi,
I am using PIC microcontroller. If I wish to use an external crystal oscillator for my project, then is it necessary to include some lines of code in my program to tell that I'm using an external oscillator now? If it is needed, then how to write this in CCS C language?
Thanks a lot. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Dec 23, 2008 6:36 am |
|
|
For the different oscillator configurations you have to specify a Configuration bit. CCS calls these settings 'fuses'
Code: | External crystal 0 - 200kHz: LP
External crystal 200kHz - 4MHz: XT
External crystal 4MHz - 25MHz: HS
External Oscillator: EC (or use 'EC_IO' to free the OSC2 output for normal I/O) |
Depending on the processor model you are using there will be more options available, see the top of the header file for your chip. Also read the chapter 'Oscillator Configurations' in your chip's data sheet.
Example: Code: | #include <18F458.H>
#fuses HS,NOWDT,NOLVP
#use delay(clock=16M) |
|
|
|
winson
Joined: 03 Dec 2008 Posts: 24
|
|
Posted: Thu Dec 25, 2008 10:37 pm |
|
|
Quote: |
#include <18F458.H>
#fuses HS,NOWDT,NOLVP
#use delay(clock=16M)
|
Thanks ckielstra.
Can i know what is NOLVP? |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Fri Dec 26, 2008 8:05 am |
|
|
NOLVP = No Low Voltage Programming
NOWDT = No Watch Dog Timer
LVP allows the PIC to generate its own high voltage for programming instead of taking it from the MCLR pin. This can cause accidental programming under certain circumstances, which trashes your programmed code. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
winson
Joined: 03 Dec 2008 Posts: 24
|
|
Posted: Sun Dec 28, 2008 1:38 pm |
|
|
Thanks SherpaDoug.
So every time just put
#fuses HS,NOWDT,NOLVP
Then can throw all the headache away. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Sun Dec 28, 2008 2:39 pm |
|
|
Well it depends on what you are doing. If your clock is a crystal slower than 4 MHz you don't want HS (see ckielstra's post), and if your product is running in the real world you may want the Watch Dog enabled.... All those choices are useful for somebody. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
|