|
|
View previous topic :: View next topic |
Author |
Message |
germans
Joined: 04 Feb 2016 Posts: 11
|
PIC18f4550 + Crystal 20MHz --> Problems |
Posted: Thu Feb 04, 2016 12:47 pm |
|
|
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
|
|
Posted: Thu Feb 04, 2016 12:55 pm |
|
|
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: 9255 Location: Greensville,Ontario
|
|
Posted: Thu Feb 04, 2016 1:07 pm |
|
|
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: 19569
|
|
Posted: Fri Feb 05, 2016 2:11 am |
|
|
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
|
|
Posted: Wed Feb 10, 2016 10:58 pm |
|
|
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: 19569
|
|
Posted: Thu Feb 11, 2016 2:23 am |
|
|
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: 9255 Location: Greensville,Ontario
|
|
Posted: Thu Feb 11, 2016 6:43 am |
|
|
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 |
|
|
|
|
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
|