-
Notifications
You must be signed in to change notification settings - Fork 0
/
DR_PLL.c
118 lines (83 loc) · 5.31 KB
/
DR_PLL.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Kit_Inic.c
*
* Created on: 06/05/2016
* Author: Usuario
*/
/*******************************************************************************************************************************//**
*
* @file Kit_Inic.c
* @brief Inicialización del Kit
* @date 8/05/2016
* @author INFORMATICA II
*
**********************************************************************************************************************************/
/***********************************************************************************************************************************
*** INCLUDES
**********************************************************************************************************************************/
#include "DR_PLL.h"
/***********************************************************************************************************************************
*** DEFINES PRIVADOS AL MODULO
**********************************************************************************************************************************/
/***********************************************************************************************************************************
*** MACROS PRIVADAS AL MODULO
**********************************************************************************************************************************/
/***********************************************************************************************************************************
*** TIPOS DE DATOS PRIVADOS AL MODULO
**********************************************************************************************************************************/
/***********************************************************************************************************************************
*** TABLAS PRIVADAS AL MODULO
**********************************************************************************************************************************/
/***********************************************************************************************************************************
*** VARIABLES GLOBALES PUBLICAS
**********************************************************************************************************************************/
/***********************************************************************************************************************************
*** VARIABLES GLOBALES PRIVADAS AL MODULO
**********************************************************************************************************************************/
/***********************************************************************************************************************************
*** PROTOTIPO DE FUNCIONES PRIVADAS AL MODULO
**********************************************************************************************************************************/
/***********************************************************************************************************************************
*** FUNCIONES PRIVADAS AL MODULO
**********************************************************************************************************************************/
/***********************************************************************************************************************************
*** FUNCIONES GLOBALES AL MODULO
**********************************************************************************************************************************/
void InitPLL ( void )
{
//Este bloque de codigo habilita el oscilador externo como fuente de clk
//del micro, y configura un dispositivo conocido como PLL (Phase Locked Loop)
//para generar un clock interno de 100MHz a partir del oscilador conectado
SCS = SCS_Value;
if (SCS_Value & (1 << 5)) /* If Main Oscillator is enabled */
while ((SCS & (1<<6)) == 0);/* Wait for Oscillator to be ready */
CCLKCFG = CCLKCFG_Value; /* Setup Clock Divider */
PCLKSEL0 = PCLKSEL0_Value; /* Peripheral Clock Selection */
PCLKSEL1 = PCLKSEL1_Value;
CLKSRCSEL = CLKSRCSEL_Value; /* Select Clock Source for PLL0 */
PLL0CFG = PLL0CFG_Value; /* configure PLL0 */
PLL0FEED = 0xAA;
PLL0FEED = 0x55;
PLL0CON = 0x01; /* PLL0 Enable */
PLL0FEED = 0xAA;
PLL0FEED = 0x55;
while (!(PLL0STAT & (1<<26)));/* Wait for PLOCK0 */
PLL0CON = 0x03; /* PLL0 Enable & Connect */
PLL0FEED = 0xAA;
PLL0FEED = 0x55;
while (!(PLL0STAT & ((1<<25) | (1<<24))));/* Wait for PLLC0_STAT & PLLE0_STAT */
PLL1CFG = PLL1CFG_Value;
PLL1FEED = 0xAA;
PLL1FEED = 0x55;
PLL1CON = 0x01; /* PLL1 Enable */
PLL1FEED = 0xAA;
PLL1FEED = 0x55;
while (!(PLL1STAT & (1<<10)));/* Wait for PLOCK1 */
PLL1CON = 0x03; /* PLL1 Enable & Connect */
PLL1FEED = 0xAA;
PLL1FEED = 0x55;
while (!(PLL1STAT & ((1<< 9) | (1<< 8))));/* Wait for PLLC1_STAT & PLLE1_STAT */
PCONP = PCONP_Value; /* Power Control for Peripherals */
CLKOUTCFG = CLKOUTCFG_Value; /* Clock Output Configuration */
FLASHCFG = (FLASHCFG & ~0x0000F000) | FLASHCFG_Value;
}