View previous topic :: View next topic |
Author |
Message |
viki2000
Joined: 08 May 2013 Posts: 233
|
24HJ64GP202 – Clock settings – Internal oscillator |
Posted: Mon May 29, 2017 7:26 am |
|
|
I just make a simple test with 10ms on and 10ms off with 1 pin and I get 17ms on and 17ms off in reality.
I want to set the internal clock to 80MHz using PLL.
I have an error somewhere.
Do you have any suggestions to track it down?
Code: | #include <24HJ64GP202.h>
#FUSES HS
#FUSES FRC_PLL
#FUSES NOWDT // Mo Watch Dog Timer
#FUSES WPRES32 //Watch Dog Timer PreScalar 1:32
#FUSES WPOSTS1 //Watch Dog Timer PostScalar 1:1
#FUSES NOWRTB //Boot block not write protected
#FUSES NOBSS //No boot segment
#FUSES NORBS //No Boot RAM defined
#FUSES NOWRTSS //Secure segment not write protected
#FUSES NOSSS //No secure segment
#FUSES NORSS //No secure segment RAM
#FUSES NOWRT //Program memory not write protected
#FUSES NOPROTECT //Code not protected from reading
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES NOOSCIO //OSC2 is clock output
#FUSES IOL1WAY //Allows only one reconfiguration of peripheral pins
#FUSES CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES WINDIS //Watch Dog Timer in non-Window mode
#FUSES PUT128 //Power On Reset Timer value 128ms
#FUSES NOALTI2C1 //I2C1 mapped to SDA1/SCL1 pins
#FUSES NOJTAG //JTAG disabled
#use delay(internal=80000000)
//#use delay(clock=80000000)
void main()
{
while(TRUE)
{
OUTPUT_HIGH(PIN_B8);
DELAY_MS(10);
OUTPUT_LOW(PIN_B8);
DELAY_MS(10);
}
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19524
|
|
Posted: Mon May 29, 2017 8:44 am |
|
|
You are giving it two conflicting settings. HS is for an external crystal, then saying to use the internal. It falls back to the internal (because the external fails), but hasn't then setup the PLL correctly:
Code: |
#FUSES FRC_PLL
#FUSES NOWDT // Mo Watch Dog Timer
#FUSES WPRES32 //Watch Dog Timer PreScalar 1:32
#FUSES WPOSTS1 //Watch Dog Timer PostScalar 1:1
#FUSES NOWRTB //Boot block not write protected
#FUSES NOBSS //No boot segment
#FUSES NORBS //No Boot RAM defined
#FUSES NOWRTSS //Secure segment not write protected
#FUSES NOSSS //No secure segment
#FUSES NORSS //No secure segment RAM
#FUSES NOWRT //Program memory not write protected
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOIESO //No switchover
#FUSES NOOSCIO //OSC2 is clock output
#FUSES IOL1WAY //Allows only one reconfiguration of peripheral pins
#FUSES WINDIS //Watch Dog Timer in non-Window mode
#FUSES PUT128 //Power On Reset Timer value 128ms
#FUSES NOALTI2C1 //I2C1 mapped to SDA1/SCL1 pins
#FUSES NOJTAG //JTAG disabled
#use delay(internal=80MHz)
|
Correctly programs the PLL for just under 80Mhz (can't quite get it right from 7.37Mhz). |
|
|
viki2000
Joined: 08 May 2013 Posts: 233
|
|
Posted: Mon May 29, 2017 10:07 am |
|
|
I have tried various settings, don't remember exactly what, but I think I have tried also without #FUSES HS and also without #FUSES FRC_PLL, because I have used Wizard for PIC24 and the fuses were generated automatically.
I have used also during the trials #use delay(internal=80MHz) instead of #use delay(internal=80000000), but without good results.
I am aware that cannot be exactly 80MHz, but I just want a proper timing seen at one pin. When I say 10ms on then it should be 10ms or around that, but not 17ms.
I will check one more time tomorrow with your suggestions. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19524
|
|
Posted: Mon May 29, 2017 10:23 am |
|
|
Before posting, I compiled the settings, and with a current compiler (5.071), these correctly set the oscillator and PLL to give just over 79MHz. |
|
|
viki2000
Joined: 08 May 2013 Posts: 233
|
|
Posted: Tue May 30, 2017 12:43 am |
|
|
Something strange happend.
I tried again my initial code, recompiled it today, programmed again the chip and works fine now. I can see the 10ms on and 10ms off on oscilloscope.
I have no idea what was the problem yesterday.
But I understand the HS problem and I removed that fuse.
I tested also your fuses and of course they work too.
There is only one more problem.
I would like to see the clock at one pin. I have the 28 pin SPDIP package, so that should be pin 10, RA3 wher is OSC2/CLKO, but I see no signal there.
What additional settings shall I do besides #FUSES NOOSCIO in order to see Clock Out at OSC2 pin? |
|
|
viki2000
Joined: 08 May 2013 Posts: 233
|
|
Posted: Wed May 31, 2017 1:07 am |
|
|
Can someone double check this for me?
No matter how I set “#FUSES NOOSCIO” or “#FUSES OSCIO”, after compilation in .lst file I see always “OSCIO” in configuration word 5. It is at the end of the .lst file specified as WORD 5L.
I tested with compiler 5.070.
I need to know if it is a bug that must be reported to CCS or perhaps if I need to set the fuses in a certain order.
How can I correct this, in case it is a bug, by forcing that value manually?
In the Device Editor the values for OSCIO and NOOSCIO seem fine:
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19524
|
|
Posted: Wed May 31, 2017 4:13 am |
|
|
Yes...
It is interesting. If you try setting all the bits in this word. So:
It generates:
Code: |
Word 5L: FFFB NOPR OSCIO IOL1WAY
H: 0000
|
However if you look in the device editor, the mask/values for the OSCIO and NOOSCIO fuses are correct.
Now there is a comment in the data sheet that this bit is 'not available in XT or HS modes', but it looks as if somehow it has got set to 'not available' in all modes.... |
|
|
viki2000
Joined: 08 May 2013 Posts: 233
|
|
Posted: Wed May 31, 2017 5:01 am |
|
|
If I set as last fuse:
Then in .lst file I still see:
Code: | Word 5L: 0023 NOPR OSCIO IOL1WAY CKSFSM
H: 0000 |
Which means that OSCIO/NOOSCIO is never changing.
I declare it a bug and I will contact CCS. |
|
|
viki2000
Joined: 08 May 2013 Posts: 233
|
|
Posted: Wed May 31, 2017 5:07 am |
|
|
I was looking in my emails to search CCS contact info and I found a previous explanation from CCS:
Quote: | You can always overwrite the fuses #use delay() makes by placing your fuses after the #use delay() line. |
So I did.
I just placed #use delay(internal=80MHz) before FUSES and after #include <24HJ64GP202.h> and everything works now. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19524
|
|
Posted: Wed May 31, 2017 7:35 am |
|
|
That makes total sense. The default setting for the internal oscillator, is assuming you don't want a clock output.
Never occurred to me that they would include the OSCIO fuse in this override (I know it overrides the oscillator selections, but the I/O one didn't 'click').... |
|
|
|