Digital Power Starter Kit 3 Firmware
dsPIC33C Buck 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 
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 
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 op-amp
65  retval &= sysOpAmp_Initialize(DAC_BUFFER_OPA_INSTANCE, true); // Initialize op-amp #2 used to drive the reference voltage for current sense amplifiers
66 
67  // Initialize DAC
68  retval &= sysDacModule_Initialize(); // Initialize DAC module
69  retval &= sysDacOutput_Initialize(DAC_OUTPUT_INSTANCE, DAC_OUTPUT_INIT_VALUE); // Initialize DAC #1 used to generate the reference voltage for current sense amplifiers
70  retval &= sysDacOutput_Enable(DAC_OUTPUT_INSTANCE); // Enable DAC providing reference to current sense amplifiers
71 
72  // Enable op-amp
73  retval &= sysOpAmp_ModuleEnable(); // Enable the operational amplifier module
74 
75  // Initialize debugging Pins
76  #ifdef DBGPIN1_PIN
77  DBGPIN1_Init();
78  DBGPIN1_Clear(); // Clear debug pin #1
79  #endif
80  #ifdef DBGPIN2_PIN
81  DBGPIN2_Init();
82  DBGPIN2_Clear(); // Clear debug pin #2
83  #endif
84 
85  return(retval);
86 
87 }
88 
89 
102 volatile uint16_t sysUserTasks_Initialize(void) {
103 
104  volatile uint16_t retval=1;
105 
106  // Initialize task scheduler time base
107  retval &= sysOsTimer_Initialize(); // Set up Timer1 as scheduler time base (see MAIN_EXECUTION_PERIOD for details)
108 
109  // Initialize software modules
110  retval &= appLCD_Initialize(); // Initialize LC Display task
111  retval &= appLED_Initialize(); // Initialize Debugging LED task
112  retval &= appPushButton_Initialize(); // Initialize user switch button
113  retval &= appPowerSupply_Initialize(); // Initialize BUCK converter object and state machine
114  retval &= appFaultMonitor_Initialize(); // Initialize fault objects and fault handler task
115 
116  return(retval);
117 
118 }
119 
120 // end of file
sysDacModule_Initialize
volatile uint16_t sysDacModule_Initialize(void)
DAC Module Base Register Initialization.
Definition: init_dac.c:39
appLCD_Initialize
volatile uint16_t appLCD_Initialize(void)
Initializes the LC display.
Definition: app_lcd.c:88
sysDsp_Initialize
volatile uint16_t sysDsp_Initialize(void)
Digital Signal Processor initialization.
Definition: init_dsp.c:48
sysUserTasks_Initialize
volatile uint16_t sysUserTasks_Initialize(void)
Initializes the user-defined tasks.
Definition: system.c:102
sysOpAmp_ModuleEnable
volatile uint16_t sysOpAmp_ModuleEnable(void)
Enables the on-chip operational amplifier module.
Definition: init_opa.c:77
appLED_Initialize
volatile uint16_t appLED_Initialize(void)
Initializes the LED driving GPIO.
Definition: app_led.c:30
DBGPIN1_Init
#define DBGPIN1_Init()
Macro instruction initializing the specified GPIO as output.
Definition: dpsk3_hwdescr.h:202
sysGpio_Initialize
volatile uint16_t sysGpio_Initialize(void)
Resets the device input/output pins to digital inputs.
Definition: init_gpio.c:27
sysOpAmp_ModuleReset
volatile uint16_t sysOpAmp_ModuleReset(void)
Resets the on-chip operational amplifier module.
Definition: init_opa.c:102
sysDacOutput_Enable
volatile uint16_t sysDacOutput_Enable(volatile uint16_t dacInstance)
Definition: init_dac.c:99
sysAclk_Initialize
volatile uint16_t sysAclk_Initialize(void)
Initializes the auxiliary clock of the device.
Definition: init_fosc.c:55
DBGPIN2_Init
#define DBGPIN2_Init()
Macro instruction initializing the specified GPIO as output.
Definition: dpsk3_hwdescr.h:213
appPushButton_Initialize
volatile uint16_t appPushButton_Initialize(void)
Initializes the USER push button on DPSK3.
Definition: app_push_button.c:45
DAC_OUTPUT_INSTANCE
#define DAC_OUTPUT_INSTANCE
Special Function chip resources declarations.
Definition: dpsk3_hwdescr.h:264
sysOpAmp_Initialize
volatile uint16_t sysOpAmp_Initialize(volatile uint16_t opaInstance, volatile bool disable_n_channel)
Initializes the on-chip operational amplifier module.
Definition: init_opa.c:34
DAC_OUTPUT_INIT_VALUE
#define DAC_OUTPUT_INIT_VALUE
initial value of the Digital-To-Analog Converter debugging output
Definition: dpsk3_hwdescr.h:266
SYSTEM_Initialize
volatile uint16_t SYSTEM_Initialize(void)
Initializes essential chip resources.
Definition: system.c:28
sysUserPeriperhals_Initialize
volatile uint16_t sysUserPeriperhals_Initialize(void)
Initializes the user-defined chip resources.
Definition: system.c:57
DAC_BUFFER_OPA_INSTANCE
#define DAC_BUFFER_OPA_INSTANCE
Operational amplifier instance used to buffer DAC output.
Definition: dpsk3_hwdescr.h:265
sysOsTimer_Initialize
volatile uint16_t sysOsTimer_Initialize(void)
Initializes the timer used as time-base for the task scheduler.
Definition: init_timer1.c:40
sysFosc_Initialize
volatile uint16_t sysFosc_Initialize(void)
System oscillator initialization.
Definition: init_fosc.c:32
DBGPIN2_Clear
#define DBGPIN2_Clear()
Macro instruction to set a pin state to logic LOW.
Definition: dpsk3_hwdescr.h:211
appPowerSupply_Initialize
volatile uint16_t appPowerSupply_Initialize(void)
Calls the application layer power controller initialization.
Definition: app_power_control.c:133
appFaultMonitor_Initialize
volatile uint16_t appFaultMonitor_Initialize(void)
Initialization of user-defined fault objects.
Definition: app_fault_monitor.c:138
sysDacOutput_Initialize
volatile uint16_t sysDacOutput_Initialize(volatile uint16_t dacInstance, volatile uint16_t initValue)
Initializes a user specified DAC instance with DAC output enabled.
Definition: init_dac.c:71
DBGPIN1_Clear
#define DBGPIN1_Clear()
Macro instruction to set a pin state to logic LOW.
Definition: dpsk3_hwdescr.h:200