View previous topic :: View next topic |
Author |
Message |
martinj Guest
|
How to setup internal OSC in PIC16F616? |
Posted: Sun Jun 29, 2008 11:10 am |
|
|
Could anyone tell how to setup PIC16F616 to use internal oscillator 8Mhz and have 2MHz output at OSC2?
Many thanks! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jun 29, 2008 11:53 am |
|
|
The program shown below should work. The OSCTUNE register has to
be set to 0, to work around a bug in the start-up code in vs. 4.075.
The OSCTUNE register is being set as if it was the OSCCON register,
except that there is no OSCCON register in this PIC.
The following program will blink an LED on pin C5.
Code: |
#include <16F616.H>
#fuses INTRC, NOWDT, NOPROTECT, BROWNOUT, PUT
#use delay (clock=8000000)
#byte OSCTUNE = 0x90
//=================================
void main()
{
OSCTUNE = 0;
while(1)
{
output_high(PIN_C5);
delay_ms(500);
output_low(PIN_C5);
delay_ms(500);
}
} |
|
|
|
martinj Guest
|
|
Posted: Sun Jun 29, 2008 12:04 pm |
|
|
Thanks!
Then what is IOSC4 and IOSC8 doing if INTRC was used? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jun 29, 2008 12:15 pm |
|
|
The IOFCS bit in the Config word is set by the compiler, based upon
the #fuses statement and the #use delay() statement in your program.
Here are the settings that the compiler uses for the program that I posted:
Quote: |
Configuration Fuses:
Word 1: 3FE5 INTRC NOPROTECT IOSC8 MCLR NOWDT PUT BROWNOUT |
|
|
|
martinj Guest
|
|
Posted: Sun Jun 29, 2008 1:01 pm |
|
|
Thank you.
But looks IOSC8 is not a must, the code works fine without it.
My code is :
#fuses INTRC
#fuses NOPROTECT
#fuses PUT
#fuses NOWDT
#byte OSCTUNE = 0x90
#use delay(clock=8000000) |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jun 29, 2008 1:15 pm |
|
|
I am going to say this one last time.
You don't directly control the IOSCx setting. It is set (or cleared) by
the compiler, based upon your settings for the oscillator and the #use
delay() frequency.
Quote: | #fuses INTRC
#fuses NOPROTECT
#fuses PUT
#fuses NOWDT
#byte OSCTUNE = 0x90
#use delay(clock=8000000) |
The fuse settings shown above produce the following Config bits.
These show that the compiler does set the IOSC8 bit for your code.
Code: | Configuration Fuses:
Word 1: 3FE5 INTRC NOPROTECT IOSC8 MCLR NOWDT PUT BROWNOUT |
|
|
|
|