Bar Logo Dual Active Bridge Development Board (Part-No. )
 
Content
     
Loading...
Searching...
No Matches
cmp2.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 "../cmp2.h"
43
44// Section: File specific functions
45
46static void (*CMP2_EventHandler)(void) = NULL;
47
48// Section: Driver Interface
51 .Disable = &CMP2_DACDisable,
52 .DataWrite = &CMP2_DACDataWrite,
53};
54
55const struct CMP_INTERFACE DAC_DEBUG = {
57 .Deinitialize = &CMP2_Deinitialize,
58 .Enable = &CMP2_Enable,
59 .Disable = &CMP2_Disable,
60 .StatusGet = &CMP2_StatusGet,
61
62 .EventCallbackRegister = &CMP2_EventCallbackRegister,
63 .Tasks = &CMP2_Tasks,
64 .cmp_dac_dc_interface = &dac2_dc_interface
65};
66
67// Section: CMP2 Module APIs
68
70{
71 // Comparator Register settings
72 DACCTRL1L = 0x40; //FCLKDIV 1:1; CLKDIV 1:1; CLKSEL FVCO/2; DACSIDL disabled; DACON disabled;
73 DACCTRL2H = 0x8A; //SSTIME 138;
74 DACCTRL2L = 0x55; //TMODTIME 85;
75 DAC2CONH = 0x0; //TMCB 0;
76 DAC2CONL = 0x8200; //HYSSEL None; HYSPOL Rising Edge; INSEL CMP2A; CMPPOL Non Inverted; FLTREN disabled; DACOEN enabled; CBE disabled; IRQM Interrupts are disabled; DACEN enabled;
77
78 //Slope Settings
79 DAC2DATH = 0xCD; //DACDATH 205;
80 DAC2DATL = 0xCD; //DACDATL 205;
81 SLP2CONH = 0x0; //PSE Negative; TWME disabled; HME disabled; SLOPEN disabled;
82 SLP2CONL = 0x0; //SLPSTRT None; SLPSTOPB None; SLPSTOPA None; HCFSEL None;
83 SLP2DAT = 0x0; //SLPDAT 0;
84
86
87
88 DACCTRL1Lbits.DACON = 1;
89}
90
92{
93 DACCTRL1Lbits.DACON = 0;
94
95
96 // Comparator Register settings
97 DACCTRL1L = 0x0;
98 DACCTRL2H = 0x8A;
99 DACCTRL2L = 0x55;
100 DAC2CONH = 0x0;
101 DAC2CONL = 0x0;
102
103 //Slope Settings
104 DAC2DATH = 0x0;
105 DAC2DATL = 0x0;
106 SLP2CONH = 0x0;
107 SLP2CONL = 0x0;
108 SLP2DAT = 0x0;
109}
110
112{
113 return (DAC2CONLbits.CMPSTAT);
114}
115
116void CMP2_Enable(void)
117{
118 DACCTRL1Lbits.DACON = 1;
119}
120
121void CMP2_Disable(void)
122{
123 DACCTRL1Lbits.DACON = 0;
124}
125
127{
128 DAC2CONLbits.DACEN = 1;
129}
130
132{
133 DAC2CONLbits.DACEN = 0;
134}
135
136void CMP2_DACDataWrite(size_t value)
137{
138 DAC2DATHbits.DACDATH = value;
139}
140
141void CMP2_EventCallbackRegister(void (*handler)(void))
142{
143 if(NULL != handler)
144 {
145 CMP2_EventHandler = handler;
146 }
147}
148
150{
151
152}
153
154void CMP2_Tasks(void)
155{
156 if(IFS4bits.CMP2IF == 1)
157 {
158 // CMP2 callback function
159 if(NULL != CMP2_EventHandler)
160 {
161 (*CMP2_EventHandler)();
162 }
163
164 // clear the CMP2 interrupt flag
165 IFS4bits.CMP2IF = 0;
166 }
167}
168
void __attribute__((weak))
Definition cmp2.c:149
static void(* CMP2_EventHandler)(void)
Definition cmp2.c:46
const struct DAC_DC_INTERFACE dac2_dc_interface
Definition cmp2.c:49
bool CMP2_StatusGet(void)
Returns the comparator output status.
Definition cmp2.c:111
void CMP2_Disable(void)
Disables the common DAC module.
Definition cmp2.c:121
void CMP2_Initialize(void)
Initialize the CMP2 module.
Definition cmp2.c:69
void CMP2_EventCallbackRegister(void(*handler)(void))
This function can be used to override default callback and to define custom callback for CMP2 Event e...
Definition cmp2.c:141
void CMP2_Deinitialize(void)
Deinitializes the CMP2 to POR values.
Definition cmp2.c:91
void CMP2_DACEnable(void)
Enables the individual DAC module.
Definition cmp2.c:126
void CMP2_EventCallback(void)
This is the default callback with weak attribute. The user can override and implement the default cal...
void CMP2_DACDisable(void)
Disables the individual DAC module.
Definition cmp2.c:131
const struct CMP_INTERFACE DAC_DEBUG
Structure object of type CMP_INTERFACE with the custom name given by the user in the Melody Driver Us...
Definition cmp2.c:55
void CMP2_DACDataWrite(size_t value)
CMP DAC Data write to register.
Definition cmp2.c:136
void CMP2_Tasks(void)
The Task function can be called in the main application using the High Speed Comparator,...
Definition cmp2.c:154
void CMP2_Enable(void)
Enables the common DAC module.
Definition cmp2.c:116
Structure containing the function pointers of DAC driver in DC mode.
void(* Enable)(void)
Pointer to CMPx_DACEnable e.g. CMP1_DACEnable.
Structure containing the function pointers of CMP driver.
void(* Initialize)(void)
Pointer to CMPx_Initialize e.g. CMP1_Initialize.