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 support@ccsinfo.com

Problem to set internal oscillator in pic16f676!

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



Joined: 04 Dec 2007
Posts: 5
Location: Brazil

View user's profile Send private message MSN Messenger

Problem to set internal oscillator in pic16f676!
PostPosted: Tue Dec 04, 2007 10:18 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Dec 04, 2007 11:10 am     Reply with quote

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

View user's profile Send private message MSN Messenger

Problem to set internal oscillator in pic16f676!
PostPosted: Wed Dec 05, 2007 9:37 am     Reply with quote

Thanks,

The problem is solved.

João Paulo.
sahu77



Joined: 08 Sep 2011
Posts: 202

View user's profile Send private message

PostPosted: Fri Sep 09, 2011 1:48 pm     Reply with quote

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: 19338

View user's profile Send private message

PostPosted: Fri Sep 09, 2011 2:38 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Sep 10, 2011 9:18 am     Reply with quote

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: 19338

View user's profile Send private message

PostPosted: Sun Sep 11, 2011 2:41 am     Reply with quote

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
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