Dataq DI-159 User Manual page 75

Table of Contents

Advertisement

Sample Programs
programmed to output a precise frequency using the method shown here. Frequency can range
from 0 to several kHz in 1 Hz steps. Analog input values are in millivolts and range from ±10,
000. The calculation in line 280 above yields a frequency scaled between DC and 200 Hz for a
–full scale to +full scale range respectively.
Example #7 Channel Output
Object
Print variables in this order: sample counter, all eight analog channels, and the state of the dig-
ital inputs and outputs. Pressing the general-purpose pushbutton resets the sample counter, and
the digital output states reflect the value of the sample counter. Finally, LED0 and LED1 dis-
play the state of the two LSBs of the sample rate counter.
Code
200 dim cr
210 configure timer 0 for 1 s
220 on timer 0 do gosub readin
230 on push_button==0 do cr = 0
240 while 1 do
250 endwhile
260 sub readin
270 cr = cr+1
280 let o0 = cr&1
290 let o1 = cr&2
300 let o2 = cr&4
310 let o3 = cr&8
320 print cr, c0, c1, c2, c3, c4, c5,
c6, c7, i0, i1, i2, i3, o0, o1, o2, o3
330 led0 = o0
340 led1 = o1
350 endsub
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.
'dimension cr, which will be used as a counter
'set up a timer for a sample rate of 1 Hz
'go to subroutine 'readin' when the timer fires
'reset the sample counter if the pushbutton is pressed
'do nothing while waiting for the 1 Hz timer to fire
'
'arrive here when the timer fires
'increment the sample rate counter
'assign dig out 0 to the LSB of the sample counter
'assign dig out 1 to bit 1 of the sample counter
'assign dig out 2 to bit 2 of the sample counter
'assign dig out 3 to the MSB of the sample counter
'stream sample counter, all analog input values, and
'state of the digital inputs and outputs
'assign the state of dig out 0 to LED0
'assign the state of dig out 1 to LED1
'return
75
DI-159 PLC Hardware Manual

Advertisement

Table of Contents
loading

Table of Contents