| Digital Power Starter Kit 3 Firmware dsPIC33C Boost Converter Voltage Mode Control Example |

rtos_fosc.c
1 /*
2 * File: init_fosc.c
3 * Author: M91406
4 *
5 * Created on July 8, 2019, 1:55 PM
6 */
7
8
9 #include <xc.h> // include processor files - each processor file is guarded.
10 #include <stdint.h> // include standard integer data types
11 #include <stdbool.h> // include standard boolean data types
12 #include <stddef.h> // include standard definition data types
13
14 #include "rtos_fosc.h" // include RTOS oscillator initialization header file
15 #include "common/p33c_pral/xc16_pral.h" // include common peripheral abstraction layer driver header file
16
17 #define TIMEOUT_LIMIT 5000 // timeout counter maximum
18
19 /***********************************************************************************
20 * @fn uint16_t osFosc_Initialize(void)
21 * @ingroup clock-initialization
22 * @brief System oscillator initialization
23 * @return unsigned integer
24 * 0=failure
25 * 1=success
26 *
27 * @details
28 * This function initializes the internal 8 MHz RC oscillator as the main
29 * oscillator and initializes the PLL to operate the CPU at maximum performance
30 * of 100 MHz instruction cycle.
31 *
32 **********************************************************************************/
33 volatile uint16_t osFosc_Initialize(void)
34 {
35 volatile uint16_t retval=1;
36
37 #if defined (__P33SMPS_CK__) || defined (__P33SMPS_CH_SEC__)
38 retval = p33c_OscFrc_DefaultInitialize(CPU_SPEED_100_MIPS);
39 #elif defined (__P33SMPS_CH_MAIN__)
40 retval = p33c_OscFrc_DefaultInitialize(CPU_SPEED_90_MIPS);
41 #endif
42 retval &= p33c_Osc_GetFrequencies();
43
44 return(retval);
45
46 }
47
48 /***********************************************************************************
49 * @fn uint16_t osAclk_Initialize(void)
50 * @ingroup clock-initialization
51 * @brief Initializes the auxiliary clock of the device
52 * @return unsigned integer (0=failure, 1=success)
53 *
54 * @details
55 * This function initializes the auxiliary PLL for operating ADC and PWM module
56 * at maximum performance at an input clock of 500 MHz. Each peripheral module
57 * may use additional frequency scalers and multipliers to further convert this
58 * frequency.
59 *
60 **********************************************************************************/
61 volatile uint16_t osAclk_Initialize(void) {
62
63 volatile uint16_t retval=1;
64
65 retval &= p33c_OscAuxClk_DefaultInitialize(AFPLLO_500_MHZ);
66
67 return(retval);
68 }
69
70 // end of file
71