Facebook Pixel

AN-00064 ViSi 6 Channel PWM

Description This document is focused on the fundamental usage of the basic use of the built-in pulse width modulation feature of the DIABLO16 Graphics Processor. The projects includes 6 sliders that changes the width of the output pulse. The pulse width values are then applied to RGB LEDs connected on several PWM-capable IO-pins.
Supported Processor DIABLO16
Supported Environment ViSi
Difficulty Difficult

File Downloads


This application note is intended to demonstrating to the user the set-up, initialization and operation of the built-in pulse width modulation feature of the Diablo16 display module.


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

for non-gen4 displays(uLCD-xxx)

for gen4 displays (gen4-uLCD-xxx)

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

This document is focused on the fundamental usage of the basic use of the built-in pulse width modulation feature of the DIABLO16 Graphics Processor. The projects includes 6 sliders that changes the width of the output pulse. The pulse width values are then applied to RGB LEDs connected on several PWM-capable IO-pins.

  Setup Procedure

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 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

For this application project a couple of sliders and custom LED digits will be needed. Add objects by navigating to the Layout the objects similar to the one below.


After all the objects have been laid-out, let’s continue with the other half which involves the coding of the project. This will be presented in a sectional manner so as not to create confusion with the project. For an in-depth detail of the functions used in this application note please refer to the Diablo16 Internal Functions Reference Manual.

The Include Section

This project starts with the identification of the platform being used as declared by the #platform function. For the program to be able to function properly files are included herein using the #inherit function.


In this application note, quad_inConst.inc, contains all the information about the objects that are used in the project. Meanwhile, the leddigitsdisplay.inc contains the function for the proper operation of the led digits objects.

The Main Program

The main program for this projects contains several sections: the mounting of the micro-SD card, the initial displaying and image touch setup for objects, the setup for quadrature and input-output control, the repeat-forever loops which contains the continuous registry reading and touch conditions. Also, the main program calls out sub-routine functions that perform a particular functions.


The micro-SD Card Initialization

Let’s start with the initialization of the uSD card. The uSD card contains all the image information about the objects used in the project. The object information and data are saved under a *.DAT and a *.GCI filename extension which is copied to the uSD during project compilation. Mounting of the disk in this application note was done using the following set of program statements.


When starting a new project in the ViSi environment these set of statements are already included in the coding area. The last part of this set of statements uses a function file_LoadImageControl() to call on the object data/information files on the uSD drive. This initializes the data to be called in using the variable ‘hndl’. Likewise, additional variable were also assigned as image control for some graphics composer generated GCI and DAT files.


Having been able to load and initialize the uSD drive, the processor is now able to access the information stored therein. As mentioned from the previous section, the filenames with an extension of DAT and GCI has the image data and information.


Therefore, the next part of the main program is to display all the objects that were placed on the Workshop IDE form viewer. To do so, a special button from the Object Inspector can help reduce the time of coding of this part. The ‘Paste Code” simply pastes object code into the coding area.


Initial Image Display and Image Touch Setup

In this part of the program, the img_Show() function calls out the object image and information found in the microSD drive. This set of statements displays every object that were included in the application project. The displaying of the images is directly done using the img_Show() function.

In this segment of the program statements. We have displayed all the slider and LED digit images that were used to provide the value for the width of the modulated pulse. Also included in this segment of the main program is the displaying of the labels for our objects.

Moving to the next part of the main program, this segment is all related to the image touch detection setup.


This statements uses the img_SetWord() function. The primary objective of this set of statement is to enable the touch detection for the slider image. The slider images on this project serves as an input objects which utilizes the touch feature of the device. At the end, of this segment we would notice that the touch feature of the device was enabled using the touch_Set(TOUCH_ENABLE) statement.


The Repeat-forever Touch Detection Loop

At this end part of the main program, the routine was to detect any activity on the touch screen. Please refer to the image on the next page. Three touch states were included in the repetitive routine: the detection for a pressed state, a released state, and a moving state. Prior to the touch detection, a variable ‘n’ is assigned to store temporary image touch detection result. The img_Touched() function checks the object being touched and return the name of the object enlisted in the variable ‘hndl


Moving to the touch detection routines, when a touch status of ‘pressed’ is detected the value of the coordinates are saved on the variables x and y.


The most significant segment of this routine is the moving touch state, it is in this conditional loop that the image touch detection is made use. If a touch was detected over the slider image, a sub-routine or a function is called upon and executed by the processor.


Let us take the above statement as an example. From the start of the repeat- forever loop, the img_Touched() function saves the result of an image touch to a  variable ‘n’, this is then checked in  the touch  moving conditional statements. If it proves to be equal to one of the conditions then the sub- routine will be executed. For this statement a moveSlider1() sub-routine is being called and executed. Referring to the image following this section, we

The moveSlider Sub-routine

In the earlier part of this application note it was mentioned that the PWM function will be used in the sub-routines of the main program. This sub- routines are named moveSlider and appended with their respective numbers. This would mean that when an image Slider1 object is touched then this will result to a call and execute of a moveSlider1() sub-routine.


The first part of the sub-routine includes the slider codes that are automatically generated using the ‘Paste Code’ tab on the object inspector window. This is also true with the LED digits objects. The paste code function is a very good tool to minimize the coding of the objects.


The last line of the sub-routine includes the pwm_Init(). There are no particular assignment or hierarchy for this function.


At any time, this function will be able to initialize the GPIO with that has a PWM output function. The initialization and value are contained in the arguments section of the function.  The first argument is the GPIO pin number, followed by a mode of PWM and lastly the value of the PWM duty cycle or percent width modulation. The width of the modulation operates on a 0 % to 100 %. But the numerical value that is acceptable in the function ranges from 0 up to 1000. This was done so as to enable precision of pulse width modulation. For this reason, the output of the slider object was multiplied with a factor of ten during pwm_Init() function call.

  Run the Project

After building and downloading to the display module the R-G-B LED can be directly wired into the 30-way header pins. The connection to the display module can be reference from the figure on the images below. The ground pin of the common cathode RGB LED must be connected to the ground pin of the display module to complete the circuit. Also, understand that the GPIO in the display device are a set of 3.3 volt TTL pins.

The pulse width modulation feature of these devices can be utilized in various range of application. However, the requirement of the output load must be considered. If the output load shall require a higher current and a higher voltage rating then additional components – such as transistors or opto-couplers for switching. These PWM signal can be fed into a transistor’s base to turn off/on the transistor.


Referring to the image below. This image shows the output of the application project. As the sliders are moved the value of the modulation for each colour of the RGB LED is shown on the right. Hence, changing the slider value would mean a change in the intensity of the colour.

The PWM feature of the DIABLO16 can be used to provide a signal for mini DC servo motors, and to normal DC motor with additional circuitry.