|  | Dual Active Bridge Development Board (Part-No. ) |
Content |  |  |  |  |  |

Loading...
Searching...
No Matches
cmp1.c
Go to the documentation of this file.
1
18/*
19© [2024] Microchip Technology Inc. and its subsidiaries.
20
21 Subject to your compliance with these terms, you may use Microchip
22 software and any derivatives exclusively with Microchip products.
23 You are responsible for complying with 3rd party license terms
24 applicable to your use of 3rd party software (including open source
25 software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
26 NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
27 SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
28 MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
29 WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
30 INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
31 KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
32 MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
33 FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
34 TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
35 EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
36 THIS SOFTWARE.
37*/
38
39// Section: Included Files
40
41#include <xc.h>
42#include "../cmp1.h"
43
44// Section: File specific functions
45
46 static void (*CMP1_EventHandler)(void) = NULL;
47
48// Section: Driver Interface
49 const struct DAC_DC_INTERFACE dac1_dc_interface = {
50 .Enable = &CMP1_DACEnable,
51 .Disable = &CMP1_DACDisable,
52 .DataWrite = &CMP1_DACDataWrite,
53};
54
55 const struct CMP_INTERFACE CMP_ISEC_SC = {
56 .Initialize = &CMP1_Initialize,
57 .Deinitialize = &CMP1_Deinitialize,
58 .Enable = &CMP1_Enable,
59 .Disable = &CMP1_Disable,
60 .StatusGet = &CMP1_StatusGet,
61
62 .EventCallbackRegister = &CMP1_EventCallbackRegister,
63 .Tasks = &CMP1_Tasks,
64 .cmp_dac_dc_interface = &dac1_dc_interface
65};
66
67// Section: CMP1 Module APIs
68
69 void CMP1_Initialize(void)
70{
71 // Comparator Register settings
72 DACCTRL1L = 0x77; //FCLKDIV 1:8; CLKDIV 1:4; CLKSEL FVCO/2; DACSIDL disabled; DACON disabled;
73 DACCTRL2H = 0x8A; //SSTIME 138;
74 DACCTRL2L = 0x55; //TMODTIME 85;
75 DAC1CONH = 0x0; //TMCB 0;
76 DAC1CONL = 0x8108; //HYSSEL None; HYSPOL Rising Edge; INSEL CMP1B; CMPPOL Non Inverted; FLTREN enabled; DACOEN disabled; CBE disabled; IRQM Interrupts are disabled; DACEN enabled;
77
78 //Slope Settings
79 DAC1DATH = 0xF32; //DACDATH 3890;
80 DAC1DATL = 0xCD; //DACDATL 205;
81 SLP1CONH = 0x0; //PSE Negative; TWME disabled; HME disabled; SLOPEN disabled;
82 SLP1CONL = 0x0; //SLPSTRT None; SLPSTOPB None; SLPSTOPA None; HCFSEL None;
83 SLP1DAT = 0x0; //SLPDAT 0;
84
85 CMP1_EventCallbackRegister(&CMP1_EventCallback);
86
87
88 DACCTRL1Lbits.DACON = 1;
89}
90
91 void CMP1_Deinitialize(void)
92{
93 DACCTRL1Lbits.DACON = 0;
94
95
96 // Comparator Register settings
97 DACCTRL1L = 0x0;
98 DACCTRL2H = 0x8A;
99 DACCTRL2L = 0x55;
100 DAC1CONH = 0x0;
101 DAC1CONL = 0x0;
102
103 //Slope Settings
104 DAC1DATH = 0x0;
105 DAC1DATL = 0x0;
106 SLP1CONH = 0x0;
107 SLP1CONL = 0x0;
108 SLP1DAT = 0x0;
109}
110
111 bool CMP1_StatusGet(void)
112{
113 return (DAC1CONLbits.CMPSTAT);
114}
115
116 void CMP1_Enable(void)
117{
118 DACCTRL1Lbits.DACON = 1;
119}
120
121 void CMP1_Disable(void)
122{
123 DACCTRL1Lbits.DACON = 0;
124}
125
126 void CMP1_DACEnable(void)
127{
128 DAC1CONLbits.DACEN = 1;
129}
130
131 void CMP1_DACDisable(void)
132{
133 DAC1CONLbits.DACEN = 0;
134}
135
136 void CMP1_DACDataWrite(size_t value)
137{
138 DAC1DATHbits.DACDATH = value;
139}
140
141 void CMP1_EventCallbackRegister(void (*handler)(void))
142{
143 if(NULL != handler)
144 {
145 CMP1_EventHandler = handler;
146 }
147}
148
149 void __attribute__ ((weak)) CMP1_EventCallback(void)
150{
151
152}
153
154 void CMP1_Tasks(void)
155{
156 if(IFS4bits.CMP1IF == 1)
157 {
158 // CMP1 callback function
159 if(NULL != CMP1_EventHandler)
160 {
161 (*CMP1_EventHandler)();
162 }
163
164 // clear the CMP1 interrupt flag
165 IFS4bits.CMP1IF = 0;
166 }
167}
168
dac1_dc_interface
const struct DAC_DC_INTERFACE dac1_dc_interface
Definition cmp1.c:49
CMP1_EventHandler
static void(* CMP1_EventHandler)(void)
Definition cmp1.c:46
__attribute__
void __attribute__((weak))
Definition cmp1.c:149
CMP1_Enable
void CMP1_Enable(void)
Enables the common DAC module.
Definition cmp1.c:116
CMP1_EventCallback
void CMP1_EventCallback(void)
This is the default callback with weak attribute. The user can override and implement the default cal...
CMP1_StatusGet
bool CMP1_StatusGet(void)
Returns the comparator output status.
Definition cmp1.c:111
CMP1_Deinitialize
void CMP1_Deinitialize(void)
Deinitializes the CMP1 to POR values.
Definition cmp1.c:91
CMP1_Tasks
void CMP1_Tasks(void)
The Task function can be called in the main application using the High Speed Comparator,...
Definition cmp1.c:154
CMP_ISEC_SC
const struct CMP_INTERFACE CMP_ISEC_SC
Structure object of type CMP_INTERFACE with the custom name given by the user in the Melody Driver Us...
Definition cmp1.c:55
CMP1_Initialize
void CMP1_Initialize(void)
Initialize the CMP1 module.
Definition cmp1.c:69
CMP1_DACEnable
void CMP1_DACEnable(void)
Enables the individual DAC module.
Definition cmp1.c:126
CMP1_DACDisable
void CMP1_DACDisable(void)
Disables the individual DAC module.
Definition cmp1.c:131
CMP1_Disable
void CMP1_Disable(void)
Disables the common DAC module.
Definition cmp1.c:121
CMP1_EventCallbackRegister
void CMP1_EventCallbackRegister(void(*handler)(void))
This function can be used to override default callback and to define custom callback for CMP1 Event e...
Definition cmp1.c:141
CMP1_DACDataWrite
void CMP1_DACDataWrite(size_t value)
CMP DAC Data write to register.
Definition cmp1.c:136
DAC_DC_INTERFACE
Structure containing the function pointers of DAC driver in DC mode.
Definition cmp_interface.h:55
DAC_DC_INTERFACE::Enable
void(* Enable)(void)
Pointer to CMPx_DACEnable e.g. CMP1_DACEnable.
Definition cmp_interface.h:56
CMP_INTERFACE
Structure containing the function pointers of CMP driver.
Definition cmp_interface.h:73
CMP_INTERFACE::Initialize
void(* Initialize)(void)
Pointer to CMPx_Initialize e.g. CMP1_Initialize.
Definition cmp_interface.h:74