Bar Logo 4kW dsPIC33C PSFB DC-DC DA (Part-No. )
 
Content
     
Loading...
Searching...
No Matches
cmp3.c
Go to the documentation of this file.
1
18/*
19© [2025] 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
50 .Enable = &CMP3_DACEnable,
51 .Disable = &CMP3_DACDisable,
52 .DataWrite = &CMP3_DACDataWrite,
53};
54
56 .Initialize = &CMP3_Initialize,
57 .Deinitialize = &CMP3_Deinitialize,
58 .Enable = &CMP3_Enable,
59 .Disable = &CMP3_Disable,
60 .StatusGet = &CMP3_StatusGet,
61
62 .EventCallbackRegister = &CMP3_EventCallbackRegister,
63 .Tasks = NULL,
64 .cmp_dac_dc_interface = &dac3_dc_interface
65};
66
67// Section: CMP3 Module APIs
68
70{
71 // Comparator Register settings
72 DACCTRL1L = 0x46; //FCLKDIV 1:7; CLKDIV 1:1; CLKSEL FVCO/2; DACSIDL disabled; DACON disabled;
73 DACCTRL2H = 0x8A; //SSTIME 138;
74 DACCTRL2L = 0x55; //TMODTIME 85;
75 DAC3CONH = 0x0; //TMCB 0;
76 DAC3CONL = 0xA308; //HYSSEL None; HYSPOL Rising Edge; INSEL CMP3B; CMPPOL Non Inverted; FLTREN enabled; DACOEN enabled; CBE disabled; IRQM Rising edge detect; DACEN enabled;
77
78 //Slope Settings
79 DAC3DATH = 0xF00; //DACDATH 3840;
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 // Clearing IF flag before enabling the interrupt.
88 IFS4bits.CMP3IF = 0;
89 // Enabling CMP3 interrupt.
90 IEC4bits.CMP3IE = 1;
91
92 DACCTRL1Lbits.DACON = 1;
93}
94
96{
97 DACCTRL1Lbits.DACON = 0;
98
99 IFS4bits.CMP3IF = 0;
100 IEC4bits.CMP3IE = 0;
101
102 // Comparator Register settings
103 DACCTRL1L = 0x0;
104 DACCTRL2H = 0x8A;
105 DACCTRL2L = 0x55;
106 DAC3CONH = 0x0;
107 DAC3CONL = 0x0;
108
109 //Slope Settings
110 DAC3DATH = 0x0;
111 DAC3DATL = 0x0;
112 SLP3CONH = 0x0;
113 SLP3CONL = 0x0;
114 SLP3DAT = 0x0;
115}
116
118{
119 return (DAC3CONLbits.CMPSTAT);
120}
121
122void CMP3_Enable(void)
123{
124 DACCTRL1Lbits.DACON = 1;
125}
126
127void CMP3_Disable(void)
128{
129 DACCTRL1Lbits.DACON = 0;
130}
131
133{
134 DAC3CONLbits.DACEN = 1;
135}
136
138{
139 DAC3CONLbits.DACEN = 0;
140}
141
142void CMP3_DACDataWrite(size_t value)
143{
144 DAC3DATHbits.DACDATH = value;
145}
146
147void CMP3_EventCallbackRegister(void (*handler)(void))
148{
149 if(NULL != handler)
150 {
151 CMP3_EventHandler = handler;
152 }
153}
154
156{
157
158}
159
160void __attribute__ ( ( interrupt, no_auto_psv ) ) _CMP3Interrupt(void)
161{
162 // CMP3 callback function
163 if(NULL != CMP3_EventHandler)
164 {
165 (*CMP3_EventHandler)();
166 }
167
168 // clear the CMP3 interrupt flag
169 IFS4bits.CMP3IF = 0;
170}
171
This is the generated driver header file for the CMP3 driver.
void __attribute__((weak))
Definition cmp3.c:155
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:147
bool CMP3_StatusGet(void)
Returns the comparator output status.
Definition cmp3.c:117
void CMP3_Enable(void)
Enables the common DAC module.
Definition cmp3.c:122
void CMP3_Disable(void)
Disables the common DAC module.
Definition cmp3.c:127
void CMP3_DACDataWrite(size_t value)
CMP DAC Data write to register.
Definition cmp3.c:142
void CMP3_Deinitialize(void)
Deinitializes the CMP3 to POR values.
Definition cmp3.c:95
void CMP3_Initialize(void)
Initialize the CMP3 module.
Definition cmp3.c:69
const struct CMP_INTERFACE CMP_DAC3_PCT
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_DACEnable(void)
Enables the individual DAC module.
Definition cmp3.c:132
void CMP3_DACDisable(void)
Disables the individual DAC module.
Definition cmp3.c:137
Structure containing the function pointers of DAC driver in DC mode.
Structure containing the function pointers of CMP driver.