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

p33c_opa.c
1 /* Microchip Technology Inc. and its subsidiaries. You may use this software
2 * and any derivatives exclusively with Microchip products.
3 *
4 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
5 * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
6 * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
7 * PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
8 * WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
9 *
10 * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
11 * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
12 * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
13 * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
14 * FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS
15 * IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF
16 * ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
17 *
18 * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
19 * TERMS.
20 */
21
22 // Include standard header files
23 #include <xc.h> // include processor files - each processor file is guarded.
24 #include <stdint.h> // include standard integer data types
25 #include <stdbool.h> // include standard boolean data types
26 #include <stddef.h> // include standard definition data types
27
28 #include "p33c_opa.h"
29
30 /*********************************************************************************
31 * @fn uint16_t p33c_OpaModule_Dispose(void)
32 * @ingroup lib-layer-pral-functions-public-opa
33 * @brief Resets all Op-Amp Module registers to their RESET default values
34 * @return unsigned integer
35 * @return 0 = failure, disposing OP-Amp module was not successful
36 * @return 1 = success, disposing OP-Amp module was successful
37 *
38 * @details
39 * This function clears all op-amp module registers to their
40 * default values set when the device comes out of RESET.
41 *
42 * Default configuration:
43 * - all operational amplifiers are turned off
44 * - the operational amplifier module is turned off
45 * - all operational amplifier negative inputs are enabled
46 *
47 *********************************************************************************/
48
49 volatile uint16_t p33c_OpaModule_Dispose(void)
50 {
51 volatile uint16_t retval=1;
52
53 retval = p33c_OpaModule_ConfigWrite(opaModuleConfigClear);
54
55 return(retval);
56 }
57
58 /*********************************************************************************
59 * @fn struct P33C_OPA_MODULE_s p33c_OpaModule_ConfigRead(void)
60 * @ingroup lib-layer-pral-functions-public-opa
61 * @brief Read the current configuration from the op-amp module base registers
62 * @return struct P33C_OPA_MODULE_s
63 *
64 * @details
65 * This function reads all registers with their current configuration into
66 * a data structure of type P33C_OPA_MODULE_s. Users can read and
67 * verify or modify the configuration to write it back to the op-amp
68 * module registers.
69 *
70 *********************************************************************************/
71
72 volatile struct P33C_OPA_MODULE_s p33c_OpaModule_ConfigRead(void)
73 {
74 volatile struct P33C_OPA_MODULE_s* opa;
75
76 // Set pointer to memory address of desired Op-Amp instance
77 opa = p33c_OpaModule_GetHandle();
78
79 return(*opa);
80
81 }
82
83 /*********************************************************************************
84 * @fn uint16_t p33c_OpaModule_ConfigWrite(volatile struct P33C_OPA_MODULE_s opaModuleConfig)
85 * @ingroup lib-layer-pral-functions-public-opa
86 * @brief Writes a user-defined configuration to the op-amp module base registers
87 * @param opaModuleConfig Operation Amplifier Peripheral SFR data object of type struct P33C_OPA_MODULE_s
88 * @return unsigned integer
89 * @return 0 = failure, writing op-amp module was not successful
90 * @return 1 = success, writing op-amp module was successful
91 *
92 * @details
93 * This function writes a user-defined op-amp module configuration of
94 * type P33C_OPA_MODULE_s to the op-amp module base registers. The
95 * individual register configurations have to be set in user-code
96 * before calling this function. To simplify the configuration process
97 * of standard functions, this driver provides templates, which can be
98 * loaded and written directly.
99 *
100 *********************************************************************************/
101
102 volatile uint16_t p33c_OpaModule_ConfigWrite(
103 volatile struct P33C_OPA_MODULE_s opaModuleConfig
104 )
105 {
106 volatile uint16_t retval=1;
107 volatile struct P33C_OPA_MODULE_s* opa;
108
109 // Set pointer to memory address of the op-amp module base registers
110 opa = p33c_OpaModule_GetHandle();
111 *opa = opaModuleConfig;
112
113 return(retval);
114
115 }
116
117 /*********************************************************************************
118 * @var opaModuleConfigClear
119 * @ingroup lib-layer-pral-functions-public-opa
120 * @brief Default RESET configuration of the op-amp module base SFRs
121 *
122 * @details
123 * Default configuration of the op-amp module SFRs with all its registers
124 * being reset to their default state when the device comes out of RESET.
125 * Programmers can use this template to reset (dispose) a previously used
126 * op-amp module when it's not used anymore or to ensure a known startup
127 * condition before writing individual configurations to its SFRs.
128 *
129 ********************************************************************************/
130
131 volatile struct P33C_OPA_MODULE_s opaModuleConfigClear = {
132
133 .AmpCon1L.value = 0x0000,
134 .AmpCon1H.value = 0x0000
135
136 };
137
138 /*********************************************************************************
139 * @var opaModuleDefault
140 * @ingroup lib-layer-pral-functions-public-opa
141 * @brief Default configuration of op-amp module running from 500 MHz input clock
142 *
143 * @details
144 * Default configuration of the op-amp module SFRs with all its registers
145 * being reset to their default state when the device comes out of RESET.
146 *
147 * Programmers can use this template to reset a previously used
148 * op-amp module when it's not used anymore or to ensure a known startup
149 * condition before writing individual configurations to its SFRs.
150 *
151 ********************************************************************************/
152 /* */
153 volatile struct P33C_OPA_MODULE_s opaModuleDefault = {
154
155 .AmpCon1L.value = 0x0000,
156 .AmpCon1H.value = 0x0007,
157
158 };
159
160
161
162 // end of file
P33C_OPA_MODULE_s
Definition: p33c_opa.h:48
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