CMSIS-Driver_PIC32CM-JH  
Peripheral Library (PLIB) Documentation
 
Loading...
Searching...
No Matches
AC Interface

Driver API for AC (plib_ac.h) More...

Macros

#define AC_COMP_NUMBER   4U
 Number of comparators available in the AC peripheral.
 
#define AC_WIN_NUMBER   2U
 Number of window comparators available in the AC peripheral.
 

Typedefs

typedef void(* AC_CALLBACK_HANDLER) (uint8_t status)
 AC interrupt callback function type.
 

Enumerations

enum  AC_EVENT {
  AC_EVENT_COMP0 = 0 , AC_EVENT_COMP1 = 1 , AC_EVENT_COMP2 = 2 , AC_EVENT_COMP3 = 3 ,
  AC_EVENT_WIN0 = 4 , AC_EVENT_WIN1 = 5 , AC_EVENT_NONE = 6
}
 AC Comparator events. More...
 
enum  AC_OUTPUT { AC_OUTPUT_OFF = 0 , AC_OUTPUT_ASYNC = 1 , AC_OUTPUT_SYNC = 2 }
 AC output options. More...
 

Functions

void AC_Enable (void)
 Enables the AC peripheral.
 
void AC_Disable (void)
 Disables the AC peripheral.
 
void AC_ResetSoftware (void)
 Performs a software reset of the AC peripheral.
 
bool AC_EnableChannel (uint8_t channel)
 Enables the specified AC channel.
 
bool AC_DisableChannel (uint8_t channel)
 Disables the specified AC channel.
 
bool AC_SetRunInStandby (uint8_t channel, bool enable)
 Sets the run-in-standby mode for the specified channel.
 
bool AC_SelectChannelInputs (uint8_t channel, uint32_t pos, uint32_t neg)
 Selects the positive and negative inputs for the specified channel.
 
bool AC_SetComparisonMode (uint8_t channel, uint8_t single)
 Set comparison mode for the comparator channel.
 
bool AC_SetSpeed (uint8_t channel, uint32_t speed)
 Set speed for comparator channel.
 
bool AC_SetVddScaler (uint8_t channel, uint8_t value)
 Sets the VDD scaler value for the specified channel.
 
bool AC_SetHysteresis (uint8_t channel, bool enable)
 Enables or disables hysteresis for the specified channel.
 
bool AC_SetFilterLength (uint8_t channel, uint32_t flen)
 Set Filter length for comparator channel.
 
bool AC_SwapInputs (uint8_t channel, bool enable)
 Swaps the inputs.
 
bool AC_EnableOutput (uint8_t channel, AC_OUTPUT value)
 Enables or disables the output for the specified channel.
 
bool AC_StartComparison (uint8_t channel)
 Starts comparison.
 
bool AC_CheckOutputReady (uint8_t channel)
 Check if output is ready.
 
bool AC_GetStatus (uint8_t channel)
 Gets the status of the specified channel.
 
bool AC_SetInvertedInput (uint8_t channel)
 Invert the input event.
 
bool AC_ClearInvertedInput (uint8_t channel)
 Clear the inverted input event setting.
 
bool AC_StartComparisonOnEvent (uint8_t channel)
 Start comparison on input event.
 
bool AC_DisableComparisonOnEvent (uint8_t channel)
 Disable start comparison on input event.
 
bool AC_EnableCompEventOutput (uint8_t channel)
 Enables Comparator event output.
 
bool AC_DisableCompEventOutput (uint8_t channel)
 Disables Comparator event output.
 
bool AC_EnableWindowEventOutput (uint8_t instance)
 Enables window event output.
 
bool AC_DisableWindowEventOutput (uint8_t instance)
 Disables window event output.
 
bool AC_EnableInterrupt (uint8_t channel, uint32_t mode)
 Enables interrupt for the specified channel.
 
bool AC_DisableInterrupt (uint8_t channel)
 Disables interrupt for the specified channel.
 
bool AC_ClearInterruptFlag (uint8_t channel)
 Clears the interrupt flag for the specified channel.
 
bool AC_EnableWindowInterrupt (uint8_t instance, uint32_t mode)
 Enables window interrupt with the specified mode.
 
bool AC_DisableWindowInterrupt (uint8_t instance)
 Disables window interrupt.
 
bool AC_ClearWindowInterruptFlag (uint8_t instance)
 Clears the window interrupt flag.
 
bool AC_EnableWindowMode (uint8_t instance)
 Enables window mode.
 
bool AC_DisableWindowMode (uint8_t instance)
 Disables window mode.
 
uint8_t AC_GetWindowModeStatus (uint8_t instance)
 Gets the status of the Window mode output.
 
void AC_SetCallbackHandler (AC_CALLBACK_HANDLER callback)
 Register a callback for AC interrupts.
 

Description

Driver API for AC (plib_ac.h)

Usage Example

The following example demonstrates typical usage of the AC peripheral:

#include "plib_ac.h"
int32_t configure_ac(void) {
const uint8_t AC_CHANNEL_0 = 0U;
// Reset the AC registers
// Select channel 0 positive input as AIN0 and negative input as internal reference
#if defined(AC_COMPCTRL_MUXPOS_AIN0)
AC_SelectChannelInputs(AC_CHANNEL_0, AC_COMPCTRL_MUXPOS_AIN0, AC_COMPCTRL_MUXNEG_VSCALE);
#else
AC_SelectChannelInputs(AC_CHANNEL_0, AC_COMPCTRL_MUXPOS_PIN0, AC_COMPCTRL_MUXNEG_VSCALE);
#endif
//Set speed as High
AC_SetSpeed(0, AC_COMPCTRL_SPEED_HIGH_Val);
//Set Hysteresis
AC_SetHysteresis(0, true);
//Select VDD scaler
AC_SetVddScaler(0, 32U);
// Enable the Analog Comparator (AC) module
// Enable channel 0 of the AC module
AC_EnableChannel(AC_CHANNEL_0);
return 0;
}
bool AC_EnableChannel(uint8_t channel)
Enables the specified AC channel.
bool AC_SelectChannelInputs(uint8_t channel, uint32_t pos, uint32_t neg)
Selects the positive and negative inputs for the specified channel.
bool AC_SetVddScaler(uint8_t channel, uint8_t value)
Sets the VDD scaler value for the specified channel.
void AC_ResetSoftware(void)
Performs a software reset of the AC peripheral.
bool AC_SetSpeed(uint8_t channel, uint32_t speed)
Set speed for comparator channel.
void AC_Enable(void)
Enables the AC peripheral.
bool AC_SetHysteresis(uint8_t channel, bool enable)
Enables or disables hysteresis for the specified channel.
Analog comparator PLIB interface.

Macro Definition Documentation

◆ AC_COMP_NUMBER

#define AC_COMP_NUMBER   4U

Number of comparators available in the AC peripheral.

◆ AC_WIN_NUMBER

#define AC_WIN_NUMBER   2U

Number of window comparators available in the AC peripheral.

Typedef Documentation

◆ AC_CALLBACK_HANDLER

typedef void(* AC_CALLBACK_HANDLER) (uint8_t status)

AC interrupt callback function type.

This function pointer type is used to register a user callback for the Analog Comparator (AC) interrupt. The callback is invoked when an AC interrupt occurs, providing the interrupt flags and user context.

Parameters
int_flagsInterrupt flags indicating the source of the AC interrupt.
contextUser-defined context value passed during callback registration.

Enumeration Type Documentation

◆ AC_EVENT

enum AC_EVENT

AC Comparator events.

Enumerator
AC_EVENT_COMP0 
AC_EVENT_COMP1 
AC_EVENT_COMP2 
AC_EVENT_COMP3 
AC_EVENT_WIN0 
AC_EVENT_WIN1 
AC_EVENT_NONE 

◆ AC_OUTPUT

enum AC_OUTPUT

AC output options.

Enumerator
AC_OUTPUT_OFF 
AC_OUTPUT_ASYNC 
AC_OUTPUT_SYNC 

Function Documentation

◆ AC_CheckOutputReady()

bool AC_CheckOutputReady ( uint8_t channel)

Check if output is ready.

Parameters
channelComparator channel number 0 to 3.
Returns
true if successful, false otherwise.

◆ AC_ClearInterruptFlag()

bool AC_ClearInterruptFlag ( uint8_t channel)

Clears the interrupt flag for the specified channel.

Parameters
channelChannel number.
Returns
true if successful, false otherwise.

◆ AC_ClearInvertedInput()

bool AC_ClearInvertedInput ( uint8_t channel)

Clear the inverted input event setting.

Parameters
channelComparator channel number 0 to 3.
Returns
true if successful, false otherwise.

◆ AC_ClearWindowInterruptFlag()

bool AC_ClearWindowInterruptFlag ( uint8_t instance)

Clears the window interrupt flag.

Parameters
instanceSelect window instance 0 or 1.
Returns
true if successful, false otherwise.

◆ AC_Disable()

void AC_Disable ( void )

Disables the AC peripheral.

◆ AC_DisableChannel()

bool AC_DisableChannel ( uint8_t channel)

Disables the specified AC channel.

Parameters
channelChannel number to disable.
Returns
true if successful, false otherwise.

◆ AC_DisableComparisonOnEvent()

bool AC_DisableComparisonOnEvent ( uint8_t channel)

Disable start comparison on input event.

Parameters
channelComparator channel number 0 to 3.
Returns
true if successful, false otherwise.

◆ AC_DisableCompEventOutput()

bool AC_DisableCompEventOutput ( uint8_t channel)

Disables Comparator event output.

Parameters
channelComparator channel number 0 to 3.
Returns
true if successful, false otherwise.

◆ AC_DisableInterrupt()

bool AC_DisableInterrupt ( uint8_t channel)

Disables interrupt for the specified channel.

Parameters
channelChannel number.
Returns
true if successful, false otherwise.

◆ AC_DisableWindowEventOutput()

bool AC_DisableWindowEventOutput ( uint8_t instance)

Disables window event output.

Parameters
instanceSelect window instance 0 or 1.
Returns
true if successful, false otherwise.

◆ AC_DisableWindowInterrupt()

bool AC_DisableWindowInterrupt ( uint8_t instance)

Disables window interrupt.

Parameters
instanceSelect window instance 0 or 1.
Returns
true if successful, false otherwise.

◆ AC_DisableWindowMode()

bool AC_DisableWindowMode ( uint8_t instance)

Disables window mode.

Parameters
instanceSelect window instance 0 or 1.
Returns
true if successful, false otherwise.

◆ AC_Enable()

void AC_Enable ( void )

Enables the AC peripheral.

◆ AC_EnableChannel()

bool AC_EnableChannel ( uint8_t channel)

Enables the specified AC channel.

Parameters
channelChannel number to enable.
Returns
true if successful, false otherwise.

◆ AC_EnableCompEventOutput()

bool AC_EnableCompEventOutput ( uint8_t channel)

Enables Comparator event output.

Parameters
channelComparator channel number 0 to 3.
Returns
true if successful, false otherwise.

◆ AC_EnableInterrupt()

bool AC_EnableInterrupt ( uint8_t channel,
uint32_t mode )

Enables interrupt for the specified channel.

Parameters
channelChannel number.
modeInterrupt mode selection.
Returns
true if successful, false otherwise.

◆ AC_EnableOutput()

bool AC_EnableOutput ( uint8_t channel,
AC_OUTPUT value )

Enables or disables the output for the specified channel.

Parameters
channelChannel number.
valueAC_OUTPUT OFF, ASYNC, SYNC.
Returns
true if successful, false otherwise.

◆ AC_EnableWindowEventOutput()

bool AC_EnableWindowEventOutput ( uint8_t instance)

Enables window event output.

Parameters
instanceSelect window instance 0 or 1.
Returns
true if successful, false otherwise.

◆ AC_EnableWindowInterrupt()

bool AC_EnableWindowInterrupt ( uint8_t instance,
uint32_t mode )

Enables window interrupt with the specified mode.

Parameters
instanceSelect window instance 0 or 1.
modeWindow interrupt mode selection.
Returns
true if successful, false otherwise.

◆ AC_EnableWindowMode()

bool AC_EnableWindowMode ( uint8_t instance)

Enables window mode.

Parameters
instanceSelect window instance 0 or 1.
Returns
true if successful, false otherwise.

◆ AC_GetStatus()

bool AC_GetStatus ( uint8_t channel)

Gets the status of the specified channel.

Parameters
channelChannel number.
Returns
true if the comparator output is high, false otherwise.

◆ AC_GetWindowModeStatus()

uint8_t AC_GetWindowModeStatus ( uint8_t instance)

Gets the status of the Window mode output.

Parameters
instanceSelect window instance 0 or 1.
Returns
true if successful, false otherwise.

◆ AC_ResetSoftware()

void AC_ResetSoftware ( void )

Performs a software reset of the AC peripheral.

◆ AC_SelectChannelInputs()

bool AC_SelectChannelInputs ( uint8_t channel,
uint32_t pos,
uint32_t neg )

Selects the positive and negative inputs for the specified channel.

Parameters
channelChannel number.
posPositive input selection.
negNegative input selection.
Returns
true if successful, false otherwise.

◆ AC_SetCallbackHandler()

void AC_SetCallbackHandler ( AC_CALLBACK_HANDLER callback)

Register a callback for AC interrupts.

Registers a user callback to be called from the AC interrupt handler when any enabled AC interrupt occurs. The callback receives the interrupt flags and user context.

Parameters
[in]callbackPointer to the callback function (AC_CALLBACK).

◆ AC_SetComparisonMode()

bool AC_SetComparisonMode ( uint8_t channel,
uint8_t single )

Set comparison mode for the comparator channel.

Parameters
channelComparator channel number 0 to 3.
singleSingle mode selection.
Returns
true if successful, false otherwise.

◆ AC_SetFilterLength()

bool AC_SetFilterLength ( uint8_t channel,
uint32_t flen )

Set Filter length for comparator channel.

Parameters
channelComparator channel number 0 to 3.
flenFilter length.
Returns
true if successful, false otherwise.

◆ AC_SetHysteresis()

bool AC_SetHysteresis ( uint8_t channel,
bool enable )

Enables or disables hysteresis for the specified channel.

Parameters
channelChannel number.
enabletrue to enable, false to disable.
Returns
true if successful, false otherwise.

◆ AC_SetInvertedInput()

bool AC_SetInvertedInput ( uint8_t channel)

Invert the input event.

Parameters
channelComparator channel number 0 to 3.
Returns
true if successful, false otherwise.

◆ AC_SetRunInStandby()

bool AC_SetRunInStandby ( uint8_t channel,
bool enable )

Sets the run-in-standby mode for the specified channel.

Parameters
channelChannel number.
enabletrue to enable, false to disable.
Returns
true if successful, false otherwise.

◆ AC_SetSpeed()

bool AC_SetSpeed ( uint8_t channel,
uint32_t speed )

Set speed for comparator channel.

Parameters
channelComparator channel number 0 to 3.
speedSpeed selection.
Returns
true if successful, false otherwise.

◆ AC_SetVddScaler()

bool AC_SetVddScaler ( uint8_t channel,
uint8_t value )

Sets the VDD scaler value for the specified channel.

Parameters
channelChannel number.
valueScaler value.
Returns
true if successful, false otherwise.

◆ AC_StartComparison()

bool AC_StartComparison ( uint8_t channel)

Starts comparison.

Parameters
channelComparator channel number 0 to 3.
Returns
true if successful, false otherwise.

◆ AC_StartComparisonOnEvent()

bool AC_StartComparisonOnEvent ( uint8_t channel)

Start comparison on input event.

Parameters
channelComparator channel number 0 to 3.
Returns
true if successful, false otherwise.

◆ AC_SwapInputs()

bool AC_SwapInputs ( uint8_t channel,
bool enable )

Swaps the inputs.

Parameters
channelComparator channel number 0 to 3.
enabletrue to enable, false to disable.
Returns
true if successful, false otherwise.