Advertisement

Quick Links

Copyright © 2013 by DATAQ Instruments, Inc. The Information contained herein is the exclusive property
of DATAQ Instruments, Inc., except as otherwise indicated and shall not be reproduced, transmitted, tran-
scribed, stored in a retrieval system, or translated into any human or computer language, in any form or by
any means, electronic, mechanical, magnetic, optical, chemical, manual, or otherwise without expressed
written authorization from the company. The distribution of this material outside the company may occur
only as authorized by the company in writing.
Portions Copyright © 2008-2011; All rights reserved. http://www.cpustick.com.
DATAQ Instruments' hardware and software products are not designed to be used in the diagnosis and treat-
ment of humans, nor are they to be used as critical components in any life-support systems whose failure to
perform can reasonably be expected to cause significant injury to humans.
DATAQ, the DATAQ logo, and W
reserved.
D
are registered trademarks of DATAQ Instruments, Inc. All rights
IN
AQ
DATAQ Instruments, Inc.
241 Springside Drive
Akron, Ohio 44333 U.S.A.
Telephone: 330-668-1444
Fax: 330-666-5434
Designed and manufactured in the
United States of America
The way PC-based instrumentation should be
PLC Data Acquisition Device
User's Manual
DI-159
Manual Revision A

Advertisement

Table of Contents
loading

Summary of Contents for Dataq DI-159

  • Page 1 Portions Copyright © 2008-2011; All rights reserved. http://www.cpustick.com. DATAQ Instruments' hardware and software products are not designed to be used in the diagnosis and treat- ment of humans, nor are they to be used as critical components in any life-support systems whose failure to perform can reasonably be expected to cause significant injury to humans.
  • Page 2: Warranty And Service Policy

    1. All products returned to DATAQ Instruments for service, regardless of warranty status, must be on a freight-prepaid basis. 2. DATAQ Instruments will repair or replace any defective product within 5 days of its receipt. 3. For in-warranty repairs, DATAQ Instruments will return repaired items to the buyer freight prepaid.
  • Page 3: Analog Inputs

    The DI-159 features eight differential analog inputs located on two sixteen-position screw ter- minal blocks for easy connection and operation (other terminals used for digital I/O). Connect the DI-159 PLC to any pre-amplified signal in the typical range of ±5 to ±10VFS. Please note: The DI-159 does not support analog outputs.
  • Page 4: Digital Inputs

    1.8V. The inputs float at 1 level, about 3.3V relative to the "-" terminal, and require sink- ing about 50uA to bring them down to 0.8V and guarantee a 0. Digital Outputs The DI-159 contains four general purpose digital output lines (30 VDC or peak AC, 500 mA max) to initiate external discrete (on/off) control. Software StickOS BASIC is embedded in the device for easy programming and is accessible via any ter- minal emulator program that can hook a COM port.
  • Page 5: Specifications

    Specifications Analog Inputs Number of Channels: Channel Configuration: Differential Voltage Measurement Range: ±10V Full Scale Input impedance: 2 MΩ, differential Isolation: none Overall inaccuracy: ±64mV (at 25°C) Minimum common mode rejec- 40db @ 50-60 Hz and @ 25°C tion: Max input without damage: ±75 V peak continuous;...
  • Page 6: Indicators And Connections

    < 4 oz. (< 140 grams) Software Support Embedded: StickOS(TM) BASIC (www.cpustick.com) DI-159 PLC Windows-based Utility software for terminal emulation, program archive, and data logging. Supports Downloadable: Windows XP and both 32- and 64-bit versions of Win- dows Vista, Windows 7, and Windows 8.
  • Page 7: Installation

    USB Drivers for the DI-159 PLC can be installed via a downloadable executable directly from the DATAQ Instruments web site. No CD is shipped with the device. If you are going to install and run the DATAQ Instruments DI-159 PLC Terminal Emulator program, you do not...
  • Page 8 PLC terminal program. Connecting the Instrument to Your Computer DI-159 instruments can be connected to your computer’s USB port using the provided USB cable. No external power is required. Connect one end of the communications cable to the instrument port and the other to your PC’s port.
  • Page 9: Controls, Indicators And Connections

    Controls, Indicators, and Connections Please note: The SD card slot is not used in the DI-159. Allowing foreign materials to enter the device through the SD card slot may result in damage to the instrument. Mini-B USB Connection Use the supplied USB cable to connect and power the instrument through your computer’s USB port.
  • Page 10 Connect Analog Input Channel 0 Use the following diagram to connect Analog Input Channel 0. Connecting Signal Leads To connect signal leads to the DI-159: 1. Insert the stripped end of a signal lead into the desired terminal directly under the screw.
  • Page 11 3. Tug gently on the signal lead to ensure that it is firmly secured. Digital Inputs The DI-159 contains 4 general purpose digital inputs. Valid signals are switch closures or dis- crete levels with a maximum input of 30 V and a threshold of 1.8 V.
  • Page 12: Led Indicators

    Heartbeat: Indicates the device is powered (slow heartbeat at once per second) or when a program is running (fast heartbeat at about 4 times per second). Push Button The DI-159 provides a general-purpose push button whose function is defined by the program written to the device.
  • Page 13 StickOS StickOS is a BASIC programming engine embedded in the DI-159 PLC. It offers transparent line-by-line compilation, as well as integer variable, string variable, and array support. Block- structured programming is also supported using easily-recognized IF, FOR, WHILE, DO, and GOSUB constructs.
  • Page 14 DI-159 PLC Hardware Manual StickOS Read/Data Statements Conditional Statements Looping Conditional Statements Subroutines Timers Digital I/O Analog Input Frequency Output Other Statements...
  • Page 15 StickOS DI-159 PLC Hardware Manual StickOS Quick Reference Commands Device Statements Expressions Strings General Statements Modes Block Statements Variables Commands stop running program <Ctrl-C> automatically number program lines auto [line] clear ram [and flash] variables clear [flash] clear terminal screen...
  • Page 16: General Statements

    DI-159 PLC Hardware Manual StickOS Expressions the following operators are supported as in C, in order of decreasing precedence: decimal constant hexadecimal constant character constant 'c’ simple variable variable array variable element variable[expression] length of array or string variable# grouping...
  • Page 17 StickOS DI-159 PLC Hardware Manual delete program line Line enter program line line statement // comment assign variable variable[$] = expression, ... print strings/expressions ? [dec|hex|raw] expression, ...[;] break if expression is false assert expression read-only data data n [, ...] dimension variables dim variable[$][[n]] [as ...], ...
  • Page 18 DI-159 PLC Hardware Manual StickOS [(break|continue) [n]] until expression gosub subname [expression, ...] sub subname [param, ...] [return] endsub Variables all variables must be dimensioned variables dimensioned in a sub are local to that sub simple variables are passed to sub params by reference...
  • Page 19: Command Lines

    StickOS DI-159 PLC Hardware Manual Command Lines In the command and statement specifications that follow, the following nomenclatures are used: literal text; enter exactly as shown bold parameterized text; enter actual parameter value italics alternated text; enter exactly one alternate value (alternate1| alternate2| ...)
  • Page 20 DI-159 PLC Hardware Manual StickOS StickOS Commands StickOS commands are used to control the StickOS BASIC program. Unlike BASIC program statements, StickOS commands cannot be entered into the StickOS BASIC program with a line number. Help Command Entering Programs Running Programs...
  • Page 21: Help Command

    StickOS DI-159 PLC Hardware Manual Help Command The help command displays the top level list of help topics: help To get help on a subtopic, use the command: helpsubtopic Examples > help for more information: help about help commands help modes...
  • Page 22 DI-159 PLC Hardware Manual StickOS -- renumber program lines (and save) -- reset the DI-159 PLC! run [<line>] -- run program save [<name>] -- save code ram to flash mem- undo upgrade -- undo code changes since last uptime save...
  • Page 23: Entering Programs

    Note that statements are initially entered into a RAM buffer to avoid excessive writes to flash memory, and therefore can be lost if the DI-159 PLC is reset or loses power before the pro- gram has been saved. When a program is run, the (newly edited) statements in RAM are seam- lessly merged with the (previously saved) statements in flash memory, to give the appearance of a single "current program", at a slight performance penalty.
  • Page 24 DI-159 PLC Hardware Manual StickOS list line- list line-line Alternately, you can list an entire subroutine by name with the command: list subname To set the listing indent mode, use the command: indent (on|off) To display the listing indent mode, use the command:...
  • Page 25 To save the BASIC program permanently to flash memory, use the command: save Note that any unsaved changes to the BASIC program will be lost if the DI-159 PLC is reset or loses power. To renumber the BASIC program by 10's and save the BASIC program permanently to flash...
  • Page 26 DI-159 PLC Hardware Manual StickOS 20 for a = 1 to 10 30 print a 40 next > renumber > list 10 rem this is a comment 20 dim a 30 for a = 1 to 10 40 print a 50 next >...
  • Page 27: Running Programs

    To display the autorun mode for the saved BASIC program, use the command: autorun If the autorun mode is on, when the DI-159 PLC is reset, it will start running the saved BASIC program automatically. Note that any unsaved changes to the BASIC program will be lost if the DI-159 PLC is reset or loses power.
  • Page 28 DI-159 PLC Hardware Manual StickOS > 40 endwhile > save > run <Ctrl-C> STOP at line 40! > print a 5272 > cont <Ctrl-C> STOP at line 30! > print a 11546 > autorun > autorun on > _...
  • Page 29 The "current program" has no name and is saved and run by default. In addition to the current program, StickOS can load and store two named BASIC programs in the DI-159. Named pro- grams are simply copies of the current program that can be retrieved at a later time, but are otherwise unaffected by all other StickOS commands than these.
  • Page 30: Debugging Programs

    DI-159 PLC Hardware Manual StickOS Debugging Programs There are a number of techniques you can use for debugging StickOS BASIC programs. The simplest debugging technique is simply to insert print statements in the program at strategic locations, and display the values of variables.
  • Page 31 It also allows you to modify the value of variables, with an immediate mode statement like: let variable = expression Note that if an immediate mode statement references a pin variable, the live DI-159 PLC pin is examined or manipulated, providing a very powerful debugging technique for the embedded...
  • Page 32 DI-159 PLC Hardware Manual StickOS Additionally, while single-step mode is on, pressing <Enter> (essentially entering what would otherwise be a blank command) is the same as the cont command. To set the trace mode for the BASIC program, use the command:...
  • Page 33 StickOS DI-159 PLC Hardware Manual > step on > list 10 dim a, sum 20 for a = 1 to 10000 30 let sum = sum+a 40 next 50 print sum > run 10 dim a, sum STOP at line 10! >...
  • Page 34: Other Commands

    To display the StickOS memory usage, use the command: memory To reset the DI-159 PLC as if it was just powered up, use the command: reset Note that the reset command inherently breaks the USB or Ethernet connection between the DI-159 PLC and host computer;...
  • Page 35 StickOS DI-159 PLC Hardware Manual > memory 4% ram code bytes used (unsaved changes!) 0% flash code bytes used 19% ram variable bytes used 0% flash parameter bytes used 1% variables used > save > memory 0% ram code bytes used...
  • Page 36 DI-159 PLC Hardware Manual StickOS Basic Program Statements BASIC Program statements are typically entered into the StickOS BASIC program with an associated line number, and then are executed when the program runs. Most BASIC program statements can also be executed in immediate mode at the command prompt, without a line number, just as if the program had encountered the statement at the cur- rent point of execution.
  • Page 37: Variable Declarations

    StickOS DI-159 PLC Hardware Manual Variable Declarations All variables must be dimensioned prior to use. Accessing undimensioned variables results in an error and a value of 0. Simple RAM variables Simple RAM variables can be dimensioned as either integer (32 bits, signed, by default), short...
  • Page 38 DI-159 PLC Hardware Manual StickOS DI-159 PLC register variables Variables can also be dimensioned as DI-159 PLC register variables at absolute addresses with the following statements: dim varabs at address addr dim varabs as (short|byte) at address addr dim varabs[n] at address addr dim varabs[n] as (short|byte) at address addr Note that you can trivially crash your DI-159 PLC by accessing registers incorrectly.
  • Page 39 StickOS DI-159 PLC Hardware Manual > 10 dim array[4], b, volatile > 20 dim led as pin dtin0 for digital output > 30 dim potentiometer as pin an0 for analog input > 40 dim persistent as flash > 50 for b = 0 to 3 >...
  • Page 40: System Variables

    DI-159 PLC Hardware Manual StickOS System Variables The following system variables may be used in expressions or simply with "print" statements to examine internal system state. These variables are all read-only. analog supply millivolts analog most recent console character getchar...
  • Page 41 Variable Assignments Simple variables are assigned with the following statement: let variable = expression If the variable represents an output "pin variable", the corresponding DI-159 PLC output pin is immediately updated. Similarly, array variable elements are assigned with the following statement:...
  • Page 42 Logical and equality/inequality operators, above, evaluate to 1 if true, and 0 if false. For con- ditional expressions, any non-0 value is considered to be true, and 0 is considered to be false. If the expression references an input "pin variable", the corresponding DI-159 PLC input pin is sampled to evaluate the expression.
  • Page 43 StickOS DI-159 PLC Hardware Manual superfluous parenthesis (not to mention spaces) will be removed from the expression, based on the precedence rules above. Examples > 10 print 2*(3+4) > 20 print 2+(3*4) > list 10 print 2*(3+4) 20 print 2+3*4 >...
  • Page 44 DI-159 PLC Hardware Manual StickOS Strings StickOS supports string variables as a null-terminated views into byte arrays. A string variable may be declared, with a maximum length n, with: dim var$[n] A string may then be assigned with: let variable$ = string...
  • Page 45 StickOS DI-159 PLC Hardware Manual > 40 print a$[i:1] > 50 next > run ? hello > new > 10 dim a$[10] > 20 input a$ > 30 if a$ ~ "y" then > 40 print "yes" > 50 else >...
  • Page 46 DI-159 PLC Hardware Manual StickOS Print Statements While the DI-159 PLC is connected to the host computer, print statements can be observed on the Hyper Terminal console window. Print statements can be used to print integer expressions, using either a decimal or hexadecimal output radix, or printing raw ASCII bytes: print [dec|hex|raw] expression [;]...
  • Page 47 StickOS DI-159 PLC Hardware Manual Variable Print Statements Variable print statements can be used to convert strings to integers and vice versa, as well as integers from decimal to hexadecimal radix, etc. Basically, variable print statements are iden- tical to print statements, except rather than printing the result to the console, the result is "printed"...
  • Page 48 DI-159 PLC Hardware Manual StickOS Input Statements While the DI-159 PLC is connected to the host computer, input statements can be serviced from the Hyper Terminal console window. Input statements can be used to input integer expressions, using either a decimal or hex- adecimal output radix, or input raw ASCII bytes: input [dec|hex|raw] variable[$], ...
  • Page 49 StickOS DI-159 PLC Hardware Manual Read/Data Statements A program can declare read-only data in its code statements, and then consume the data at run- time. To declare the read-only data, use the data statement as many times as needed: data n data n, n, ...
  • Page 50: Conditional Statements

    DI-159 PLC Hardware Manual StickOS Conditional Statements Non-looping conditional statements are of the form: if expression then statements elseif expression then statements else statements endif Where statements is one or more program statements and the elseif and else clauses (and their corresponding statements) are optional.
  • Page 51 StickOS DI-159 PLC Hardware Manual 4 is even > _...
  • Page 52 DI-159 PLC Hardware Manual StickOS Looping Conditional Statements Looping conditional statements include the traditional BASIC for-next loop and the more struc- tured while-endwhile and do-until loops. The for-next loop statements are of the form: for variable = expression to expression step expression...
  • Page 53 StickOS DI-159 PLC Hardware Manual until expression Where statements is one or more program statements . Alternately, the string form of this statement is: statements until string relation string The do-until loop conditional expression is evaluated on each exit from the loop. If it is false (0), the loop repeats again.
  • Page 54 DI-159 PLC Hardware Manual StickOS > 20 while 1 do > 30 if a==10 then > 40 break > 50 endif > 60 let sum = 0 > 70 for b = 0 to a > 80 let sum = sum+b >...
  • Page 55 StickOS DI-159 PLC Hardware Manual Subroutines A subroutine is called with the following statement: gosub subname [expression, ...] A subroutine is declared with the following statements: sub subname [param, ...] statements endsub The sub can be exited prematurely using the statement:...
  • Page 56 DI-159 PLC Hardware Manual StickOS > 60 sub sumit numbers > 70 dim a, sum > 80 for a = 1 to numbers > 90 let sum = sum+a > 100 next > 110 print "sum of integers 0 thru", numbers, "is", sum >...
  • Page 57 StickOS DI-159 PLC Hardware Manual Timers StickOS supports up to four internal interval timers (0 thru 3) for use by the program. Timer interrupts are delivered when the specified time interval has elapsed since the previous interrupt was delivered. Timer interrupt intervals are configured with the statement: configure timer n for m (s|ms|us) This configures timer n to interrupt every m seconds, milliseconds, or microseconds.
  • Page 58 DI-159 PLC Hardware Manual StickOS > 90 sub fast > 100 let ticks = ticks+1 > 110 endsub > run slow slow slow ticks is 14 > _...
  • Page 59 DI-159 PLC Hardware Manual Digital I/O Digital I/O pins are designated in the DI-159 just as the label on the device states. For example, digital input channel 0 is Di0. The example Boilerplate code provided shows all pin des- ignations in the DI-159 PLC. Use the following for quick reference to pinnames:...
  • Page 60 Line 10 configures the "dtin0" pin for digital output, and creates a variable named "square" whose updates are reflected at that pin. Line 20 starts an infinite loop (typically DI-159 PLC programs run forever). Line 30 inverts the state of the dtin0 pin from its previous state -- note that you can examine as well as manipulate the (digital or analog or servo or frequency) output pins.
  • Page 61 StickOS DI-159 PLC Hardware Manual 20 while 1 do 30 let square = !square let square = 0 40 sleep 500 ms <Ctrl-C> STOP at line 40! > trace off > _ Again, press <Ctrl-C> to stop the program. Note that almost all statements that can be run in a program can also be run in "immediate"...
  • Page 62: Analog Input

    DI-159 PLC Hardware Manual StickOS Analog Input Analog Input pins are designated in the DI-159 just as the label on the device states. For exam- ple, analog input channel 0 is Ch0. Please note: The DI-159 hardware does not support analog output.
  • Page 63 This value defaults to 3300 mV and is stored in flash and affects all analog I/O pins. Example The DI-159 PLC can perform analog input as simply as digital I/O. The following BASIC program takes a single measurement of an analog input at pin "an0" and displays it: >...
  • Page 64: Frequency Output

    Reading the variable varpin will return the output frequency, in hertz (Hz). Example The DI-159 PLC can perform frequency output as simply as digital I/O or analog input. The following BASIC program generates a 1kHz square wave on a frequency output pin “dtin0” for 1 second: >...
  • Page 65: Other Statements

    StickOS DI-159 PLC Hardware Manual Other Statements You can delay program execution for a number of seconds, milliseconds, or microseconds using the statement: sleep expression (s|ms|us) Note that the minimum sleep resolution is the clock tick, which is 0.25 milliseconds. Note also that in general it would be a bad idea to use a sleep statement in the on handler for a timer.
  • Page 66: Main Window

    DATAQ Instruments terminal emulator is provided free of charge for use with any DI-159 PLC device. Any terminal software that can hook a com port can be used with the DI-159 - The DATAQ Instruments Terminal is not required for use with the DI-159 PLC. USB drivers...
  • Page 67: Menu Items

    DI-159 PLC Hardware Manual DATAQ Instruments Terminal Menu Items File Menu Load Text File. Opens the Windows Open File dialog box. Allows you to open a BASIC pro- gram saved to a text file. Save As (Ctrl + S). Opens the Windows Save File dialog box. Allows you to save the cur- rently loaded program to a text file on your computer.
  • Page 68: Output Display

    DI-159, overwriting what is currently there. See Sample Programs for more infor- mation. About DATAQ Terminal. Provides the Version number of the software and copyright infor- mation. Icons Opens the Windows File Selection dialog box allowing you to load a Load BASIC program saved as a text file.
  • Page 69 DI-159 PLC Hardware Manual DATAQ Instruments Terminal Once open, the device immediately begins to stream data and print it out in the Output Display window (as long as a print statement is specified in your program). Each row represents a sam- ple taken and outputs the data as specified in your program.
  • Page 70 The Editor window allows you to easily edit the program currently loaded into memory. If there is no program loaded into the DI-159, this window would be blank allowing you to create a program from scratch. Programing errors will not be identified until the code is saved into memory.
  • Page 71: Sample Programs

    Sample Programs Aside from actually applying a DI-159 PLC in your control application, the best way to under- stand how easy the instrument is to use is by example. The following just scratches the surface, but should give you a solid understanding of the range of DI-159 PLC control possibilities.
  • Page 72 DI-159 PLC Hardware Manual Sample Programs Example #2 General-purpose LED Object Flash general-purpose LED0 at a precise one second on/off interval. Code 200 let led0 = 0 'start with LED on 210 configure timer 0 for 1 s 'configure one of four timers for 1 sec interval 220 on timer 0 do gosub flasher 'execute subroutine "flasher"...
  • Page 73 Sample Programs DI-159 PLC Hardware Manual Comment Extends the example above to include two timers, each running at a precise, independent, and different rate. Each timer indirectly controls the state of a peripheral, in this case the two gen- eral-purpose LEDs.
  • Page 74 'New_o0 is different so change frequency 330 endsub Comment Note that the pushbutton and LEDs are low true. A 0 written to either LED lights it, and the pushbutton transitions from 1 to 0 when pressed. Any DI-159 PLC digital output port may be...
  • Page 75 'assign the state of dig out 1 to LED1 350 endsub 'return Comment This example, when used with the provided DATAQ Terminal program for Windows, allows recorded values to be streamed to a CSV file via the PRINT statement, which is easily imported to Microsoft Excel.
  • Page 76 DI-159 Block Diagram...
  • Page 77: Dimensional Drawing

    Dimensional Drawing...
  • Page 78 Support Please visit the DI-159 product page for support issues and documentation at http://www.dataq.com/plc-data-acquisition/di-159-plc.html. If you cannot find an answer to your question there please fill out a support ticket at http://www.dataq.com/ticket.
  • Page 79 DATAQ Instruments, Inc. 241 Springside Drive Akron, Ohio 44333 Telephone: 330-668-1444 Fax: 330-666-5434 Submit a support ticket to: www.dataq.com/ticket Direct Product Links (click on text to jump to page) Data Acquisition | Data Logger | Chart Recorder...

Table of Contents