View previous topic :: View next topic |
Author |
Message |
Jody
Joined: 08 Sep 2006 Posts: 182
|
18F2450 running slow |
Posted: Mon Jun 07, 2010 5:00 am |
|
|
Hello,
I am using the 18F2450 with the internal oscillator...
And when I toggle an output in it runs very slow.
I think I have mashed something up with the oscillator settings but have no idea what......
Code:
Code: |
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_oscillator(OSC_INTRC);
while(1)
{
delay_ms(1);
output_high(PIN_C0);
delay_ms(1);
output_low(PIN_C0);
}
}
|
Header file:
Code: |
#include <18F2450.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC //Internal RC Osc
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV20 //Brownout reset at 4.3V
#FUSES NOPUT //Power Up Timer
#FUSES NOVREGEN //USB voltage regulator disabled
#FUSES NOSTVREN //Stack full/underflow will cause reset
#FUSES DEBUG //Debug mode for use with ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOLPT1OSC //Timer1 configured for low-power operation
#use delay(clock= 8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
|
Anybody an idea??
PIC is running a factor of 500 too slow.....
Regards,
Jody |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jun 07, 2010 10:41 am |
|
|
Try a more simple program that blinks an LED once per second.
If it doesn't work, then post your compiler version, Vdd voltage for the
PIC, and post if you have all the required external connections such as
the MCLR pull-up resistor. Also post if you are testing this in hardware
or in Proteus.
Code: |
#include <18F2450.h>
#fuses INTRC_IO,NOWDT,PUT,NOBROWNOUT,NOLVP
#use delay(clock=4000000)
//======================================
void main(void)
{
while(1)
{
delay_ms(500);
output_high(PIN_C0);
delay_ms(500);
output_low(PIN_C0);
}
} |
|
|
|
mskala
Joined: 06 Mar 2007 Posts: 100 Location: Massachusetts, USA
|
|
Posted: Mon Jun 07, 2010 11:28 am |
|
|
Code: | setup_oscillator(OSC_INTRC); |
on this device is going to be the 31K oscillator, I believe. So telling the
code that clock is 8000000 will be a problem. |
|
|
Jody
Joined: 08 Sep 2006 Posts: 182
|
|
Posted: Mon Jun 07, 2010 12:46 pm |
|
|
mmmh I think that Mskala is right...
I will connect a oscillator to the pic to check if I can get it working any faster....
Thanks for the assistance,
I will let you know
Regards,
Jody |
|
|
Jody
Joined: 08 Sep 2006 Posts: 182
|
connec a 8MHz crystal |
Posted: Tue Jun 08, 2010 2:28 am |
|
|
And still it is running slow.....
Anybody an idea??
Changed the fuse setting to HS for the crystal...
Regards,
Jody |
|
|
mkuang
Joined: 14 Dec 2007 Posts: 257
|
|
Posted: Tue Jun 08, 2010 7:10 am |
|
|
What do you mean it is running slow? You are trying to toggle the pin every ms, are you looking at it with a scope? You are not going to see anything with your bare eyes.
Did you try PCM Programmer's program? It toggles the output every 1/2 a second. |
|
|
mskala
Joined: 06 Mar 2007 Posts: 100 Location: Massachusetts, USA
|
|
Posted: Tue Jun 08, 2010 12:16 pm |
|
|
I agree you should run his program, but unless I read the data sheet
wrong you will need to change the clock=4000000 to clock=31000.
Fuse HS won't affect the internal oscillator.
And your initial statement that it is running 500 times too slow is a
clue. 8000000 / 500 = 16000, and I think you may have forgot your
toggle factor, so 16000 * 2 = 32KHz. |
|
|
|