View previous topic :: View next topic |
Author |
Message |
slavka012
Joined: 10 Feb 2012 Posts: 28
|
PIC24F64GA306, can't set #fuses properly |
Posted: Fri Mar 03, 2017 11:44 am |
|
|
Command line:
Code: |
"C:\PROGRA~2\PICC\CCSCON.exe" out="build/default/production\_ext\1472" ../foot-board-main.c +FD +DF +CC +Y=9 +EA +DF +LN +T +A +M +J +EA +Z -P #__PIC24FJ64GA306__=1
|
Compiler version 5.059
The compiler refuses to set initial clock to LPRC if I have a call to Code: |
setup_oscillator( OSC_INTERNAL, 32000000);
| in the code.
if I comment this line I'm getting correct fuses. If I uncomment it, it writes FRCPLL into the fuses.
Why? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19540
|
|
Posted: Fri Mar 03, 2017 1:39 pm |
|
|
FRCPLL is the correct fuse for 32MHz. The internal oscillator only gives 8MHz. To get 32MHz, you have to have the PLL. Sounds as if the compiler is setting the fuses correctly... |
|
|
slavka012
Joined: 10 Feb 2012 Posts: 28
|
|
Posted: Fri Mar 03, 2017 4:06 pm |
|
|
I don't care if it is correct settings for 32MHz.
I want to start chip at a slow clock LPRC. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19540
|
|
Posted: Sat Mar 04, 2017 1:39 am |
|
|
What clock setting do you have?.
The point is that the compiler looks at the clock you are specifying, and if it is above 8MHz, will enable the PLL.
#USE DELAY(INTERNAL=8MHz)
Will give you LPRC operation. |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1354
|
|
Posted: Sat Mar 04, 2017 8:23 am |
|
|
There is a note in the data sheet that when switching to a PLL, you need to enable the non PLL base clock first (it's worded for "between PLL modes", but CCS is applying it to LPRC...which may be correct...I don't know).
Try these settings integrated into your code:
Code: |
#include <24FJ64GA306.h>
#fuses LPRC //Internal low power RC Oscillator
#fuses NOPR //Pimary oscillaotr disabled
#fuses CKSNOFSM //Clock Switching is enabled, fail Safe clock monitor is disabled
#use delay(clock=32000000) //needs to say clock to avoid fuse changes
void main(){
setup_oscillator( OSC_INTERNAL, 8000000); //Enable just FRC first
setup_oscillator( OSC_INTERNAL, 32000000,8000000); //now PLL
while(TRUE){
}
}
|
with 5.067 this gives:
Code: |
Configuration Fuses:
Word 1L: 3F9F WPOSTS16 WDT128 NOWDT WINDIS ICSP1 NOLVR NODEBUG NOWRT NOPROTECT NOJTAG
H: 0000
Word 2L: FD5F NOPR IOL1WAY OSCIO CKSNOFSM LPRC VREFNORM_CVREFNORM IESO
H: 0000
Word 3L: FEFF WPFP VBATBOR SOSC_DIG WDTWIN_25% BROWNOUT WPDIS NOWPCFG WPEND
H: 0000
Word 4L: FFFF DSWDTCK_LPRC DSBOR DSWDT DS_SW
H: 0000
|
I would recommend sending CCS support an email asking why it has to be done this way versus the other and see if they can highlight the reasoning. It may just be a bug or it may actually be required. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19540
|
|
Posted: Sat Mar 04, 2017 8:50 am |
|
|
He says he doesn't want 32Mhz:
Quote: |
I don't care if it is correct settings for 32MHz.
I want to start chip at a slow clock LPRC.
|
But he is setting the clock to 32MHz, then complaining that the compiler is selecting FRCPLL!....
If he simply does:
Code: |
#include <24FJ64GA306.h>
#use delay(INTERNAL=8MHz) //8MHz
|
The compiler correctly turns off the PLL, and selects FRC_PS (RC with postscaler), and selects the postscaler to be 1.
What you are describing is not needed on the current compilers
Code: |
#include <24FJ64GA306.h>
#use delay(INTERNAL=32MHz) //32MHz
|
The compiler select FRC_PLL, and boots directly to 32MHz. It is this that he is complaining about!... |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1354
|
|
Posted: Sat Mar 04, 2017 9:43 am |
|
|
I read their post as they wanted to power on the chip in LPRC and then switch to 32MHz later. That's what I was addressing. I may have read their post wrong though. |
|
|
slavka012
Joined: 10 Feb 2012 Posts: 28
|
|
Posted: Sat Mar 04, 2017 11:47 am |
|
|
jeremiah wrote: | I read their post as they wanted to power on the chip in LPRC and then switch to 32MHz later. That's what I was addressing. I may have read their post wrong though. |
This exactly the scenario. I thought it was fairly obvious. Thank you, I will try your suggestions.
#delay does not seem to have any effect on this. But I will try to add another setup_oscillator call.
Mr. Ttelmah, you should not immediately assume people do something stupid. Maybe you just don't understand. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19540
|
|
Posted: Sat Mar 04, 2017 11:54 am |
|
|
OK. That makes sense. If you are going to do this though, and want clocking to be correct, then just use:
Code: |
#include <24FJ64GA306.h>
#use delay(INTERNAL=8MHz) //boot at 8MHz
//then in the code, when you want the high speed
setup_oscillator(OSC_INTERNAL, OSC_32MHZ);
#use delay(CLOCK=32MHz) //setup 32MHz operation
|
That you can have multiple clock statements is often not realised.
However _caveat_. Anything that is called using timings before the second #use, will have it's timings set for the first statement not the second.
This includes things like #USE RS232. This is why it is worth using a #define to handle re-calculating baud rates to get them right for the second clock. Details of this have been posted here many times. |
|
|
slavka012
Joined: 10 Feb 2012 Posts: 28
|
|
Posted: Mon Mar 06, 2017 7:09 pm |
|
|
jeremiah wrote: |
Try these settings integrated into your code:
|
Thanks a lot, that worked. I guess compiler is trying to be smarter than it is capable of.
I would prefer it to issue a warning if fuses are not set according to the setup_oscillator call instead of overriding them. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19540
|
|
Posted: Tue Mar 07, 2017 1:47 am |
|
|
The compiler just does this sequentially.
If you do the clock settings before the fuses, no override occurs.
If you do the clock setting after the fuses, then if the clock settings contain anything that will affect the fuses (so 'internal' etc.), then these will override the fuses. If you just use 'clock=', then no fuse settings are created.
It's very simple. |
|
|
|