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

init_opa.c
1 /*
2 * File: init_opa.c
3 * Author: M91406
4 *
5 * Created on May 19, 2020, 1:19 PM
6 */
7
8
9 #include <xc.h>
10 #include <stdint.h>
11 #include <stdbool.h>
12
13 #include "init_opa.h"
14
19 /***********************************************************************************
20 * @fn uint16_t sysOpAmp_Initialize(volatile uint16_t opaInstance, volatile bool disable_n_channel)
21 * @brief Initializes the on-chip operational amplifier module
22 * @return unsigned integer
23 * @return 0=failure
24 * @return 1=success
25 *
26 * @details
27 * The EPC9143 300W 16th brick power module reference designs uses one of the on-chip
28 * operational amplifiers as buffer op-amp for the current reference signal applied
29 * to external high-side current sense shunt amplifier devices. This operational
30 * amplifier is initialized here.
31 *
32 **********************************************************************************/
33
34 volatile uint16_t sysOpAmp_Initialize(volatile uint16_t opaInstance, volatile bool disable_n_channel)
35 {
36 volatile uint16_t retval=1;
37 volatile uint16_t idum=0;
38 volatile struct P33C_OPA_MODULE_s* opa = p33c_OpaModule_GetHandle();
39
40 // If instance is set = 0, op-amp will be skipped and op-amps will be turned off
41 if(opaInstance > 0)
42 {
43 // Disables Op Amp N channel input stage
44 if (disable_n_channel)
45 {
46 idum = (((uint16_t)disable_n_channel) << (opaInstance - 1));
47 opa->AmpCon1H.value |= idum;
48 }
49 else
50 {
51 idum = (1 << (opaInstance - 1));
52 opa->AmpCon1H.value &= (~idum);
53 }
54
55 // Enable op-amp instance
56 idum = (0x0001 << (opaInstance - 1));
57 opa->AmpCon1L.value |= idum;
58 }
59
60 return (retval);
61 }
62
63 /***********************************************************************************
64 * @fn uint16_t sysOpAmp_ModuleEnable
65 * @brief Enables the on-chip operational amplifier module
66 * @return unsigned integer
67 * @return 0=failure
68 * @return 1=success
69 *
70 * @details
71 * The on-chip operational amplifier module allows the configuration of multiple
72 * operational amplifier instances. The module itself provides an additional
73 * master enable bit to turn on/off the entire module.
74 *
75 **********************************************************************************/
76
77 volatile uint16_t sysOpAmp_ModuleEnable(void)
78 {
79 volatile struct P33C_OPA_MODULE_s* opa = p33c_OpaModule_GetHandle();
80 opa->AmpCon1L.bits.AMPON = true; // Enable Op-Amp module
81 return (opa->AmpCon1L.bits.AMPON);
82 }
83
84
85 /***********************************************************************************
86 * @fn uint16_t sysOpAmp_ModuleReset
87 * @brief Resets the on-chip operational amplifier module
88 * @return unsigned integer
89 * @return 0=failure
90 * @return 1=success
91 *
92 * @details
93 * The on-chip operational amplifier module allows the configuration of multiple
94 * operational amplifier instances. The module itself provides an additional
95 * master enable bit to turn on/off the entire module as well as to enable/disable
96 * the N-inputs of individual op-amps. This function resets the op-amp module
97 * to its default disabling the N-channel inputs of all op-amps, disables all
98 * individual op-amps as well as turns of the op-amp module master switch.
99 *
100 **********************************************************************************/
101
102 volatile uint16_t sysOpAmp_ModuleReset(void)
103 {
104 volatile struct P33C_OPA_MODULE_s* opa = p33c_OpaModule_GetHandle();
105
106 // Disable and reset op-amp module
107 *opa = opaModuleDefault; // Load configuration defaults
108 opa->AmpCon1L.value = 0; // Disable and reset Op-Amp module
109
110 return (1-opa->AmpCon1L.bits.AMPON);
111 }
112 // end of group op-amp-initialization
114
115 // end of file
P33C_OPA_MODULE_s
Definition: p33c_opa.h:48
P33C_OPA_MODULE_s::AmpCon1H
union P33C_OPA_MODULE_s::@202 AmpCon1H
P33C_OPA_MODULE_s::bits
volatile struct tagAMPCON1LBITS bits
Definition: p33c_opa.h:50
sysOpAmp_Initialize
volatile uint16_t sysOpAmp_Initialize(volatile uint16_t opaInstance, volatile bool disable_n_channel)
Definition: init_opa.c:34
sysOpAmp_ModuleEnable
volatile uint16_t sysOpAmp_ModuleEnable(void)
Definition: init_opa.c:77
P33C_OPA_MODULE_s::AmpCon1L
union P33C_OPA_MODULE_s::@201 AmpCon1L
P33C_OPA_MODULE_s::value
volatile uint16_t value
Definition: p33c_opa.h:51
sysOpAmp_ModuleReset
volatile uint16_t sysOpAmp_ModuleReset(void)
Definition: init_opa.c:102