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 with internal oscillator INTRC_IO

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








Problem with internal oscillator INTRC_IO
PostPosted: Wed Feb 06, 2008 11:50 am     Reply with quote

Hi, I need a help to this problem. I can not properly configure the Internal oscillator.

See my CCS code:
___________________________________________________
#include <16F688.h>

#fuses INTRC_IO,FCMEN,BROWNOUT,NOWDT,,NOMCLR,PUT
#BYTE OSCCON = 0b01110100 //8MHZ
#use delay(internal=8000000)
___________________________________________

This program does not work without crystal in the pins OSC1 and OSC2, but if putting the crystal already works.

But, I do not want to use the external crystal.

Please help me

Best Regards
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Feb 06, 2008 12:22 pm     Reply with quote

What is your compiler version number?

Where is your code line defining OSCCON?

Code:
#use delay(internal=8000000)
I don't think 'internal' is a valid keyword (it's not in my v4 manual).

Try
Code:
#include <16F688.h>

#fuses INTRC_IO,FCMEN,BROWNOUT,NOWDT,NOMCLR,PUT
#use delay(clock=8000000)
Guest








PostPosted: Wed Feb 06, 2008 12:36 pm     Reply with quote

ckielstra wrote:
What is your compiler version number?

Where is your code line defining OSCCON?

Code:
#use delay(internal=8000000)
I don't think 'internal' is a valid keyword (it's not in my v4 manual).

Try
Code:
#include <16F688.h>

#fuses INTRC_IO,FCMEN,BROWNOUT,NOWDT,NOMCLR,PUT
#use delay(clock=8000000)


My compiler version number is:4.013
the code line defining OSCCON is after the fuses

Ialready tested this code, but not working
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Wed Feb 06, 2008 1:25 pm     Reply with quote

You don't need to set up OSCCON manually, you should set up your internal oscillator like this:

Code:
#use delay(clock=8000000);

setup_oscillator(OSC_8MHZ);


That should set it up properly.

See if that works better.

Ronald
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Feb 06, 2008 5:01 pm     Reply with quote

V4.013 is crap. Maybe your problem can be solved but there are so many other problems with the first v4.0xx releases that you are wasting time.

The v4.xxx versions started to compile old v3.x projects around release v4.030 and the latest v4.06x versions get few complaints. Either revert to v3.249 or update to the latest release.
Guest








PostPosted: Thu Feb 07, 2008 3:36 am     Reply with quote

Hi,
Problem solved with the next CCS code :

_______________________________________________________
#include <16F688.h>

#fuses INTRC_IO, NOWDT,NOMCLR, NOPROTECT, BROWNOUT,PUT
#BYTE OSCCON = 0x71 //
#use delay(clock=8000000) //
______________________________________________
I change the bit 0 in the OSCCON register.

Best Regards
Ttelmah
Guest







PostPosted: Thu Feb 07, 2008 4:21 am     Reply with quote

Actually, there is a 'glaring' misunderstanding about what 'byte' does here....
The declaration:
#BYTE OSCCON = 0b01110100

Declares a C variable _called_ OSCCON, to be _located_ at address 0b0110100

It doesn't put _anything_ into this location.
This location is in the RAM =, as is the 0x71 tried latter.
The byte declaration does _nothing_ as shown.

The correct declaration, would be:

#BYTE OSCCON = 0x8F //The _address_of the OSCCON register

Then if you want to put a value _into_ OSCCON, in the main code, you just have:

OSCCON=0x71;

What is happening, is that in the older compiler, the OSCCON register is not being properly setup by the compiler, and the added declaration is incorrect, so does not work. In the latter compiler, the added declaration still does nothing, but the compiler by then has been fixed, and itself puts the required value into OSCCON...

Best Wishes
Guest








PostPosted: Thu Feb 07, 2008 8:15 am     Reply with quote

Ttelmah wrote:
Actually, there is a 'glaring' misunderstanding about what 'byte' does here....
The declaration:
#BYTE OSCCON = 0b01110100

Declares a C variable _called_ OSCCON, to be _located_ at address 0b0110100

It doesn't put _anything_ into this location.
This location is in the RAM =, as is the 0x71 tried latter.
The byte declaration does _nothing_ as shown.

The correct declaration, would be:

#BYTE OSCCON = 0x8F //The _address_of the OSCCON register

Then if you want to put a value _into_ OSCCON, in the main code, you just have:

OSCCON=0x71;

What is happening, is that in the older compiler, the OSCCON register is not being properly setup by the compiler, and the added declaration is incorrect, so does not work. In the latter compiler, the added declaration still does nothing, but the compiler by then has been fixed, and itself puts the required value into OSCCON...

Best Wishes


Thanks for your explanation Ttelmah.
I changed the CCS code and verify improvements. The code is :

Code:
#include <16F688.h>


#fuses INTRC_IO, NOWDT,NOMCLR, NOPROTECT, BROWNOUT,PUT
#use delay(clock=8000000)
#BYTE OSCCON = 0x8F  //endereço do OSCCON register
//#BYTE OSCCON = 0x71



void main(void) {
   OSCCON=0x71;  //Configuração do registo OSCCON
  //......................


Best Regards
ralph79



Joined: 29 Aug 2007
Posts: 87

View user's profile Send private message

PostPosted: Mon Apr 14, 2008 10:58 am     Reply with quote

I think that I have a problem very similar to the one reported by "Guest", but the solution that solve the situation to "Guest" don´t seems to solves my problem.
I have a 16f688 connected to an RF receiver (TDA5200). The DATA pin of the TDA is connected to the RC5 of the 16F688.
Initially I have the TDA5200 with a crystal of 13.225625 with tolerances (60ppm) and load capacitance (40pF) quite higher than it was supposed.
With these crystal the system works quite well with the 16F688 at 9600 bps using the internal oscillator at 4Mhz or at 8Mhz.
But now I find another crystal with the exact frequency but with much better tolerances (20 ppm) and CL (12pF).
I thought that with these new crystal my system should work much better. But now with the better crystal, I only can work at 4800bps and with internal clock at 4Mhz. If I put the internal clock at 8Mhz it doesn't work.
At this moment I have:
Code:

#include <16F688.h>
#device *=16
#fuses INTRC_IO,NOWDT,PUT, NOPROTECT,NOMCLR,BROWNOUT,NOIESO,NOFCMEN
#use delay(clock=4000000)
#use rs232(baud=4800, parity=N, xmit=PIN_C4, rcv=PIN_C5, bits=8, STOP=1, errors)

#use fast_io(A)
#use fast_io(C)

void main (void)
{
setup_oscillator(OSC_8MHZ);

   setup_adc_ports(NO_ANALOGS|VSS_VDD);   // Make PORT A Inputs Digital
   setup_adc(ADC_OFF);            // Turn OFF ADC
   setup_comparator(NC_NC);   // Disconnect Comparators
   setup_vref(FALSE);

   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);
   enable_interrupts(INT_RDA);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(INT_TIMER1);

   set_tris_a(0b00100000);     
   set_tris_c(0b00100000);
   port_a_pullups(0b00100000);

   enable_interrupts(GLOBAL);
        while(TRUE)
        {
            //....................
        }
}



I have been watching the 16F688 data sheet and at 8Mhz the micro is well capable of work at 9600bps, the error is quite low.
One more thing my version is the 4.0.65
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