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

DSPIC33EP512GP806 clock setup question

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



Joined: 20 Jul 2011
Posts: 21
Location: Finland

View user's profile Send private message

DSPIC33EP512GP806 clock setup question
PostPosted: Thu Jun 26, 2014 1:16 pm     Reply with quote

Hello!
Is this correct way to set up external crystal for that chip?
External crystal is 10Mhz

Code:

#include <33EP512GP806.h>
#device adc=10
//#device PSV=16         //program storage visibility

#FUSES NOWRT            //Program memory not write protected
#FUSES HS               //Crystal Oscillator High Speed
#FUSES NOWDT            //No Watch Dog Timer
#FUSES NOPUT            //No Power Up Timer
#FUSES NOJTAG            //JTAG disabled
#FUSES PR_PLL            //Primary Oscillator w/ PLL
#FUSES NODEBUG

#use delay(clock=140Mhz)


And if i want setup hardware SPI2 is this correct way?
Code:

setup_spi2(SPI_MASTER | SPI_L_TO_H | SPI_XMIT_L_TO_H | SPI_CLK_DIV_4);


My compiler is PCWHD 5.015 and i use MPLAB 8.92
MikeP



Joined: 07 Sep 2003
Posts: 49

View user's profile Send private message

PostPosted: Thu Jun 26, 2014 11:45 pm     Reply with quote

Code:
#use delay(xtal=10m, clock=40Mhz)


Not sure if the PLL can up the xtal by 14x?
TMLtech



Joined: 20 Jul 2011
Posts: 21
Location: Finland

View user's profile Send private message

PostPosted: Fri Jun 27, 2014 2:14 am     Reply with quote

MikeP wrote:
Code:
#use delay(xtal=10m, clock=40Mhz)


Not sure if the PLL can up the xtal by 14x?

I dont know but that chip max speed is 70mips.
TMLtech



Joined: 20 Jul 2011
Posts: 21
Location: Finland

View user's profile Send private message

PostPosted: Fri Jun 27, 2014 4:12 am     Reply with quote

I try to use ccsc tcp/ip stack with enc28j60. Processor starts but my tcpip stackinit hangs. I changed hwsetup and add that SPI2.
TMLtech



Joined: 20 Jul 2011
Posts: 21
Location: Finland

View user's profile Send private message

PostPosted: Sat Aug 02, 2014 3:39 pm     Reply with quote

Hello I still try to use primary clock at 140Mhz and 10Mhz crystal. But that setup doesn't work..

Code:

#FUSES NOWRT            
#FUSES HS               
#FUSES NOWDT            //No Watch Dog Timer
#FUSES NOPUT            //No Power Up Timer
#FUSES NOJTAG            //JTAG disabled
#FUSES PR_PLL            //Primary Oscillator w/ PLL
#FUSES NODEBUG

#use delay(clock=140MHZ, crystal=10MHZ)


Processor running very slowly..

Thanks for your help.
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Aug 02, 2014 5:31 pm     Reply with quote

I don't use that PIC but...

Have you got MPLAB 'build configuration' set you 'release' and NOT 'debug' ?

hth
jay
TMLtech



Joined: 20 Jul 2011
Posts: 21
Location: Finland

View user's profile Send private message

PostPosted: Sun Aug 03, 2014 4:01 am     Reply with quote

Yes it is release mode.
Ttelmah



Joined: 11 Mar 2010
Posts: 19495

View user's profile Send private message

PostPosted: Sun Aug 03, 2014 6:28 am     Reply with quote

Are you sure the crystal actually is starting?.

Start with PUT enabled. This is really wanted for a crystal.

Do a basic test just with HS, and PR (no PLL), and turn off fail safe clock monitoring. Does the chip start and run at 10MHz?.

My guess would be that the crystal oscillator is not running, and it is 'failing safe' back to the internal oscillator.

If it doesn't then run, look carefully around your crystal. Sure the capacitors are correct?. Add a large resistor across the crystal (3MR). If the supply rise time is slow, the crystal sometimes won't start. Could the crystal be over-driving?. Some with high gains, need a series resistor.

Keep it 'really simple' a flash an LED test, and get the oscillator running correctly before trying anything else.

And, 'yes' the PLL circuit on this can give 14*.

It needs PLLPRE=0, PLLDIV=54, PLLPOST=0.
This gives incoming clock /2 (PLLPRE+2), 5MHz into the main PLL. Then *56 (PLLDIV + 2), to give 280MHz out of the PLL, which is then divided by 2*(PLLPOST+1) (2), to give 140MHz.

It does work, with the OSC/CRYSTAL settings already given, which is why I think the oscillator is not actually running.
TMLtech



Joined: 20 Jul 2011
Posts: 21
Location: Finland

View user's profile Send private message

PostPosted: Sun Aug 03, 2014 5:45 pm     Reply with quote

Ttelmah wrote:
Are you sure the crystal actually is starting?.

Start with PUT enabled. This is really wanted for a crystal.

Do a basic test just with HS, and PR (no PLL), and turn off fail safe clock monitoring. Does the chip start and run at 10MHz?.

My guess would be that the crystal oscillator is not running, and it is 'failing safe' back to the internal oscillator.

If it doesn't then run, look carefully around your crystal. Sure the capacitors are correct?. Add a large resistor across the crystal (3MR). If the supply rise time is slow, the crystal sometimes won't start. Could the crystal be over-driving?. Some with high gains, need a series resistor.

Keep it 'really simple' a flash an LED test, and get the oscillator running correctly before trying anything else.

And, 'yes' the PLL circuit on this can give 14*.

It needs PLLPRE=0, PLLDIV=54, PLLPOST=0.
This gives incoming clock /2 (PLLPRE+2), 5MHz into the main PLL. Then *56 (PLLDIV + 2), to give 280MHz out of the PLL, which is then divided by 2*(PLLPOST+1) (2), to give 140MHz.

It does work, with the OSC/CRYSTAL settings already given, which is why I think the oscillator is not actually running.


Hello Mr Ttelmah
I just measured that crystal with oscilloscope (very poor one) and i saw sine wave on that crystal.

I try to set these fuse's tomorrow.

That probably works OK. (internal clock)
Code:

#fuses NOWDT,NOPROTECT,NOPR
#use delay(clock = 7372800)


And main:
Code:

output_high (LED1);
delay_ms(1000);
output_low (LED1);
delay_ms(1000);
Ttelmah



Joined: 11 Mar 2010
Posts: 19495

View user's profile Send private message

PostPosted: Mon Aug 04, 2014 3:00 am     Reply with quote

Have not got 5.015, but have .014, and .016.

Can confirm on both these, that they correctly set FNOSC, POSCMD, all the prescalers and postscalers, to select S3 as the clock, with *14.
Code used to test:
Code:

#include <33EP256GP806.h> //256, not 512 for me.
#device adc=10

#FUSES NOWRT            //Program memory not write protected
#FUSES HS                   //Crystal Oscillator High Speed
#FUSES NOWDT            //No Watch Dog Timer
#FUSES PUT2                //Power Up Timer 2mSec
#FUSES NOJTAG            //JTAG disabled
#FUSES PR_PLL             //Primary Oscillator w/ PLL
#FUSES NODEBUG

#use delay(clock=140Mhz, crystal=10MHz)

void main(void)
{
   do
   {
      output_toggle(PIN_B0);
   } while (TRUE);
}

Measuring 17.5MHz on B0.

Takes a few cycles for the clock to stabilise. It is starting using FRC, and then switching to the PLL after a moment.

On mine, the parallel resistor across the crystal, is 1MR, and this is the value recommended in the data sheet for this chip.:
"If the oscillator is used with XT or HS modes, an external parallel resistor with the value of 1 M must be connected."

Are you sure your programmer is actually programming the configuration words?. The default for an erased device, is FRC.

If your crystal is high gain, try using XT, not HS. 10Mhz, is the 'changeover' frequency on these chips, and if the crystal gain is high, it can result in the PLL not locking.
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