CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

delay_ms problems

 
Post new topic   Reply to topic    CCS Forum Index -> CCS ICD / Mach X / Load-n-Go
View previous topic :: View next topic  
Author Message
Guest
Guest







delay_ms problems
PostPosted: Fri Jul 08, 2005 4:18 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jul 08, 2005 4:55 pm     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Fri Jul 08, 2005 5:01 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jul 08, 2005 6:25 pm     Reply with quote

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








PostPosted: Mon Jul 11, 2005 1:58 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jul 11, 2005 2:05 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> CCS ICD / Mach X / Load-n-Go All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group