Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Digital-to-Analog Converter Controller (DACC)

Purpose

Driver for the Digital-to-Analog Converter Controller. It provides access to the main features of the DAC controller.

Usage
  1. DACC clock should be enabled before using it.
  2. Reset DACC with dacc_reset().
  3. If DACC can be enabled/disabled, uses dacc_enable() and dacc_disable().
  4. Initialize DACC timing with dacc_set_timing() (different DAC peripheral may require different parameters).
  5. Write conversion data with dacc_write_conversion_data().
  6. Configure trigger with dacc_set_trigger() and dacc_disable_trigger().
  7. Configure FIFO transfer mode with dacc_set_transfer_mode().
  8. Control interrupts with dacc_enable_interrupt(), dacc_disable_interrupt(), dacc_get_interrupt_mask() and dacc_get_interrupt_status().
  9. DACC registers support write protect with dacc_set_writeprotect() and dacc_get_writeprotect_status().
  10. If the DACC can work with PDC, use dacc_get_pdc_base() to get PDC register base for the DAC controller.
  11. If the DACC has several channels to process, the following functions can be used:

Dependencies

This driver does not depend on other modules.

Modules

 

Macros

#define DACC_WP_KEY   (0x444143)
 DACC Write Protect Key "DAC" in ASCII. More...
 
#define DACC_WPMR_WPKEY_PASSWD   DACC_WPMR_WPKEY(DACC_WP_KEY)
 
#define MAX_CH_NB   1
 Max channel number. More...
 

Functions

void dacc_disable (Dacc *p_dacc)
 Disable DACC. More...
 
uint32_t dacc_disable_channel (Dacc *p_dacc, uint32_t ul_channel)
 Disable DACC channel. More...
 
void dacc_disable_interrupt (Dacc *p_dacc, uint32_t ul_interrupt_mask)
 Disable DACC interrupts. More...
 
void dacc_disable_trigger (Dacc *p_dacc)
 Disable trigger (free run mode). More...
 
void dacc_enable (Dacc *p_dacc)
 Enable DACC. More...
 
uint32_t dacc_enable_channel (Dacc *p_dacc, uint32_t ul_channel)
 Enable DACC channel. More...
 
void dacc_enable_flexible_selection (Dacc *p_dacc)
 Enable the flexible channel selection mode (TAG). More...
 
void dacc_enable_interrupt (Dacc *p_dacc, uint32_t ul_interrupt_mask)
 Enable DACC interrupts. More...
 
uint32_t dacc_get_analog_control (Dacc *p_dacc)
 Get the analog control value. More...
 
uint32_t dacc_get_channel_status (Dacc *p_dacc)
 Get the channel status. More...
 
uint32_t dacc_get_interrupt_mask (Dacc *p_dacc)
 Get the interrupt mask. More...
 
uint32_t dacc_get_interrupt_status (Dacc *p_dacc)
 Get the interrupt status. More...
 
Pdc * dacc_get_pdc_base (Dacc *p_dacc)
 Get PDC registers base address. More...
 
uint32_t dacc_get_writeprotect_status (Dacc *p_dacc)
 Get the write protect status. More...
 
void dacc_reset (Dacc *p_dacc)
 Reset DACC. More...
 
uint32_t dacc_set_analog_control (Dacc *p_dacc, uint32_t ul_analog_control)
 Set the analog control value. More...
 
uint32_t dacc_set_channel_selection (Dacc *p_dacc, uint32_t ul_channel)
 Disable flexible (TAG) mode and select a channel for DAC outputs. More...
 
uint32_t dacc_set_power_save (Dacc *p_dacc, uint32_t ul_sleep_mode, uint32_t ul_fast_wakeup_mode)
 Set the power save mode. More...
 
uint32_t dacc_set_timing (Dacc *p_dacc, uint32_t ul_startup, uint32_t ul_clock_divider)
 Set the DACC timing. More...
 
uint32_t dacc_set_timing (Dacc *p_dacc, uint32_t ul_refresh, uint32_t ul_maxs, uint32_t ul_startup)
 Set DACC timings. More...
 
uint32_t dacc_set_transfer_mode (Dacc *p_dacc, uint32_t ul_mode)
 Set the transfer mode. More...
 
uint32_t dacc_set_trigger (Dacc *p_dacc, uint32_t ul_trigger)
 Enable trigger and set the trigger source. More...
 
void dacc_set_writeprotect (Dacc *p_dacc, uint32_t ul_enable)
 Enable or disable write protect of DACC registers. More...
 
void dacc_write_conversion_data (Dacc *p_dacc, uint32_t ul_data)
 Write data to conversion register. More...
 

#define DACC_WP_KEY   (0x444143)

DACC Write Protect Key "DAC" in ASCII.

#define DACC_WPMR_WPKEY_PASSWD   DACC_WPMR_WPKEY(DACC_WP_KEY)

Referenced by dacc_set_writeprotect().

#define MAX_CH_NB   1

void dacc_disable ( Dacc *  p_dacc)

Disable DACC.

Parameters
p_daccPointer to a DACC instance.
Returns
DACC_RC_OK for OK.
uint32_t dacc_disable_channel ( Dacc *  p_dacc,
uint32_t  ul_channel 
)

Disable DACC channel.

Parameters
p_daccPointer to a DACC instance.
ul_channelThe output channel to disable.
Returns
DACC_RC_OK for OK.

References DACC_RC_INVALID_PARAM, DACC_RC_OK, and MAX_CH_NB.

void dacc_disable_interrupt ( Dacc *  p_dacc,
uint32_t  ul_interrupt_mask 
)

Disable DACC interrupts.

Parameters
p_daccPointer to a DACC instance.
ul_interrupt_maskThe interrupt mask.
void dacc_disable_trigger ( Dacc *  p_dacc)

Disable trigger (free run mode).

Parameters
p_daccPointer to a DACC instance.

Referenced by main().

void dacc_enable ( Dacc *  p_dacc)

Enable DACC.

Parameters
p_daccPointer to a DACC instance.

Referenced by main().

uint32_t dacc_enable_channel ( Dacc *  p_dacc,
uint32_t  ul_channel 
)

Enable DACC channel.

Parameters
p_daccPointer to a DACC instance.
ul_channelThe output channel to enable.
Returns
DACC_RC_OK for OK.

References DACC_RC_INVALID_PARAM, DACC_RC_OK, and MAX_CH_NB.

Referenced by main().

void dacc_enable_flexible_selection ( Dacc *  p_dacc)

Enable the flexible channel selection mode (TAG).

In this mode the 2 bits, DACC_CDR[13:12] which are otherwise unused, are employed to select the channel in the same way as with the USER_SEL field. Finally, if the WORD field is set, the 2 bits, DACC_CDR[13:12] are used for channel selection of the first data and the 2 bits, DACC_CDR[29:28] for channel selection of the second data.

Parameters
p_daccPointer to a DACC instance.
void dacc_enable_interrupt ( Dacc *  p_dacc,
uint32_t  ul_interrupt_mask 
)

Enable DACC interrupts.

Parameters
p_daccPointer to a DACC instance.
ul_interrupt_maskThe interrupt mask.
uint32_t dacc_get_analog_control ( Dacc *  p_dacc)

Get the analog control value.

Parameters
p_daccPointer to a DACC instance.
Returns
Current setting of analog control.
uint32_t dacc_get_channel_status ( Dacc *  p_dacc)

Get the channel status.

Parameters
p_daccPointer to a DACC instance.
Returns
DACC channel status.
uint32_t dacc_get_interrupt_mask ( Dacc *  p_dacc)

Get the interrupt mask.

Parameters
p_daccPointer to a DACC instance.
Returns
The interrupt mask.
uint32_t dacc_get_interrupt_status ( Dacc *  p_dacc)

Get the interrupt status.

Parameters
p_daccPointer to a DACC instance.
Returns
The interrupt status.

Referenced by SysTick_Handler().

Pdc* dacc_get_pdc_base ( Dacc *  p_dacc)

Get PDC registers base address.

Parameters
p_daccPointer to a DACC instance.
Returns
DACC PDC register base address.

References UNUSED.

uint32_t dacc_get_writeprotect_status ( Dacc *  p_dacc)

Get the write protect status.

Parameters
p_daccPointer to a DACC instance.
Returns
Write protect status.
void dacc_reset ( Dacc *  p_dacc)

Reset DACC.

Parameters
p_daccPointer to a DACC instance.

Referenced by main().

uint32_t dacc_set_analog_control ( Dacc *  p_dacc,
uint32_t  ul_analog_control 
)

Set the analog control value.

Parameters
p_daccPointer to a DACC instance.
ul_analog_controlAnalog control configuration.
Returns
DACC_RC_OK for OK.

References DACC_RC_OK.

Referenced by main().

uint32_t dacc_set_channel_selection ( Dacc *  p_dacc,
uint32_t  ul_channel 
)

Disable flexible (TAG) mode and select a channel for DAC outputs.

Parameters
p_daccPointer to a DACC instance.
ul_channelChannel to select.
Returns
DACC_RC_OK if successful.

References DACC_RC_INVALID_PARAM, DACC_RC_OK, and MAX_CH_NB.

Referenced by main().

uint32_t dacc_set_power_save ( Dacc *  p_dacc,
uint32_t  ul_sleep_mode,
uint32_t  ul_fast_wakeup_mode 
)

Set the power save mode.

Parameters
p_daccPointer to a DACC instance.
ul_sleep_modeSleep mode configuration.
ul_fast_wakeup_modeFast wakeup mode configuration.
Returns
DACC_RC_OK if successful.

References DACC_RC_OK.

Referenced by main().

uint32_t dacc_set_timing ( Dacc *  p_dacc,
uint32_t  ul_startup,
uint32_t  ul_clock_divider 
)

Set the DACC timing.

Parameters
p_daccPointer to a DACC instance.
ul_startupStartup time selection.
ul_clock_dividerClock divider for internal trigger.
Returns
DACC_RC_OK for OK.

References DACC_RC_OK.

Referenced by main().

uint32_t dacc_set_timing ( Dacc *  p_dacc,
uint32_t  ul_refresh,
uint32_t  ul_maxs,
uint32_t  ul_startup 
)

Set DACC timings.

Parameters
p_daccPointer to a DACC instance.
ul_refreshRefresh period setting value.
ul_maxsMax speed mode configuration.
ul_startupStartup time selection.
Returns
DACC_RC_OK for OK.

References DACC_RC_OK.

uint32_t dacc_set_transfer_mode ( Dacc *  p_dacc,
uint32_t  ul_mode 
)

Set the transfer mode.

Parameters
p_daccPointer to a DACC instance.
ul_modeTransfer mode configuration.
Returns
DACC_RC_OK for OK.

References DACC_RC_OK.

Referenced by main().

uint32_t dacc_set_trigger ( Dacc *  p_dacc,
uint32_t  ul_trigger 
)

Enable trigger and set the trigger source.

Parameters
p_daccPointer to a DACC instance.
ul_triggerTrigger source number.
Returns
DACC_RC_OK for OK.

References DACC_RC_OK.

void dacc_set_writeprotect ( Dacc *  p_dacc,
uint32_t  ul_enable 
)

Enable or disable write protect of DACC registers.

Parameters
p_daccPointer to a DACC instance.
ul_enable1 to enable, 0 to disable.

References DACC_WPMR_WPKEY_PASSWD.

void dacc_write_conversion_data ( Dacc *  p_dacc,
uint32_t  ul_data 
)

Write data to conversion register.

Note
The ul_data could be output data or data with channel TAG when flexible mode is used.

In flexible mode the 2 bits, DACC_CDR[13:12] which are otherwise unused, are employed to select the channel in the same way as with the USER_SEL field. Finally, if the WORD field is set, the 2 bits, DACC_CDR[13:12] are used for channel selection of the first data and the 2 bits, DACC_CDR[29:28] for channel selection of the second data.

See Also
dacc_enable_flexible_selection()
Parameters
p_daccPointer to a DACC instance.
ul_dataThe data to be transferred to analog value.

Referenced by main(), and SysTick_Handler().