Introduction
The COMPA module provides the low-level APIs to manage the high-performance continuous-time comparator located in the AUX domain.
The COMPA driverlib module supports the following features:
- Operating the COMPA peripheral in MCU active power mode
- Selecting the source connected to the positive and reference input of COMPA
- Registering/unregistering a callback on the interrupt triggered by COMPA's output, as well as clearing the interrupt flag
- Enabling and disabling the COMPA module
COMPA supports the following inputs:
- Positive input from:
- Reference input from:
- Analog-capable I/O pins
- Internal chip voltages
- Reference DAC
The COMPA driverlib module has the following limitation:
- Cannot operate the COMPA peripheral in standby mode
- Cannot setup COMPA as a wakeup source from standby
COMPA output is routed to the event bus where it holds a dedicated interrupt line.
On devices equipped with sensor controller, a CPU application that uses COMPA must configure ownership of the module through AUX hardware semaphores. When using the DAC as reference, ownership of both DAC and COMPA modules is required. The table below shows the conventional matching between AUX semaphores IDs and AUX peripherals:
SMPH_ID | Resource Allocation |
1 | TDC |
2 | ADC + COMPB |
3 | COMPA + ISRC |
4 | Reference DAC |
5 | Timer2 |
6 | Unassigned by TI |
7 | Unassigned by TI |
COMPA operations are tightly integrated with the reference DAC present in the AUX domain, which can be connected to the reference input of COMPA. When using the DAC as reference for COMPA, it is discouraged to use the RTOS-based DAC driver. The RTOS-based DAC driver has been designed to support the specific use case of driving external loads, therefore it is not compatible with the COMPA driverlib module. When using the DAC as reference for COMPA, use the DAC driverlib module instead, which provides more flexibility and can adapt to this particular use case.
Code example
The following code example demonstrates how to set up COMPA with:
- an analog IO pin connected to its positive input
- the reference DAC connected to its reference input in order to trigger an interrupt on a rising edge of its output.
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_adi_4_aux.h"
#include "inc/hw_aux_aiodio.h"
#define DAC_CLOCK_FREQ_24MHZ 0U
#define MICROVOLTS_PER_MILLIVOLT 1000
#define CALIBRATION_VDDS 3000
#define REF_DAC_UVOLT 1500000
static volatile uint32_t vdds = 0;
void aux_compaISR(void)
{
}
void test_compa_interrupt_with_dacref(uint32_t in_iothDacOutput)
{
uint32_t dacMax = 0;
uint32_t dacMin = 0;
uint32_t vdds = 0;
uint32_t tempReg;
bool auxSmphIsAcquired = false;
dacMax = ((
AUXDACCalcMax() * vdds) / CALIBRATION_VDDS) * MICROVOLTS_PER_MILLIVOLT;
uint8_t dacCode = (uint8_t)
AUXDACCalcCode (REF_DAC_UVOLT, dacMin, dacMax);
}
§ AUXCOMPADisable()
static void AUXCOMPADisable |
( |
void |
| ) |
|
|
inlinestatic |
Disables COMPA.
This function disables COMPA and it must be called before re-enabling the module using AUXCOMPAEnable().
140 ADI8BitsClear(AUX_ADI4_BASE, ADI_4_AUX_O_COMP, ADI_4_AUX_COMP_COMPA_EN_M);
static void ADI8BitsClear(uint32_t ui32Base, uint32_t ui32Reg, uint8_t ui8Val)
Clear specific bits in an 8 bit ADI register.
Definition: adi.h:512
§ AUXCOMPAEnable()
static void AUXCOMPAEnable |
( |
void |
| ) |
|
|
inlinestatic |
Enables COMPA.
This function enables COMPA. This function must be called after having selected an input and reference for COMPA.
153 ADI8BitsSet(AUX_ADI4_BASE, ADI_4_AUX_O_COMP, ADI_4_AUX_COMP_COMPA_EN_M);
static void ADI8BitsSet(uint32_t ui32Base, uint32_t ui32Reg, uint8_t ui8Val)
Set specific bits in a single 8 bit ADI register.
Definition: adi.h:371
§ AUXCOMPAIntClear()
static void AUXCOMPAIntClear |
( |
void |
| ) |
|
|
inlinestatic |
Clears COMPA's interrupt flag.
This function clears the interrupt flag related to the COMPA interrupt line. This function should be called inside the ISR registered with AUXCOMPAIntRegister().
Referenced by AUXCOMPAIntRegister().
290 HWREG(AUX_EVCTL_BASE + AUX_EVCTL_O_EVTOMCUFLAGSCLR) = AUX_EVCTL_EVTOMCUFLAGSCLR_AUX_COMPA;
§ AUXCOMPAIntRegister()
static void AUXCOMPAIntRegister |
( |
uint8_t |
polarity, |
|
|
void(*)(void) |
fnHandler |
|
) |
| |
|
inlinestatic |
Registers an interrupt handler on COMPA output trigger.
This function registers an interrupt handler and enables the AUX_COMPA interrupt line. Before enabling the interrupt line the function:
- sets whether the interrupt should trigger on a rising or falling edge of COMPA output
- clears the flag of the AUX_COMPA interrupt line After enabling COMPA using AUXCOMPAEnable() and before registering an interrupt using AUXCOMPAIntRegister(), a delay of at least 10us is required to let COMPA output stabilize. This allows to avoid incorrect interrupt triggers in the brief interval following the enablement of COMPA.
- Parameters
-
polarity | Edge polarity of COMPA output on which the interrupt is triggered:
|
fnHandler | Interrupt handler invoked when COMPA output triggers with the specified edge polarity |
static void AUXCOMPAIntSetPolarity(uint8_t polarity)
Selects the edge polarity of COMPA output on which an interrupt is triggered.
Definition: aux_compa.h:264
static void AUXCOMPAIntClear(void)
Clears COMPA's interrupt flag.
Definition: aux_compa.h:287
void IntRegister(uint32_t ui32Interrupt, void(*pfnHandler)(void))
Registers a function as an interrupt handler in the dynamic vector table.
Definition: interrupt.c:151
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt or system exception.
Definition: interrupt.c:281
§ AUXCOMPAIntSetPolarity()
static void AUXCOMPAIntSetPolarity |
( |
uint8_t |
polarity | ) |
|
|
inlinestatic |
Selects the edge polarity of COMPA output on which an interrupt is triggered.
This function selects whether a rising or falling edge of COMPA output will trigger an interrupt on the COMPA hw interrupt line. This function is called inside AUXCOMPAIntRegister() before registering the handler and enabling the interrupt line.
- Parameters
-
polarity | Edge polarity of COMPA output on which the interrupt is triggered:
|
Referenced by AUXCOMPAIntRegister().
269 HWREGB(AUX_EVCTL_BASE + AUX_EVCTL_O_EVTOMCUPOL) &= ~(1 << AUX_EVCTL_EVTOMCUPOL_AUX_COMPA_S);
274 HWREGB(AUX_EVCTL_BASE + AUX_EVCTL_O_EVTOMCUPOL) |= (1 << AUX_EVCTL_EVTOMCUPOL_AUX_COMPA_S);
#define AUXCOMPA_POL_RISE
Definition: aux_compa.h:121
§ AUXCOMPAIntUnregister()
static void AUXCOMPAIntUnregister |
( |
void |
| ) |
|
|
inlinestatic |
Disables and unregisters the interrupt handler on COMPA output trigger.
This function disables interrupts on the AUX_COMPA line, and unregister a previously set interrupt handler. Note that this function does not clear COMPA's interrupt flag. The interrupt flag is either cleared implicitly when calling AUXCOMPAIntRegister() or explicitly with AUXCOMPAIntClear().
void IntUnregister(uint32_t ui32Interrupt)
Unregisters an interrupt handler in the dynamic vector table.
Definition: interrupt.c:187
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt or system exception.
Definition: interrupt.c:325
§ AUXCOMPASelectDacRef()
void AUXCOMPASelectDacRef |
( |
void |
| ) |
|
Selects the DAC output as analog reference of COMPA.
This function selects the reference DAC output as analog reference for COMPA. The function makes sure that any previously connected reference is disconnected from the COMPA_REF line, before connecting the DAC reference. This function must be called before enabling COMPA using AUXCOMPAEnable().
Referenced by AUXCOMPASelectGpioRef().
67 HWREG(AUX_ANAIF_BASE + AUX_ANAIF_O_DACCTL) &= ~AUX_ANAIF_DACCTL_DAC_VOUT_SEL_M;
71 ADI8BitsClear(AUX_ADI4_BASE, ADI_4_AUX_O_MUX0, ADI_4_AUX_MUX0_COMPA_REF_M);
72 ADI8RegWrite(AUX_ADI4_BASE, ADI_4_AUX_O_MUX4, ADI_4_AUX_MUX4_COMPA_REF_NC);
75 HWREG(AUX_ANAIF_BASE + AUX_ANAIF_O_DACCTL) &= ~AUX_ANAIF_DACCTL_DAC_BUFFER_EN_M;
78 dacCtl = HWREG(AUX_ANAIF_BASE + AUX_ANAIF_O_DACCTL);
79 HWREG(AUX_ANAIF_BASE + AUX_ANAIF_O_DACCTL) = (dacCtl & ~AUX_ANAIF_DACCTL_DAC_VOUT_SEL_M) | \
80 AUX_ANAIF_DACCTL_DAC_VOUT_SEL_COMPA_REF;
static void ADI8BitsClear(uint32_t ui32Base, uint32_t ui32Reg, uint8_t ui8Val)
Clear specific bits in an 8 bit ADI register.
Definition: adi.h:512
static void ADI8RegWrite(uint32_t ui32Base, uint32_t ui32Reg, uint8_t ui8Val)
Write an 8 bit value to a register in an ADI slave.
Definition: adi.h:147
§ AUXCOMPASelectGpioInput()
static void AUXCOMPASelectGpioInput |
( |
uint8_t |
auxio | ) |
|
|
inlinestatic |
Selects an AUXIO pin as analog input of COMPA.
This function selects one the available AUXIOs as analog input for COMPA. This function must be called before enabling COMPA using AUXCOMPAEnable().
- Parameters
-
static void ADI8RegWrite(uint32_t ui32Base, uint32_t ui32Reg, uint8_t ui8Val)
Write an 8 bit value to a register in an ADI slave.
Definition: adi.h:147
§ AUXCOMPASelectGpioRef()
static void AUXCOMPASelectGpioRef |
( |
uint8_t |
auxio | ) |
|
|
inlinestatic |
Selects an AUXIO pin as analog reference of COMPA.
This function selects one of the available AUXIOs as analog reference for COMPA. The function makes sure that any previously connected reference is disconnected from the COMPA_REF line, before connecting the AUXIO reference. This function must be called before enabling COMPA using AUXCOMPAEnable().
- Parameters
-
auxio | COMPA external analog reference:
|
206 HWREG(AUX_ANAIF_BASE + AUX_ANAIF_O_DACCTL) &= ~AUX_ANAIF_DACCTL_DAC_VOUT_SEL_M;
209 ADI8BitsClear(AUX_ADI4_BASE, ADI_4_AUX_O_MUX0, ADI_4_AUX_MUX0_COMPA_REF_M);
static void ADI8BitsClear(uint32_t ui32Base, uint32_t ui32Reg, uint8_t ui8Val)
Clear specific bits in an 8 bit ADI register.
Definition: adi.h:512
static void ADI8RegWrite(uint32_t ui32Base, uint32_t ui32Reg, uint8_t ui8Val)
Write an 8 bit value to a register in an ADI slave.
Definition: adi.h:147
§ AUXCOMPASelectInternalRef()
void AUXCOMPASelectInternalRef |
( |
uint8_t |
internalRef | ) |
|
Selects an internal voltage as analog reference of COMPA.
This function selects one of the available internal voltages as analog reference for COMPA. The function makes sure that any previously connected reference is disconnected from the COMPA_REF line, before connecting the internal voltage reference. This function must be called before enabling COMPA using AUXCOMPAEnable().
- Parameters
-
internalRef | COMPA internal analog reference:
|
Referenced by AUXCOMPASelectGpioRef().
49 HWREG(AUX_ANAIF_BASE + AUX_ANAIF_O_DACCTL) &= ~AUX_ANAIF_DACCTL_DAC_VOUT_SEL_M;
52 ADI8RegWrite(AUX_ADI4_BASE, ADI_4_AUX_O_MUX4, ADI_4_AUX_MUX4_COMPA_REF_NC);
55 ADI8SetValBit(AUX_ADI4_BASE, ADI_4_AUX_O_MUX0, ADI_4_AUX_MUX0_COMPA_REF_M, internalRef);
static void ADI8RegWrite(uint32_t ui32Base, uint32_t ui32Reg, uint8_t ui8Val)
Write an 8 bit value to a register in an ADI slave.
Definition: adi.h:147
static void ADI8SetValBit(uint32_t ui32Base, uint32_t ui32Reg, uint16_t ui16Mask, uint16_t ui16Val)
Set a value on any bits inside an 8 bit register in the ADI slave.
Definition: adi.h:704
§ AUXCOMPA_GPIO_IN_AUX19
#define AUXCOMPA_GPIO_IN_AUX19 ADI_4_AUX_MUX1_COMPA_IN_AUXIO19 |
§ AUXCOMPA_GPIO_IN_AUX20
#define AUXCOMPA_GPIO_IN_AUX20 ADI_4_AUX_MUX1_COMPA_IN_AUXIO20 |
§ AUXCOMPA_GPIO_IN_AUX21
#define AUXCOMPA_GPIO_IN_AUX21 ADI_4_AUX_MUX1_COMPA_IN_AUXIO21 |
§ AUXCOMPA_GPIO_IN_AUX22
#define AUXCOMPA_GPIO_IN_AUX22 ADI_4_AUX_MUX1_COMPA_IN_AUXIO22 |
§ AUXCOMPA_GPIO_IN_AUX23
#define AUXCOMPA_GPIO_IN_AUX23 ADI_4_AUX_MUX1_COMPA_IN_AUXIO23 |
§ AUXCOMPA_GPIO_IN_AUX24
#define AUXCOMPA_GPIO_IN_AUX24 ADI_4_AUX_MUX1_COMPA_IN_AUXIO24 |
§ AUXCOMPA_GPIO_IN_AUX25
#define AUXCOMPA_GPIO_IN_AUX25 ADI_4_AUX_MUX1_COMPA_IN_AUXIO25 |
§ AUXCOMPA_GPIO_IN_AUX26
#define AUXCOMPA_GPIO_IN_AUX26 ADI_4_AUX_MUX1_COMPA_IN_AUXIO26 |
§ AUXCOMPA_GPIO_IN_NC
#define AUXCOMPA_GPIO_IN_NC ADI_4_AUX_MUX1_COMPA_IN_NC |
§ AUXCOMPA_GPIO_REF_AUX19
#define AUXCOMPA_GPIO_REF_AUX19 ADI_4_AUX_MUX4_COMPA_REF_AUXIO19 |
§ AUXCOMPA_GPIO_REF_AUX20
#define AUXCOMPA_GPIO_REF_AUX20 ADI_4_AUX_MUX4_COMPA_REF_AUXIO20 |
§ AUXCOMPA_GPIO_REF_AUX21
#define AUXCOMPA_GPIO_REF_AUX21 ADI_4_AUX_MUX4_COMPA_REF_AUXIO21 |
§ AUXCOMPA_GPIO_REF_AUX22
#define AUXCOMPA_GPIO_REF_AUX22 ADI_4_AUX_MUX4_COMPA_REF_AUXIO22 |
§ AUXCOMPA_GPIO_REF_AUX23
#define AUXCOMPA_GPIO_REF_AUX23 ADI_4_AUX_MUX4_COMPA_REF_AUXIO23 |
§ AUXCOMPA_GPIO_REF_AUX24
#define AUXCOMPA_GPIO_REF_AUX24 ADI_4_AUX_MUX4_COMPA_REF_AUXIO24 |
§ AUXCOMPA_GPIO_REF_AUX25
#define AUXCOMPA_GPIO_REF_AUX25 ADI_4_AUX_MUX4_COMPA_REF_AUXIO25 |
§ AUXCOMPA_GPIO_REF_AUX26
#define AUXCOMPA_GPIO_REF_AUX26 ADI_4_AUX_MUX4_COMPA_REF_AUXIO26 |
§ AUXCOMPA_GPIO_REF_NC
#define AUXCOMPA_GPIO_REF_NC ADI_4_AUX_MUX4_COMPA_REF_NC |
§ AUXCOMPA_INT_REF_ADCVREFP
#define AUXCOMPA_INT_REF_ADCVREFP ADI_4_AUX_MUX0_COMPA_REF_ADCVREFP |
§ AUXCOMPA_INT_REF_DCOUPL
#define AUXCOMPA_INT_REF_DCOUPL ADI_4_AUX_MUX0_COMPA_REF_DCOUPL |
§ AUXCOMPA_INT_REF_NC
#define AUXCOMPA_INT_REF_NC ADI_4_AUX_MUX0_COMPA_REF_NC |
§ AUXCOMPA_INT_REF_VDDS
#define AUXCOMPA_INT_REF_VDDS ADI_4_AUX_MUX0_COMPA_REF_VDDS |
§ AUXCOMPA_INT_REF_VSS
#define AUXCOMPA_INT_REF_VSS ADI_4_AUX_MUX0_COMPA_REF_VSS |
§ AUXCOMPA_POL_FALL
#define AUXCOMPA_POL_FALL 0x01 |
§ AUXCOMPA_POL_RISE
#define AUXCOMPA_POL_RISE 0x00 |