The Simplecortex has one Analog output pin. This tutorial will teach you how to use the DAC pin to create an analog output. For this tutorial the DAC library is needed. This library can be downloaded from our repository.
To begin it is needed to include the libraries. This is done by these commands:
The libraries for the microcontroller itself and the variables have to be included to:
3. Write to the DAC
First the DAC has to be initialized in the main code with the command:
To write a value to the DAC the command use this code:
The DAC is a 10 bits DAC, this means that a value of 1023 will make the output equal to power supply (3.3V for the Simplecortex). A 0 for value will make the output equal to 0V and a value of 512 will make the output equal 1.65V. The formula to calculate the output variable is:
Voutput = (value / 1023) * Power supply voltage.
To set the Analog output to 1.1V the correct command is:
1.1V = (343/1023) * 3.3V