| View previous topic :: View next topic |
| Author |
Message |
jmb1539
Joined: 29 Mar 2010 Posts: 15
|
| Reference Clock Out - dsPIC33CK - SOLVED |
Posted: Thu Apr 23, 2026 4:40 pm |
|
|
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
|
|
Posted: Thu Apr 23, 2026 4:48 pm |
|
|
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
|
|
Posted: Thu Apr 23, 2026 4:55 pm |
|
|
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
|
|
Posted: Mon Apr 27, 2026 9:50 am |
|
|
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
|
|
 |
jmb1539
Joined: 29 Mar 2010 Posts: 15
|
|
Posted: Tue Apr 28, 2026 6:57 am |
|
|
| 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
|
|
Posted: Tue Apr 28, 2026 9:52 am |
|
|
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
|
|
Posted: Tue Apr 28, 2026 10:34 am |
|
|
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
|
|
Posted: Tue Apr 28, 2026 11:33 am |
|
|
| 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. |
|
 |
|