View previous topic :: View next topic |
Author |
Message |
oliveira.felipede
Joined: 27 Jun 2012 Posts: 5
|
PIC18F14K50 Oscillation problem |
Posted: Wed Jun 27, 2012 9:15 am |
|
|
Hey Guys.
I'm facing a problem using the PIC18F14K50 relate to it's oscillation frequency.
I was trying to implement a simple code just to blink a led to confirm the right frequency.
The code is that
Code: |
#include <18F14K50.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV19 //Brownout reset at 1.9V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOWRTC //configuration not registers write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOMCLR //No Master Clear pin enabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOCPB //No Boot Block code protection
#FUSES NOWRTB //Boot block not write protected
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES HFOFST
#FUSES USBDIV1
#FUSES BBSIZ2K //2K words Boot Block size
#FUSES PLLEN
#FUSES CPUDIV1 //System Clock by 4
#FUSES PCLKEN
#FUSES NODEBUG //No Debug mode for ICD
#use delay(crystal=10000000,clock=40000000)
#BIT led = 0xf82.1
void main(){
setup_wdt(WDT_OFF);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER1);
set_tris_c(0b00000101);
while(1){
led=1;
delay_ms(100);
led=0;
delay_ms(100);
}
} |
I'm using CCS Compiler in it's 4.110 version.
Using the scope to measure the LED blinking, I had a period of 4s instead of 100ms.
May anyone help me?
Thank you, and forgive me if there is anything wrong in the post (my first one). |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jun 27, 2012 12:31 pm |
|
|
Do you want to run the PIC at 40 MHz ? Do you have a 10 MHz crystal
(and capacitors) installed on your board and connected to the PIC's
oscillator pins ? |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Wed Jun 27, 2012 1:16 pm |
|
|
also...
it's really dangerous to enable interrupts without an ISR. either disable all interrupts until you get the blinking LED to work, or code a 'dummy' ISR. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19368
|
|
Posted: Wed Jun 27, 2012 2:31 pm |
|
|
Your symptoms are classic, that the chip is not seeing the oscillator as running, so with FCMEN enabled, drops back to the internal oscillator, that is running at 1MHz.
So, first, simplify a bit. About half the fuses you have selected are not needed.
Code: |
#include <18F14K50.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES PLLEN
#FUSES PCLKEN
#FUSES CPUDIV1 //System Clock by 4
#FUSES NOFCMEN
#FUSES NOBROWNOUT //No brownout reset
#FUSES PUT //Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NOMCLR //No Master Clear pin enabled
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NODEBUG //No Debug mode for ICD
#use delay(clock=40MHz)
#define LED PIN_C1
#use rs232(baud=9600,parity=N,UART1,ERRORS)
void main(){
while(1){
output_toggle(LED);
delay_ms(100);
}
}
|
Just put this into a 14K50, and it merrily runs at the right rate. If your's doesn't start, you have a hardware problem with the crystal oscillator.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
oliveira.felipede
Joined: 27 Jun 2012 Posts: 5
|
|
Posted: Thu Jun 28, 2012 5:32 am |
|
|
PCM programmer wrote: | Do you want to run the PIC at 40 MHz ? Do you have a 10 MHz crystal
(and capacitors) installed on your board and connected to the PIC's
oscillator pins ? |
That's it, I have a board with capacitors and a 10MHz Crystal. I'd already used this configuration for this osc frequency. But it didn't work in this micro. |
|
![](templates/subSilver/images/spacer.gif) |
oliveira.felipede
Joined: 27 Jun 2012 Posts: 5
|
|
Posted: Thu Jun 28, 2012 5:57 am |
|
|
Ttelmah,
Even this simple code doesn't work.
In fact I had changed the micro and using the same configuration in the board, I was using PIC18F1320 and changed to PIC18F14K50.
I think that the problem isn't in the board because the 18F1320 was working well.
Any other suggestion? Even after knowing this situation?
Thank you all! |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jun 28, 2012 1:28 pm |
|
|
Try using the internal oscillator. I tested this program just now on a
Microchip Low Pin Count board with CCS vs. 4.110 and worked fine.
It blinks an LED on Pin C1 at a rate of once per second.
Code: |
#include <18F14K50.H>
#fuses INTRC_IO, NOWDT, PUT, BROWNOUT, NOLVP, CPUDIV1
#use delay(clock=32M)
//=================================
void main()
{
while(1)
{
output_high(PIN_C1);
delay_ms(500);
output_low(PIN_C1);
delay_ms(500);
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19368
|
|
Posted: Thu Jun 28, 2012 2:29 pm |
|
|
Er.
You do realise the pin-outs between the 1320, and 14K50 are completely different. The clock is on different pins on the 14K50, to the 1320?.....
Pins 2&3 on the former, pins 17&18 on the latter.
Also Vdd/Vss to different/extra pins on the 1320.
So running with the 1320, proves nothing.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
oliveira.felipede
Joined: 27 Jun 2012 Posts: 5
|
|
Posted: Fri Jun 29, 2012 5:14 am |
|
|
I realize that they are different.
I did the changes in the pins in order to organize to this new one micro. |
|
![](templates/subSilver/images/spacer.gif) |
oliveira.felipede
Joined: 27 Jun 2012 Posts: 5
|
|
Posted: Fri Jun 29, 2012 5:27 am |
|
|
The internal OSC is working good.
I'd already checked all the fuses and till now hadn't found anything wrong :(
I'll keep searching...
Thank's |
|
![](templates/subSilver/images/spacer.gif) |
|