manufacturer of I/O-rich SBCs, operator interfaces, handheld instruments, and development tools for embedded control low cost single board computers, embedded controllers, and operator interfaces for scientific instruments & industrial control development tools for embedded control order our low cost I/O-rich embedded control products embedded controller manufacturer profile single board computers & embedded controllers development tools & starter kits for your embedded design operator interfaces with touchscreens and graphical user interface plug-in expansion modules for digital & analog I/O C language & Forth language integrated development tools, IDE single board and embedded computer accessories embedded controller enclosures, bezels, environmental gaskets

The C Programmer’s Guide to the QVGA Controller

Table of Contents

PART 1 GETTING STARTED

Introduction. How to Use This Manual

Chapter 1: Getting to Know Your QVGA

PART 2 PROGRAMMING THE QVGA CONTROLLER

Chapter 2: Your First Program

Chapter 3: The IDE: Writing, Compiling, Downloading and Debugging Programs

Chapter 4: Making Effective Use of Memory

Chapter 5: Programming the Graphical User Interface

Chapter 6: Real Time Programming

Chapter 7: Failure and Run-Time Error Recovery

PART 3 COMMUNICATIONS, MEASUREMENT, AND CONTROL

Chapter 8: Digital and Timer-Controlled I/O

Chapter 9: Data Acquisition Using the QVGA Controller

Chapter 10: Outputting Voltages with Digital to Analog Conversion

Chapter 11: Serial Communications

Chapter 12: The Battery-Backed Real Time Clock

Chapter 13: Customizing the QVGA's I/O

PART 4: REFERENCE DATA

Appendix A: GUI Function Reference

Appendix B: QVGA Schematics

Chapter 10

<< Previous | Next>>

Chapter 10: 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. 

Type an introduction to your chapter here.  It should be short and to the point. During writing you can use it to list the points you want to cover, and when you're done you can come back to it and summarize the Chapter for the reader. 

    List the major things the reader will learn how to do in a short bulleted list like this one.

    Keep your list items parallel, short, and descriptive.

    Make as many points as you need, but the Chapter Introduction should never exceed a page.  Half a page is ideal.

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.

 

Figure 10‑1  DAC output vs digital input code.

Initializing the DAC

[[[

Before using the 8 bit digital to analog converter (DAC), execute

INIT.A/D12&DAC

which is fully described in the Glossary.  This routine initializes the SPI (serial peripheral interface) which handles data transfer with the DAC as well as with the 12 bit A/D converter, and it also initializes the PIA (peripheral interface adapter) to be compatible with the 12 bit A/D chip selection. 

Multiple devices can use the SPI link as long as each device is activated by a unique chip select signal.  The DAC is activated by a memory mapped chip select signal which is active at addresses 80C0H through 80FFH.  This signal is generated by onboard address decoding logic, and is transparently activated by the built-in DAC driver routines described below.

]]]

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)

 

INIT.A/D12&DAC

INIT.A/D12&DACInitAD12andDAC() sets the eight DAC outputs to zero.  You can call this function from within your code, or simply type,

INIT.A/D12&DAC

at your terminal. 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

[[[

Built-in Driver Routines for the DAC

The 8 DAC channels are numbered 1...8; this is in keeping with the manufacturer’s channel specification code.  The DAC inputs (which can be reference voltages or time-varying signals) are labeled Vin1...Vin8, and the DAC outputs are labeled Vout1...Vout8 on the 40 pin analog connector.    [Note: If you are interested in consulting the DAC8841 chip schematics in Appendix G, notice that the manufacturer uses alphabet characters A through H to designate DAC channels 1 through 8.] 

To test a DAC channel, connect a 1.5 Volt reference (either the onboard 1.5VREF signal or the reference described in Figure 6.1) to the DAC’s Vin to provide a stable reference.  Then write an 8 bit value to the DAC by placing a count and channel number on the data stack and executing

>DAC  ( byte\channel# -- )

For example, to set DAC1 to its midpoint value of 1.5 Volts, connect a 1.5 Volt reference to Vin1 (pin 21 on the 40 pin analog I/O connector) and execute

DECIMAL 128 1 >DAC

You can now measure the output voltage of 1.5 Volts at Vout1 (pin 22 on the 40 pin analog I/O connector).

>DAC GETs and RELEASEs the resource variable SPI.RESOURCE which mediates access to the 8 bit DAC and the 12 bit A/D converter in multitasking applications.  Unfortunately, over half of the execution time of the >DAC routine is devoted to the GET and RELEASE overhead.  In non-multitasked applications or in applications where only one task uses the SPI, the faster routine

(>DAC)  ( byte\channel# -- )

may be used.  It updates the DAC without executing GET or RELEASE, and with an 8 MHz crystal it executes in only 80 microseconds compared to 250 microseconds for >DAC.

]]]

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

 

SetDAC( uchar count, uint channel)

 

>DAC ( byte\n -- | byte=data, n=channel# )

which expects a count in the range 0 to 255, and a channel in the range 1 to 8.  After calling the SetDAC()>DAC (pronounced “to DAC”) 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:

Eqn. 10‑1    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)

DECIMAL 255 1 >DAC

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)

DECIMAL 128 1 >DAC

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 (>DAC)FastSetDAC() executes in approximately 46 microseconds, and the multitasking version >DACSetDAC() 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. 

Getting Greater Resolution

The hardware manual also describes how to combine two DACs to construct a high-resolution 12-bit DAC; this technique is implemented for you on the QED Analog Conditioning Board which is available from Mosaic Industries.

 

<< Previous | Next>>


Home|Site Map|Products|Manuals|Resources|Order|About Us
Copyright (c) 2006 Mosaic Industries, Inc.
Your source for single board computers, embedded controllers, and operator interfaces for instruments and automation