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 support@ccsinfo.com

18F27J53 USB + quartz 20MHz issue

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



Joined: 30 Jan 2012
Posts: 218

View user's profile Send private message

18F27J53 USB + quartz 20MHz issue
PostPosted: Sun May 11, 2014 2:15 pm     Reply with quote

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: 19447

View user's profile Send private message

PostPosted: Sun May 11, 2014 2:28 pm     Reply with quote

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: 218

View user's profile Send private message

PostPosted: Sun May 11, 2014 2:38 pm     Reply with quote

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: 19447

View user's profile Send private message

PostPosted: Mon May 12, 2014 1:24 am     Reply with quote

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: 218

View user's profile Send private message

PostPosted: Mon May 12, 2014 1:47 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon May 12, 2014 1:57 am     Reply with quote

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: 218

View user's profile Send private message

PostPosted: Mon May 12, 2014 2:01 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon May 12, 2014 2:18 am     Reply with quote

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: 218

View user's profile Send private message

PostPosted: Mon May 12, 2014 2:26 am     Reply with quote

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: 218

View user's profile Send private message

PostPosted: Mon May 12, 2014 7:30 am     Reply with quote

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: 19447

View user's profile Send private message

PostPosted: Mon May 12, 2014 8:04 am     Reply with quote

PLL12!....
You can only use PLL12 with an external oscillator not a crystal, at 48MHz.
spilz



Joined: 30 Jan 2012
Posts: 218

View user's profile Send private message

PostPosted: Mon May 12, 2014 8:07 am     Reply with quote

it was to test...
same timing with PLL5

CONFIG1 -> 0x07A6
CONFIG2 -> 0x0FF5
CONFIG3 -> 0x0BFF
CONFIG4 -> 0x0BFF
spilz



Joined: 30 Jan 2012
Posts: 218

View user's profile Send private message

PostPosted: Mon May 19, 2014 2:34 am     Reply with quote

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: 19447

View user's profile Send private message

PostPosted: Mon May 19, 2014 3:25 am     Reply with quote

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'.
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