beautypg.com

Cpu clock source – Digilent 410-185P-KIT User Manual

Page 10

background image

Cerebot MC7 Reference Manual

www.digilentinc.com

page 10 of 21

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.

LEDs, set the desired bits as outputs by
clearing the corresponding bits in the TRISD
register and set the bits to the desired value in
the PORTD or LATD register. Setting a bit to 1
will illuminate the LED and setting the bit to 0
will turn it off.

Note that PORTD bits 4-7 are also used by
Pmod connector JC and by four of the RC
servo connectors.

CPU Clock Source


The dsPIC microcontroller on the Cerebot MC7
supports numerous clock source options for
the main processor operating clock. The
Cerebot MC7 board provides an external 8Mhz
crystal for use with the XT oscillator option.
This crystal is on the bottom of the board.
Oscillator options are selected via
configuration macros supplied as part of the
Microchip C30 compiler suite for the dsPIC.

In addition to the crystal oscillator using the
external 8Mhz, the dsPIC microcontroller also
has an internal 8Mhz RC oscillator. It also
provides the capability to switch clock source
and clock speed during operation.

Using the internal system clock phase-locked
loop (PLL), it is possible to select numerous
multiples or divisions of the 8Mhz oscillator to
produce CPU operating frequencies up to
40Mhz. The operating frequency can be
selected using configuration macros. Refer to
section 9.1 CPU Clocking System in the data
sheet for the
dsPIC33FJXXXMCX06A/X08A/X10A family
devices for information on how to set up the
clock source and operating frequency.

The following example code will set the
clocking options for operation at 40 MIPS.

/* The settings below set up the oscillator and PLL for 40 MIPS as
**follows:
** Crystal Frequency * (DIVISOR+2)
** Fcy = ---------------------------------
** PLLPOST * (PRESCLR+2) * 4

** Crystal = Defined in UserParms.h

** Fosc

= Crystal * dPLL defined in UserParms.h

** Fcy

= DesiredMIPs

*/


PLLFBD = (int)(40 - 2);

CLKDIVbits.PLLPOST = 0;

// N1=2

CLKDIVbits.PLLPRE = 0;

// N2=2

__builtin_write_OSCCONH(0x03);

__builtin_write_OSCCONL(0x01);


while(OSCCONbits.COSC != 0b011);

// Wait for PLL to lock

while(OSCCONbits.LOCK != 1);