6.8.1.1.3 Workflow
- Create a module software instance structure for the DAC module to store the DAC driver state while in use.
struct
dac_module dac_instance;
Note: This should never go out of scope as long as the module is in use. In most cases, this should be global. - Configure the DAC module.
- Create a DAC module configuration struct, which can be filled out to adjust the configuration of a physical DAC peripheral.
struct
dac_config config_dac;
- Initialize the DAC configuration struct with the module's default values.
dac_get_config_defaults(&config_dac);
Note: This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
- Configure the DAC channel.
- Create a DAC channel configuration struct, which can be filled out to adjust the configuration of a physical DAC output channel.
struct
dac_chan_config config_dac_chan;
- Initialize the DAC channel configuration struct with the module's default values.
dac_chan_get_config_defaults(&config_dac_chan);
Note: This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings. - Configure the DAC channel with the desired channel settings.
dac_chan_set_config(&dac_instance, DAC_CHANNEL_0, &config_dac_chan);
- Enable the DAC channel so that it can output a voltage.
dac_chan_enable(&dac_instance, DAC_CHANNEL_0);
- Enable the DAC module.
dac_enable(&dac_instance);