FRC CLOCK PROBLEM for DSPIC33EP128MC502

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
JustinS
Flowcode v5 User
Posts: 40
Joined: Wed Sep 12, 2012 1:59 pm
Has thanked: 1 time
Been thanked: 7 times

FRC CLOCK PROBLEM for DSPIC33EP128MC502

Post by JustinS »

I have problem with setting DSPIC33EP128MC502 to work with 120MHz.

Below I've included my code and my Project Settings. I would be grateful for any help.
Attachments
Clipboard01.jpg
(204.71 KiB) Downloaded 1852 times
DSPIC33EP128MC502fc-test.fcfx
Project code.
(4.4 KiB) Downloaded 314 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FRC CLOCK PROBLEM for DSPIC33EP128MC502

Post by Benj »

I have some known working code for this.

I'll try and remember to dig it out for you tonight.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FRC CLOCK PROBLEM for DSPIC33EP128MC502

Post by Benj »

This code works for me, adjust the timings as needed.

Code: Select all

//Setup configuration for 138.1875MHz or 69MIPs using 7.37MHz Internal Osc
PLLFBD = 73;// M=75
CLKDIVbits.PLLPOST = 0;// N1=2
CLKDIVbits.PLLPRE = 0;// N2=2
OSCTUN = 0;//Tune FRC oscillator, if FRC is used

//Disable Watch Dog Timer
RCONbits.SWDTEN = 0;// Clock switching to incorporate PLL

__builtin_write_OSCCONH(0x01);// Initiate Clock Switch to FRC

// Oscillator with PLL (NOSC=0b011)
__builtin_write_OSCCONL(0x01);// Start clock switching

while(OSCCONbits.COSC != 0b001);

// Wait for Clock switch to occur
while(OSCCONbits.LOCK != 1);
You also need the right config settings for it to work.
Config.jpg
Config.jpg (185.65 KiB) Viewed 5186 times

JustinS
Flowcode v5 User
Posts: 40
Joined: Wed Sep 12, 2012 1:59 pm
Has thanked: 1 time
Been thanked: 7 times

Re: FRC CLOCK PROBLEM for DSPIC33EP128MC502

Post by JustinS »

Thank you very much! You're a life saver :)

Post Reply