|
|
View previous topic :: View next topic |
Author |
Message |
Oli Guest
|
manually changing oscillator source on PIC24 [how-to] |
Posted: Fri Feb 12, 2010 5:33 am |
|
|
I needed to change the clock source and found the setup_oscillator function inadequate, especially if switching from a non-PLL mode to PLL mode. There is an unlocking sequence that must be followed first and executed in assembly.
The code below changes the NOSC 2:1 bits to 011 to select the oscillator source as primary, with PLL enabled.
Code: | #asm
//;Place the new oscillator selection in W0
MOV.b #0x03, w0 // NOSC2:0 = 011 - primary osc with PLL
//;OSCCONH (high byte) Unlock Sequence
MOV #0x0743,w1
MOV #0x78, w2
MOV #0x9A, w3
//DISI #0x5 // uncomment if you have interrupts enabled
MOV.b w2, [w1]
MOV.b w3, [w1]
//;Set new oscillator selection
MOV.b w0, [w1]
mov #0x01, w0 // clock switching enabled
//;OSCCONL (low byte) unlock sequence
MOV #0x0742,w1
MOV #0x46, w2
MOV #0x57, w3
//DISI #0x5 // uncomment if you have interrupts enabled
MOV.b w2, [w1]
MOV.b w3, [w1]
//;Start oscillator switch operation
MOV.b w0, [w1]
#endasm |
EDIT: The values 0x0742 and 0x0742 are the addresses for the OSCCON high and low bytes on the PIC24FJ256GB110
Last edited by Oli on Fri Feb 12, 2010 8:44 am; edited 2 times in total |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Fri Feb 12, 2010 7:27 am |
|
|
Yes, curiously CCS PCD is using a non-operational unlocking sequence in some places. The below code (used in PCD #PIN_SELECT code) does not work, because W0 is loaded between both writes to the unlock register. In this case, the pin select register shall be proteceted, but they aren't.
Code: | 00334: MOV #46,W0
00336: MOV.B W0L,742
00338: MOV #57,W0
0033A: MOV.B W0L,742
0033C: BSET.B 742.6 |
|
|
|
|
|
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
|