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 CCS Technical Support

Reference Clock Out - dsPIC33CK - SOLVED

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



Joined: 29 Mar 2010
Posts: 15

View user's profile Send private message

Reference Clock Out - dsPIC33CK - SOLVED
PostPosted: Thu Apr 23, 2026 4:40 pm     Reply with quote

Probably dumb question, but I'm looking to use the Reference Clock Out on a dsPIC33CK256MP208 to drive the clock in on a peripheral. I'm not finding information in the CCS C manual. Am I missing it, or do I need to use asm to implement it?

Thanks,


Last edited by jmb1539 on Mon Apr 27, 2026 9:59 am; edited 1 time in total
temtronic



Joined: 01 Jul 2010
Posts: 9641
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Apr 23, 2026 4:48 pm     Reply with quote

While don't use the PIC, but I'd look in the device.H 'header' file to see what CCS has done.
It might be a simple 'set bit to enable ' ??
newguy



Joined: 24 Jun 2004
Posts: 1936

View user's profile Send private message

PostPosted: Thu Apr 23, 2026 4:55 pm     Reply with quote

Just ensure that you don't have the slew rate control enabled for that particular pin. If the processor comes with that ability, the default is for it to be on/enabled.

Learned that the hard way some time ago when I also tried to enable the reference clock out.
jmb1539



Joined: 29 Mar 2010
Posts: 15

View user's profile Send private message

PostPosted: Mon Apr 27, 2026 9:50 am     Reply with quote

I reached out to CCS for their input, they do not have built-in functions for configuring the reference clock output, however they did provide example code to implement the feature.

Code:

#word REFOCONL    =  getenv("SFR:REFOCONL")  // point to REFOCONL SFR
#word REFOCONH    =  getenv("SFR:REFOCONH")  // point to REFOCONH SFR
#word REFOTRIMH   =  getenv("SFR:REFOTRIMH") // point to REFOTRIMH SFR

#pin_select REFCLKO=pin_D15      // map refclko to pin_D15


Code:

void initialize()

   REFOTRIMH=0x0000;             // no frequency trimming
   REFOCONH=0x0004;              // divide ext osc frequency by (2 * 4) -> 8MHz / 8 = 1MHz
   REFOCONL=0x9202;              // enable ref clock
                                 // enable output pin
                                 // switch to divisor set in REFCONH
                                 // set clock source to ext osc
}


This gave the 1MHz output I was looking for, however it was heavily slewed, essentially giving a triangle wave with a DC offset. I initially had mapped REFCLO to C1, which has many analog mappable options, so I changed to RD15, which is digital only and the signal cleared up nicely.
Ttelmah



Joined: 11 Mar 2010
Posts: 20075

View user's profile Send private message

PostPosted: Mon Apr 27, 2026 11:17 am     Reply with quote

Did you read Newguy's reply?.......

This was raised years ago in this thread:
[url]
https://www.ccsinfo.com/forum/viewtopic.php?t=57171&start=15
[/url]

As you see, he was the poster with this problem, which is why he pointed
out exactly what you need to do.
jmb1539



Joined: 29 Mar 2010
Posts: 15

View user's profile Send private message

PostPosted: Tue Apr 28, 2026 6:57 am     Reply with quote

Yes Ttelmah, I did......did you? He said "If the processor comes with that ability...", well guess what, it doesn't so that thread doesn't apply here.
temtronic



Joined: 01 Jul 2010
Posts: 9641
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Apr 28, 2026 9:52 am     Reply with quote

Curious, so downloaded the PDF..
.seems the refout can go to any PPS pin, so the triangular waveform should have been fixed when you disabled the analog peripherals.

Seems analog is the default, though in the beginning all PIC were pure digital,so the default should be digital.
Ttelmah



Joined: 11 Mar 2010
Posts: 20075

View user's profile Send private message

PostPosted: Tue Apr 28, 2026 10:34 am     Reply with quote

Almost certainly there was an analog component left turned on. This is
a classic issue. Also you should be aware that this chip only has about
1/3rd the output drive capability of many of the older PIC's, so the
waveform will become degrade sooner with load than on these chips.

The default on all the PIC's with analog is that they wake with these
functions enabled (think about it, if you are using a pin for an analog
operation, you never want the pin to wake with a logic signal on it,
since this could damage analog circuitry). So I suspect you were not
disabling the analog functions completely on the first pin your tried.
jmb1539



Joined: 29 Mar 2010
Posts: 15

View user's profile Send private message

PostPosted: Tue Apr 28, 2026 11:33 am     Reply with quote

Thanks for the feedback both of you. There wasn't a built in CCS function, so I did what was shown earlier, but in doing so, I didn't explicitly clear the corresponding ANSELx bit as you are assuming. Once I verify the POC for the project, I'll go back and play with that more. The flexibility in the pins will be beneficial and hopefully allow me to get away from the 80-pin device.
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