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

Driver API for DAC (plib_dac.h) More...

Content

 DAC Reference Selection Macros
 
 DAC Output Mode Macros
 
 DAC Dithering Macros
 

Macros

#define DAC_DATA_MSB_MASK   (0x03FFU)
 
#define DAC_REFSEL_INTREF   DAC_CTRLB_REFSEL(DAC_CTRLB_REFSEL_INTREF_Val)
 
#define DAC_REFSEL_AVDD   DAC_CTRLB_REFSEL(DAC_CTRLB_REFSEL_AVDD_Val)
 
#define DAC_REFSEL_VREFA   DAC_CTRLB_REFSEL(DAC_CTRLB_REFSEL_VREFA_Val)
 
#define DAC_OUTPUT_MODE_ANALOG_COMPARATOR   DAC_CTRLB_IOEN(1UL)
 
#define DAC_OUTPUT_MODE_INTERNAL_AND_EXTERNAL   (DAC_CTRLB_IOEN(1UL) | DAC_CTRLB_EOEN(1UL))
 
#define DAC_OUTPUT_MODE_EXTERNAL   DAC_CTRLB_EOEN(1UL)
 
#define DAC_OUTPUT_MODE_NONE   0UL
 
#define DAC_DITHER_ENABLE   DAC_CTRLB_DITHER(1UL)
 
#define DAC_DITHER_DISABLE   DAC_CTRLB_DITHER(0UL)
 

Typedefs

typedef void(* DAC_CALLBACK) (DAC_INT_FLAG interruptFlags)
 DAC interrupt callback function type.
 

Enumerations

enum  DAC_START_EVENT_EDGE { DAC_START_EVENT_EDGE_RISING = 0U , DAC_START_EVENT_EDGE_FALLING = 1U }
 Edge selection for the DAC Start Event Input. More...
 
enum  DAC_INT_FLAG { DAC_INTFLAG_NONE = 0U , DAC_INT_UNDERRUN = (1U << 0) , DAC_INT_EMPTY = (1U << 1) }
 DAC interrupt/event/flag sources (bitmask). More...
 

Functions

void DAC_SetReference (uint8_t refsel_mask)
 Set the DAC reference voltage.
 
void DAC_SetOutputMode (uint8_t mode_mask)
 Set the DAC output mode.
 
void DAC_EnableDithering (bool enable)
 Enable or disable DAC dithering.
 
void DAC_EnableVoltagePump (bool enable)
 Enable or disable the DAC voltage pump.
 
void DAC_EnableDataBufferEmptyEvent (bool enable)
 Enable or disable the Data Buffer Empty Event Output.
 
void DAC_EnableStartConversionOnEvent (bool enable)
 Enable or disable Start Conversion on Event.
 
void DAC_SetStartEventEdge (DAC_START_EVENT_EDGE edge)
 Set the edge detection for the DAC Start Event Input.
 
void DAC_Enable (void)
 Enable the DAC.
 
void DAC_Disable (void)
 Disable the DAC.
 
void DAC_ResetSoftware (void)
 Perform a software reset of the DAC.
 
void DAC_WriteData (uint16_t data)
 Write data to the DAC.
 
bool DAC_IsReady (void)
 Check if the DAC is ready for new data.
 
void DAC_EnableRunInStandby (void)
 Enable the DAC output buffer in standby sleep mode.
 
void DAC_DisableRunInStandby (void)
 Disable the DAC output buffer in standby sleep mode.
 
uint8_t DAC_GetResolution (void)
 Get the current DAC resolution (10 or 14 bits).
 
void DAC_EnableInterrupts (DAC_INT_FLAG flag)
 Enable selected DAC interrupts.
 
void DAC_DisableInterrupts (DAC_INT_FLAG flag)
 Disable selected DAC interrupts.
 
bool DAC_IsInterruptFlagsSet (DAC_INT_FLAG flag)
 Check if any of the specified DAC interrupt/event/flags are set.
 
void DAC_ClearInterruptFlags (DAC_INT_FLAG flag)
 Clear specified DAC interrupt/event/flags.
 
void DAC_RegisterCallback (DAC_CALLBACK callback)
 Register a callback function for DAC interrupts.
 

Description

Driver API for DAC (plib_dac.h)

Usage Example

The following example demonstrates typical usage of the DAC peripheral:

#include "plib_dac.h"
#include<stdint.h>
int configure_dac(void)
{
uint16_t initial_dac_value = 0U;
/* Configure DAC settings */
/* Enable DAC */
while (DAC_IsReady() == false)
{
/* Wait for DAC ready */
}
/* Write initial DAC value */
DAC_WriteData(initial_dac_value);
return 0;
}
void DAC_SetReference(uint8_t refsel_mask)
Set the DAC reference voltage.
#define DAC_OUTPUT_MODE_EXTERNAL
Definition plib_dac.h:70
#define DAC_REFSEL_AVDD
Definition plib_dac.h:62
void DAC_EnableVoltagePump(bool enable)
Enable or disable the DAC voltage pump.
void DAC_DisableRunInStandby(void)
Disable the DAC output buffer in standby sleep mode.
void DAC_EnableDithering(bool enable)
Enable or disable DAC dithering.
void DAC_SetOutputMode(uint8_t mode_mask)
Set the DAC output mode.
void DAC_WriteData(uint16_t data)
Write data to the DAC.
void DAC_Enable(void)
Enable the DAC.
bool DAC_IsReady(void)
Check if the DAC is ready for new data.

Macro Definition Documentation

◆ DAC_DATA_MSB_MASK

#define DAC_DATA_MSB_MASK   (0x03FFU)

◆ DAC_DITHER_DISABLE

#define DAC_DITHER_DISABLE   DAC_CTRLB_DITHER(0UL)

Disable dithering

◆ DAC_DITHER_ENABLE

#define DAC_DITHER_ENABLE   DAC_CTRLB_DITHER(1UL)

Enable dithering

◆ DAC_OUTPUT_MODE_ANALOG_COMPARATOR

#define DAC_OUTPUT_MODE_ANALOG_COMPARATOR   DAC_CTRLB_IOEN(1UL)

Analog comparator mode

◆ DAC_OUTPUT_MODE_EXTERNAL

#define DAC_OUTPUT_MODE_EXTERNAL   DAC_CTRLB_EOEN(1UL)

External output enabled

◆ DAC_OUTPUT_MODE_INTERNAL_AND_EXTERNAL

#define DAC_OUTPUT_MODE_INTERNAL_AND_EXTERNAL   (DAC_CTRLB_IOEN(1UL) | DAC_CTRLB_EOEN(1UL))

Internal and external output enabled

◆ DAC_OUTPUT_MODE_NONE

#define DAC_OUTPUT_MODE_NONE   0UL

No output mode

◆ DAC_REFSEL_AVDD

#define DAC_REFSEL_AVDD   DAC_CTRLB_REFSEL(DAC_CTRLB_REFSEL_AVDD_Val)

AVDD reference

◆ DAC_REFSEL_INTREF

#define DAC_REFSEL_INTREF   DAC_CTRLB_REFSEL(DAC_CTRLB_REFSEL_INTREF_Val)

Internal reference

◆ DAC_REFSEL_VREFA

#define DAC_REFSEL_VREFA   DAC_CTRLB_REFSEL(DAC_CTRLB_REFSEL_VREFA_Val)

External VREFA reference

Typedef Documentation

◆ DAC_CALLBACK

typedef void(* DAC_CALLBACK) (DAC_INT_FLAG interruptFlags)

DAC interrupt callback function type.

Parameters
interruptFlagsBitmask of interrupt flags (see DAC_INTFLAG_*).

Enumeration Type Documentation

◆ DAC_INT_FLAG

DAC interrupt/event/flag sources (bitmask).

Enumerator
DAC_INTFLAG_NONE 
DAC_INT_UNDERRUN 

Underrun interrupt/event/flag

DAC_INT_EMPTY 

Data buffer empty interrupt/event/flag

◆ DAC_START_EVENT_EDGE

Edge selection for the DAC Start Event Input.

Enumerator
DAC_START_EVENT_EDGE_RISING 

Detect rising edge on Start Event Input

DAC_START_EVENT_EDGE_FALLING 

Detect falling edge on Start Event Input

Function Documentation

◆ DAC_ClearInterruptFlags()

void DAC_ClearInterruptFlags ( DAC_INT_FLAG flag)

Clear specified DAC interrupt/event/flags.

Parameters
flagBitwise OR of DAC_INTFLAG_* values.
Returns
None

◆ DAC_Disable()

void DAC_Disable ( void )

Disable the DAC.

Parameters
None
Returns
None

◆ DAC_DisableInterrupts()

void DAC_DisableInterrupts ( DAC_INT_FLAG flag)

Disable selected DAC interrupts.

Parameters
flagBitwise OR of DAC_INTFLAG_* values.
Returns
None

◆ DAC_DisableRunInStandby()

void DAC_DisableRunInStandby ( void )

Disable the DAC output buffer in standby sleep mode.

Parameters
None
Returns
None

◆ DAC_Enable()

void DAC_Enable ( void )

Enable the DAC.

Parameters
None
Returns
None

◆ DAC_EnableDataBufferEmptyEvent()

void DAC_EnableDataBufferEmptyEvent ( bool enable)

Enable or disable the Data Buffer Empty Event Output.

Parameters
enabletrue to enable, false to disable.
Returns
None

◆ DAC_EnableDithering()

void DAC_EnableDithering ( bool enable)

Enable or disable DAC dithering.

Parameters
enabletrue to enable, false to disable.
Returns
None

◆ DAC_EnableInterrupts()

void DAC_EnableInterrupts ( DAC_INT_FLAG flag)

Enable selected DAC interrupts.

Parameters
flagBitwise OR of DAC_INTFLAG_* values.
Returns
None

◆ DAC_EnableRunInStandby()

void DAC_EnableRunInStandby ( void )

Enable the DAC output buffer in standby sleep mode.

Parameters
None
Returns
None

◆ DAC_EnableStartConversionOnEvent()

void DAC_EnableStartConversionOnEvent ( bool enable)

Enable or disable Start Conversion on Event.

Parameters
enabletrue to enable, false to disable.
Returns
None

◆ DAC_EnableVoltagePump()

void DAC_EnableVoltagePump ( bool enable)

Enable or disable the DAC voltage pump.

Parameters
enabletrue to enable, false to disable.
Returns
None

◆ DAC_GetResolution()

uint8_t DAC_GetResolution ( void )

Get the current DAC resolution (10 or 14 bits).

Parameters
None
Returns
14 if DITHER is enabled, 10 if disabled.

◆ DAC_IsInterruptFlagsSet()

bool DAC_IsInterruptFlagsSet ( DAC_INT_FLAG flag)

Check if any of the specified DAC interrupt/event/flags are set.

Parameters
flagBitwise OR of DAC_INTFLAG_* values.
Returns
true if any specified flag is set, false otherwise.

◆ DAC_IsReady()

bool DAC_IsReady ( void )

Check if the DAC is ready for new data.

Parameters
None
Returns
true if ready, false otherwise.

◆ DAC_RegisterCallback()

void DAC_RegisterCallback ( DAC_CALLBACK callback)

Register a callback function for DAC interrupts.

The callback will be called from the DAC interrupt handler when any enabled DAC interrupt occurs. The callback receives the set interrupt flags and the

Parameters
callbackPointer to the callback function.
Returns
None

◆ DAC_ResetSoftware()

void DAC_ResetSoftware ( void )

Perform a software reset of the DAC.

Parameters
None
Returns
None

◆ DAC_SetOutputMode()

void DAC_SetOutputMode ( uint8_t mode_mask)

Set the DAC output mode.

Parameters
mode_maskOutput mode mask (use DAC_OUTPUT_MODE_* macros).
Returns
None

◆ DAC_SetReference()

void DAC_SetReference ( uint8_t refsel_mask)

Set the DAC reference voltage.

Parameters
refsel_maskReference selection mask (use DAC_REFSEL_* macros).
Returns
None

◆ DAC_SetStartEventEdge()

void DAC_SetStartEventEdge ( DAC_START_EVENT_EDGE edge)

Set the edge detection for the DAC Start Event Input.

Parameters
edgeEdge selection (use DAC_START_EVENT_EDGE_RISING or DAC_START_EVENT_EDGE_FALLING).

◆ DAC_WriteData()

void DAC_WriteData ( uint16_t data)

Write data to the DAC.

Parameters
data10-bit data value to write.
Returns
None