View previous topic :: View next topic |
Author |
Message |
Marco27293
Joined: 09 May 2020 Posts: 126
|
PIC18F46J50 CCS C Compiler 5.090 #use delay doubt |
Posted: Sat May 09, 2020 7:55 am |
|
|
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: 9229 Location: Greensville,Ontario
|
|
Posted: Sat May 09, 2020 8:28 am |
|
|
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
|
|
Posted: Sat May 09, 2020 8:32 am |
|
|
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: 126
|
|
Posted: Sat May 09, 2020 8:43 am |
|
|
What about USB mode and clock? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Sun May 10, 2020 12:34 am |
|
|
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... |
|
|
|