Facebook Pixel

AN-00052 Designer or ViSi Analogue Input

Description This application note demonstrates how to perform Analog to Digital Conversion (ADC) and how to print and graph the results using a Diabo16 display module.
Supported Processor DIABLO16
Supported Environment Designer, ViSi
Difficulty Medium

 

File Downloads
Files

  Description

This application note demonstrates how to perform Analog-to-Digital Conversion (ADC) and how to print and graph the results using a Diabo16 display module. The 4DGL code of the Designer project can be copied and pasted to an empty ViSi project and it should compile normally. The code can also be integrated to that of an existing ViSi project.

 

Before getting started, the following are required:

 

Visit www.4dsystems.com.au to see the latest display module products that use the Diablo16 processor.

 

for non-gen4 displays(uLCD-xxx)

for gen4 displays (gen4-uLCD-xxx)

  • Workshop 4 IDE (installed according to the installation document)
  • A 10-kiloohm potentiometer, a breadboard, and connecting wires
  • When downloading an application note, a list of recommended application notes is shown. It is assumed that the user has read or has a working knowledge of the topics presented in these recommended application notes.

 

  Application Overview

The Designer environment enables the user to write 4DGL code in its natural form to program the display module. 4DGL is a graphics oriented language allowing rapid application development, and the syntax structure was designed using elements of popular languages such as C, Basic, Pascal and others. Programmers familiar with these languages will feel right at home with 4DGL.

The Diablo16 has four pins (PA0, PA1, PA2, and PA3) which can be configured as analog inputs. These four pins can operate in any of the three analog modes – the standard, averaged, and high-speed modes. These modes differ in sampling rate and resolution. The maximum analog input voltage for all modes is 3.3 volts. In the application developed in this document, the standard mode (12-bit, >40k samples per second) is used.

The application works in a manner illustrated in the diagram on the next page. First, the wiper of a trimmer potentiometer, acting as a voltage divider, is connected to pin PA0 of the Diablo16 display module.

 

The voltage level at pin PA0 can be of any value between 0 and 3.3 volts.  Thru ADC, an analog voltage level sampled by pin PA0 is given a 12-bit binary equivalent value. Given the reference voltage, which is 3.3 volts, the digital voltage value can now be computed and displayed onscreen.

 

Text and graphics objects such as lines and rectangles are used to display and graph the results onscreen. The 4DGL commands for printing text and drawing lines and rectangles are easy and straight forward, the basics of which are discussed in the following application notes:

 

Designer Getting Started - First Project

Designer or ViSi How to Draw Circles and Rectangles

 

This document comes with a Designer file, the 4DGL code of which is discussed in the section “Understanding the Code”. The code can be used to develop more complex applications related to ADC. The last section shows how the display module and trimmer potentiometer are connected.

 

  Setup Procedure

For instructions on how to launch Workshop 4, how to open a Designer project, and how to change the target display, kindly refer to the section “Setup Procedure” of the application note

 

Designer Getting Started - First Project

 

For instructions on how to launch Workshop 4, how to open a ViSi project, and how to change the target display, kindly refer to the section “Setup Procedure” of the application note

 

ViSi Getting Started - First Project for Picaso and Diablo16

 

  Create a New Project

For instructions on how to create a new Designer project, please refer to the section “Create a New Project” of the application note

 

Designer Getting Started - First Project

 

For instructions on how to create a new ViSi project, please refer to the section “Create a New Project” of the application note

 

ViSi Getting Started - First Project for Picaso and Diablo16

 

  Design the Project

The Program Skeleton

Everything is now ready to start designing a project. Workshop automatically provides the program skeleton, which contains basic parts needed to start designing an application. The user is advised to have a copy of the DIABLO16 Internal Functions Manual on hand. The document contains detailed information on the different functions used in this application note. To start coding, place additional codes before line 11. If repetitive operation is desired, the programmer can also insert additional codes between lines 11 and 12 instead. The application note Designer Getting Started - First Project shows the basics of creating a Designer program.

 

Understanding the Code

The code is well commented for the benefit of the user. The following sections will serve as a supplementary explanation. Open the attached Designer file to have a better and complete view of the code. It can be broken down into five separate steps:

 

  1. Draw background labels
  2. Configure pin PA0 as an analog input
  3. Read from pin PA0
  4. Compute for the equivalent digital voltage
  5. Display and graph the results on the screen

 

Items 1 and 2 are executed only once at the start of the program. Items 3 to 5 are executed indefinitely using a loop.

Draw the Background Labels

The code for drawing the background is defined in a separate function, drawBackground( ), so as to keep the main function simple. The function drawBackground( ) is defined just after the main function.

 

Scroll down on the Designer window to see the complete code. All that this function does is draw the static labels for the display, as shown below.

 

To print the text “Basic Analogue Input Demo”:

 

The statement in line 80 will change the text font colour to yellow. The statement in line 81 will move the origin to point (35, 15) on the screen. From this point the text will be printed. Omitting line 81 will result to the text being printed starting from point (0,0) (top left corner) which is the default origin. The special character ‘\n’ is for a newline. The other labels are printed using the same functions.

Configure Pin PA0 as an Analog Input

To configure pin PA0 as an analog input (standard mode), use the function below.

 

To configure pin PA0 as an analog input (averaged mode), use the function below.

 

Standard mode results in a single sample being immediately read. This mode can read over 40000 values per second at a 12-bit resolution.

Averaged mode results in 16 samples being immediately read and their average returned. Averaged mode can read approximately 20000 values per second at a 12-bit resolution.

High-speed mode collects a user specified number of samples at a user specified rate/frequency and can execute a user function when complete. The updated value updates approximately 250000 times across 1-4 channels. This mode operates at a 10-bit resolution. The use of this mode will be demonstrated along with the use of the gfx_Scope ( ) function in a separate application note.

Read from Pin PA0

The statement

 

will return the result of ADC to the variable Vsteps. Since ADC resolution is 12 bits, the range of possible values for Vsteps is 0 to 4095. Take note that this line is now inside the infinite for loop.

 

Compute for the Equivalent Digital Voltage

Note that at the beginning part of the code, a global array is declared for storing the computed digital voltage value.

 

The function below is then used to compute the equivalent digital voltage value of the reading held by Vsteps.

 

This function is defined after the main function.

 

After getVoltage ( ) has been called, the computed equivalent digital voltage value, which is actually a string, is then stored in the global array Voltage. The function performs the computation below.

 

Observe that inside the function, there are several closely related functions used.

 

These are 4DGL floating point functions. Note that when performing the computation

 

floating point numbers are involved. Floating point numbers in 4DGL are stored in float variables, which are two-word arrays.

 

The lines containing floating point functions have been commented for the benefit of the user. These functions are documented in section 2.21 of the DIABLO16 Internal Functions Manual. Discussion of floating point numbers and functions will be covered in a separate application note.

 

Display and Graph the Results on the Screen

Print the Results on the Screen

To print the value of Vsteps before it is scaled:

 

The result is shown below.

 

[DEC4Z] is the format for the number to be printed. See more number formats in section 2.4.7 of the DIABLO16 Internal Functions Manual.

To print the content of Voltage,

 

The statement indicated above is an alternative function for printing strings on the screen. The result is shown below.

 

The contents of Voltage is printed again in a larger font size through the use of the functions txt_Width ( ) and txt_Height ( ). Here, the font dimensions are multiplied by a factor of 3.

 

The outcome is shown below.

 

Graph the Results on the Screen

Two rectangles and multiple lines are used to make a visual representation of the voltage readings. Again, the variable Vsteps can be of any value from 0 to 4095. This range is scaled down to a range of 0 to 230, since the rectangles to be used have a varying height of only 0 to 230 pixels.

 

Remember that the screen has a limited VGA resolution (320x480 pixels for the uLCD-35DT).

Shorthand in 4DGL

The statement

is the same as

The statement

is the same as

 

Black and green rectangles, the varying height dimensions of which are determined by Vsteps, are then used to show a bar graph.

 

Multiple green lines are also added.

 

To learn more about drawing lines and rectangles, refer to the following application notes.

 

Designer Getting Started - First Project

Designer or ViSi How to Draw Circles and Rectangles

 

A 200-millisecond delay is then added to make the displayed value more readable. In effect, five readings are displayed every second.

 

Note: The various analog modes can interfere with the operation of the touch screen if their functions are called too frequently. It is recommended to limit the calls of the analog functions to a maximum of once every millisecond. Please refer to the Internal Functions documentation for further information on this topic.

 

  Run the Program

For instructions on how to save a Designer project, how to connect the target display to the PC, how to select the program destination, and how to compile and download a program, please refer to the section “Run the Program” of the application note

 

Designer Getting Started - First Project

 

For instructions on how to save a ViSi project, how to connect the target display to the PC, how to select the program destination (this option is not available for Goldelox displays), and how to compile and download a program, please refer to the section “Run the Program” of the application note

 

ViSi Getting Started - First Project for Picaso and Diablo16

 

The uLCD-35DT display module is commonly used as an example, but the procedure is the same for other displays.

 

  Connect the Trimmer Potentiometer

Datasheet and Pin Configuration

Download the datasheet for your display module to get acquainted with the pin configurations. The datasheet for a display module can be downloaded from its product page: http://www.4dsystems.com.au/products/. Here the uLCD-35DT will be used as a model.

 

Section 3 of the uLCD-35DT datasheet shows the device’s pin configuration.

 

The Trimmer Potentiometer

 

Header H1

Pin PA0 is in header H1 as indicated in the image below. The Diablo16 also has a 3.3-volt output, which can be used to supply voltage across the trimmer potentiometer.

 

The Project

 

Connection Diagram

 

Schematic Diagram

 

Adjusting the Trimmer Potentiometer

 

Voltage at Minimum

 

At around 2.0 Volts

With a Digital Multimeter

Share: