Bar Logo 3.8/7.6 kw Totem pole Demonstration Application (Part-No. (not specified))
 
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
46static void (*CMP1_EventHandler)(void) = NULL;
47
48// Section: Driver Interface
51 .Disable = &CMP1_DACDisable,
52 .DataWrite = &CMP1_DACDataWrite,
53};
54
55const struct CMP_INTERFACE CMP_DAC1 = {
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
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 DAC1CONH = 0x0; //TMCB 0;
76 DAC1CONL = 0x8200; //HYSSEL None; HYSPOL Rising Edge; INSEL S1CMP1A; CMPPOL Non Inverted; FLTREN disabled; DACOEN enabled; CBE disabled; IRQM Interrupts are disabled; DACEN enabled;
77
78 //Slope Settings
79 DAC1DATH = 0xCD; //DACDATH 205;
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
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 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
112{
113 return (DAC1CONLbits.CMPSTAT);
114}
115
116void CMP1_Enable(void)
117{
118 DACCTRL1Lbits.DACON = 1;
119}
120
121void CMP1_Disable(void)
122{
123 DACCTRL1Lbits.DACON = 0;
124}
125
127{
128 DAC1CONLbits.DACEN = 1;
129}
130
132{
133 DAC1CONLbits.DACEN = 0;
134}
135
136void CMP1_DACDataWrite(size_t value)
137{
138 DAC1DATHbits.DACDATH = value;
139}
140
141void CMP1_EventCallbackRegister(void (*handler)(void))
142{
143 if(NULL != handler)
144 {
145 CMP1_EventHandler = handler;
146 }
147}
148
149void __attribute__ ((weak)) CMP1_EventCallback(void)
150{
151
152}
153
154void 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
171
const struct CMP_INTERFACE CMP_DAC1
Structure object of type CMP_INTERFACE with the custom name given by the user in the Melody Driver Us...
Definition cmp1.c:55
void CMP1_Enable(void)
Enables the common DAC module.
Definition cmp1.c:116
void CMP1_EventCallback(void)
This is the default callback with weak attribute. The user can override and implement the default cal...
Definition cmp1.c:149
bool CMP1_StatusGet(void)
Returns the comparator output status.
Definition cmp1.c:111
void CMP1_Deinitialize(void)
Deinitializes the CMP1 to POR values.
Definition cmp1.c:91
void CMP1_Tasks(void)
The Task function can be called in the main application using the High Speed Comparator,...
Definition cmp1.c:154
void CMP1_Initialize(void)
Initialize the CMP1 module.
Definition cmp1.c:69
void CMP1_DACEnable(void)
Enables the individual DAC module.
Definition cmp1.c:126
void CMP1_DACDisable(void)
Disables the individual DAC module.
Definition cmp1.c:131
void CMP1_Disable(void)
Disables the common DAC module.
Definition cmp1.c:121
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
void CMP1_DACDataWrite(size_t value)
CMP DAC Data write to register.
Definition cmp1.c:136
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.
This is the generated driver header file for the CMP1 driver.
const struct DAC_DC_INTERFACE dac1_dc_interface
Definition cmp1.c:49
static void(* CMP1_EventHandler)(void)
Definition cmp1.c:46