Defines | Functions
compb.h File Reference

Go to the source code of this file.

Defines

#define __MSP430_HAS_COMPB__
#define COMPB_INPUT0   (CBIPSEL_0)
#define COMPB_INPUT1   (CBIPSEL_1)
#define COMPB_INPUT2   (CBIPSEL_2)
#define COMPB_INPUT3   (CBIPSEL_3)
#define COMPB_INPUT4   (CBIPSEL_4)
#define COMPB_INPUT5   (CBIPSEL_5)
#define COMPB_INPUT6   (CBIPSEL_6)
#define COMPB_INPUT7   (CBIPSEL_7)
#define COMPB_INPUT8   (CBIPSEL_8)
#define COMPB_INPUT9   (CBIPSEL_9)
#define COMPB_INPUT10   (CBIPSEL_10)
#define COMPB_INPUT11   (CBIPSEL_11)
#define COMPB_INPUT12   (CBIPSEL_12)
#define COMPB_INPUT13   (CBIPSEL_13)
#define COMPB_INPUT14   (CBIPSEL_14)
#define COMPB_INPUT15   (CBIPSEL_15)
#define COMPB_VREF   (0x10)
#define COMPB_POWERMODE_HIGHSPEED   (CBPWRMD_0)
#define COMPB_POWERMODE_NORMALMODE   (CBPWRMD_1)
#define COMPB_POWERMODE_ULTRALOWPOWER   (CBPWRMD_2)
#define COMPB_FILTEROUTPUT_OFF   0x00
#define COMPB_FILTEROUTPUT_DLYLVL1   (CBF + CBFDLY_0)
#define COMPB_FILTEROUTPUT_DLYLVL2   (CBF + CBFDLY_1)
#define COMPB_FILTEROUTPUT_DLYLVL3   (CBF + CBFDLY_2)
#define COMPB_FILTEROUTPUT_DLYLVL4   (CBF + CBFDLY_3)
#define COMPB_NORMALOUTPUTPOLARITY   ( !(CBOUTPOL) )
#define COMPB_INVERTEDOUTPUTPOLARITY   (CBOUTPOL)
#define COMPB_VREFBASE_VCC   (CBREFL_0)
#define COMPB_VREFBASE1_5V   (CBREFL_1)
#define COMPB_VREFBASE2_0V   (CBREFL_2)
#define COMPB_VREFBASE2_5V   (CBREFL_3)
#define COMPB_FALLINGEDGE   ( !(CBIES) )
#define COMPB_RISINGEDGE   (CBIES)
#define COMPB_LOW   (0x0)
#define COMPB_HIGH   (0x1)

Functions

unsigned short COMPB_init (unsigned int baseAddress, unsigned char positiveTerminalInput, unsigned char negativeTerminalInput, unsigned int powerModeSelect, unsigned char outputFilterEnableAndDelayLevel, unsigned short invertedOutputPolarity)
void COMPB_setReferenceVoltage (unsigned int baseAddress, unsigned int supplyVoltageReferenceBase, unsigned int lowerLimitSupplyVoltageFractionOf32, unsigned int upperLimitSupplyVoltageFractionOf32)
void COMPB_enableInterrupt (unsigned int baseAddress, unsigned int mask)
void COMPB_disableInterrupt (unsigned int baseAddress, unsigned int mask)
void COMPB_clearInterrupt (unsigned int baseAddress, unsigned int mask)
unsigned char COMPB_getInterruptStatus (unsigned int baseAddress, unsigned int mask)
void COMPB_interruptSetEdgeDirection (unsigned int baseAddress, unsigned short edgeDirection)
void COMPB_interruptToggleEdgeDirection (unsigned int baseAddress)
void COMPB_enable (unsigned int baseAddress)
void COMPB_disable (unsigned int baseAddress)
void COMPB_enableShortOfInputs (unsigned int baseAddress)
void COMPB_disableShortOfInputs (unsigned int baseAddress)
void COMPB_disableInputBuffer (unsigned int baseAddress, unsigned char inputPort)
void COMPB_enableInputBuffer (unsigned int baseAddress, unsigned char inputPort)
void COMPB_IOSwap (unsigned int baseAddress)
unsigned short COMPB_outputValue (unsigned int baseAddress)

Define Documentation

#define __MSP430_HAS_COMPB__
#define COMPB_INPUT0   (CBIPSEL_0)
#define COMPB_INPUT1   (CBIPSEL_1)
#define COMPB_INPUT2   (CBIPSEL_2)
#define COMPB_INPUT3   (CBIPSEL_3)
#define COMPB_INPUT4   (CBIPSEL_4)
#define COMPB_INPUT5   (CBIPSEL_5)
#define COMPB_INPUT6   (CBIPSEL_6)
#define COMPB_INPUT7   (CBIPSEL_7)
#define COMPB_INPUT8   (CBIPSEL_8)
#define COMPB_INPUT9   (CBIPSEL_9)
#define COMPB_INPUT10   (CBIPSEL_10)
#define COMPB_INPUT11   (CBIPSEL_11)
#define COMPB_INPUT12   (CBIPSEL_12)
#define COMPB_INPUT13   (CBIPSEL_13)
#define COMPB_INPUT14   (CBIPSEL_14)
#define COMPB_INPUT15   (CBIPSEL_15)
#define COMPB_VREF   (0x10)

Referenced by COMPB_init().

#define COMPB_POWERMODE_HIGHSPEED   (CBPWRMD_0)
#define COMPB_POWERMODE_NORMALMODE   (CBPWRMD_1)
#define COMPB_POWERMODE_ULTRALOWPOWER   (CBPWRMD_2)

Referenced by COMPB_init().

#define COMPB_FILTEROUTPUT_OFF   0x00
#define COMPB_FILTEROUTPUT_DLYLVL1   (CBF + CBFDLY_0)
#define COMPB_FILTEROUTPUT_DLYLVL2   (CBF + CBFDLY_1)
#define COMPB_FILTEROUTPUT_DLYLVL3   (CBF + CBFDLY_2)
#define COMPB_FILTEROUTPUT_DLYLVL4   (CBF + CBFDLY_3)

Referenced by COMPB_init().

#define COMPB_NORMALOUTPUTPOLARITY   ( !(CBOUTPOL) )
#define COMPB_INVERTEDOUTPUTPOLARITY   (CBOUTPOL)
#define COMPB_VREFBASE_VCC   (CBREFL_0)
#define COMPB_VREFBASE1_5V   (CBREFL_1)
#define COMPB_VREFBASE2_0V   (CBREFL_2)
#define COMPB_VREFBASE2_5V   (CBREFL_3)
#define COMPB_FALLINGEDGE   ( !(CBIES) )
#define COMPB_RISINGEDGE   (CBIES)
#define COMPB_LOW   (0x0)

Referenced by COMPB_outputValue().

#define COMPB_HIGH   (0x1)

Referenced by COMPB_outputValue().


Function Documentation

unsigned short COMPB_init ( unsigned int  baseAddress,
unsigned char  positiveTerminalInput,
unsigned char  negativeTerminalInput,
unsigned int  powerModeSelect,
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 COMPB_INPUT0 [Default] COMPB_INPUT1 COMPB_INPUT2 COMPB_INPUT3 COMPB_INPUT4 COMPB_INPUT5 COMPB_INPUT6 COMPB_INPUT7 COMPB_INPUT8 COMPB_INPUT9 COMPB_INPUT10 COMPB_INPUT11 COMPB_INPUT12 COMPB_INPUT13 COMPB_INPUT14 COMPB_INPUT15 COMPB_VREF Modified bits are CBIPSEL and CBIPEN of CBCTL0 register, CBRSEL of CBCTL2 register, and CBPDx of CBCTL3 register.
negativeTerminalInputselects the input to the negative terminal. Valid values are COMPB_INPUT0 [Default] COMPB_INPUT1 COMPB_INPUT2 COMPB_INPUT3 COMPB_INPUT4 COMPB_INPUT5 COMPB_INPUT6 COMPB_INPUT7 COMPB_INPUT8 COMPB_INPUT9 COMPB_INPUT10 COMPB_INPUT11 COMPB_INPUT12 COMPB_INPUT13 COMPB_INPUT14 COMPB_INPUT15 COMPB_VREF Modified bits are CBIMSEL and CBIMEN of CBCTL0 register, CBRSEL of CBCTL2 register, and CBPDx of CBCTL3 register.
powerModeSelectselects the power mode at which the comparator module will operate at. Valid values are COMPB_POWERMODE_HIGHSPEED [Default] COMPB_POWERMODE_NORMALMODE COMPB_POWERMODE_ULTRALOWPOWER Modified bits are CBWRMD of CBCTL1 register.
outputFilterEnableAndDelayLevelcontrols the output filter delay state, which is either off or enabled with a specified delay level. Valid values are COMPB_FILTEROUTPUT_OFF [Default] COMPB_FILTEROUTPUT_DLYLVL1 COMPB_FILTEROUTPUT_DLYLVL2 COMPB_FILTEROUTPUT_DLYLVL3 COMPB_FILTEROUTPUT_DLYLVL4 This parameter is device specific and delay levels should be found in the device's datasheet. Modified bits are CBF and CBFDLY of CBCTL1 register.
invertedOutputcontrols if the output will be inverted or not Valid values are COMPB_NORMALOUTPUTPOLARITY - indicates the output should be normal. [Default] COMPB_INVERTEDOUTPUTPOLARITY - the output should be inverted. Modified bits are CBOUTPOL of CBCTL1 register.

Upon successful initialization of the Comparator module, this function will have reset all neccessary register bits and set the given options in the registers. To actually use the comparator module, the COMPB_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, COMPB_FILTEROUTPUT_DLYLVL4, COMPB_POWERMODE_ULTRALOWPOWER, COMPB_VREF, HWREG, and STATUS_SUCCESS.

void COMPB_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.
supplyVoltageBasedecides the source and max amount of Voltage that can be used as a reference. Valid values are COMPB_VREFBASE_VCC COMPB_VREFBASE1_5V COMPB_VREFBASE2_0V COMPB_VREFBASE2_5V Modified bits are CBREFL of CBCTL2 register.
upperLimitSupplyVoltageFractionOf32is the numerator of the equation to generate the reference voltage for the upper limit reference voltage. Modified bits are CBREF1 of CBCTL2 register.
lowerLimitSupplyVoltageFractionOf32is the numerator of the equation to generate the reference voltage for the lower limit reference voltage. Modified bits are CBREF0 of CBCTL2 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, COMPB_VREFBASE2_5V, COMPB_VREFBASE_VCC, and HWREG.

void COMPB_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 vlaue is the logical OR of any of the following CBIE - Output interrupt enable CBIIE - 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 COMPB_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 vlaue is the logical OR of any of the following CBIE - Output interrupt enable CBIIE - 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 COMPB_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 vlaue is the logical OR of any of the following CBIFG - Output interrupt flag CBIIFG - 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 COMPB_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 vlaue is the logical OR of any of the following CBIFG - Output interrupt flag CBIIFG - 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 COMPB_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 COMPB_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] COMPB_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 CBIES of CBCTL1 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, COMPB_FALLINGEDGE, COMPB_RISINGEDGE, and HWREG.

void COMPB_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.

Returns:
NONE

References HWREG.

void COMPB_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 COMPB_disable ( unsigned int  baseAddress)

Turns off the Comparator module.

Parameters:
baseAddressis the base address of the Comparator module.

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

Returns:
NONE

References HWREG.

void COMPB_enableShortOfInputs ( unsigned int  baseAddress)
void COMPB_disableShortOfInputs ( unsigned int  baseAddress)
void COMPB_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 COMPB_INPUT0 [Default] COMPB_INPUT1 COMPB_INPUT2 COMPB_INPUT3 COMPB_INPUT4 COMPB_INPUT5 COMPB_INPUT6 COMPB_INPUT7 COMPB_INPUT8 COMPB_INPUT9 COMPB_INPUT10 COMPB_INPUT11 COMPB_INPUT12 COMPB_INPUT13 COMPB_INPUT14 COMPB_INPUT15 COMPB_VREF Modified bits are CBPDx of CBCTL3 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 COMPB_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 COMPB_INPUT0 [Default] COMPB_INPUT1 COMPB_INPUT2 COMPB_INPUT3 COMPB_INPUT4 COMPB_INPUT5 COMPB_INPUT6 COMPB_INPUT7 COMPB_INPUT8 COMPB_INPUT9 COMPB_INPUT10 COMPB_INPUT11 COMPB_INPUT12 COMPB_INPUT13 COMPB_INPUT14 COMPB_INPUT15 COMPB_VREF Modified bits are CBPDx of CBCTL3 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 COMPB_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.

Returns:
NONE

References HWREG.

unsigned short COMPB_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:
COMPB_HIGH or COMPB_LOW as the output value of the Comparator module.

References COMPB_HIGH, COMPB_LOW, and HWREG.


Copyright 2012, Texas Instruments Incorporated