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

[SOLVED] Oscillator setup on dsPIC33FJ128GP202

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



Joined: 12 Feb 2012
Posts: 10

View user's profile Send private message

[SOLVED] Oscillator setup on dsPIC33FJ128GP202
PostPosted: Sun Feb 12, 2012 5:02 pm     Reply with quote

Hi everybody!

I need help to setup the oscillator on my board. I'm using a dsPIC33FJ128GP202 with 40mhz crystal, 22pf load caps, and 1Mohm parallel resistor (as suggested in the datasheet).

I'm having trouble setting up the delay method and other timings.

These are my #FUSES:
Code:

#FUSES PR                      //Primary Oscillator
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES OSCIO                   
#FUSES NOIOL1WAY                //Allows multiple reconfigurations of peripheral pins
#FUSES NOCKSFSM                 //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOWINDIS                 //Watch Dog Timer in Window mode
#FUSES NOPUT                    //No Power Up Timer
#FUSES ICSP2                    //ICD uses PGC2/PGD2 pins
#FUSES NOJTAG                   //JTAG disabled

#use delay(xtal=40000000)

If I want to have a 1ms interrupt I tried to do like this:
Code:

setup_timer1(TMR_INTERNAL | TMR_DIV_BY_1,20000);

TMR_DIV_BY_1 means 40mhz / 2 = 20mhz is that right? instruction time is 2 clocks pulses on dsPIC33.
by setting the period to 20000 i make a 1ms interrupt routine because 20mhz = 50ns -> 50ns * 20000 = 1ms

I tried to blink a led every sec in my ISR routine:
Code:

#int_TIMER1
void TIMER1_isr(void)
{
   if(led_run<500)
   {
   output_high(PIN_RUN);
   
   }
   
   if(led_run>=500)
   {
   output_low(PIN_RUN);
   }
   
   if(led_run++>1000)
   {
      led_run=0;
   }
}

But it doesn't blink at 1s rate, but slower!

Can you help me with all this mess??

I'm also having trouble with the integrated UART, but I suppose it's because of the wrong oscillator setting...

Thanks a lot Smile


Last edited by simonspt on Sat Feb 18, 2012 7:17 am; edited 1 time in total
simonspt



Joined: 12 Feb 2012
Posts: 10

View user's profile Send private message

PostPosted: Thu Feb 16, 2012 6:03 pm     Reply with quote

I tried to setup the internal fast rc oscillator like this:
Code:

#FUSES WPRES32                  //Watch Dog Timer PreScalar 1:32
#FUSES WPOSTS1                  //Watch Dog Timer PostScalar 1:1
#FUSES FRC_PLL                  //Internal Fast RC oscillator with PLL

#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES NOCKSFSM                   //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES NOWINDIS                 //Watch Dog Timer in Window mode
#FUSES PUT128                    //No Power Up Timer
#FUSES ICSP2                    //ICD uses PGC2/PGD2 pins

#use delay(clock=40000000)


and in an inizialization routine i put this:
setup_oscillator( OSC_INTERNAL, 40000000);

and now the timing is correct and the rs232 link is working properly..

well...it's ok now, but i put a crystal in my circuit so i would like to make it work...

anyone has suggestions about that?

thanks!
miro



Joined: 15 Jan 2011
Posts: 62

View user's profile Send private message

PostPosted: Sat Feb 18, 2012 6:33 am     Reply with quote

..40MHz crystal..
The crystals above ~22-25MHz are mostly (or, I would say "always" Sad ) so called "3rd or 5th overtone" one. It means that its fundamental frequency is ie. 1/3 of that seen on the package. Most probably your crystal resonate at 13.333MHz.. M.
simonspt



Joined: 12 Feb 2012
Posts: 10

View user's profile Send private message

PostPosted: Sat Feb 18, 2012 7:02 am     Reply with quote

You're so right!!!! :( I didn't know that! I checked the datasheet of my crystals and it says "operating mode 3rd overtone" that's why...

thanks so much for your explanation, i'll change my crystal to a smaller one and use the internall PLL of the dsPIC..

do you know why they write 40mhz on it even if it oscillates ad 13.33mhz ?
does it means that i would have to add some inductor/capacitor series circuit to make it resonate at 40mhz?
miro



Joined: 15 Jan 2011
Posts: 62

View user's profile Send private message

PostPosted: Sat Feb 18, 2012 7:16 am     Reply with quote

The third or fifth overtone crystals are made up to ~150MHz. The reason why they show ie. 40MHz on the package is the crystal is "cut" to resonate (at 3rd harmonic) "exactly" at 40MHz when connected to an "appropriate" circut. In order to run such a crystal at ie. 40MHz you must have a special designed oscillator circuit with proper impedancies the crystal is connected to (for example you may suppress or force a harmonic frequency with a serial or parallel LC circuit, but the design is tricky).M.
simonspt



Joined: 12 Feb 2012
Posts: 10

View user's profile Send private message

PostPosted: Sat Feb 18, 2012 7:17 am     Reply with quote

thanks for the help Smile
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