View previous topic :: View next topic |
Author |
Message |
adamp524
Joined: 06 May 2010 Posts: 22
|
Using the delay_ms function / oscillator configuration |
Posted: Thu May 06, 2010 9:55 am |
|
|
Hi,
I'm using a PIC18F4580 and using its internal 8Mhz oscillator.
As far as I know the delay_ms function will create a delay in milliseconds of the parameter you give to it. But it seems that this is not working in my code or at least working at a much greater rate than it should - when I use the function it seems as if there is no delay at all!
I have the following code in my main.c file:
Code: | #include "main.h"
void main()
{
output_high(PIN_B2);
output_low(PIN_B3);
while(TRUE)
{
delay_ms(1000);
output_toggle(PIN_B3);
delay_ms(1000);
output_toggle(PIN_B2);
}
|
In my main.h file I have:
Code: | #include <18F4580.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV21 //Brownout reset at 2.1V
#FUSES NOPUT //No 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 NOIESO //Internal External Switch Over mode disabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES BBSIZ2K //2K words Boot Block size
#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
#use delay(clock=8000000)
|
I have LED outputs connected to B2 and B3. When I run this code they should blink alternately but so far one just stays lit all the time and the other does not light.
Have I got my program configured correctly to use the internal oscillator for this chip?
And if so, why is the delay_ms function not working as it should?
Thanks |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Thu May 06, 2010 10:03 am |
|
|
Change XINST, to NOXINST. CCS does not support XINST.
Have you got a pull up on MCLR.
Have you got a pull down on the PGM pin. You have LVP selected, if this is wanted (it rarely is....), you _must_ ensure the PGM pin is pulled down, when you want to run the chip.
Best Wishes |
|
|
adamp524
Joined: 06 May 2010 Posts: 22
|
|
Posted: Fri May 07, 2010 1:46 am |
|
|
Thanks,
Changing to NOXINST and removing LVP fixed it! |
|
|
|