![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Louati
Joined: 26 Mar 2012 Posts: 16
|
Internal oscillator PIC18F2550 |
Posted: Mon Mar 26, 2012 8:05 am |
|
|
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);
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19383
|
|
Posted: Mon Mar 26, 2012 8:15 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Louati
Joined: 26 Mar 2012 Posts: 16
|
|
Posted: Mon Mar 26, 2012 8:35 am |
|
|
Thank you for help
I solve the problem in the two case ![Smile](images/smiles/icon_smile.gif) |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|