View previous topic :: View next topic |
Author |
Message |
Mrinmoy
Joined: 20 Dec 2023 Posts: 15
|
PIC24F Oscillator Output PIN Problem |
Posted: Wed Dec 20, 2023 12:41 am |
|
|
Hi,
I am using PIC24FJ512GL406 in one of my projects using CCS compiler version 5.101. I am trying to use PIN No. 40 of above mentioned IC as GPIO; type Output. But as per the datasheet by default, the pin is an OSC2/CLKO type PIN which always gives oscillator frequency. I want to use the PIN as general output using CCS compiler. Is it possible? if Yes then how?
Thanks in advance. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Wed Dec 20, 2023 4:55 am |
|
|
Assuming you are not using an Xtal look in the PICC directory at the file
Fuses.txt, line 365 OSCIO fuse. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Wed Dec 20, 2023 10:32 am |
|
|
Post your clock setup and fuses.
It should not default to outputing the clock unless you are using a setting
that enables this. |
|
|
Mrinmoy
Joined: 20 Dec 2023 Posts: 15
|
|
Posted: Thu Dec 21, 2023 12:03 am |
|
|
@Ttelmah
Code: |
#pragma fuses EC,XT,HS,PR,NOPROTECT,WDT,NOBROWNOUT,DEBUG,CKSNOFSM,NOJTAG,NOWRT
#pragma use delay(clock=32000000,restart_wdt)
|
Above code is my fuse bits and clock setup.
only using OSCIO fuse bit is not the solve. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Thu Dec 21, 2023 2:38 am |
|
|
Er. Your fuses are insane.
You are telling the chip you want to use the slow speed crystal oscillator,
the high speed crystal, and an external clock. All at once. Not surprising
the compiler throws a wobbly.....
Read up on how the oscillator needs to be setup (examples, and here). |
|
|
Mrinmoy
Joined: 20 Dec 2023 Posts: 15
|
|
Posted: Tue Dec 26, 2023 10:04 am |
|
|
@Ttelmah
I can't find this exactly. Can you help me to setup fuse bits where I am using an external oscillator circuit to generate a clock of 32MHz for the PIC24F family microcontroller. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Tue Dec 26, 2023 10:32 am |
|
|
First thing, do you need 32MHz for something else?. If not, then think
again and use a slower oscillator. Having such a fast external oscillator
running round your board increases RF noise. The key is that the PIC
has an internal PLL which can generate it's operating frequency from
a slower clock. 4 or 8MHz is all you need, and you can still run at 32MHz.
So, 'think again', unless the 32MHz is needed for something else.
For operating from a 4MHz external oscillator:
Code: |
#include <24FJ512GL406.h>
#device ICSP=1
#use delay(CLOCK=32MHz,OSCILLATOR=4MHz)
#FUSES NOWDT, CKSFSM, BROWNOUT
|
Using the keyword 'OSCILLATOR' tells the compiler to setup for an
external oscillator at this frequency. It'll select PR_PLL, and generate
32MHz from this.
If you must use 32MHz externally, then simply:
Code: |
#include <24FJ512GL406.h>
#device ICSP=1
#use delay(oscillator=32MHz)
#FUSES NOWDT, CKSFSM, BROWNOUT
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Tue Dec 26, 2023 10:45 am |
|
|
Possible option ?
I'm pretty sure that PIC has an internal oscillator,so that may work for you, providing you don't need super accurate timing that only an external crystal or
module can give. It also could possibly free up TWO I/O pins ??
Check the datasheet though ! Not all PICs were created equally !! |
|
|
Mrinmoy
Joined: 20 Dec 2023 Posts: 15
|
|
Posted: Tue Dec 26, 2023 10:46 am |
|
|
@Ttelmah
Your point is good and make me rethink about the clock setup for our control boards. But I am little confused; in your fuse bits there is no oscillator source
selection bits and their types like HS or XT or EC.
Also please draw some light on my main question to use OSC output PIN as GPIO.
Please pardon me if I am asking any dumb questions. |
|
|
gaugeguy
Joined: 05 Apr 2011 Posts: 303
|
|
Posted: Tue Dec 26, 2023 10:55 am |
|
|
the #use delay( ) command will set the fuses based on what you specify.
You can verify this by compiling the code and looking at the bottom of the list file. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Tue Dec 26, 2023 1:29 pm |
|
|
my comment.
Pretty sure Mr.T is letting the compiler to set the 'clock' fuses as it thinks best. |
|
|
Mrinmoy
Joined: 20 Dec 2023 Posts: 15
|
|
Posted: Wed Dec 27, 2023 1:56 am |
|
|
@Gaugeguy & @temtronic
Now it is clear to me. For clock selection fuse bits the #use delay() command will automatically set that. No need to specify it explicitely. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Wed Dec 27, 2023 2:37 am |
|
|
Yes.
Four specific keywords. CRYSTAL, OSCILLATOR, INTERNAL and RC.
The first will setup the crystal oscillator. Using XT for a low speed oscillator,
and HS for a fast one. OSCILLATOR says you have an external oscillator
(the one for you). INTERNAL uses the internal oscillator. RC says you are
using an external RC (very rare now).
Now your original fuses were trying to select to use an external oscillator,
a low speed crystal, and a high speed crystal all at once!... It's this type
of mistake that letting the delay statement do the settings avoids.
By default all the #use delay settings default to turning off the clock out.
There is a (pretty much undocumented!...) extra keyword for #use delay
CLOCK_OUT to turn this on if needed.
Using #use delay is right 99.99% of the time. I have in years only seen
about two occasions where it was wrong. There was a classic example
in a recent thread of it being 'right', but the poster thought it was wrong.
It was selecting HS, when the poster thought XT was right. However if
you look at the errata for the chip, this says the chip has a problem with
XT and HS should be selected for anything but the slowest setup!...
Now I point out in this same thread the critical thing. If you want to
override the fuses selected by #use delay for the clock, simply do your
fuse settings _after_ the delay statement.
Also a lot of the more complex chips (DsPIC's etc.), have a PLL that has
to be setup in code, not by fuses. Hence on these doing the setup with
#use delay becomes essential. Here the statement automatically adds the
setup code to the hidden boot code at the start of the main. Brilliant.
So let the compiler do it's job.
On the internal oscillator, this is good enough for a lot of applications.
There is also another option to this which is needed with USB. 'ACT=USB'.
This enables 'Active Clock Tuning'. A PLL that will synchronise the internal
oscillator to the USB clock when this is attached. Makes it possible to use
the internal oscillator for this which requires a clock much more accurate
than the internal oscillator can manage. This is available on most of the
newer USB chips, but not on the oldest. |
|
|
|