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 CCS Technical Support

Internal oscillator PIC18F2550

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



Joined: 26 Mar 2012
Posts: 16

View user's profile Send private message

Internal oscillator PIC18F2550
PostPosted: Mon Mar 26, 2012 8:05 am     Reply with quote

Hello,
I have a problem on setting the internal oscillator of my pic 18F2550.
In fact the Micro controller is working but with wrong delay :/
when I put " delay_ms(1000);" it actually in practice wait for about 3 second !!
I even tried to use external clock and always the same problem !!!

This is my code:

For external oscillator:
Code:

   #fuses HS,NOWDT,NOPROTECT,MCLR,PUT
   #use delay(clock=20000000)

   #byte trisc = 0xF94
   #define leda pin_C0

   void main (void){
     trisc=0b10000000;
     while (1){
        output_low(leda);
        delay_ms(1000);
        output_high(leda);
        delay_ms(1000); 
     }
   }

For internal oscillator:
Code:

   #fuses NOWDT,NOPROTECT,MCLR,INTRC
   #use delay(clock=8000000)

   #byte trisc = 0xF94
   #define leda pin_C0

   void main (void){
     setup_oscillator(OSC_8MHZ);
     trisc=0b10000000;
     while (1){
        output_low(leda);
        delay_ms(1000);
        output_high(leda);
        delay_ms(1000); 
     }
   }
Ttelmah



Joined: 11 Mar 2010
Posts: 19498

View user's profile Send private message

PostPosted: Mon Mar 26, 2012 8:15 am     Reply with quote

What crystal are you using?.
The value used in the #use delay statement, _must_ match exactly the frequency you are actually using. Now for the internal oscillator, the maximum available frequency is 8MHz. So:
Code:

#include <18F2550.h>
#FUSES NOWDT, WDT128, PLL1, CPUDIV1, NOUSBDIV, INTEC_IO, NOFCMEN, NOIESO, BORV27, NOVREGEN, NOPBADEN, NOLPT1OSC, NOMCLR, NOLVP, NOXINST
#use delay(clock=8000000)

#define LEDa pin_c0

void main(void) {
   //You don't need to touch TRIS. If you do, then use the compiler instruction
   do {
      output_toggle(LEDa);
      delay_ms(1000);
   } while(TRUE);
}


Quite a few extra fuses - have turned off LVP, XINST, made sure the dividers are set correctly, and that the USB regulator is off (no point in having it on, since you can't run USB with the internal clock). PUT, is a good idea with the crystal, but not needed with the internal RC oscillator.

Best Wishes
Louati



Joined: 26 Mar 2012
Posts: 16

View user's profile Send private message

PostPosted: Mon Mar 26, 2012 8:35 am     Reply with quote

Thank you for help Smile
I solve the problem in the two case Smile
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