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

PIC18f4550 + Crystal 20MHz --> Problems

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
germans



Joined: 04 Feb 2016
Posts: 11

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

PIC18f4550 + Crystal 20MHz --> Problems
PostPosted: Thu Feb 04, 2016 12:47 pm     Reply with quote

Hi guys. I'm trying to configure a pic18f4550 + crystal 20MHz (+ two 15pF capacitors connected as shown in 18f4550 datasheet).

Here is my code:
Code:

#include <18f4550.h>

#fuses HSPLL,NOWDT,NOPROTECT,NOLVP
#fuses NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)

void main(void)
{
while(1)
  {
   output_high(PIN_D0);
   delay_ms(500);
   output_low(PIN_D0);
   delay_ms(500);
  }
}

I'm sure that PLL5, HSPLL, CPUDIV1 and USBDIV are correct, but i don't know how to set properly.

I tested my code in a circuit mounted on a protoboard, but it doesn't work properly. Can anyone please send me a corrected code?

Thanks a lot, and sorry for my bad english :P
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Thu Feb 04, 2016 12:55 pm     Reply with quote

Keep it simple.

Get rid of everything you don't need and make sure it works at 20MHz.
(ie without PLL, USB etc.)

Mike
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Feb 04, 2016 1:07 pm     Reply with quote

These are from a CCS USB example program

#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)

and yours look the same, so hopefully correct.

I did printout the 'clock diagram' to confirm the proper signal paths and with a 20MHz xtal, you do need to div by 5 for the PLL prescaler to get 4MHz to the 96 MHz PLL, that divided by 2 does give the CPU clock of 48Mhz.

Now you could have a wiring problem though I've used white bimboards for decades.

You should create a new 'flashing LED 'program using the internal oscillator block and run at 8MHz. If the program runs then you HAVE a wiring problem, bad xtal, or ?? with the primary oscillator section.
If the internal clock doesn't work, maybe a broken PIC ?

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Fri Feb 05, 2016 2:11 am     Reply with quote

Other things:

1) What smoothing have you got right by the chip?. You need smoothing capacitors right adjacent to the PIC. Always true, and especially on a breadboard...
2) There also needs to be a capacitor on Vusb, or it can/will oscillate.
3) Add the line:

setup_psp(PSP_DISABLED);

Pin D0, is a SPP pin, and this could be overriding it's use.
germans



Joined: 04 Feb 2016
Posts: 11

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

PostPosted: Wed Feb 10, 2016 10:58 pm     Reply with quote

Hey guys, thank you for your help.

I think there is a problem working with 20Mhz crystals in a protoboard. I tried with a 4MHz crystal and it works!
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Thu Feb 11, 2016 2:23 am     Reply with quote

Also, may just be a question of 'what' 20MHz crystal you have?. Cut, recommended loading, gain etc..
The internal capacitance of the board may well be more than it is meant to have, without any added capacitance. Some do need parallel resistors to help them start, and some may need series resistors to avoid overloading the PLL. The PLL on the 4550, is more fussy that the ones on many later chips.
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Feb 11, 2016 6:43 am     Reply with quote

I've used 20MHx xtals on white bimboards for 2 decades, always worked. I think you need 15 Pfd caps for the 4550 xtal ? been awhile since I played with one.

Mr T may be right, could even be a bad xtal

Jay
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion 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