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

Operating PIC18F2550 at 8MHz with internal osc in CCS?

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



Joined: 04 Jan 2010
Posts: 9

View user's profile Send private message Yahoo Messenger

Operating PIC18F2550 at 8MHz with internal osc in CCS?
PostPosted: Sat Mar 22, 2014 3:56 am     Reply with quote

Hi,

I am new to CCS Compiler, previously I used to use mikroC for PIC.

I want to operate my PIC18F2550 at 8MHz with internal oscillator.
what fuses and configuration bits I need to set for this purpose?

Currently, I have developed an application in CCS Compiler for PIC18F2550 but my PIC18F2550 is operating at 2MHz with internal oscillator. I need to operate PIC18F2550 at 8MHz with internal oscillator.

How can it be done?

regards
m.yasir
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Mar 22, 2014 6:43 am     Reply with quote

Which compiler are you using?

These two lines should do it:-
Code:
#fuses INTRC
#use delay(clock=8000000)


If not you may have to use
Code:
setup_oscillator(OSC_8MHZ);


Mike
yasir9909



Joined: 04 Jan 2010
Posts: 9

View user's profile Send private message Yahoo Messenger

PostPosted: Sat Mar 22, 2014 1:22 pm     Reply with quote

I am using CCS C Compiler version 5.015

I have tried following configurations and fuses settings for oscillator:

#fuses NOWDT
#use delay(internal=8MHz)

but these settings didn't work

I have also tried the following settings:

#fuses INTRC,NOWDT,NOPROTECT,NOMCLR
#use delay(clock=8MHz)

these settings didn't work either

regards
m.yasir
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Mar 22, 2014 5:32 pm     Reply with quote

Setup_oscillator() allows you to change frequency on the fly.

If all else fails look at the appropriate registers and play with them.

Mike
temtronic



Joined: 01 Jul 2010
Posts: 9162
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 24, 2014 5:26 am     Reply with quote

Please post a very small, compilable program(1HZ LED) that doesn't work for you that shows all the fuses.
It is possible that another 'fuse' is overriding your configuration.

hth
jay
yasir9909



Joined: 04 Jan 2010
Posts: 9

View user's profile Send private message Yahoo Messenger

PostPosted: Wed Mar 26, 2014 4:17 am     Reply with quote

Here is the simple code for character loop back in CCS for PIC Compiler Version 5.015:

Code:


// character loop back test

#if defined(__PCM__)
#include <18F2550.h>
#fuses NOWDT,INTXT
#use delay(internal=8000000)
#use rs232(baud=38400, xmit=PIN_C6, rcv=PIN_C7)
#include <C:\Program Files (x86)\PICC\Drivers\stdlib.h>
#include <C:\Program Files (x86)\PICC\Drivers\math.h>
#include <C:\Program Files (x86)\PICC\Drivers\stdio.h>
#define compiler __PCM__

#elif defined(__PCB__)
#include <18F2550.h>
#fuses NOWDT,INTXT
#use delay(internal=8000000)
#use rs232(baud=38400, xmit=PIN_C6, rcv=PIN_C7)
#include <C:\Program Files (x86)\PICC\Drivers\stdlib.h>
#include <C:\Program Files (x86)\PICC\Drivers\math.h>
#include <C:\Program Files (x86)\PICC\Drivers\stdio.h>
#define compiler __PCB__

#elif defined(__PCH__)
#include <18F2550.h>
#fuses NOWDT,INTXT
#use delay(internal=8000000)
#use rs232(baud=38400, xmit=PIN_C6, rcv=PIN_C7)
#include <C:\Program Files (x86)\PICC\Drivers\stdlib.h>
#include <C:\Program Files (x86)\PICC\Drivers\math.h>
#include <C:\Program Files (x86)\PICC\Drivers\stdio.h>
#define compiler __PCH__

#elif defined(__PCD__)
#include <18F2550.h>
#fuses NOWDT,INTXT
#use delay(internal=8000000)
#use rs232(baud=38400, xmit=PIN_C6, rcv=PIN_C7)
#include <C:\Program Files (x86)\PICC\Drivers\stdlib.h>
#include <C:\Program Files (x86)\PICC\Drivers\math.h>
#include <C:\Program Files (x86)\PICC\Drivers\stdio.h>
#define compiler __PCD__
#endif

void main()
{

   char value;
   
   setup_oscillator( OSC_8MHZ );
   
   printf("\r\nStart typing:\r\n");
   
   while(TRUE)
   {
         
      while(!kbhit());
     
      value = getc();
           
      putc(value);
     
   }
}



This piece of code simply loops back what you type on serial interface software like 'PLC Test' (or through your own program written in Labview for this purpose) when the microntroller hardware is connected with serial port of PC.
The issue that I am facing is that the baud rate being generated through above piece of code is 1/4th of what I intend to configure the micrcontroller for.

I have set the baud rate to 38400 but in actual I am getting 9600 ( = 38400/4) baud rate which is 1/4th of what I have configured my controller for through above piece of code.
Ttelmah



Joined: 11 Mar 2010
Posts: 19330

View user's profile Send private message

PostPosted: Wed Mar 26, 2014 5:12 am     Reply with quote

Start by getting rid of all the if/else's.

They won't work, and are just confusing you. PCB, PCM, and PCD, all cannot compile code for the 18 family chips.

KISS.

Then since you don't have an external crystal, as you have already been told, use INTRC.
You do realise, that you cannot use USB on this chip without an external oscillator/crystal?. So pointless to enable the USB voltage regulator etc.. Just wastes power. If you have an external crystal, then why run the CPU off the internal (low accuracy) oscillator?. You also realise that the internal oscillator, is _only just_ accurate enough for RS232, if the unit is in a 'room temperature' environment?.

Code:

#include <18F2550.h>
#fuses NOWDT,INTRC,NOLVP,NOXINST,NOVREGEN,NOPDADEN
#use delay(internal=8000000)
#use rs232(baud=9600, UART1, ERRORS)
#include <C:\Program Files (x86)\PICC\Drivers\stdlib.h>
#include <C:\Program Files (x86)\PICC\Drivers\math.h>
#include <C:\Program Files (x86)\PICC\Drivers\stdio.h>

void main(void)
{
   char value;
   
   printf("\r\nStart typing:\r\n");
   
   while(TRUE)
   {         
      while(!kbhit());
      value = getc();     
      putc(value);
   }
}

Merrily runs at 9600bps, on both 5.014, and 5.016 (the two nearest versions I have to your compiler)...
temtronic



Joined: 01 Jul 2010
Posts: 9162
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Mar 26, 2014 5:25 am     Reply with quote

At first I thought the fuse INTXT was in error, so I looked at the 4550, as it's the bigger brother of the 2550. It's a valid fuse but I do recall when using the 4550 there are a LOT of fuses! I don't know what INTXT really does.


edit: OK, Mr. T replied while I got my coffee refilled ! I read the fuses.txt file and it is 'silly' to have that configuration.Having a real crystal (and caps) on board is always better. The time 'saved' by using the internal osc is only a few ms..hardly worth the effort in my opinion,especially if you have PUT enabled!

When I finally got a valid, working set of fuses, I put them in a separate file (4550_program_name.fuz) and just #included it. It saves a lot of visual clutter in the program and I _know_ they work.

You should printout the listing or examine them in MPLAB to see what the REAL 'fuses' configuration is. I know the 4550 will run fine using the internal 8MHz oscillator, so I suspect a faulty 'configuration', either by not selecting them correctly of a compiler 'bug'.

Also , if you're only using one compiler, you should remove the long conditional IF-ELSE at the beginning.One wrong 'typo' can cause you problems!

hth
jay


Last edited by temtronic on Wed Mar 26, 2014 5:37 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19330

View user's profile Send private message

PostPosted: Wed Mar 26, 2014 5:31 am     Reply with quote

INTXT is 99% the same as INTRC. However it sets both the oscillator I/O bits for oscillator use, rather than for I/O, enables the XT oscillator, and requires a crystal on the OSC pins. to run the USB. It is slightly pointless, since once you have such a crystal, you might as well run the CPU off it!.... Smile
It's designed for systems where you might want to get the fastest boot, for the CPU, by using the RC oscillator, but still want to use USB, or are going to disable the USB at times. Normally you'd switch oscillators as soon as the crystal is running and stable, if using this.

Best Wishes
yasir9909



Joined: 04 Jan 2010
Posts: 9

View user's profile Send private message Yahoo Messenger

@ Ttelmah
PostPosted: Fri Mar 28, 2014 3:05 am     Reply with quote

Ttelmah,the code that you have posted does not work either as it gives error for "NOPDADEN "

The actually working code that I have tried is given below
Code:


// character loop back test

#include <18F2550.h>
#fuses NOWDT,NOPROTECT,NOLVP
#use delay(internal=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#include <C:\Program Files (x86)\PICC\Drivers\stdlib.h>
#include <C:\Program Files (x86)\PICC\Drivers\math.h>
#include <C:\Program Files (x86)\PICC\Drivers\stdio.h>

void main(void)
{

     setup_oscillator( OSC_8MHZ|OSC_INTRC,OSC_STATE_STABLE );

     char value;
     printf("\r\nStart typing:\r\n");
     while(TRUE)
     {

          while(!kbhit());
          value = getc();
          putc(value);

     }

}




This code is working fine at 8MHz on internal oscillator and serial port is operating at a baud rate of 9600.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Fri Mar 28, 2014 8:36 am     Reply with quote

I believe Ttelmah did a 'fat finger'. It should be NOPBADEN. This sets portb as digital I/O instead of analog(PBADEN).

Ronald
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