View previous topic :: View next topic |
Author |
Message |
spilz
Joined: 30 Jan 2012 Posts: 220
|
18F27J53 USB + quartz 20MHz issue |
Posted: Sun May 11, 2014 2:15 pm |
|
|
hello,
i'm trying to use a 18F27J53 with a quartz 20MHz for USB project.
I think I have to use clock PLL at 48MHz for USB.
But I don't find a good fuses configuration :(
I try this : Code: | #include <18F27J53.h>
#device ADC=16
#fuses HSPLL,NOCPUDIV, PLL12, PLLEN
#use delay(clock=48MHz,crystal=20MHz,USB_FULL)
void main(void)
{
while(true){
output_high(pin_b7);
delay_ms(500);
output_low(pin_b7);
delay_ms(500);
}
}
|
but it does not blink every second, it's about 3s
do you have any suggestion for my problem ?
thanks for your help
Spilz
Last edited by spilz on Sun May 11, 2014 2:32 pm; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19588
|
|
Posted: Sun May 11, 2014 2:28 pm |
|
|
I'd suspect 4 seconds.
Call setup_oscillator to turn the PLL on.
On this chip, 'HSPLL' means _software controllable PLL_. It has to be enabled in the code.
I'd also explicitly select CPUDIV.
Code: |
#include <18F27J53.h>
#device ADC=16
#fuses HSPLL,PLL5,NOCPUDIV
#use delay(clock=48MHz,USB_FULL)
void main(void)
{
setup_oscillator(OSC_PLL_ON);
while(true){
output_high(pin_b7);
delay_ms(500);
output_low(pin_b7);
delay_ms(500);
}
}
|
This runs at the correct speed for me. |
|
|
spilz
Joined: 30 Jan 2012 Posts: 220
|
|
Posted: Sun May 11, 2014 2:38 pm |
|
|
hi,
thanks for your quick reply,
unfortunately it doesn't solve the problem for me :(
do you use a 20Mhz quartz and be able to run it at 48MHz ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19588
|
|
Posted: Mon May 12, 2014 1:24 am |
|
|
Yes.
Have used exactly that chip at that clock rate.
Are you sure your crystal is oscillating correctly?. Do a basic test without the PLL, just HS, and NOCPUDIV, and verify that the chip runs at 20MHz. I'd suspect your oscillator is not running properly, and the chip is dropping back to the internal RC and running at 16MHz. This would explain the 3 seconds..... |
|
|
spilz
Joined: 30 Jan 2012 Posts: 220
|
|
Posted: Mon May 12, 2014 1:47 am |
|
|
Hi,
I try this : Code: | #fuses HS,NOCPUDIV
#use delay(clock=20MHz)
|
It works well, but It's not enouth for USB :( |
|
|
oxo
Joined: 13 Nov 2012 Posts: 219 Location: France
|
|
Posted: Mon May 12, 2014 1:57 am |
|
|
If Ttelmah's code does not solve your problem, then you must have something else wrong.
p36 of the datasheet shows how you get 48 MHz from a 20 MHz crystal. |
|
|
spilz
Joined: 30 Jan 2012 Posts: 220
|
|
Posted: Mon May 12, 2014 2:01 am |
|
|
Hi,
to OXO : thanks for your help, I will read it ...
to Ttelmah : is there a way you send the .hex file where you blink the led on pin_b7 to try it and see if it comes from my hardware ... |
|
|
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
|
Posted: Mon May 12, 2014 2:18 am |
|
|
If the Ttelmah's code doesn't run as you expect to, then the problem is probably in the compiller. May be the PLL block doesn't work correctly, try another chip (nevertheless I don't believe that).
What the compiler version is? _________________ A person who never made a mistake never tried anything new. |
|
|
spilz
Joined: 30 Jan 2012 Posts: 220
|
|
Posted: Mon May 12, 2014 2:26 am |
|
|
Hi,
I'm using V5.015
I tried to change PLL rate, but nothing change,
I guess it run at 20MHz and think it's 48MHz, that why it doen't blink every second but evry 2.4s ... |
|
|
spilz
Joined: 30 Jan 2012 Posts: 220
|
|
Posted: Mon May 12, 2014 7:30 am |
|
|
When I use this : Code: | #fuses HSPLL,PLL12,NOCPUDIV,PLLEN
#use delay(clock=48MHz) |
I have with my programer this configuration :
CONFIG1 -> 0x07A0
CONFIG2 -> 0x0FF5
CONFIG3 -> 0x0BFF
CONFIG4 -> 0x0BFF
do you have the same ?
Is it the good config ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19588
|
|
Posted: Mon May 12, 2014 8:04 am |
|
|
PLL12!....
You can only use PLL12 with an external oscillator not a crystal, at 48MHz. |
|
|
spilz
Joined: 30 Jan 2012 Posts: 220
|
|
Posted: Mon May 12, 2014 8:07 am |
|
|
it was to test...
same timing with PLL5
CONFIG1 -> 0x07A6
CONFIG2 -> 0x0FF5
CONFIG3 -> 0x0BFF
CONFIG4 -> 0x0BFF |
|
|
spilz
Joined: 30 Jan 2012 Posts: 220
|
|
Posted: Mon May 19, 2014 2:34 am |
|
|
Hi,
After reading the datasheet, I understand p535 that I can't use a quartz at 20MHz, I have to use an external clock.
Or I have to use a 16MHz quartz with PLL4.
Do I understand right? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19588
|
|
Posted: Mon May 19, 2014 3:25 am |
|
|
For specified operation, yes.
Personally I always try to use 8Mhz.
There is no point in running the oscillator faster than you need (more power consumption, and RF noise). The PLL, seems to prefer running off a divided input on some chips (hence I ignore 4MHz).
Most of the oscillators on the PIC's are rated to go to 25Mhz, but this one is the exception, being rated to 16MHz max. However most seem to actually work to 20Mhz, if the crystal gain is high, but they you are 'out of spec'.
Many do run (every one I've seen), with a 20MHz crystal.
Microchip actually supplied a batch to a customer, who was updating an existing design that used a 20MHz crystal, and certified these to work with this, but your failure, suggests that:
1) Your crystal may have a rather low gain.
2) Your particular PIC's may be bottom end of the spec's here.
3) The ability is affected by supply voltage, temperature etc., so your design may just be 'not helping'.
However for good reliability, bringing the chip inside it's specification, is the 'way to go'. |
|
|
|