MSP432E4 DriverLib API Guide  1.11.00.03
Functions
Comp_api

Functions

void ComparatorConfigure (uint32_t ui32Base, uint32_t ui32Comp, uint32_t ui32Config)
 
void ComparatorRefSet (uint32_t ui32Base, uint32_t ui32Ref)
 
bool ComparatorValueGet (uint32_t ui32Base, uint32_t ui32Comp)
 
void ComparatorIntRegister (uint32_t ui32Base, uint32_t ui32Comp, void(*pfnHandler)(void))
 
void ComparatorIntUnregister (uint32_t ui32Base, uint32_t ui32Comp)
 
void ComparatorIntEnable (uint32_t ui32Base, uint32_t ui32Comp)
 
void ComparatorIntDisable (uint32_t ui32Base, uint32_t ui32Comp)
 
bool ComparatorIntStatus (uint32_t ui32Base, uint32_t ui32Comp, bool bMasked)
 
void ComparatorIntClear (uint32_t ui32Base, uint32_t ui32Comp)
 

Detailed Description

Introduction

The comparator API provides a set of functions for programming and using the analog comparators. A comparator can compare a test voltage against an individual external reference voltage, a shared single external reference voltage, or a shared internal reference voltage. It can provide its output to a device pin, acting as a replacement for an analog comparator on the board, or it can be used to signal the application via interrupts or triggers to the ADC to start capturing a sample sequence. The interrupt generation logic is independent from the ADC triggering logic. As a result, the comparator can generate an interrupt based on one event and an ADC trigger based on another event. For example, an interrupt can be generated on a rising edge and the ADC triggered on a falling edge.

API Functions

The comparator API is fairly simple, like the comparators themselves. There are functions for configuring a comparator and reading its output (ComparatorConfigure(), ComparatorRefSet() and ComparatorValueGet()) and functions for dealing with an interrupt handler for the comparator (ComparatorIntRegister(), ComparatorIntUnregister(), ComparatorIntEnable(), ComparatorIntDisable(), ComparatorIntStatus(), and ComparatorIntClear()).

Programming Example

The following example shows how to use the comparator API to configure the comparator and read its value.

//
// Enable the COMP module.
//
//
// Wait for the COMP module to be ready.
//
{
}
//
// Configure the internal voltage reference.
//
//
// Configure comparator 0.
//
ComparatorConfigure(COMP_BASE, 0,
//
// Delay for some time...
//
//
// Read the comparator output value.
//
ComparatorValueGet(COMP_BASE, 0);

Function Documentation

§ ComparatorConfigure()

void ComparatorConfigure ( uint32_t  ui32Base,
uint32_t  ui32Comp,
uint32_t  ui32Config 
)

Configures a comparator.

Parameters
ui32Baseis the base address of the comparator module.
ui32Compis the index of the comparator to configure.
ui32Configis the configuration of the comparator.

This function configures a comparator. The ui32Config parameter is the result of a logical OR operation between the COMP_TRIG_xxx, COMP_INT_xxx, COMP_ASRCP_xxx, and COMP_OUTPUT_xxx values.

The COMP_TRIG_xxx term can take on the following values:

  • COMP_TRIG_NONE to have no trigger to the ADC.
  • COMP_TRIG_HIGH to trigger the ADC when the comparator output is high.
  • COMP_TRIG_LOW to trigger the ADC when the comparator output is low.
  • COMP_TRIG_FALL to trigger the ADC when the comparator output goes low.
  • COMP_TRIG_RISE to trigger the ADC when the comparator output goes high.
  • COMP_TRIG_BOTH to trigger the ADC when the comparator output goes low or high.

The COMP_INT_xxx term can take on the following values:

  • COMP_INT_HIGH to generate an interrupt when the comparator output is high.
  • COMP_INT_LOW to generate an interrupt when the comparator output is low.
  • COMP_INT_FALL to generate an interrupt when the comparator output goes low.
  • COMP_INT_RISE to generate an interrupt when the comparator output goes high.
  • COMP_INT_BOTH to generate an interrupt when the comparator output goes low or high.

The COMP_ASRCP_xxx term can take on the following values:

  • COMP_ASRCP_PIN to use the dedicated Comp+ pin as the reference voltage.
  • COMP_ASRCP_PIN0 to use the Comp0+ pin as the reference voltage (this the same as COMP_ASRCP_PIN for the comparator 0).
  • COMP_ASRCP_REF to use the internally generated voltage as the reference voltage.

The COMP_OUTPUT_xxx term can take on the following values:

  • COMP_OUTPUT_NORMAL to enable a non-inverted output from the comparator to a device pin.
  • COMP_OUTPUT_INVERT to enable an inverted output from the comparator to a device pin.
Returns
None.

References ASSERT, COMP_O_ACCTL0, and HWREG.

§ ComparatorRefSet()

void ComparatorRefSet ( uint32_t  ui32Base,
uint32_t  ui32Ref 
)

Sets the internal reference voltage.

Parameters
ui32Baseis the base address of the comparator module.
ui32Refis the desired reference voltage.

This function sets the internal reference voltage value. The voltage is specified as one of the following values:

  • COMP_REF_OFF to turn off the reference voltage
  • COMP_REF_0V to set the reference voltage to 0 V
  • COMP_REF_0_1375V to set the reference voltage to 0.1375 V
  • COMP_REF_0_275V to set the reference voltage to 0.275 V
  • COMP_REF_0_4125V to set the reference voltage to 0.4125 V
  • COMP_REF_0_55V to set the reference voltage to 0.55 V
  • COMP_REF_0_6875V to set the reference voltage to 0.6875 V
  • COMP_REF_0_825V to set the reference voltage to 0.825 V
  • COMP_REF_0_928125V to set the reference voltage to 0.928125 V
  • COMP_REF_0_9625V to set the reference voltage to 0.9625 V
  • COMP_REF_1_03125V to set the reference voltage to 1.03125 V
  • COMP_REF_1_134375V to set the reference voltage to 1.134375 V
  • COMP_REF_1_1V to set the reference voltage to 1.1 V
  • COMP_REF_1_2375V to set the reference voltage to 1.2375 V
  • COMP_REF_1_340625V to set the reference voltage to 1.340625 V
  • COMP_REF_1_375V to set the reference voltage to 1.375 V
  • COMP_REF_1_44375V to set the reference voltage to 1.44375 V
  • COMP_REF_1_5125V to set the reference voltage to 1.5125 V
  • COMP_REF_1_546875V to set the reference voltage to 1.546875 V
  • COMP_REF_1_65V to set the reference voltage to 1.65 V
  • COMP_REF_1_753125V to set the reference voltage to 1.753125 V
  • COMP_REF_1_7875V to set the reference voltage to 1.7875 V
  • COMP_REF_1_85625V to set the reference voltage to 1.85625 V
  • COMP_REF_1_925V to set the reference voltage to 1.925 V
  • COMP_REF_1_959375V to set the reference voltage to 1.959375 V
  • COMP_REF_2_0625V to set the reference voltage to 2.0625 V
  • COMP_REF_2_165625V to set the reference voltage to 2.165625 V
  • COMP_REF_2_26875V to set the reference voltage to 2.26875 V
  • COMP_REF_2_371875V to set the reference voltage to 2.371875 V
Returns
None.

References ASSERT, COMP_O_ACREFCTL, and HWREG.

§ ComparatorValueGet()

bool ComparatorValueGet ( uint32_t  ui32Base,
uint32_t  ui32Comp 
)

Gets the current comparator output value.

Parameters
ui32Baseis the base address of the comparator module.
ui32Compis the index of the comparator.

This function retrieves the current value of the comparator output.

Returns
Returns true if the comparator output is high and false if the comparator output is low.

References ASSERT, COMP_ACSTAT0_OVAL, COMP_O_ACSTAT0, and HWREG.

§ ComparatorIntRegister()

void ComparatorIntRegister ( uint32_t  ui32Base,
uint32_t  ui32Comp,
void(*)(void)  pfnHandler 
)

Registers an interrupt handler for the comparator interrupt.

Parameters
ui32Baseis the base address of the comparator module.
ui32Compis the index of the comparator.
pfnHandleris a pointer to the function to be called when the comparator interrupt occurs.

This function sets the handler to be called when the comparator interrupt occurs and enables the interrupt in the interrupt controller. It is the interrupt handler's responsibility to clear the interrupt source via ComparatorIntClear().

See also
IntRegister() for important information about registering interrupt handlers.
Returns
None.

References ASSERT, COMP_O_ACINTEN, HWREG, INT_COMP0, IntEnable(), and IntRegister().

§ ComparatorIntUnregister()

void ComparatorIntUnregister ( uint32_t  ui32Base,
uint32_t  ui32Comp 
)

Unregisters an interrupt handler for a comparator interrupt.

Parameters
ui32Baseis the base address of the comparator module.
ui32Compis the index of the comparator.

This function clears the handler to be called when a comparator interrupt occurs. This function also masks off the interrupt in the interrupt controller so that the interrupt handler no longer is called.

See also
IntRegister() for important information about registering interrupt handlers.
Returns
None.

References ASSERT, COMP_O_ACINTEN, HWREG, INT_COMP0, IntDisable(), and IntUnregister().

§ ComparatorIntEnable()

void ComparatorIntEnable ( uint32_t  ui32Base,
uint32_t  ui32Comp 
)

Enables the comparator interrupt.

Parameters
ui32Baseis the base address of the comparator module.
ui32Compis the index of the comparator.

This function enables generation of an interrupt from the specified comparator. Only enabled comparator interrupts can be reflected to the processor.

Returns
None.

References ASSERT, COMP_O_ACINTEN, and HWREG.

§ ComparatorIntDisable()

void ComparatorIntDisable ( uint32_t  ui32Base,
uint32_t  ui32Comp 
)

Disables the comparator interrupt.

Parameters
ui32Baseis the base address of the comparator module.
ui32Compis the index of the comparator.

This function disables generation of an interrupt from the specified comparator. Only enabled comparator interrupts can be reflected to the processor.

Returns
None.

References ASSERT, COMP_O_ACINTEN, and HWREG.

§ ComparatorIntStatus()

bool ComparatorIntStatus ( uint32_t  ui32Base,
uint32_t  ui32Comp,
bool  bMasked 
)

Gets the current interrupt status.

Parameters
ui32Baseis the base address of the comparator module.
ui32Compis the index of the comparator.
bMaskedis false if the raw interrupt status is required and true if the masked interrupt status is required.

This function returns the interrupt status for the comparator. Either the raw or the masked interrupt status can be returned.

Returns
true if the interrupt is asserted and false if it is not asserted.

References ASSERT, COMP_O_ACMIS, COMP_O_ACRIS, and HWREG.

§ ComparatorIntClear()

void ComparatorIntClear ( uint32_t  ui32Base,
uint32_t  ui32Comp 
)

Clears a comparator interrupt.

Parameters
ui32Baseis the base address of the comparator module.
ui32Compis the index of the comparator.

The comparator interrupt is cleared, so that it no longer asserts. This function must be called in the interrupt handler to keep the handler from being called again immediately upon exit. Note that for a level-triggered interrupt, the interrupt cannot be cleared until it stops asserting.

Note
Because there is a write buffer in the Cortex-M processor, it may take several clock cycles before the interrupt source is actually cleared. Therefore, it is recommended that the interrupt source be cleared early in the interrupt handler (as opposed to the very last action) to avoid returning from the interrupt handler before the interrupt source is actually cleared. Failure to do so may result in the interrupt handler being immediately reentered (because the interrupt controller still sees the interrupt source asserted).
Returns
None.

References ASSERT, COMP_O_ACMIS, and HWREG.

© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale