In this use case, the DAC will be configured with the following settings:
- Analog VCC as reference
- Internal output disabled
- Drive the DAC output to the VOUT pin
- Right adjust data
- The output buffer is disabled when the chip enters STANDBY sleep mode
Quick Start
Prerequisites
There are no special setup requirements for this use-case.
Code
Add to the main application source file, outside of any functions:
Copy-paste the following setup code to your user application:
Add to user application initialization (typically the start of main()
):
Workflow
- Create a module software instance structure for the DAC module to store the DAC driver state while in use.
- 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.
- Initialize the DAC configuration struct with the module's default values.
- 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.
- Initialize the DAC channel configuration struct with the module's default values.
- 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.
- Enable the DAC channel so that it can output a voltage.
- Enable the DAC module.
Use Case
Code
Copy-paste the following code to your user application:
uint16_t i = 0;
while (1) {
if (++i == 0x3FF) {
i = 0;
}
}
Workflow
- Create a temporary variable to track the current DAC output value.
- Enter an infinite loop to continuously output new conversion values to the DAC.
- Write the next conversion value to the DAC, so that it will be output on the device's DAC analog output pin.
- Increment and wrap the DAC output conversion value, so that a ramp pattern will be generated.
if (++i == 0x3FF) {
i = 0;
}