Bar Logo Dual Active Bridge Development Board (Part-No. )
 
Content
     
Loading...
Searching...
No Matches
cmp3.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 "../cmp3.h"
43
44// Section: File specific functions
45
46static void (*CMP3_EventHandler)(void) = NULL;
47
48// Section: Driver Interface
51 .Disable = &CMP3_DACDisable,
52 .DataWrite = &CMP3_DACDataWrite,
53};
54
55const struct CMP_INTERFACE CMP_IPRI_SC = {
57 .Deinitialize = &CMP3_Deinitialize,
58 .Enable = &CMP3_Enable,
59 .Disable = &CMP3_Disable,
60 .StatusGet = &CMP3_StatusGet,
61
62 .EventCallbackRegister = &CMP3_EventCallbackRegister,
63 .Tasks = &CMP3_Tasks,
64 .cmp_dac_dc_interface = &dac3_dc_interface
65};
66
67// Section: CMP3 Module APIs
68
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 DAC3CONH = 0x0; //TMCB 0;
76 DAC3CONL = 0x8108; //HYSSEL None; HYSPOL Rising Edge; INSEL CMP3B; CMPPOL Non Inverted; FLTREN enabled; DACOEN disabled; CBE disabled; IRQM Interrupts are disabled; DACEN enabled;
77
78 //Slope Settings
79 DAC3DATH = 0xF32; //DACDATH 3890;
80 DAC3DATL = 0xCD; //DACDATL 205;
81 SLP3CONH = 0x0; //PSE Negative; TWME disabled; HME disabled; SLOPEN disabled;
82 SLP3CONL = 0x0; //SLPSTRT None; SLPSTOPB None; SLPSTOPA None; HCFSEL None;
83 SLP3DAT = 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 DAC3CONH = 0x0;
101 DAC3CONL = 0x0;
102
103 //Slope Settings
104 DAC3DATH = 0x0;
105 DAC3DATL = 0x0;
106 SLP3CONH = 0x0;
107 SLP3CONL = 0x0;
108 SLP3DAT = 0x0;
109}
110
112{
113 return (DAC3CONLbits.CMPSTAT);
114}
115
116void CMP3_Enable(void)
117{
118 DACCTRL1Lbits.DACON = 1;
119}
120
121void CMP3_Disable(void)
122{
123 DACCTRL1Lbits.DACON = 0;
124}
125
127{
128 DAC3CONLbits.DACEN = 1;
129}
130
132{
133 DAC3CONLbits.DACEN = 0;
134}
135
136void CMP3_DACDataWrite(size_t value)
137{
138 DAC3DATHbits.DACDATH = value;
139}
140
141void CMP3_EventCallbackRegister(void (*handler)(void))
142{
143 if(NULL != handler)
144 {
145 CMP3_EventHandler = handler;
146 }
147}
148
150{
151
152}
153
154void CMP3_Tasks(void)
155{
156 if(IFS4bits.CMP3IF == 1)
157 {
158 // CMP3 callback function
159 if(NULL != CMP3_EventHandler)
160 {
161 (*CMP3_EventHandler)();
162 }
163
164 // clear the CMP3 interrupt flag
165 IFS4bits.CMP3IF = 0;
166 }
167}
168
void __attribute__((weak))
Definition cmp3.c:149
static void(* CMP3_EventHandler)(void)
Definition cmp3.c:46
const struct DAC_DC_INTERFACE dac3_dc_interface
Definition cmp3.c:49
void CMP3_EventCallback(void)
This is the default callback with weak attribute. The user can override and implement the default cal...
void CMP3_EventCallbackRegister(void(*handler)(void))
This function can be used to override default callback and to define custom callback for CMP3 Event e...
Definition cmp3.c:141
bool CMP3_StatusGet(void)
Returns the comparator output status.
Definition cmp3.c:111
void CMP3_Enable(void)
Enables the common DAC module.
Definition cmp3.c:116
void CMP3_Tasks(void)
The Task function can be called in the main application using the High Speed Comparator,...
Definition cmp3.c:154
void CMP3_Disable(void)
Disables the common DAC module.
Definition cmp3.c:121
const struct CMP_INTERFACE CMP_IPRI_SC
Structure object of type CMP_INTERFACE with the custom name given by the user in the Melody Driver Us...
Definition cmp3.c:55
void CMP3_DACDataWrite(size_t value)
CMP DAC Data write to register.
Definition cmp3.c:136
void CMP3_Deinitialize(void)
Deinitializes the CMP3 to POR values.
Definition cmp3.c:91
void CMP3_Initialize(void)
Initialize the CMP3 module.
Definition cmp3.c:69
void CMP3_DACEnable(void)
Enables the individual DAC module.
Definition cmp3.c:126
void CMP3_DACDisable(void)
Disables the individual DAC module.
Definition cmp3.c:131
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.