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

PIC24F Oscillator Output PIN Problem

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



Joined: 20 Dec 2023
Posts: 5

View user's profile Send private message Send e-mail AIM Address

PIC24F Oscillator Output PIN Problem
PostPosted: Wed Dec 20, 2023 12:41 am     Reply with quote

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: 1912
Location: Norman, OK

View user's profile Send private message

PostPosted: Wed Dec 20, 2023 4:55 am     Reply with quote

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: 19231

View user's profile Send private message

PostPosted: Wed Dec 20, 2023 10:32 am     Reply with quote

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: 5

View user's profile Send private message Send e-mail AIM Address

PostPosted: Thu Dec 21, 2023 12:03 am     Reply with quote

@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: 19231

View user's profile Send private message

PostPosted: Thu Dec 21, 2023 2:38 am     Reply with quote

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: 5

View user's profile Send private message Send e-mail AIM Address

PostPosted: Tue Dec 26, 2023 10:04 am     Reply with quote

@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: 19231

View user's profile Send private message

PostPosted: Tue Dec 26, 2023 10:32 am     Reply with quote

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: 9117
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Dec 26, 2023 10:45 am     Reply with quote

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: 5

View user's profile Send private message Send e-mail AIM Address

PostPosted: Tue Dec 26, 2023 10:46 am     Reply with quote

@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: 289

View user's profile Send private message

PostPosted: Tue Dec 26, 2023 10:55 am     Reply with quote

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: 9117
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Dec 26, 2023 1:29 pm     Reply with quote

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: 5

View user's profile Send private message Send e-mail AIM Address

PostPosted: Wed Dec 27, 2023 1:56 am     Reply with quote

@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: 19231

View user's profile Send private message

PostPosted: Wed Dec 27, 2023 2:37 am     Reply with quote

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.
Very Happy

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.
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