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

PIC18F46J50 CCS C Compiler 5.090 #use delay doubt

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



Joined: 09 May 2020
Posts: 115

View user's profile Send private message

PIC18F46J50 CCS C Compiler 5.090 #use delay doubt
PostPosted: Sat May 09, 2020 7:55 am     Reply with quote

Reviewing a PIC18F46J50 firmware I found this setting:
Code:
#use delay(internal=48MHz,restart_wdt,ACT=USB)

The PIC and USB communication seem to work fine, but does it actually work at 48Mhz?

What is actual USB module clock?
Is USB as default set to Low-Speed mode?

I thought the correct setting was:
Code:
#use delay(internal=8MHz,clock=48MHz,restart_wdt,ACT=USB)

There is any difference?

Compiler version is CCS C 5.090

Regards,

Marco
temtronic



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

View user's profile Send private message

PostPosted: Sat May 09, 2020 8:28 am     Reply with quote

I downloaded the datasheet to see how the clock is in the die...

Since you're using that PIC ,you should create 2 small programs/compile/ then look at the listing file.

While the 2nd is seems correct(int RC clk is 8MHz), it could be the compiler is smart enough to 'recode' the 1st version and set/clr the proper bits in the proper registers.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat May 09, 2020 8:32 am     Reply with quote

I compiled both with vs. 5.093 and got identical fuses at the end of the
.LST files, and identical start-up code at the beginning of main().
Marco27293



Joined: 09 May 2020
Posts: 115

View user's profile Send private message

PostPosted: Sat May 09, 2020 8:43 am     Reply with quote

What about USB mode and clock?
Ttelmah



Joined: 11 Mar 2010
Posts: 19260

View user's profile Send private message

PostPosted: Sun May 10, 2020 12:34 am     Reply with quote

Low speed operation is only available with a 24MHz clock.
From the data sheet:
Quote:

All clock frequencies, except 24 MHz, are exclusively associated with
full-speed USB operation (USB clock of 48 MHz).


Now there is a big issue. Your PIC (J50), does not have active clock tuning
for the USB (The K50 has this, but not the J50). This is required for
full speed USB to be reliable without a crystal. The compiler is not
complaining, since it just sets the bits that are meant to do this, but
does not know they do not work. So you might as well remove the
setting ACT=USB. This is doing nothing.
Your chip though is specifically specified to have an internal oscillator
that meets the low speed USB timing requirements, but it does not meet
the full speed requirements. So though it is working, it is likely to
be unreliable with different chips, and when the temperature changes.
If you want full speed, you need to either use a crystal, or change
to a chip that does support ACT.

If you look at the top of the data sheet for a chip with this, you see:
Quote:

Crystal-less Full Speed (12 Mb/s) and Low-Speed
Operation (1.5 Mb/s)

and in the sheet:
Quote:

Active Clock Tuning: This option allows the
internal oscillator to automatically tune itself to
match USB host or external 32.768 kHz
secondary oscillator clock sources. Full-speed
USB operation can now meet specification
requirements without an external crystal, enabling
lower-cost designs.


This is missing from your sheet... Sad
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