View previous topic :: View next topic |
Author |
Message |
adalucio
Joined: 16 Mar 2009 Posts: 29
|
pic18f2455 oscillator problem |
Posted: Sat May 09, 2009 4:35 am |
|
|
Hi all
I have a pic18f2455, a 20mhz crystal, two 15pF capacitors.
this is the program
Code: |
#include "C:\pic\18f2455_led\main.h"
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_8_BIT);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
while(1)
{
output_high(PIN_A0);
delay_ms(1500);
output_low(PIN_A0);
delay_ms(1500);
}
}
|
Code: |
#include <18F2455.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOWDT //No Watch Dog Timer
#FUSES HSPLL //High Speed Crystal/Resonator with PLL enabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES PUT //Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES LVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES MCLR //Master Clear pin enabled
#FUSES XINST //Extended set extension and Indexed Addressing mode enabled
#FUSES PLL5 //Divide By 5(20MHz oscillator input)
#FUSES USBDIV //USB clock source comes from PLL divide by 2
#FUSES CPUDIV1 //System Clock /1
#FUSES VREGEN //USB voltage regulator enabled
#use delay(clock=20000000)
|
led should blink every 1500, but it doesn't. it blink very fast.
(this is a test program, the next step is adding usb full speed support, so the configuration must work also for the usb)
what is the problem?
Thanks
sorry for my english
|
|
|
bungee-
Joined: 27 Jun 2007 Posts: 206
|
|
Posted: Sat May 09, 2009 5:47 am |
|
|
Here is your problem.
#FUSES HSPLL //High Speed Crystal/Resonator with PLL enabled
#FUSES PLL5 //Divide By 5(20MHz oscillator input)
Your clock is not 20MHz but much higher.... with settings like that on PIC18F4550 clock would be 48MHz |
|
|
adalucio
Joined: 16 Mar 2009 Posts: 29
|
|
Posted: Sat May 09, 2009 6:52 am |
|
|
so I have to write
Code: |
#use delay(clock=48000000)
|
is it ok? |
|
|
adalucio
Joined: 16 Mar 2009 Posts: 29
|
|
Posted: Sat May 09, 2009 6:58 am |
|
|
adalucio wrote: | so I have to write
Code: |
#use delay(clock=48000000)
|
is it ok? |
I tried it. it doesn't work, led blink very fast |
|
|
adalucio
Joined: 16 Mar 2009 Posts: 29
|
|
Posted: Sat May 09, 2009 7:06 am |
|
|
|
|
|
adalucio
Joined: 16 Mar 2009 Posts: 29
|
|
Posted: Sat May 09, 2009 7:18 am |
|
|
OMG
now it works
Code: |
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HSPLL //High Speed Crystal/Resonator with PLL enabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV43 //Brownout reset at 4.3V
#FUSES PUT //Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES LVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES MCLR //Master Clear pin enabled
#FUSES XINST //Extended set extension and Indexed Addressing mode enabled
#FUSES PLL5 //Divide By 5(20MHz oscillator input)
#FUSES USBDIV //USB clock source comes from PLL divide by 2
#FUSES CPUDIV1 //System Clock by 1
#FUSES VREGEN //USB voltage regulator enabled
#use delay(clock=48000000)
|
Big thanks |
|
|
Ttelmah Guest
|
|
Posted: Sat May 09, 2009 7:23 am |
|
|
However you won't get much other code to work, till you get rid of the XINST fuse.
CCS, does _not_ use/support XINST.
A really simple program (LED flasher), won't do anything using the extended instructions, but as soon as you try to code anything more complex, the code will stop working....
Best Wishes |
|
|
|