MSP430 DriverLib for MSP430FR2xx_4xx Devices  2.91.13.01
ecomp.h
1 //*****************************************************************************
2 //
3 // ecomp.h - Driver for the ECOMP Module.
4 //
5 //*****************************************************************************
6 
7 #ifndef __MSP430WARE_ECOMP_H__
8 #define __MSP430WARE_ECOMP_H__
9 
10 #include "inc/hw_memmap.h"
11 
12 #ifdef __MSP430_HAS_ECOMPx__
13 
14 //*****************************************************************************
15 //
16 // If building with a C++ compiler, make all of the definitions in this header
17 // have a C binding.
18 //
19 //*****************************************************************************
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif
24 
25 #include "inc/hw_memmap.h"
26 //*****************************************************************************
27 //
28 //! \brief Used in the EComp_init() function as the param parameter.
29 //
30 //*****************************************************************************
31 typedef struct EComp_initParam {
32  //! Selects the input to the positive terminal
33  //! \n Valid values are:
34  //! - \b ECOMP_INPUT_0
35  //! - \b ECOMP_INPUT_1
36  //! - \b ECOMP_INPUT_2
37  //! - \b ECOMP_INPUT_3
38  //! - \b ECOMP_INPUT_DEVICE_SPECIFIC_0
39  //! - \b ECOMP_INPUT_DEVICE_SPECIFIC_1
40  //! - \b ECOMP_INPUT_DAC
41  //! - \b ECOMP_INPUT_DISABLED
43  //! Selects the input to the negative terminal
44  //! \n Valid values are:
45  //! - \b ECOMP_INPUT_0
46  //! - \b ECOMP_INPUT_1
47  //! - \b ECOMP_INPUT_2
48  //! - \b ECOMP_INPUT_3
49  //! - \b ECOMP_INPUT_DEVICE_SPECIFIC_0
50  //! - \b ECOMP_INPUT_DEVICE_SPECIFIC_1
51  //! - \b ECOMP_INPUT_DAC
52  //! - \b ECOMP_INPUT_DISABLED
54  //! Controls the output filter delay state, which is either off or enabled
55  //! with a specified delay level. This parameter is device specific and
56  //! delay levels should be found in the device's datasheet.
57  //! \n Valid values are:
58  //! - \b ECOMP_FILTER_DELAY_OFF [Default]
59  //! - \b ECOMP_FILTER_DELAY_450NS
60  //! - \b ECOMP_FILTER_DELAY_900NS
61  //! - \b ECOMP_FILTER_DELAY_1800NS
62  //! - \b ECOMP_FILTER_DELAY_3600NS
64  //! Controls if the output will be inverted or not
65  //! \n Valid values are:
66  //! - \b ECOMP_NORMAL_OUTPUT_POLARITY [Default]
67  //! - \b ECOMP_INVERTED_OUTPUT_POLARITY
70 
71 //*****************************************************************************
72 //
73 //! \brief Used in the EComp_configureDAC() function as the param parameter.
74 //
75 //*****************************************************************************
76 typedef struct EComp_configureDACParam {
77  //! Selects the built-in DAC reference voltage.
78  //! \n Valid values are:
79  //! - \b ECOMP_DAC_REFERENCE_VOLTAGE_VDD [Default]
80  //! - \b ECOMP_DAC_REFERENCE_VOLTAGE_VREF
82  //! Selects the built-in DAC buffer controlled source.
83  //! \n Valid values are:
84  //! - \b ECOMP_DAC_BUFFER_SOURCE_COMP_OUTPUT
85  //! - \b ECOMP_DAC_BUFFER_SOURCE_DUAL_BUFFER_1 [Default]
86  //! - \b ECOMP_DAC_BUFFER_SOURCE_DUAL_BUFFER_2
87  uint8_t bufferSource;
88  //! Sets the first DAC buffer data (0~63).
89  uint16_t firstBufferData;
90  //! Sets the second DAC buffer data (0~63). The reset value for the second
91  //! DAC buffer is 0x1.
92  uint16_t secondBufferData;
94 
95 
96 
97 //*****************************************************************************
98 //
99 // The following are values that can be passed to the param parameter for
100 // functions: EComp_init(), and EComp_init().
101 //
102 //*****************************************************************************
103 #define ECOMP_INPUT_0 0x0
104 #define ECOMP_INPUT_1 0x1
105 #define ECOMP_INPUT_2 0x2
106 #define ECOMP_INPUT_3 0x3
107 #define ECOMP_INPUT_DEVICE_SPECIFIC_0 0x4
108 #define ECOMP_INPUT_DEVICE_SPECIFIC_1 0x5
109 #define ECOMP_INPUT_DAC 0x6
110 #define ECOMP_INPUT_DISABLED 0x7
111 
112 //*****************************************************************************
113 //
114 // The following are values that can be passed to the param parameter for
115 // functions: EComp_init().
116 //
117 //*****************************************************************************
118 #define ECOMP_FILTER_DELAY_OFF 0x0
119 #define ECOMP_FILTER_DELAY_450NS (CPFLT|CPFLTDLY_0)
120 #define ECOMP_FILTER_DELAY_900NS (CPFLT|CPFLTDLY_1)
121 #define ECOMP_FILTER_DELAY_1800NS (CPFLT|CPFLTDLY_2)
122 #define ECOMP_FILTER_DELAY_3600NS (CPFLT|CPFLTDLY_3)
123 
124 //*****************************************************************************
125 //
126 // The following are values that can be passed to the param parameter for
127 // functions: EComp_init().
128 //
129 //*****************************************************************************
130 #define ECOMP_NORMAL_OUTPUT_POLARITY 0x0
131 #define ECOMP_INVERTED_OUTPUT_POLARITY CPINV
132 
133 //*****************************************************************************
134 //
135 // The following are values that can be passed to the hysteresisMode parameter
136 // for functions: EComp_selectHysteresisMode().
137 //
138 //*****************************************************************************
139 #define ECOMP_HYSTERESIS_MODE_DISABLE CPHSEL_0
140 #define ECOMP_HYSTERESIS_MODE_10MV CPHSEL_1
141 #define ECOMP_HYSTERESIS_MODE_20MV CPHSEL_2
142 #define ECOMP_HYSTERESIS_MODE_30MV CPHSEL_3
143 
144 //*****************************************************************************
145 //
146 // The following are values that can be passed to the powerMode parameter for
147 // functions: EComp_selectPowerMode().
148 //
149 //*****************************************************************************
150 #define ECOMP_POWER_MODE_HIGH_POWER_HIGH_SPEED 0x0
151 #define ECOMP_POWER_MODE_LOW_POWER_LOW_SPEED CPMSEL
152 
153 //*****************************************************************************
154 //
155 // The following are values that can be passed to the interruptMask parameter
156 // for functions: EComp_enableInterrupt(), and EComp_disableInterrupt().
157 //
158 //*****************************************************************************
159 #define ECOMP_OUTPUT_INTERRUPT CPIE
160 #define ECOMP_INVERTED_POLARITY_INTERRUPT CPIIE
161 
162 //*****************************************************************************
163 //
164 // The following are values that can be passed to the interruptFlagMask
165 // parameter for functions: EComp_clearInterrupt(), and
166 // EComp_getInterruptStatus() as well as returned by the
167 // EComp_getInterruptStatus() function.
168 //
169 //*****************************************************************************
170 #define ECOMP_OUTPUT_INTERRUPT_FLAG CPIFG
171 #define ECOMP_INVERTED_POLARITY_INTERRUPT_FLAG CPIIFG
172 
173 //*****************************************************************************
174 //
175 // The following are values that can be passed to the edgeDirection parameter
176 // for functions: EComp_setInterruptEdgeDirection().
177 //
178 //*****************************************************************************
179 #define ECOMP_OUTPUT_INTERRUPT_RISING_EDGE 0x0
180 #define ECOMP_OUTPUT_INTERRUPT_FALLING_EDGE CPIES
181 
182 //*****************************************************************************
183 //
184 // The following are values that can be passed toThe following are values that
185 // can be returned by the EComp_outputValue() function.
186 //
187 //*****************************************************************************
188 #define ECOMP_LOW 0x0
189 #define ECOMP_HIGH CPOUT
190 
191 //*****************************************************************************
192 //
193 // The following are values that can be passed to the param parameter for
194 // functions: EComp_configureDAC().
195 //
196 //*****************************************************************************
197 #define ECOMP_DAC_REFERENCE_VOLTAGE_VDD 0x0
198 #define ECOMP_DAC_REFERENCE_VOLTAGE_VREF CPDACREFS
199 
200 //*****************************************************************************
201 //
202 // The following are values that can be passed to the param parameter for
203 // functions: EComp_configureDAC().
204 //
205 //*****************************************************************************
206 #define ECOMP_DAC_BUFFER_SOURCE_COMP_OUTPUT 0x0
207 #define ECOMP_DAC_BUFFER_SOURCE_DUAL_BUFFER_1 (CPDACBUFS)
208 #define ECOMP_DAC_BUFFER_SOURCE_DUAL_BUFFER_2 (CPDACBUFS|CPDACSW)
209 
210 //*****************************************************************************
211 //
212 // Prototypes for the APIs.
213 //
214 //*****************************************************************************
215 
216 //*****************************************************************************
217 //
218 //! \brief Initializes the EComp
219 //!
220 //! Upon successful initialization of the EComp module, this function will have
221 //! reset all necessary register bits and set the given options in the
222 //! registers. To actually use the EComp_E module, the EComp_enable() function
223 //! must be explicitly called before use. (If a Reference Voltage is set to a
224 //! terminal, the Voltage should be set using the EComp_configureDAC()
225 //! function.)
226 //!
227 //! \param baseAddress is the base address of the ECOMP module.
228 //!
229 //! \return None
230 //
231 //*****************************************************************************
232 extern void EComp_init(uint16_t baseAddress,
233  EComp_initParam *param);
234 
235 //*****************************************************************************
236 //
237 //! \brief Sets the hysteresis mode
238 //!
239 //! This function sets the hysteresis mode.
240 //!
241 //! \param baseAddress is the base address of the ECOMP module.
242 //! \param hysteresisMode decides the hysteresis mode
243 //! Valid values are:
244 //! - \b ECOMP_HYSTERESIS_MODE_DISABLE [Default]
245 //! - \b ECOMP_HYSTERESIS_MODE_10MV
246 //! - \b ECOMP_HYSTERESIS_MODE_20MV
247 //! - \b ECOMP_HYSTERESIS_MODE_30MV
248 //!
249 //! Modified bits are \b CPHSEL of \b CPCTL1 register.
250 //!
251 //! \return None
252 //
253 //*****************************************************************************
254 extern void EComp_selectHysteresisMode(uint16_t baseAddress,
255  uint16_t hysteresisMode);
256 
257 //*****************************************************************************
258 //
259 //! \brief Sets the power mode
260 //!
261 //! This function sets the power mode.
262 //!
263 //! \param baseAddress is the base address of the ECOMP module.
264 //! \param powerMode decides the power mode
265 //! Valid values are:
266 //! - \b ECOMP_POWER_MODE_HIGH_POWER_HIGH_SPEED [Default]
267 //! - \b ECOMP_POWER_MODE_LOW_POWER_LOW_SPEED
268 //!
269 //! \return None
270 //
271 //*****************************************************************************
272 extern void EComp_selectPowerMode(uint16_t baseAddress,
273  uint16_t powerMode);
274 
275 //*****************************************************************************
276 //
277 //! \brief Turns on the EComp module
278 //!
279 //! This function sets the bit that enables the operation of the EComp module.
280 //!
281 //! \param baseAddress is the base address of the ECOMP module.
282 //!
283 //! Modified bits are \b CPEN of \b CPCTL1 register.
284 //!
285 //! \return None
286 //
287 //*****************************************************************************
288 extern void EComp_enable(uint16_t baseAddress);
289 
290 //*****************************************************************************
291 //
292 //! \brief Turns off the EComp module
293 //!
294 //! This function clears the CPEN bit disabling the operation of the EComp
295 //! module, saving from excess power consumption.
296 //!
297 //! \param baseAddress is the base address of the ECOMP module.
298 //!
299 //! Modified bits are \b CPEN of \b CPCTL1 register.
300 //!
301 //! \return None
302 //
303 //*****************************************************************************
304 extern void EComp_disable(uint16_t baseAddress);
305 
306 //*****************************************************************************
307 //
308 //! \brief Enables selected EComp interrupt sources
309 //!
310 //! Enables the indicated EComp interrupt sources. Only the sources that are
311 //! enabled can be reflected to the processor interrupt; disabled sources have
312 //! no effect on the processor. <b>Does not clear interrupt flags.</b>
313 //!
314 //! \param baseAddress is the base address of the ECOMP module.
315 //! \param interruptMask
316 //! Mask value is the logical OR of any of the following:
317 //! - \b ECOMP_OUTPUT_INTERRUPT - Output interrupt
318 //! - \b ECOMP_INVERTED_POLARITY_INTERRUPT - Output interrupt inverted
319 //! polarity
320 //!
321 //! \return None
322 //
323 //*****************************************************************************
324 extern void EComp_enableInterrupt(uint16_t baseAddress,
325  uint16_t interruptMask);
326 
327 //*****************************************************************************
328 //
329 //! \brief Disables selected EComp interrupt sources
330 //!
331 //! Disables the indicated EComp interrupt sources. Only the sources that are
332 //! enabled can be reflected to the processor interrupt; disabled sources have
333 //! no effect on the processor. <b>Does not clear interrupt flags.</b>
334 //!
335 //! \param baseAddress is the base address of the ECOMP module.
336 //! \param interruptMask
337 //! Mask value is the logical OR of any of the following:
338 //! - \b ECOMP_OUTPUT_INTERRUPT - Output interrupt
339 //! - \b ECOMP_INVERTED_POLARITY_INTERRUPT - Output interrupt inverted
340 //! polarity
341 //!
342 //! \return None
343 //
344 //*****************************************************************************
345 extern void EComp_disableInterrupt(uint16_t baseAddress,
346  uint16_t interruptMask);
347 
348 //*****************************************************************************
349 //
350 //! \brief Clears EComp interrupt flags
351 //!
352 //! The EComp interrupt source is cleared, so that it no longer asserts. The
353 //! highest interrupt flag is automatically cleared when an interrupt vector
354 //! generator is used.
355 //!
356 //! \param baseAddress is the base address of the ECOMP module.
357 //! \param interruptFlagMask
358 //! Mask value is the logical OR of any of the following:
359 //! - \b ECOMP_OUTPUT_INTERRUPT_FLAG - Output interrupt flag
360 //! - \b ECOMP_INVERTED_POLARITY_INTERRUPT_FLAG - Output interrupt flag
361 //! inverted polarity
362 //!
363 //! \return None
364 //
365 //*****************************************************************************
366 extern void EComp_clearInterrupt(uint16_t baseAddress,
367  uint16_t interruptFlagMask);
368 
369 //*****************************************************************************
370 //
371 //! \brief Gets the current EComp interrupt status
372 //!
373 //! This returns the interrupt status for the EComp_E module based on which
374 //! flag is passed.
375 //!
376 //! \param baseAddress is the base address of the ECOMP module.
377 //! \param interruptFlagMask
378 //! Mask value is the logical OR of any of the following:
379 //! - \b ECOMP_OUTPUT_INTERRUPT_FLAG - Output interrupt flag
380 //! - \b ECOMP_INVERTED_POLARITY_INTERRUPT_FLAG - Output interrupt flag
381 //! inverted polarity
382 //!
383 //! \return Logical OR of any of the following:
384 //! - \b ECOMP_OUTPUT_INTERRUPT_FLAG Output interrupt flag
385 //! - \b ECOMP_INVERTED_POLARITY_INTERRUPT_FLAG Output interrupt flag
386 //! inverted polarity
387 //! \n indicating the status of the masked flags
388 //
389 //*****************************************************************************
390 extern uint8_t EComp_getInterruptStatus(uint16_t baseAddress,
391  uint16_t interruptFlagMask);
392 
393 //*****************************************************************************
394 //
395 //! \brief Explicitly sets the edge direction that would trigger an interrupt
396 //!
397 //! This function will set which direction the output will have to go, whether
398 //! rising or falling, to generate an interrupt based on a non-inverted
399 //! interrupt.
400 //!
401 //! \param baseAddress is the base address of the ECOMP module.
402 //! \param edgeDirection determines which direction the edge would have to go
403 //! to generate an interrupt based on the non-inverted interrupt flag.
404 //! Valid values are:
405 //! - \b ECOMP_OUTPUT_INTERRUPT_RISING_EDGE [Default] - sets the bit to
406 //! generate an interrupt when the output of the EComp rises from LOW
407 //! to HIGH if the normal interrupt bit is set(and HIGH to LOW if the
408 //! inverted interrupt enable bit is set).
409 //! - \b ECOMP_OUTPUT_INTERRUPT_FALLING_EDGE - sets the bit to generate
410 //! an interrupt when the output of the EComp falls from HIGH to LOW
411 //! if the normal interrupt bit is set(and LOW to HIGH if the
412 //! inverted interrupt enable bit is set).
413 //! \n Modified bits are \b CPIES of \b CPCTL1 register.
414 //!
415 //! \return None
416 //
417 //*****************************************************************************
418 extern void EComp_setInterruptEdgeDirection(uint16_t baseAddress,
419  uint16_t edgeDirection);
420 
421 //*****************************************************************************
422 //
423 //! \brief Toggles the edge direction that would trigger an interrupt
424 //!
425 //! This function will toggle which direction the output will have to go,
426 //! whether rising or falling, to generate an interrupt based on a non-inverted
427 //! interrupt. If the direction was rising, it is now falling, if it was
428 //! falling, it is now rising.
429 //!
430 //! \param baseAddress is the base address of the ECOMP module.
431 //!
432 //! Modified bits are \b CPIES of \b CPCTL1 register.
433 //!
434 //! \return None
435 //
436 //*****************************************************************************
437 extern void EComp_toggleInterruptEdgeDirection(uint16_t baseAddress);
438 
439 //*****************************************************************************
440 //
441 //! \brief Returns the output value of the EComp module
442 //!
443 //! Returns the output value of the EComp module.
444 //!
445 //! \param baseAddress is the base address of the ECOMP module.
446 //!
447 //! \return indicating the output value of the EComp module
448 //! Return one of the following:
449 //! - \b ECOMP_LOW
450 //! - \b ECOMP_HIGH
451 //! \n indicating the output value of the EComp module
452 //
453 //*****************************************************************************
454 extern uint8_t EComp_outputValue(uint16_t baseAddress);
455 
456 //*****************************************************************************
457 //
458 //! \brief Configures the built-in DAC for internal reference
459 //!
460 //! This function will configure the built-in DAC register bits including
461 //! reference voltage and DAC buffer source.
462 //!
463 //! \param baseAddress is the base address of the ECOMP module.
464 //!
465 //! \return None
466 //
467 //*****************************************************************************
468 extern void EComp_configureDAC(uint16_t baseAddress,
469  EComp_configureDACParam *param);
470 
471 //*****************************************************************************
472 //
473 //! \brief Enables DAC output
474 //!
475 //! This function will enable DAC output.
476 //!
477 //! \param baseAddress is the base address of the ECOMP module.
478 //!
479 //! \return None
480 //
481 //*****************************************************************************
482 extern void EComp_enableDAC(uint16_t baseAddress);
483 
484 //*****************************************************************************
485 //
486 //! \brief Disables DAC output
487 //!
488 //! This function will disable DAC output. When it is disabled, the DAC always
489 //! output low.
490 //!
491 //! \param baseAddress is the base address of the ECOMP module.
492 //!
493 //! \return None
494 //
495 //*****************************************************************************
496 extern void EComp_disableDAC(uint16_t baseAddress);
497 
498 //*****************************************************************************
499 //
500 // Mark the end of the C bindings section for C++ compilers.
501 //
502 //*****************************************************************************
503 #ifdef __cplusplus
504 }
505 #endif
506 
507 #endif
508 #endif // __MSP430WARE_ECOMP_H__
uint8_t EComp_outputValue(uint16_t baseAddress)
Returns the output value of the EComp module.
Definition: ecomp.c:94
uint8_t bufferSource
Definition: ecomp.h:87
void EComp_setInterruptEdgeDirection(uint16_t baseAddress, uint16_t edgeDirection)
Explicitly sets the edge direction that would trigger an interrupt.
Definition: ecomp.c:82
void EComp_enableInterrupt(uint16_t baseAddress, uint16_t interruptMask)
Enables selected EComp interrupt sources.
Definition: ecomp.c:61
uint16_t firstBufferData
Sets the first DAC buffer data (0~63).
Definition: ecomp.h:89
Used in the EComp_configureDAC() function as the param parameter.
Definition: ecomp.h:76
void EComp_selectPowerMode(uint16_t baseAddress, uint16_t powerMode)
Sets the power mode.
Definition: ecomp.c:45
Used in the EComp_init() function as the param parameter.
Definition: ecomp.h:31
void EComp_enableDAC(uint16_t baseAddress)
Enables DAC output.
Definition: ecomp.c:111
void EComp_configureDAC(uint16_t baseAddress, EComp_configureDACParam *param)
Configures the built-in DAC for internal reference.
Definition: ecomp.c:99
void EComp_selectHysteresisMode(uint16_t baseAddress, uint16_t hysteresisMode)
Sets the hysteresis mode.
Definition: ecomp.c:38
void EComp_disableInterrupt(uint16_t baseAddress, uint16_t interruptMask)
Disables selected EComp interrupt sources.
Definition: ecomp.c:66
void EComp_disable(uint16_t baseAddress)
Turns off the EComp module.
Definition: ecomp.c:56
void EComp_enable(uint16_t baseAddress)
Turns on the EComp module.
Definition: ecomp.c:51
uint16_t secondBufferData
Definition: ecomp.h:92
void EComp_disableDAC(uint16_t baseAddress)
Disables DAC output.
Definition: ecomp.c:116
void EComp_clearInterrupt(uint16_t baseAddress, uint16_t interruptFlagMask)
Clears EComp interrupt flags.
Definition: ecomp.c:71
uint8_t positiveTerminalInput
Definition: ecomp.h:42
uint16_t invertedOutputPolarity
Definition: ecomp.h:68
void EComp_toggleInterruptEdgeDirection(uint16_t baseAddress)
Toggles the edge direction that would trigger an interrupt.
Definition: ecomp.c:89
uint8_t referenceVoltage
Definition: ecomp.h:81
void EComp_init(uint16_t baseAddress, EComp_initParam *param)
Initializes the EComp.
Definition: ecomp.c:21
uint8_t negativeTerminalInput
Definition: ecomp.h:53
uint16_t outputFilterEnableAndDelayLevel
Definition: ecomp.h:63
uint8_t EComp_getInterruptStatus(uint16_t baseAddress, uint16_t interruptFlagMask)
Gets the current EComp interrupt status.
Definition: ecomp.c:76

Copyright 2020, Texas Instruments Incorporated