Midnight Sun Firmware
Loading...
Searching...
No Matches
DAC

DAC library. More...

Macros

#define NUM_DAC_CHANNELS   2U
 
#define DAC_MAX_VALUE   4095U
 
#define DAC_VREF_MV   3300U
 

Enumerations

enum  DacChannel { DAC_CHANNEL1 = 0 , DAC_CHANNEL2 = 1 }
 DAC channel identifiers. More...
 

Functions

StatusCode dac_init (void)
 Initialize the DAC peripheral. More...
 
StatusCode dac_enable_channel (DacChannel channel)
 Enable a specific DAC channel. More...
 
StatusCode dac_set_raw (DacChannel channel, uint16_t value)
 Set DAC output using raw 12-bit value. More...
 
StatusCode dac_set_voltage (DacChannel channel, uint16_t voltage_mv)
 Set DAC output using millivolt value. More...
 
StatusCode dac_get_raw (DacChannel channel, uint16_t *value)
 Read back the current DAC setting (raw value) More...
 
StatusCode dac_get_voltage (DacChannel channel, uint16_t *voltage_mv)
 Read back the current DAC setting (voltage in mV) More...
 
StatusCode dac_disable_channel (DacChannel channel)
 Disable a specific DAC channel. More...
 

Detailed Description

DAC library.

Enumeration Type Documentation

◆ DacChannel

enum DacChannel

DAC channel identifiers.

Enumerator
DAC_CHANNEL1 

DAC Channel 1 (PA4)

DAC_CHANNEL2 

DAC Channel 2 (PA5)

Function Documentation

◆ dac_disable_channel()

StatusCode dac_disable_channel ( DacChannel  channel)

Disable a specific DAC channel.

Parameters
channelDAC channel to disable
Returns
STATUS_CODE_OK if successful STATUS_CODE_INVALID_ARGS if channel is invalid STATUS_CODE_UNINITIALIZED if DAC not initialized

◆ dac_enable_channel()

StatusCode dac_enable_channel ( DacChannel  channel)

Enable a specific DAC channel.

Parameters
channelDAC channel to enable (DAC_CHANNEL_1 or DAC_CHANNEL_2)
Returns
STATUS_CODE_OK if successful STATUS_CODE_INVALID_ARGS if channel is invalid STATUS_CODE_UNINITIALIZED if DAC not initialized STATUS_CODE_RESOURCE_EXHAUSTED if channel already enabled

◆ dac_get_raw()

StatusCode dac_get_raw ( DacChannel  channel,
uint16_t *  value 
)

Read back the current DAC setting (raw value)

Parameters
channelDAC channel to read
valuePointer to store the current raw value
Returns
STATUS_CODE_OK if successful STATUS_CODE_INVALID_ARGS if parameters are invalid STATUS_CODE_UNINITIALIZED if DAC not initialized or channel not enabled

◆ dac_get_voltage()

StatusCode dac_get_voltage ( DacChannel  channel,
uint16_t *  voltage_mv 
)

Read back the current DAC setting (voltage in mV)

Parameters
channelDAC channel to read
voltage_mvPointer to store the current voltage in millivolts
Returns
STATUS_CODE_OK if successful STATUS_CODE_INVALID_ARGS if parameters are invalid STATUS_CODE_UNINITIALIZED if DAC not initialized or channel not enabled

◆ dac_init()

StatusCode dac_init ( void  )

Initialize the DAC peripheral.

Returns
STATUS_CODE_OK if successful STATUS_CODE_RESOURCE_EXHAUSTED if already initialized

◆ dac_set_raw()

StatusCode dac_set_raw ( DacChannel  channel,
uint16_t  value 
)

Set DAC output using raw 12-bit value.

Parameters
channelDAC channel to set
valueRaw 12-bit value (0-4095)
Returns
STATUS_CODE_OK if successful STATUS_CODE_INVALID_ARGS if channel invalid or value out of range STATUS_CODE_UNINITIALIZED if DAC not initialized or channel not enabled

◆ dac_set_voltage()

StatusCode dac_set_voltage ( DacChannel  channel,
uint16_t  voltage_mv 
)

Set DAC output using millivolt value.

Parameters
channelDAC channel to set
voltage_mvVoltage in millivolts (0-3300)
Returns
STATUS_CODE_OK if successful STATUS_CODE_INVALID_ARGS if channel invalid or voltage out of range STATUS_CODE_UNINITIALIZED if DAC not initialized or channel not enabled