|
|
View previous topic :: View next topic |
Author |
Message |
ik1wvq
Joined: 21 Feb 2004 Posts: 20
|
DSPIC33 and setup_oscillator() problems.. a solution.. |
Posted: Mon Feb 18, 2008 12:28 pm |
|
|
HI all,
i try to use the SETUP_OSCILLATOR function with DS33.
The results was bad, and then i wrote this simple code to program
PLL and switch oscillator.
WARNING: this is valid ONLY for DS33.
Enjoy..
regards
Mauro ik1wvq
PS.: my english is bad, but the code is working!
---------------
// costants for "DS33_OSC_CONFIG()")
// first parameter (only one)
#define Fast_RC_Oscillator 0b00000000
#define Fast_RC_Oscillator_PLL 0b00000001
#define Primary_Oscillator 0b00000010
#define Primary_Oscillator_PLL 0b00000011
#define Secondary_Oscillator 0b00000100
#define Low_Power_RC_Oscillator 0b00000101
#define Fast_RC_Oscillator_Div16 0b00000110
#define Fast_RC_Oscillator_DivN 0b00000111
// second parameter (one or more ORed)
#define switch_osc 0b00000001
#define abil_SEC_OSC_LP 0b00000010
#define lock_modify_pin_IO 0b01000000
#define unlock_modify_pin_IO 0b00000000
void DS33_osc_config(unsigned int16 valueHI,unsigned int16 valueLO)
{
// VALID ONLY FOR DS33
#asm asis
MOV valueHI,w0
MOV #0x743, w1 ; OSCCONH 0x743
MOV #0x78, w2
MOV #0x9A, w3
MOV.B w2, [w1]
MOV.B w3, [w1]
; write valoreHI on OSCCONH
MOV.B w0, [w1]
MOV valueLO, w0
MOV #0x742, w1 ; OSCCONL 0x742
MOV #0x46, w2
MOV #0x57, w3
MOV.B w2, [w1]
MOV.B w3, [w1]
; write valoreLO on OSCCONL
MOV.B w0, [w1]
#endasm
} |
|
|
daraos
Joined: 16 Oct 2008 Posts: 18 Location: Chile
|
|
Posted: Mon Jan 26, 2009 9:30 am |
|
|
Thanks Mauro! that's exactly what I was looking for, the clock in the 33f is a real pain in the neck. Now, what I can't do, is configure the pre, post & clockdiv, the 33f assembler is waaay too much for me. If I can make it work, I'll post my code, or if you already have it, please share!
EDIT:
I made it work
so, the final code to make a 33f work at nearly 40 MIPS with the internal oscillator is:
Code: |
#byte CLKDIV_L=0x0744
#byte CLKDIV_H=0x0745
#byte PLLFBD_L=0x0746
#byte PLLFBD_H=0x0747
//Configure multipliers N1=0, N2=0, M=43
PLLFBD_L=41;
PLLFBD_H=0x00;
CLKDIV_L=0x00;
CLKDIV_H=0x00;
#asm asis
MOV 0x00,w0
MOV #0x743, w1 ;OSCCON_H 0x743
MOV #0x78, w2
MOV #0x9A, w3
MOV.B w2, [w1]
MOV.B w3, [w1]
MOV.B w0, [w1]
MOV 0x01, w0
MOV #0x742, w1 ;OSCCON_L 0x742
MOV #0x46, w2
MOV #0x57, w3
MOV.B w2, [w1]
MOV.B w3, [w1]
;write bit to switch from FRC to FRC_PLL
MOV.B w0, [w1]
#endasm
|
This datasheet has all the info about the clock configuration
http://ww1.microchip.com/downloads/en/DeviceDoc/70186b.pdf
The one I used is a dsPIC33FJ128GP802 |
|
|
logical
Joined: 21 Dec 2009 Posts: 57 Location: SouthPort, UK
|
|
Posted: Wed Mar 31, 2010 8:12 am |
|
|
Hi,
Sorry to dig up and old post but how would I go about using the above.
I have a DSPIC33FJ128GP804
Basically I can get it to run fine on the internal oscillator on 7.37M, as soon as I try to increase the speed using the PLL, problems start.
Even with doing SPI Writes, the clock scores under 2MHZ based on SPI_CLK_DIV_4
I have looked through the datasheets and fully understand the configurations but unsure where to change those values from within PICC.
Even tried with things like:
#use delay(clock=73.7M,internal)
#use delay(clock=73.7M,internal=7.37M) etc
THanks
Chris
Code: |
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOWRTB //Boot block not write protected
#FUSES NOBSS //No boot segment
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#FUSES FRC_PLL //Internal Fast RC Oscillator with PLL Enabled
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES OSCIO //OSC2 is general purpose output
#FUSES NOPR //Pimary oscillaotr disabled
#FUSES NOWINDIS //Watch Dog Timer in Window mode
#FUSES WPRES128 //Watch Dog Timer PreScalar 1:128
#FUSES WPOSTS16 //Watch Dog Timer PostScalar 1:32768
#FUSES PUT64 //Power On Reset Timer value 128ms
#FUSES IOL1WAY //Allows only one reconfiguration of peripheral pins
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NORSS //No secure segment RAM
#FUSES NOSSS //No secure segment
#FUSES NOWRTSS //Secure segment not write protected
#FUSES NORBS //No Boot RAM defined
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOCOE //Device will reset into operational mode
#FUSES NOJTAG //JTAG disabled
#FUSES ICSP3 //ICD uses PGC3/PGD3 pins
#FUSES NOALTI2C //I2C mapped to alternate pins
#use delay(clock=73.7M,internal) |
|
|
|
daraos
Joined: 16 Oct 2008 Posts: 18 Location: Chile
|
|
Posted: Wed Mar 31, 2010 9:14 am |
|
|
Try pasting the code I posted inside the main. The delay should be clock=40M
The pic must start slow and in the code you must increase the speed. so, do it like this:
Code: |
//put all your fuses here
void main(){
///////////////////////////////////
//init your variables here
///////////////////////////////////
//this code sets the multipliers
#byte CLKDIV_L=0x0744
#byte CLKDIV_H=0x0745
#byte PLLFBD_L=0x0746
#byte PLLFBD_H=0x0747
//Configure multipliers N1=0, N2=0, M=43
PLLFBD_L=41;
PLLFBD_H=0x00;
CLKDIV_L=0x00;
CLKDIV_H=0x00;
#asm asis
MOV 0x00,w0
MOV #0x743, w1 ;OSCCON_H 0x743
MOV #0x78, w2
MOV #0x9A, w3
MOV.B w2, [w1]
MOV.B w3, [w1]
MOV.B w0, [w1]
MOV 0x01, w0
MOV #0x742, w1 ;OSCCON_L 0x742
MOV #0x46, w2
MOV #0x57, w3
MOV.B w2, [w1]
MOV.B w3, [w1]
;write bit to switch from FRC to FRC_PLL
MOV.B w0, [w1]
#endasm
////////////////////////
//here you put your code. for example:
while(TRUE){
output_toogle(pin_b0);
}
//this code should give you a 5MHz pulse in pin B0 (I think, could be faster or slower :P), that's because the code use several instructions per pulse.
}
|
If the code don't do anything, try reducing PLLFBD_L=41; to 40, 39, 38, etc, that will make the pic slower but more stable.
That's all the help I can give you, I haven't used that pic in a long time and don't have the code with me |
|
|
logical
Joined: 21 Dec 2009 Posts: 57 Location: SouthPort, UK
|
|
Posted: Wed Mar 31, 2010 9:34 am |
|
|
Fantastic thanks, will give that a try later this evening and will post the result. |
|
|
petiot
Joined: 28 Jun 2010 Posts: 5
|
this code should do it |
Posted: Mon Jun 28, 2010 8:28 am |
|
|
hi,
Looking at the assembly generated, this code should do it. I have not tried it though.
Code: |
/* PLL special function registers*/
#byte CLKDIV_L=0x0744
#byte CLKDIV_H=0x0745
#byte PLLFBD_L=0x0746
#byte PLLFBD_H=0x0747
#byte OSCCON_H=0x0743
#byte OSCCON_L=0x0742
#bit OSWEN=OSCCON_L.0
#bit LOCK= OSCCON_L.5
void switch_osc()
{
//Configure PLL N1=0, N2=0, M=43 for 40MIPS 80Mhz operation
PLLFBD_L=41;
PLLFBD_H=0x00;
CLKDIV_L=0x00;
CLKDIV_H=0x00;
OSCCON_H=0x78; //OSCON_H unlock
OSCCON_H=0x9A;
OSCCON_H=0x01; //sets NOSC bits for FRC with PLL
OSCCON_L=0x46; //OSCON_L unlock
OSCCON_L=0x57;
OSCCON_L=0x01;
while(OSWEN==1);
}
|
regards,
serge |
|
|
|
|
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
|