Digital Power Starter Kit 3 Firmware
dsPIC33C Boost Converter Voltage Mode Control Example
system.c
1 /*
2  * File: system_initialize.c
3  * Author: M91406
4  *
5  * Created on November 12, 2020, 10:33 AM
6  */
7 
8 #include "apps.h"
9 #include "hal.h"
10 #include "system.h"
11 
12 /***********************************************************************************
13  * @fn uint16_t SYSTEM_Initialize(void)
14  * @ingroup mcu-initialization
15  * @brief Initializes essential chip resources
16  * @return unsigned integer
17  * 0=failure
18  * 1=success
19  *
20  * @details
21  * The SYSTEM_Initialize function covers the initialization of essential chip
22  * resources such as main oscillator, auxiliary oscillator, watchdog timer and
23  * general purpose I/Os (GPIO). All other, design specific peripherals are
24  * initialized in the User Peripheral Initialization or by the respective
25  * User Task Device Drivers included in the firmware project
26  *
27  **********************************************************************************/
28 volatile uint16_t SYSTEM_Initialize(void)
29 {
30  volatile uint16_t retval=1;
31 
32  retval &= sysFosc_Initialize();
33  retval &= sysAclk_Initialize();
34  retval &= sysGpio_Initialize();
35  retval &= sysDsp_Initialize();
36 
37  return(retval);
38 
39 }
40 
41 /***********************************************************************************
42  * @fn uint16_t sysUserPeriperhals_Initialize(void)
43  * @ingroup user-peripherals-initialization
44  * @brief Initializes the user-defined chip resources
45  * @return unsigned integer (0=failure, 1=success)
46  *
47  * @details
48  * The Digital Power Starter Kit 3 supports a Test Point allowing to observe
49  * the DAC output of the dsPIC33C device. Using this feature requires the
50  * configuration of further on-chip resources. This configuration is static
51  * and not related to any other task or function of the application and therefore
52  * needs to be added and placed manually.
53  * For this kind of Special Features, The startup procedure offers the following
54  * default function call allowing to place proprietary user code for individual
55  * device configurations beyond the default setup.
56  **********************************************************************************/
57 volatile uint16_t sysUserPeriperhals_Initialize(void) {
58 
59  volatile uint16_t retval=1;
60 
61  // Reset the operation amplifier module to a disabled default state.
62  retval &= sysOpAmp_ModuleReset();
63 
64  // Initialize boost converter current sense op-amp
65  retval &= sysOpAmp_Initialize(BOOST_ISNS_OPA_INSTANCE, false); // Initialize op-amp #2 used to amplify the low-side current sense of the boost converter
66 
67  // Initialize DAC buffer op-amp
68  retval &= sysOpAmp_Initialize(DAC_BUFFER_OPA_INSTANCE, true); // Initialize op-amp #3 used to drive the reference voltage for current sense amplifiers
69 
70  // Initialize DAC
71  retval &= sysDacModule_Initialize(); // Initialize DAC module
72  retval &= sysDacOutput_Initialize(DAC_OUTPUT_INSTANCE, DAC_OUTPUT_INIT_VALUE); // Initialize DAC #1 used to generate the reference voltage for current sense amplifiers
73  retval &= sysDacOutput_Enable(DAC_OUTPUT_INSTANCE); // Enable DAC providing reference to current sense amplifiers
74 
75  // Enable op-amp
76  retval &= sysOpAmp_ModuleEnable(); // Enable the operational amplifier module
77 
78  // Initialize debugging Pins
79  #ifdef DBGPIN1_PIN
80  DBGPIN1_Init();
81  DBGPIN1_Clear(); // Clear debug pin #1
82  #endif
83  #ifdef DBGPIN2_PIN
84  DBGPIN2_Init();
85  DBGPIN2_Clear(); // Clear debug pin #2
86  #endif
87 
88  return(retval);
89 
90 }
91 
92 /***********************************************************************************
93  * @fn uint16_t sysUserTasks_Initialize
94  * @ingroup user-task-initialization
95  * @brief Initializes the user-defined tasks
96  * @return unsigned integer (0=failure, 1=success)
97  *
98  * @details
99  * The EPC9143 16th brick power module reference design has a very simple GPIO
100  * user interface, signaling the state of the output regulation on a POWER GOOD
101  * output pin. Hence, this firmware4 mainly consists of the power control state
102  * machine and fault handler, protecting the hardware.
103  *
104  **********************************************************************************/
105 volatile uint16_t sysUserTasks_Initialize(void) {
106 
107  volatile uint16_t retval=1;
108 
109  // Initialize task scheduler time base
110  retval &= sysOsTimer_Initialize(); // Set up Timer1 as scheduler time base (see MAIN_EXECUTION_PERIOD for details)
111 
112  // Initialize software modules
113  retval &= appLCD_Initialize(); // Initialize LC Display task
114  retval &= appLED_Initialize(); // Initialize Debugging LED task
115  retval &= appPushButton_Initialize(); // Initialize user switch button
116  retval &= appPowerSupply_Initialize(); // Initialize BOOST converter object and state machine
117  retval &= appFaultMonitor_Initialize(); // Initialize fault objects and fault handler task
118 
119  return(retval);
120 
121 }
122 
123 // end of file
volatile uint16_t sysDacOutput_Initialize(volatile uint16_t dacInstance, volatile uint16_t initValue)
Definition: init_dac.c:71
volatile uint16_t sysOpAmp_Initialize(volatile uint16_t opaInstance, volatile bool disable_n_channel)
Definition: init_opa.c:34
volatile uint16_t sysDacModule_Initialize(void)
Definition: init_dac.c:39
volatile uint16_t sysOsTimer_Initialize(void)
Definition: init_timer1.c:40
volatile uint16_t sysOpAmp_ModuleEnable(void)
Definition: init_opa.c:77
#define BOOST_ISNS_OPA_INSTANCE
Operational amplifier instance used as ISNS aplifier (0 = disables op-amp option))
volatile uint16_t sysDacOutput_Enable(volatile uint16_t dacInstance)
Definition: init_dac.c:99
volatile uint16_t sysOpAmp_ModuleReset(void)
Definition: init_opa.c:102