View previous topic :: View next topic |
Author |
Message |
Guest Guest
|
delay_ms problems |
Posted: Fri Jul 08, 2005 4:18 pm |
|
|
I'm using the ICD-U40 to program a PIC18F4431. I'm trying to make two leds blink. The program seems to have problems with the line "delay_ms()" because the leds do not blink within the time I specified. The leds blink sporadically and stop. I think it might be my oscillator since it looks like a timing issue. I have a 40MHz oscillator with pin 1 as no connect, pin 7 connected to GND, pin 8 connected to OSC1 of the pic, and pin 14 connected to +5. Is there something wrong with my oscillator selection?
Also, what is the best way to send timed electrical pulses with delays in them accurately?
Here's the program for the blinking leds:
#include <18F4431.h>
#device ICD=TRUE
#fuses HS, NOLVP, NOWDT, NOPUT
#use delay(clock=40000000)
#define RED_LED PIN_B4
#define GREEN_LED PIN_B5
void main() {
while(TRUE){
output_low(GREEN_LED);
delay_ms (500);
output_high(GREEN_LED);
delay_ms (500);
output_low(RED_LED);
delay_ms (500);
output_high(RED_LED);
delay_ms (500);
}
}
Any suggestions or answers would help greatly and would be most appreciated. Thanks so much!!! |
|
|
sseidman
Joined: 14 Mar 2005 Posts: 159
|
|
Posted: Fri Jul 08, 2005 4:55 pm |
|
|
I wasn't aware that the 4431 can clock off a 40MHz crystal. I know it can clock off a 20MHz, or a 10MHz crystal at 40MHz if you use the hardware 4X PLL multiplier. To use the PLL, clock with a 10MHz crystal, and use the H4 fuse instead of HS. You will need to reset the chip after you program it with this fuse.
Scott |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Jul 08, 2005 5:01 pm |
|
|
Try it without the debugger.
Have you verified all the power and ground connections?
Do you have a pullup on the MCLR?
Quote: | Also, what is the best way to send timed electrical pulses with delays in them accurately?
|
CCP module |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jul 08, 2005 6:25 pm |
|
|
Quote: | I have a 40MHz oscillator with pin 1 as no connect, pin 7
connected to GND, pin 8 connected to OSC1 of the pic, and pin 14
connected to +5. |
Quote: | #fuses HS, NOLVP, NOWDT, NOPUT
#use delay(clock=40000000) |
The data sheet says you should use the EC or EC i/o oscillator modes
for this. Download the data sheet and look in the section on
Oscillator Configurations/External Clock Input.
You should remove the "HS" fuse setting and put in "EC" or "EC_IO".
Quote: | I wasn't aware that the 4431 can clock off a 40MHz crystal |
He's using an oscillator. |
|
|
Guest
|
|
Posted: Mon Jul 11, 2005 1:58 pm |
|
|
I replaced the HS with the EC and still have the same problem as well as checking the suggestions made about disconnecting the debugger and verifying power and gnd. I still get the same results. Is it okay to use a 40MHz clock oscillator? Or should I try a 20MHz crystal? Can I buy crystal oscillators over the counter at the stores without making an online order?
Thanks for the suggestions! |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Mon Jul 11, 2005 2:05 pm |
|
|
Anonymous wrote: | I replaced the HS with the EC and still have the same problem as well as checking the suggestions made about disconnecting the debugger and verifying power and gnd. I still get the same results. Is it okay to use a 40MHz clock oscillator? Or should I try a 20MHz crystal? Can I buy crystal oscillators over the counter at the stores without making an online order?
Thanks for the suggestions! |
Really depends on the store you shop with. I expect Fry's would have crystals. |
|
|
|