Defines | Functions
compd.h File Reference

Go to the source code of this file.

Defines

#define __MSP430_HAS_COMPD__
#define COMPD_INPUT0   (CDIPSEL_0)
#define COMPD_INPUT1   (CDIPSEL_1)
#define COMPD_INPUT2   (CDIPSEL_2)
#define COMPD_INPUT3   (CDIPSEL_3)
#define COMPD_INPUT4   (CDIPSEL_4)
#define COMPD_INPUT5   (CDIPSEL_5)
#define COMPD_INPUT6   (CDIPSEL_6)
#define COMPD_INPUT7   (CDIPSEL_7)
#define COMPD_INPUT8   (CDIPSEL_8)
#define COMPD_INPUT9   (CDIPSEL_9)
#define COMPD_INPUT10   (CDIPSEL_10)
#define COMPD_INPUT11   (CDIPSEL_11)
#define COMPD_INPUT12   (CDIPSEL_12)
#define COMPD_INPUT13   (CDIPSEL_13)
#define COMPD_INPUT14   (CDIPSEL_14)
#define COMPD_INPUT15   (CDIPSEL_15)
#define COMPD_VREF   (0x10)
#define COMPD_FILTEROUTPUT_OFF   0x00
#define COMPD_FILTEROUTPUT_DLYLVL1   (CDF + CDFDLY_0)
#define COMPD_FILTEROUTPUT_DLYLVL2   (CDF + CDFDLY_1)
#define COMPD_FILTEROUTPUT_DLYLVL3   (CDF + CDFDLY_2)
#define COMPD_FILTEROUTPUT_DLYLVL4   (CDF + CDFDLY_3)
#define COMPD_NORMALOUTPUTPOLARITY   ( !(CDOUTPOL) )
#define COMPD_INVERTEDOUTPUTPOLARITY   (CDOUTPOL)
#define COMPD_REFERENCE_AMPLIFIER_DISABLED   (CDREFL_0)
#define COMPD_VREFBASE1_5V   (CDREFL_1)
#define COMPD_VREFBASE2_0V   (CDREFL_2)
#define COMPD_VREFBASE2_5V   (CDREFL_3)
#define COMPD_VREFBASE_VCC   (CDREFL_0)
#define COMPD_FALLINGEDGE   ( !(CDIES) )
#define COMPD_RISINGEDGE   (CDIES)
#define COMPD_LOW   (0x0)
#define COMPD_HIGH   (0x1)
#define COMPD_INTERRUPT_ENABLE   CDIE
#define COMPD_INTERRUPT_ENABLE_INVERTED_POLARITY   CDIIE
#define COMPD_INTERRUPT_FLAG   CDIFG
#define COMPD_INTERRUPT_FLAG_INVERTED_POLARITY   CDIIFG

Functions

unsigned short COMPD_init (unsigned int baseAddress, unsigned char positiveTerminalInput, unsigned char negativeTerminalInput, unsigned char outputFilterEnableAndDelayLevel, unsigned short invertedOutputPolarity)
void COMPD_setReferenceVoltage (unsigned int baseAddress, unsigned int supplyVoltageReferenceBase, unsigned int lowerLimitSupplyVoltageFractionOf32, unsigned int upperLimitSupplyVoltageFractionOf32)
void COMPD_enableInterrupt (unsigned int baseAddress, unsigned int mask)
void COMPD_disableInterrupt (unsigned int baseAddress, unsigned int mask)
void COMPD_clearInterrupt (unsigned int baseAddress, unsigned int mask)
unsigned char COMPD_getInterruptStatus (unsigned int baseAddress, unsigned int mask)
void COMPD_interruptSetEdgeDirection (unsigned int baseAddress, unsigned short edgeDirection)
void COMPD_interruptToggleEdgeDirection (unsigned int baseAddress)
void COMPD_enable (unsigned int baseAddress)
void COMPD_disable (unsigned int baseAddress)
void COMPD_shortInputs (unsigned int baseAddress)
void COMPD_unshortInputs (unsigned int baseAddress)
void COMPD_disableInputBuffer (unsigned int baseAddress, unsigned char inputPort)
void COMPD_enableInputBuffer (unsigned int baseAddress, unsigned char inputPort)
void COMPD_IOSwap (unsigned int baseAddress)
unsigned short COMPD_outputValue (unsigned int baseAddress)

Define Documentation

#define __MSP430_HAS_COMPD__
#define COMPD_INPUT0   (CDIPSEL_0)
#define COMPD_INPUT1   (CDIPSEL_1)
#define COMPD_INPUT2   (CDIPSEL_2)
#define COMPD_INPUT3   (CDIPSEL_3)
#define COMPD_INPUT4   (CDIPSEL_4)
#define COMPD_INPUT5   (CDIPSEL_5)
#define COMPD_INPUT6   (CDIPSEL_6)
#define COMPD_INPUT7   (CDIPSEL_7)
#define COMPD_INPUT8   (CDIPSEL_8)
#define COMPD_INPUT9   (CDIPSEL_9)
#define COMPD_INPUT10   (CDIPSEL_10)
#define COMPD_INPUT11   (CDIPSEL_11)
#define COMPD_INPUT12   (CDIPSEL_12)
#define COMPD_INPUT13   (CDIPSEL_13)
#define COMPD_INPUT14   (CDIPSEL_14)
#define COMPD_INPUT15   (CDIPSEL_15)
#define COMPD_VREF   (0x10)

Referenced by COMPD_init().

#define COMPD_FILTEROUTPUT_OFF   0x00
#define COMPD_FILTEROUTPUT_DLYLVL1   (CDF + CDFDLY_0)
#define COMPD_FILTEROUTPUT_DLYLVL2   (CDF + CDFDLY_1)
#define COMPD_FILTEROUTPUT_DLYLVL3   (CDF + CDFDLY_2)
#define COMPD_FILTEROUTPUT_DLYLVL4   (CDF + CDFDLY_3)

Referenced by COMPD_init().

#define COMPD_NORMALOUTPUTPOLARITY   ( !(CDOUTPOL) )
#define COMPD_INVERTEDOUTPUTPOLARITY   (CDOUTPOL)
#define COMPD_REFERENCE_AMPLIFIER_DISABLED   (CDREFL_0)
#define COMPD_VREFBASE1_5V   (CDREFL_1)
#define COMPD_VREFBASE2_0V   (CDREFL_2)
#define COMPD_VREFBASE2_5V   (CDREFL_3)
#define COMPD_VREFBASE_VCC   (CDREFL_0)
#define COMPD_FALLINGEDGE   ( !(CDIES) )
#define COMPD_RISINGEDGE   (CDIES)
#define COMPD_LOW   (0x0)

Referenced by COMPD_outputValue().

#define COMPD_HIGH   (0x1)

Referenced by COMPD_outputValue().

#define COMPD_INTERRUPT_ENABLE   CDIE
#define COMPD_INTERRUPT_ENABLE_INVERTED_POLARITY   CDIIE
#define COMPD_INTERRUPT_FLAG   CDIFG
#define COMPD_INTERRUPT_FLAG_INVERTED_POLARITY   CDIIFG

Function Documentation

unsigned short COMPD_init ( unsigned int  baseAddress,
unsigned char  positiveTerminalInput,
unsigned char  negativeTerminalInput,
unsigned char  outputFilterEnableAndDelayLevel,
unsigned short  invertedOutputPolarity 
)

Initializes the Comparator Module.

Parameters:
baseAddressis the base address of the Comparator module.
positiveTerminalInputselects the input to the positive terminal. Valid values are COMPD_INPUT0 [Default] COMPD_INPUT1 COMPD_INPUT2 COMPD_INPUT3 COMPD_INPUT4 COMPD_INPUT5 COMPD_INPUT6 COMPD_INPUT7 COMPD_INPUT8 COMPD_INPUT9 COMPD_INPUT10 COMPD_INPUT11 COMPD_INPUT12 COMPD_INPUT13 COMPD_INPUT14 COMPD_INPUT15 COMPD_VREF Modified bits are CDIPSEL and CDIPEN of CDCTL0 register, CDRSEL of CDCTL2 register, and CDPDx of CDCTL3 register.
negativeTerminalInputselects the input to the negative terminal. Valid values are COMPD_INPUT0 [Default] COMPD_INPUT1 COMPD_INPUT2 COMPD_INPUT3 COMPD_INPUT4 COMPD_INPUT5 COMPD_INPUT6 COMPD_INPUT7 COMPD_INPUT8 COMPD_INPUT9 COMPD_INPUT10 COMPD_INPUT11 COMPD_INPUT12 COMPD_INPUT13 COMPD_INPUT14 COMPD_INPUT15 COMPD_VREF Modified bits are CDIMSEL and CDIMEN of CDCTL0 register, CDRSEL of CDCTL2 register, and CDPDx of CDCTL3 register.
outputFilterEnableAndDelayLevelcontrols the output filter delay state, which is either off or enabled with a specified delay level. Valid values are COMPD_FILTEROUTPUT_OFF [Default] COMPD_FILTEROUTPUT_DLYLVL1 COMPD_FILTEROUTPUT_DLYLVL2 COMPD_FILTEROUTPUT_DLYLVL3 COMPD_FILTEROUTPUT_DLYLVL4 This parameter is device specific and delay levels should be found in the device's datasheet. Modified bits are CDF and CDFDLY of CDCTL1 register.
invertedOutputcontrols if the output will be inverted or not Valid values are COMPD_NORMALOUTPUTPOLARITY - indicates the output should be normal. [Default] COMPD_INVERTEDOUTPUTPOLARITY - the output should be inverted. Modified bits are CDOUTPOL of CDCTL1 register.

Upon successful initialization of the Comparator module, this function will have reset all necessary register bits and set the given options in the registers. To actually use the comparator module, the COMPD_enable() function must be explicitly called before use. If a Reference Voltage is set to a terminal, the Voltage should be set using the setReferenceVoltage() function.

Returns:
STATUS_SUCCESS or STATUS_FAILURE of the initialization process.

References ASSERT, COMPD_FILTEROUTPUT_DLYLVL4, COMPD_VREF, HWREG, and STATUS_SUCCESS.

void COMPD_setReferenceVoltage ( unsigned int  baseAddress,
unsigned int  supplyVoltageReferenceBase,
unsigned int  lowerLimitSupplyVoltageFractionOf32,
unsigned int  upperLimitSupplyVoltageFractionOf32 
)

Generates a Reference Voltage to the terminal selected during initialization.

Parameters:
baseAddressis the base address of the Comparator module.
supplyVoltageReferenceBasedecides the source and max amount of Voltage that can be used as a reference. Valid values are COMPD_REFERENCE_AMPLIFIER_DISABLED COMPD_VREFBASE1_5V COMPD_VREFBASE2_0V COMPD_VREFBASE2_5V Modified bits are CDREFL of CDCTL2 register.
upperLimitSupplyVoltageFractionOf32is the numerator of the equation to generate the reference voltage for the upper limit reference voltage. Modified bits are CDREF1 of CDCTL2 register.
lowerLimitSupplyVoltageFractionOf32is the numerator of the equation to generate the reference voltage for the lower limit reference voltage. Modified bits are CDREF0 of CDCTL2 register.

Use this function to generate a voltage to serve as a reference to the terminal selected at initialization. The voltage is determined by the equation: Vbase * (Numerator / 32). If the upper and lower limit voltage numerators are equal, then a static reference is defined, whereas they are different then a hysteresis effect is generated.

Returns:
NONE

References ASSERT, COMPD_VREFBASE2_5V, COMPD_VREFBASE_VCC, and HWREG.

void COMPD_enableInterrupt ( unsigned int  baseAddress,
unsigned int  interruptMask 
)

Enables selected Comparator interrupt sources.

Parameters:
baseAddressis the base address of the Comparator module.
maskis the bit mask of the interrupt sources to be enabled. Mask value is the logical OR of any of the following COMPD_INTERRUPT_ENABLE - Output interrupt enable COMPD_INTERRUPT_ENABLE_INVERTED_POLARITY - Output interrupt enable inverted polarity

Enables the indicated Comparator interrupt sources. Only the sources that are enabled can be reflected to the processor interrupt; disabled sources have no effect on the processor. The default trigger for the non-inverted interrupt is a rising edge of the output, this can be changed with the interruptSetEdgeDirection() function.

Returns:
NONE

References HWREG.

void COMPD_disableInterrupt ( unsigned int  baseAddress,
unsigned int  interruptMask 
)

Disables selected Comparator interrupt sources.

Parameters:
baseAddressis the base address of the Comparator module.
maskis the bit mask of the interrupt sources to be disabled. Mask value is the logical OR of any of the following COMPD_INTERRUPT_ENABLE - Output interrupt enable COMPD_INTERRUPT_ENABLE_INVERTED_POLARITY - Output interrupt enable inverted polarity

Disables the indicated Comparator interrupt sources. Only the sources that are enabled can be reflected to the processor interrupt; disabled sources have no effect on the processor.

Returns:
NONE

References HWREG.

void COMPD_clearInterrupt ( unsigned int  baseAddress,
unsigned int  interruptFlagMask 
)

Clears Comparator interrupt flags.

Parameters:
baseAddressis the base address of the Comparator module.
maskis a bit mask of the interrupt sources to be cleared. Mask value is the logical OR of any of the following COMPD_INTERRUPT_FLAG - Output interrupt flag COMPD_INTERRUPT_FLAG_INVERTED_POLARITY - Output interrupt flag inverted polarity

The Comparator interrupt source is cleared, so that it no longer asserts. The highest interrupt flag is automatically cleared when an interrupt vector generator is used.

Returns:
NONE

References HWREG.

unsigned char COMPD_getInterruptStatus ( unsigned int  baseAddress,
unsigned int  interruptFlagMask 
)

Gets the current Comparator interrupt status.

Parameters:
baseAddressis the base address of the Comparator module.
maskis the masked interrupt flag status to be returned. Mask value is the logical OR of any of the following COMPD_INTERRUPT_FLAG - Output interrupt flag COMPD_INTERRUPT_FLAG_INVERTED_POLARITY - Output interrupt flag inverted polarity

This returns the interrupt status for the Comparator module based on which flag is passed.

Returns:
The current interrupt flag status for the corresponding mask.

References HWREG.

void COMPD_interruptSetEdgeDirection ( unsigned int  baseAddress,
unsigned short  edgeDirection 
)

Explicitly sets the edge direction that would trigger an interrupt.

Parameters:
baseAddressis the base address of the Comparator module.
edgeDirectiondetermines which direction the edge would have to go to generate an interrupt based on the non-inverted interrupt flag. Valid values are COMPD_FALLINGEDGE - sets the bit to generate an interrupt when the output of the comparator falls from HIGH to LOW if the normal interrupt bit is set(and LOW to HIGH if the inverted interrupt enable bit is set). [Default] COMPD_RISINGEDGE - sets the bit to generate an interrupt when the output of the comparator rises from LOW to HIGH if the normal interrupt bit is set(and HIGH to LOW if the inverted interrupt enable bit is set). Modified bits are CDIES of CDCTL1 register.

This function will set which direction the output will have to go, whether rising or falling, to generate an interrupt based on a non-inverted interrupt.

Returns:
NONE

References ASSERT, COMPD_FALLINGEDGE, COMPD_RISINGEDGE, and HWREG.

void COMPD_interruptToggleEdgeDirection ( unsigned int  baseAddress)

Toggles the edge direction that would trigger an interrupt.

Parameters:
baseAddressis the base address of the Comparator module.

This function will toggle which direction the output will have to go, whether rising or falling, to generate an interrupt based on a non-inverted interrupt. If the direction was rising, it is now falling, if it was falling, it is now rising.

Modified bits are CDIES of CDCTL1 register.

Returns:
NONE

References HWREG.

void COMPD_enable ( unsigned int  baseAddress)

Turns on the Comparator module.

Parameters:
baseAddressis the base address of the Comparator module.

This function sets the bit that enables the operation of the Comparator module.

Returns:
NONE

References HWREG.

void COMPD_disable ( unsigned int  baseAddress)

Turns off the Comparator module.

Parameters:
baseAddressis the base address of the Comparator module.

This function clears the CDON bit disabling the operation of the Comparator module, saving from excess power consumption.

Modified bits are CDON of CDCTL1 register.

Returns:
NONE

References HWREG.

void COMPD_shortInputs ( unsigned int  baseAddress)

Shorts the two input pins chosen during initialization.

Parameters:
baseAddressis the base address of the Comparator module.

This function sets the bit that shorts the devices attached to the input pins chosen from the initialization of the comparator.

Modified bits are CDSHORT of CDCTL1 register.

Returns:
NONE

References HWREG.

void COMPD_unshortInputs ( unsigned int  baseAddress)

Disables the short of the two input pins chosen during initialization.

Parameters:
baseAddressis the base address of the Comparator module.

This function clears the bit that shorts the devices attached to the input pins chosen from the initialization of the comparator.

Modified bits are CDSHORT of CDCTL1 register.

Returns:
NONE

References HWREG.

void COMPD_disableInputBuffer ( unsigned int  baseAddress,
unsigned char  inputPort 
)

Disables the input buffer of the selected input port to effectively allow for analog signals.

Parameters:
baseAddressis the base address of the Comparator module.
inputPortis the port in which the input buffer will be disabled. Valid values are COMPD_INPUT0 [Default] COMPD_INPUT1 COMPD_INPUT2 COMPD_INPUT3 COMPD_INPUT4 COMPD_INPUT5 COMPD_INPUT6 COMPD_INPUT7 COMPD_INPUT8 COMPD_INPUT9 COMPD_INPUT10 COMPD_INPUT11 COMPD_INPUT12 COMPD_INPUT13 COMPD_INPUT14 COMPD_INPUT15 COMPD_VREF Modified bits are CDPDx of CDCTL3 register.

This function sets the bit to disable the buffer for the specified input port to allow for analog signals from any of the comparator input pins. This bit is automatically set when the input is initialized to be used with the comparator module. This function should be used whenever an analog input is connected to one of these pins to prevent parasitic voltage from causing unexpected results.

Returns:
NONE

References HWREG.

void COMPD_enableInputBuffer ( unsigned int  baseAddress,
unsigned char  inputPort 
)

Enables the input buffer of the selected input port to allow for digital signals.

Parameters:
baseAddressis the base address of the Comparator module.
inputPortis the port in which the input buffer will be enabled. Valid values are COMPD_INPUT0 [Default] COMPD_INPUT1 COMPD_INPUT2 COMPD_INPUT3 COMPD_INPUT4 COMPD_INPUT5 COMPD_INPUT6 COMPD_INPUT7 COMPD_INPUT8 COMPD_INPUT9 COMPD_INPUT10 COMPD_INPUT11 COMPD_INPUT12 COMPD_INPUT13 COMPD_INPUT14 COMPD_INPUT15 COMPD_VREF Modified bits are CDPDx of CDCTL3 register.

This function clears the bit to enable the buffer for the specified input port to allow for digital signals from any of the comparator input pins. This should not be reset if there is an analog signal connected to the specified input pin to prevent from unexpected results.

Returns:
NONE

References HWREG.

void COMPD_IOSwap ( unsigned int  baseAddress)

Toggles the bit that swaps which terminals the inputs go to, while also inverting the output of the comparator.

Parameters:
baseAddressis the base address of the Comparator module.

This function toggles the bit that controls which input goes to which terminal. After initialization, this bit is set to 0, after toggling it once the inputs are routed to the opposite terminal and the output is inverted.

Modified bits are CDEX of CDCTL1 register.

Returns:
NONE

References HWREG.

unsigned short COMPD_outputValue ( unsigned int  baseAddress)

Returns the output value of the Comparator module.

Parameters:
baseAddressis the base address of the Comparator module.

Returns the output value of the Comparator module.

Returns:
COMPD_HIGH or COMPD_LOW as the output value of the Comparator module.

References COMPD_HIGH, COMPD_LOW, and HWREG.


Copyright 2012, Texas Instruments Incorporated