|
|
View previous topic :: View next topic |
Author |
Message |
joaojprf
Joined: 04 Dec 2007 Posts: 5 Location: Brazil
|
Problem to set internal oscillator in pic16f676! |
Posted: Tue Dec 04, 2007 10:18 am |
|
|
Hello,
I'm a new user of ccs compiler. I want to know how I can use the internal oscillator's pic16f676 of 4MHz. I looked in the 16f676.h file and I didn't find the instruction to set the internal oscillator. The file has a #fuse called INTRC, but I don't know if this fuse is for internal oscillator or RC oscillator.
In the help there is a function called setup_oscillator, but when I used this function the program didn't compile.
My code:
#if defined(__PCM__)
#include <16F676.h>
#device ICD=TRUE
#device ADC=8
#device ANSI
#fuses INTRC,WDT,PUT,NOBROWNOUT,MCLR,NOCPD,NOPROTECT,NOPROTECT
#use delay(clock=4000000,internal)
#endif
void main()
{
.......
}
Thanks,
João Paulo. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Dec 04, 2007 11:10 am |
|
|
The internal oscillator can only run at 4 MHz on the 16F676, so it
doesn't need a setup_oscillator() function. Enable the internal
oscillator by using the INTRC or INTRC_IO fuse setting, as shown below.
Code: |
#include <16F676.H>
#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT
#use delay(clock = 4000000)
//===================================
void main()
{
while(1)
{
output_high(PIN_C4);
delay_ms(500);
output_low(PIN_C4);
delay_ms(500);
}
} |
|
|
|
joaojprf
Joined: 04 Dec 2007 Posts: 5 Location: Brazil
|
Problem to set internal oscillator in pic16f676! |
Posted: Wed Dec 05, 2007 9:37 am |
|
|
Thanks,
The problem is solved.
João Paulo. |
|
|
sahu77
Joined: 08 Sep 2011 Posts: 202
|
|
Posted: Fri Sep 09, 2011 1:48 pm |
|
|
PCM programmer wrote: | The internal oscillator can only run at 4 MHz on the 16F676, so it
doesn't need a setup_oscillator() function. Enable the internal
oscillator by using the INTRC or INTRC_IO fuse setting, as shown below.
Code: |
#include <16F676.H>
#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT
#use delay(clock = 4000000)
//===================================
void main()
{
while(1)
{
output_high(PIN_C4);
delay_ms(500);
output_low(PIN_C4);
delay_ms(500);
}
} |
|
it is not work. _________________ sahu |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Fri Sep 09, 2011 2:38 pm |
|
|
The commonest reason for this, is that you have done a full erase on the chip.
The internal oscillator, _requires_ a calibration value to be stored in the last location of the program memory. The code will automatically call this location as it starts to load, which should return with the factory programmed calibration value. If this instruction is erased, the chip won't run.
Most programmers have an option to 'save calibration value', which automatically reads this value, and writes it back whenever the chip is erased.
Read the chip in your programmer.
Look at the last two bytes in program memory. These bytes should not be empty. If they are, you have incorrectly fully erased the chip.
You can get it working again, but with the oscillator 'uncalibrated', by writing the pattern 0x0D80 into the last two bytes of program memory (either directly with your programmer, or use a #ROM instruction). 80 is the LSB (first byte in memory).
In future, see if your programmer has the 'save calibration value' option (all that I know of, do), and enable this, to stop it happening again.
Some programmers (Mach-X for example), have an option to automatically re-calculate a working value with reasonable calibration. Otherwise you can gently adjust the value using a timing loop, till the chip is once again 'calibrated'.
Best Wishes |
|
|
sahu77
Joined: 08 Sep 2011 Posts: 202
|
|
Posted: Sat Sep 10, 2011 9:18 am |
|
|
Ttelmah wrote: | The commonest reason for this, is that you have done a full erase on the chip.
The internal oscillator, _requires_ a calibration value to be stored in the last location of the program memory. The code will automatically call this location as it starts to load, which should return with the factory programmed calibration value. If this instruction is erased, the chip won't run.
Most programmers have an option to 'save calibration value', which automatically reads this value, and writes it back whenever the chip is erased.
Read the chip in your programmer.
Look at the last two bytes in program memory. These bytes should not be empty. If they are, you have incorrectly fully erased the chip.
You can get it working again, but with the oscillator 'uncalibrated', by writing the pattern 0x0D80 into the last two bytes of program memory (either directly with your programmer, or use a #ROM instruction). 80 is the LSB (first byte in memory).
In future, see if your programmer has the 'save calibration value' option (all that I know of, do), and enable this, to stop it happening again.
Some programmers (Mach-X for example), have an option to automatically re-calculate a working value with reasonable calibration. Otherwise you can gently adjust the value using a timing loop, till the chip is once again 'calibrated'.
Best Wishes |
like this
Code: | #rom 0x3FF = {0x3480} |
_________________ sahu |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Sun Sep 11, 2011 2:41 am |
|
|
Yes.
However I prefer to fix it by just doing it via the programmer. Problem is that if you add this #rom to your code, and forget to remove it, you will destroy the calibration value in _all_ chips you program with this code..... :(
Best Wishes |
|
|
|
|
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
|