Link here

Outputting Voltages with Digital to Analog Conversion

The 8-channel 8-bit DAC brings to the QED Board a very exciting capability. The DACs are easy to use and flexible.

The onboard 8 channel 8 bit digital to analog converter (DAC) is interfaced to the processor via the fast serial peripheral interface (SPI), and its chip select is a memory-mapped signal generated by the onboard logic. The octal DAC allows the precise output of analog voltages ranging from 0V to 3V (or higher with the addition of simple off-board operational amplifier circuitry as provided by the QED Analog Conditioning Board). Each of the 8 DACs have an "input" voltage (named Vinx where x is the DAC channel number) that can be connected to a stable voltage reference or a voltage to be multiplied, for example, a time-varying input representing an audio signal. If the input is connected to the steady 1.5 Volt reference which is available on the QVGA Controller, the output of each channel ranges from 0 to 3 Volts in increments of 11.7 mV per digital count. Alternatively, to implement digital volume control you could connect a time-varying sound signal to the input of a DAC, and connect the DAC output to a speaker. Then the volume would be proportional to the digital code that you write to the DAC.

The DAC inputs and outputs are located on the Analog I/O connector; see the appropriate Appendix for the connector pinouts.


Fundamentals of Digital to Analog Conversion

Each DAC accepts a number between 0 and 255 which we’ll designate as N, and outputs a voltage given by

   Vout = N/128 * Vin

where Vin is the input (reference) voltage applied to the DAC. Thus Vout ranges from 0 Volts to nearly 2*Vin Volts. The maximum allowed value for Vin is 1.5 Volts, so the maximum value of Vout is nearly 3.0 Volts. Note that the output voltage of the DAC is proportional to Vin; for this reason it is called a "multiplying DAC". Vin may be a stable DC reference voltage, or it may be a time-varying analog signal. In the latter case, the DAC becomes a automated attenuator/amplifier that can take the place of potentiometers to perform volume control and other common functions.

analog voltage output

Figure 10-1    DAC output vs digital input code.


Initializing the DAC

Like the 12 bit A/D, the 8 bit DAC is interfaced to the 68HC11F1 via the high speed serial peripheral interface (SPI). The DAC is initialized by the same function that initializes the 12-bit A/D converter:

void InitAD12andDAC(void)

If you have compiled and downloaded the file, ANALOGIO.C, you can now use some of its useful functions. From the terminal you can execute,

InitAnalog( )↓

which calls InitAD12andDAC so that the DAC is ready to use. After you execute this command the DAC is ready to communicate with the 68HC11 via the SPI.


Applying a Reference Voltage

To use the DAC, you’ll first need to apply a valid input/reference voltage. To create a standard voltage output DAC with the maximum 0 to 3 volt output range, you can use the 1.5Vref voltage provided on the QVGA Controller to drive the Vin of each of the DAC channels that you want to use. For example, let’s connect 1.5Vref (pin 37 on the Analog I/O connector) to Vin1 (pin 21 on the Analog I/O connector).

This 1.5 volt reference may be used to provide a stable reference voltage for any or all of the digital-to-analog converters on the QVGA Controller, and can also provide a reference voltage for external circuitry.


Outputting a Voltage

Setting the 8-channel 8-bit DAC is very easy. To output a voltage, simply call the function:

SetDAC( uchar count, uint channel)

which expects a count in the range 0 to 255, and a channel in the range 1 to 8. After calling the SetDAC() function the multiplying DAC then outputs a voltage that is proportional to the specified count and to the analog input voltage. The analog input voltage must be between 0 and 1.5 volts, and the output voltage equals:

      Vout = 2 * Vin * count / 256 = Vin * count / 128

Using the 1.5V reference, after we have compiled and downloaded ANALOGIO.C we can interactively type from the terminal:

AnalogOut( char 255, int 1)↓

to create the full-scale output of the DAC which should be just under 3 volts. The output voltage appears at Vout1 on pin 22 of the Analog I/O connector. The AnalogOut() function is simply an interactive version (defined using _Q) of SetDAC(). Another useful function defined in ANALOGIO.C is:

VoltsOut( float voltage, int channel)

This function assumes that the DAC input voltage is 1.5Vref. It applies a simple formula to calculate the number of counts required to establish the requested voltage, clamps the calculated count to the range 0-255, and sends it to the specified DAC channel. You can interactively specify any voltage you want in the range 0 to 3 volts. For example, you can type:

VoltsOut( float 1.0, int 1)↓

and use a voltmeter connected to Vout1 to see how close the DAC comes to meeting your request.

To output a voltage of one half of the full scale range execute

AnalogOut( char 128, int 1)↓

Since 128 is half of the full 8 bit digital range, a voltage of 1.5 Volts (one half of the full 3 volt analog range) appears at the output of DAC1. You can connect a digital voltmeter to the DAC1 output (pin 22 on the Analog I/O connector) to verify that the DAC is working as expected.

The other DACs may be controlled in a similar manner. Each must have an input voltage reference that establishes that DAC's mid-range value.


DAC Execution Speed

The DAC driver FastSetDAC() executes in approximately 46 microseconds, and the multitasking version SetDAC() executes in 131 microseconds. The QVGA Controller maps the chip enable of the onboard D/A converter to page 14 (0x0E); the page addressing is responsible for appx. 6 microseconds of the execution time.

This page is about: Outputting Voltages with Digital to Analog Conversion – The 8 channel 8 bit DAC brings to QED Board very exciting capability. The DACs are easy to use and flexible. The onboard 8 channel 8 bit digital to analog converter (DAC) is interfaced to processor via fast serial peripheral interface (SPI), and its chip …