Bar Logo 3.8/7.6 kw Totem pole Demonstration Application (Part-No. (not specified))
 
Content
     
Loading...
Searching...
No Matches
clock.c
Go to the documentation of this file.
1
17/*
18© [2023] Microchip Technology Inc. and its subsidiaries.
19
20 Subject to your compliance with these terms, you may use Microchip
21 software and any derivatives exclusively with Microchip products.
22 You are responsible for complying with 3rd party license terms
23 applicable to your use of 3rd party software (including open source
24 software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
25 NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
26 SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
27 MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
28 WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
29 INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
30 KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
31 MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
32 FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
33 TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
34 EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
35 THIS SOFTWARE.
36*/
37
38// Section: Includes
39#include <xc.h>
40#include <stdint.h>
41#include "../clock.h"
42
44{
45 /*
46 Input frequency : 8.00 MHz
47 Clock source : FRC Oscillator with PLL
48 System frequency (Fosc) : 200.00 MHz [(8.00 MHz / 1) * 50 / 1 / 2 = 200.00 MHz]
49 PLL VCO frequency (Fvco) : 400.00 MHz [(8.00 MHz / 1) * 50 = 400.00 MHz]
50 PLL output frequency (Fpllo) : 400.00 MHz [(8.00 MHz / 1) * 50 / 1 = 400.00 MHz]
51 PLL VCO divider frequency (Fvcodiv) : 100.00 MHz [400.00 MHz / 4 = 100.00 MHz]
52 Clock switching enabled : true
53 Clock source when device boots : FRC Oscillator
54 Auxiliary clock source : FRC Oscillator with PLL
55 Auxiliary clock input frequency : 8.00 MHz
56 Auxiliary PLL VCO frequency (AFvco) : 1000.00 MHz [(8.00 MHz / 1) * 125 = 1000.00 MHz]
57 Auxiliary clock PLL output frequency (AFpllo) : 500.00 MHz [(8.00 MHz / 1) * 125 / 2 = 500.00 MHz]
58 Auxiliary PLL VCO divider frequency (AFvcodiv): 500.00 MHz [1000.00 MHz / 2 = 500.00 MHz]
59 */
60 // RCDIV FRC/1; PLLPRE 1:1; DOZE 1:8; DOZEN disabled; ROI disabled;
61 CLKDIV = 0x3001;
62
63 // PLLDIV 50;
64 PLLFBD = 0x32<<1; //<<< changed by hand
65 // PLLPOST 1:1; VCODIV FVCO/4; POST2DIV 1:1;
66 PLLDIV = 0x21; //<<< changed by hand
67
68 // ENAPLL enabled; FRCSEL FRC Oscillator; APLLPRE 1:1;
69 ACLKCON1 = 0x8101;
70 // APLLFBDIV 125;
71 APLLFBD1 = 0x7D;
72 // APSTSCLR 1:2; APOST2DIV 1:1; AVCODIV FVCO/2;
73 APLLDIV1 = 0x221;
74 // ROEN disabled; DIVSWEN disabled; ROSLP disabled; ROSEL ; OE disabled; ROSIDL disabled;
75 REFOCONL = 0x0;
76 // RODIV 0;
77 REFOCONH = 0x0;
78 // ROTRIM 0;
79 REFOTRIMH = 0x0;
80 // IOLOCK disabled;
81 RPCON = 0x0;
82 // ADC1MD enabled; T1MD enabled; U1MD enabled; SPI1MD enabled; QEIMD enabled; PWMMD enabled; I2C1MD enabled;
83 PMD1 = 0x0;
84 // CCP2MD enabled; CCP1MD enabled; CCP4MD enabled; CCP3MD enabled;
85 PMD2 = 0x0;
86 // REFOMD enabled;
87 PMD4 = 0x0;
88 // DMA1MD enabled; DMA0MD enabled;
89 PMD6 = 0x0;
90 // CMP1MD enabled; CMP3MD enabled; PGA1MD enabled; CMP2MD enabled;
91 PMD7 = 0x0;
92 // CLC3MD enabled; CLC4MD enabled; CLC1MD enabled; CLC2MD enabled; PGA2MD enabled; PGA3MD enabled;
93 PMD8 = 0x0;
94 // CF no clock failure; NOSC FRCPLL; CLKLOCK unlocked; OSWEN Switch is Complete;
95 __builtin_write_OSCCONH((uint8_t) (0x01));
96 __builtin_write_OSCCONL((uint8_t) (0x01));
97 // Wait for Clock switch to occur
98 while (OSCCONbits.OSWEN != 0);
99 while (OSCCONbits.LOCK != 1);
100}
101
103{
104 return ACLKCON1bits.APLLCK;
105}
106
bool CLOCK_AuxPllLockStatusGet(void)
Returns Auxiliary PLL status.
Definition clock.c:104
void CLOCK_Initialize(void)
Initializes all the INTERNAL OSCILLATOR sources and clock switch configurations.
Definition clock.c:43