Home
Data Acquisition Toolbox User`s Guide
Contents
1. Signal buffer Amplifier A D converter o 6 OD Input Multiplexer Sample and hold circuit channels Therefore if you use multiple channels those channels cannot be sampled simultaneously and a time gap exists between consecutive sampled channels This time gap is called the channel skew You can think of the channel skew as the time it takes the analog input subsystem to sample a single channel 1 17 1 Introduction to Data Acquisition Additionally the maximum sampling rate your hardware is rated at typically applies for one channel Therefore the maximum sampling rate per channel is given by the formula Maximum board rate Maximum sampling rate per channel _ _ ___ __ png p Number of channels scanned Typically you can achieve this maximum rate only under ideal conditions In practice the sampling rate depends on several characteristics of the analog input subsystem including the settling time and the gain as well as the channel skew The sample period and channel skew for a multichannel configuration using scanning hardware is shown below A Group Group Group scan 1 scan 2 scan n O O O O O O 5 o o o 9 gt lt O o o O O O gt gt Sample period Channel skew Time If you cannot tolerate channel skew in your application you must use hardware that allows
2. Interactive functions and data Data Acquisition Toolbox M file functions Data acquisition engine Hardware driver adaptors Property values data and events Hardware driver Property values data and events K Sensors Hardware gt Actuators Toolbox Components The preceding diagram illustrates how information flows from component to component Information consists of Property values You can control the behavior of your data acquisition application by configuring property values In general you can think of a property as a characteristic of the toolbox or of the hardware driver that can be manipulated to suit your needs e Data Y ou can acquire data from a sensor connected to an anal og input subsystem and store it in MATLAB or output data from MATLAB to an actuator connected to an analog output subsystem Additionally you can transfer values 1 s and 0 s between MATLAB and a digital I O subsystem Events An event occurs at a particular time after a condition is met and may result in one or more actions that you specify Events can be generated only after you configure the associated properties Some of the ways you can use events include initiating analysis after a predetermined amount of data is acquired or displaying a message to the MATLAB workspace afte
3. mmedi ate The trigger occurs just after thestart function is issued Manual The trigger occurs just after you manually issue the trigger function Software The trigger occurs when the associated trigger condition is satisfied Trigger conditions are given by theTriggerCondition property Many devices have additional hardware trigger types which are available to you through theTri ggerType property For example to return all the trigger types for the analog input object ai created in the preceding section set ai TriggerType Manual Immediate Software HwDigital This information tells you that the National Instruments board also supports a hardware digital trigger For a description of device specific trigger types refer to Device Specific Hardware Triggers on page 5 37 ortheTriggerType reference pages in Chapter 10 Base Property Reference Note Triggering can be a complicated issue and it has many associated properties For detailed information about triggering refer to Configuring Analog Input Triggers on page 5 20 4 11 4 G etting Started with Analog Input 4 12 The Samples to Acquire per Trigger When a trigger executes a predefined number of samples are acquired for each channel group member and logged to the engine or a disk file You specify the number of samples to acquire per trigger with theSampl esPerTri gger property The default value of Sampl esPer Trigger i
4. dec A decimal value dec must be nonnegative bits Number of bits used to represent the decimal number out A logical array containing the binary vector out dec2binvec dec converts the decimal valuedec to an equivalent binary vector and stores the result as a logical array in out out dec2binvec dec bits converts thedecimal valuedec toan equivalent binary vector consisting of at least the number of bits specified by bits More About Binary Vectors A binary vector binvec is constructed with the least significant bit LSB in the first column and the most significant bit MSB in the last column F or example the decimal number 23 is written as the binvec value 1 1 1 0 1 More About Specifying the Number of Bits e Ifbits isgreater than the minimum number of bits required to represent the decimal value then the result is padded with zeros e Ifbits is less than the minimum number of bits required to represent the decimal value then the minimum number of required bits is used e Ifbits is not specified then the minimum number of bits required to represent the number s used To convert the decimal value 23 to a binvec value dec2binvec 23 ans 1 1 1 0 1 dec2binvec See Also To convert the decimal value 23 to a binvec value using six bits dec2binvec 23 6 ans 1 1 1 0 1 0 To convert the decimal value 23 to a binvec value using four bits then the result uses five bits This is the minimum numb
5. obj A device object array of device objects channels or lines PropertyName A property name PropertyValue A property value PN A cell array of property names PV A cell array of property values S A structure whose field names are device object channel or line properties props A structure array whose field names are the property names for obj or a cell array of possible values set obj displays all configurable properties for obj If a property has a finite list of possible string values then these values are also displayed props set obj returns all configurable properties toprops props isa structure array with fields given by the property names and possible property values contained in cell arrays if the property does not have a finite set of possible values then the cell array is empty set obj PropertyName displays the valid values for the property specified by PropertyName Propert yName must have a finite set of possible values props set obj PropertyName returns the valid values for PropertyNameto props props iSacell array of possible values or an empty cell array if the property does not have a finite set of possible values 9 85 set Remarks Example 9 86 set obj PropertyName PropertyValue sets multiple property values with a single statement Note that you can use structures property name property value string pairs and property name property value cell array pairs
6. 5 42 Table 5 9 Analog Input TriggerType and TriggerCondition Values for CBI Hardware Continued TriggerType TriggerCondition Description Value Value HwAnal og Tri gAbove The trigger occurs when the analog signal makes a Tri gBelow Gat eNegHys Gat ePoshys Gat eAbove Gat eBel ow Gatel nWi ndow Gat eOut Window transition from below the specified value to above The trigger occurs when the analog signal makes a transition from above the specified value to below The trigger occurs when the analog signal is more than the specified high value The acquisition stops if the analog signal is less than the specified low value The trigger occurs when the analog signal is less than the specified low value The acquisition stops if the analog signal is more than the specified high value The trigger occurs as long as the analog signal is more than the specified value The trigger occurs as long as the analog signal is less than the specified value The trigger occurs as long as the analog signal is within the specified range of values The trigger occurs as long as the analog signal is outside the specified range of values Hardware Digital Triggering If Tri ggerType iSHwDi git al the trigger is given by a digital TTL signal For example to trigger your acquisition when the positive edge of a digital signal is detected ai analoginput cbi 1 addchannel ai 0 7 set ai TriggerType HwDi
7. 8 10 Function Reference 9 OVOPrVICW aio e sae ane ida 9 2 Getting Command LineFunction Help 9 2 Functions Grouped by Category 4 9 4 Functions Listed Alphabetically 9 8 AdAChANNEL sia a ad Hea eo aa a Ae ag ads wed Audiol ae Aone ahs 9 9 addline gases Gracie a GES Joes Gree 9 14 addmuxchannel ccoo 9 17 vii viii Contents analoginput ns taheta na haria a dt 9 18 anal OgQUtpUt ne sp anaes pia 9 21 binvec2d via nim ra Ea Ea be eae eos 9 24 Cear a E Vee Ea ae as 9 25 dagaction o sses tis chee ketam ober a Deda ad ees 9 27 d gfind vuitton 9 28 daghelp siria minie a E ee eed ees 9 30 Gaghwinfo setts hake Paka a ee PPE A a Sade See 8S 9 32 GAGNON Sct ek Oe Et op aaa a wea Mabe eek 9 34 daQpropediE merino orita Mc e maki A 9 37 GAG Cad lr a a o ee rau Sal 9 39 dagregister maa kisah O ete a 9 43 AMES ii Ga 9 44 Gagschool iess ori ii ee we a eee 9 45 dec2bINVEC Lan AN 9 46 delete coo E A OER ee De eee a 9 48 ALO O isss E o as 9 50 CISD sii das a a o chee EEE Teoh E A 9 52 Hushdata cdas ista hes 9 53 RN 9 55 e ss ein sede oes Gh ied eA ee a aN 9 57 getsampl seis a See ee ale dee A 9 61 getver setmana tds a e 9 62 SO a A A ee 9 63 EX ae ares ok oee peo Reese ee Ad 9 64 SR eben a a peated Spence de keane 9 65 CA ee eae ee ey ee eG ek ee ae 9 67 aaa Tine ea er OG die Lok ps Eee es 9 69 MAKENAMES 1 tees 9 71 MUXCN ANI AX siete tae do
8. 8 9 8 Saving and Loading the Session 8 10 Alternatively you can return only object channel and hardware information with the command daqinfo daqread file info Note When you retrieve object information the entire event log is returned todaginfo Obj Info EventLog regardless of the number of samples retrieved Example Logging and Retrieving Information This example illustrates how to log information to a disk file and then retrieve the logged information to MATLAB using various calls todaqread A sound card is configured for stereo acquisition data is logged to memory and to a disk file four triggers are issued and 2 seconds of data are collected for each trigger at a sampling rate of 8 KHz You can run this example by typing daqdoc8_ 1 atthe MATLAB command line 1 Create a device object Create the analog input object ai for a sound card The installed adaptors and hardware IDs are found with daghwi nfo al analoginput winsound mai analoginput nidag 1 Mai analoginput cbi 1 2 Add channels Add two hardware channels toai ch addchannel ai 1 2 ch addchannel ai 0 1 For NI and CBI 3 Configure property values Define a 2 second acquisition for each trigger set the trigger to repeat three times and log information tothefilefi le00 daq duration 2 Two seconds of data for each trigger set ai SampleRate 8000 Actual Rate get ai SampleRate set ai
9. Extracted data Each column represents a separate input channel get data is considered a blocking function since it returns control to MATLAB only when the requested data is available Therefore samples are not missed or repeated When a trigger executes acquired data fills the engine When a get data call is processed the requested samples are returned when the data is available and then extracted from the engine 5 13 5 Doing More with Analog Input 5 14 As shown below if a fraction of the data stored in the engine is extracted then getdata always extracts the oldest data Time gt Pay ___ Extract the requested data E Data stored in engine If another get data call is issued then once again the oldest samples are extracted Time gt A O Extract the requested data E Data stored in engine MM Data has been extracted from the engine Managing Acquired Data Rules for Using getdata Using get data to extract data stored in the engine follows these rules If the requested number of samples is greater than the samples to be acquired then an error is returned If the requested data is not returned in the expected amount of time an error is returned The expected timeto return data is given by thetimeit takes the engine to fill one data block plus the time specified by theTi meout property You can issue C Control C whileget data is blocking This w
10. 0 5 ne o e 8 o E lt 0 5 1 L L L 1 L L L L L J 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 Time sec 1 e 9 3 8 8 0 5 e e 2 8 8 2 Z 0 e lt 0 5 A e 8 8 1 i fi i i i amp 1 J 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 Time sec 1 37 1 Introduction to Data Acquisition 1 38 As shown in the top figure the low sampling rate produces a sampled signal that appears to be a triangular waveform As shown in the bottom figure a higher fidelity sampled signal is produced when thesampling rateis higher In the latter case the sampled signal actually looks like a sine wave How Can Aliasing be Eliminated The primary considerations involved in antialiasing are the sampling rate of the A D converter and the frequencies present in the sampled data To eliminate aliasing you must e Establish the useful bandwidth of the measurement e Select a sensor with sufficient bandwidth e Select a low pass anti aliasing analog filter that can eliminate all frequencies exceeding this bandwidth e Sample the data at a rate at least twice that of the filter s upper cutoff frequency Selected Bibliography Selected Bibliography 1 Transducer nterfacing Handbook A Guideto Analog Signal Conditioning edited by Daniel H Sheingold Analog Devices Inc Norwood Massachusetts 1980 Bentley J ohn P Principles of Measurement Systems Second Edition Longman Scientific and Technical Ha
11. Properties TriggerCondition TriggerConditionValue TriggerType TriggerCondition Purpose Specify the condition that must be satisfied before a trigger executes Description The available trigger conditions depend on the value of Tri ggerType If TriggerType is mmedi ate or Manual the only availableTrigger Condition is None IfTriggerType iSSoft ware thenTriggerCondition can beRi sing Falling Leaving or Entering These trigger conditions require one or more voltage values to be specified for the Tri ggerConditionVal ue property Based on the hardware you are using additional trigger conditions may be available Characteristics Usage Al Common Access Read write Data type String Read only Yes when running Values All Supported Hardware The following trigger condition is used when Tri ggerType iS mmedi ate or Manual None No trigger condition is required The following trigger conditions are available when Tri ggerType isSoftware Ri sing The trigger occurs when the signal has a positive slope when passing through the specified value Falling The trigger occurs when the signal has a negative slope when passing through the specified value Leaving The trigger occurs when the signal leaves the specified range of values Entering The trigger occurs when the signal enters the specified range of values 10 85 TriggerCondition 10 86 National Instruments The following trigger condition is used
12. Property Name Description Device Objects DriveAlSenseTo Specify if AISENSE is driven to onboard Al Ground ground NumMux Boards Specify the number of external multiplexer Al devices connected Out Of Dat a Mode Specify how the value held by the analog AO output subsystem is determined TransferMode Specify how data is transferred from the Al AO data acquisition device to system memory 11 3 11 Device Specific Property Reference ComputerBoards Properties The device specific ComputerBoards Measurement Computing Corporation properties for analog input Al and analog output AO objects are given below Property Name Description Device Objects Out Of Dat aMode Specify how the value held by the analog AO output subsystem is determined TransferMode Specify how data is transferred from the Al AO data acquisition device to system memory Agilent Technologies Properties The device specific Agilent Technologies properties for analog input Al and analog output AO objects are given below Property Name Description Device Objects COLA Specify whether the source constant level AO output is enabled or disabled Coupling Specify the input coupling mode Al Groundi ngMode Specify the input channel grounding mode Al Input Mode Specify the channel input mode Al InputSource Specify the input tothe A D converter Al RampRate Specify the source ramp up and ramp down AO rate SourceMode Specify
13. The absolute time is returned using MATLAB s clock format year month day hour minute seconds The absolute time from the get data call is absti me abstime 1 0e 003 1 9990 0 0020 0 0190 0 0130 0 0260 0 0208 To convert thec ock vector toa more convenient form t fix absti me sprintf d d d t 4 t 5 t 6 ans 13 26 20 The absolute time of the first trigger is also recorded by the nitialTriggerTi me property Notethat absolute times are recorded by theEv ent Log property for each trigger executed You can always find the absolute time associated with a data sample by adding its relative time to the absolute time of the associated trigger Refer to Recording and Retrieving Event Information on page 5 49 for more information about returning absolute time information with theEvent Log property 5 19 5 Doing More with Analog Input 5 20 Configuring Analog Input Triggers An analog input trigger is defined as an event that initiates data logging Y ou can log data to the engine memory and toa disk file As shown in the figure below when a trigger occurs theLoggi ng property is automatically set On and data is stored in the specified target Logging Off Logging On X Time Trigger occurs Log data toengine and disk file When defining a trigger you must specify the trigger type Additionally you may need to specify one or more of these parameters e A trigger condition a
14. e Input single values using theget samp e function or output single values using the put samp e function e Configure theCl ockSource property toSoft ware The Quick Reference Guide The Quick Reference Guide gives you a brief but complete overview of the toolbox capabilities functions and properties You may find it useful to print this guide and keep it handy when using the toolbox You can access this guide through the Help browser Demos The toolbox includes a large collection of demos which are available through thedagschool interface To launch this interface typedaqschool at the command line dagschool Y ou can also launch individual demos by typing the appropriate M file nameat the command line Alternatively you can launch a tool box demo through the MATLAB Demo window by typing demo toolbox Data Acquisition The data acquisition demos organized by device object are listed below Note Most analog input and analog output demos require that you have a sound card installed The digital O demos require that you have a supported National Instruments board with digital I O capabilities 2 13 2 G etting Started with the Data Acquisition Toolbox dagschool is shown below Data Acquisition Toolbox Tutorials SBE Analog Input Analog Output Digital YO Common The buttons in this window will launch the Data Acquisition Toolbox demos for analog input objects Introduction illustrates a
15. For more information on overloaded functions and class directories refer to MATLAB Classes and Objects in the Help browser 9 3 9 Function Reference 9 4 Functions Grouped by Category This section contains brief descriptions of all toolbox functions The functions and the device objects they are associated with are categorized according to usage The supported device objects include analog input Al analog output AO and digital 1 O DIO A number of other MATLAB M file helper functions are provided with this toolbox to support the functions listed below These helper functions are not documented since they are not intended for direct use Creating Device Objects Al AO DIO analoginput Create an analog input object Y analogoutput Create an analog output object Y digitalio Create a digital I O object Y Adding Channels and Lines Al AO DIO addchannel Add hardware channels to an analog input or analog Y Y output object addline Add hardware lines to a digital 1 O object Y addmuxchannel Add hardware channels when using a multiplexer board v Getting and Setting Properties Al AO DIO get Return device object properties Y Y Y set Configure or display device object properties Y Y Y setverify Configure and return the specified property Y Y Y Functions Grouped by Category Executing the Object Al AO DIO start Start a device object Y Y Y stop Stop a device obj
16. Logging or Sending Data Stopping the Device Object Cleaning Up 3 2 3 3 3 4 35 3 6 3 8 3 9 3 12 3 12 3 14 3 20 3 22 3 23 3 23 3 24 3 25 3 The Data Acquisition Session Overview Thedata acquisition session comprises all the steps you are likely to take when acquiring or outputting data These steps are 1 Create a device object Y ou create a device object usingtheanal oginput anal ogoutput ordi gitalio creation function Device objects are the basic toolbox elements you use to access your hardware device 2 Add channels or lines After a device object is created you must add channels or lines to it Channels are added to analog input and analog output objects while lines are added to digital 1 O objects Channels and lines are the basic hardware device elements with which you acquire or output data 3 Configure properties To establish the device object behavior you assign values to properties using thes et function or dot notation Y ou can configure many of the properties at any time However some properties are configurable only when the device object is not running Conversely depending on your hardware settings and the requirements of your application you may be able to accept the default property values and skip this step 4 Acquire or output data To acquire or output data you must execute the device object with thest art function While the device objec
17. Returning Property Names and Property Values on page 3 14 Common Properties You can configure a single property value using thes et function set ai TriggerType Manual or the dot notation ai TriggerType Manual To configure values for multiple properties you can supply multiple property name property value pairs toset set ai SampleRate 44100 Name Test1 winsound Note that you can configure only one property value at a time using the dot notation Channel and Line Properties To configure channel line properties for one or more channels lines contained by a device object you must usethe Channel Li ne property For example to configurethesSensor Range property for the first channel contained by ai you can use the set function set ai Channel 1 SensorRange 2 2 or the dot notation ai Channel 1 SensorRange 2 2 Configuring and Returning Properties Toconfigure values for multiple channel or line properties you supply multiple property name property value pairs tos et set ai Channel 1 SensorRange 2 2 Channel Name Chan1 To configure multiple property values for multiple channels chs ai Channel 1 2 set chs SensorRange Channel Name 2 2 Chanl 0 4 Chan2 Specifying Property Names Device object property names are presented in this guide using mixed case While this makes the names easier to read you can use any case you want wh
18. Type ans 0 1 1x1 digitalio Line 1 2 1x1 digitalio Line 2 3 1x1 digitalio Line 3 4 1x1 digitalio Line 4 5 1x1 digitalio Line 5 6 1x1 digitalio Line 6 7 1x1 digitalio Line 7 8 1x1 digitalio Line Line and Port Characteristics As described in the preceding section when you add lines toa digital I O object they must be configured for either input or output You read values from an input line and write values to an output line Whether a given hardwarelineis addressable for input or output depends on the port is resides on You can classify digital O ports into these two groups based on your ability to address lines individually e Port configurable devices You cannot address the lines associated with a port configurable device individually This means that you must configure 7 Digital Input O utput all the lines for either input or output If you attempt to mix the two configurations an error is returned Y ou can add any number of available port configurable lines to a digital I O object However the engine will address all lines behind the scenes For example if one line is added to a DIO object then you automatically get all lines This means that if a digital I O object contains lines from a port configurable device and you write a value to one or more of those lines then all the lines are written to even if they are not contained by the device object
19. Actions on page 5 46 Defining a Trigger Trigger Types and Conditions Defining a trigger for an analog input object involves specifying thetrigger type with theTri ggerType property You can think of the trigger type as the source of the trigger For some trigger types you may need to specify a trigger condition and a trigger condition value Trigger conditions are specified with theTri ggerCondi tion property while trigger condition values are specified with theTriggerConditionVal ue property 5 21 5 Doing More with Analog Input 5 22 The analog input Tri ggerType andTriggerCondition values are given below Table 5 7 Analog Input TriggerType and TriggerCondition Values TriggerType TriggerCondition Description Value Value Immediate None The trigger occurs just after you issue thestart function Manual None The trigger occurs just after you manually issue thet ri gger function Software Rising The trigger occurs when the signal has a positive slope when passing through the specified value Falling The trigger occurs when the signal has a negative slope when passing through the specified value Leaving The trigger occurs when the signal leaves the specified range of values Entering The trigger occurs when the signal enters the specified range of values For some devices additional trigger types and trigger conditions are available Refer totheTriggerType and Tri ggerCondition reference pages in Chapter
20. ChannelSkew Mode Purpose Description Characteristics Values 10 22 Specify how the channel skew is determined For simultaneous sample and hold SS H hardware Channel SkewMode iSNone For scanning hardware Channel SkewMode can beMi ni mum Equisample or Manual National Instruments only SS H hardware includes Agilent Technologies devices and sound cards while scanning hardware includes most National Instruments and ComputerBoards devices Note that some supported boards from these vendors are SS H Examples include the 6110E board and the DAS4020 12 board respectively If Channel SkewMode iSMi ni mum then the minimum channel skew supported by the hardware is used If Channel SkewMode iS Equi sampl e the channel skew is given by sampling rate number of channels If Channel SkewMode is Manual then you must specify the channel skew with theChannel Skew property Usage Al Common Access Read write Data type String Read only Yes when running National Instruments Mi ni mum The channel skew is set to the minimum supported value Equisample The channel skew is given by sampling rate number of channels T Manual The channel skew is given by Channel Skew ChannelSkew Mode See Also ComputerBoards Mi ni mum The channel skew is set to the minimum supported value Equisample The channel skew is given by sampling rate number of channel s T 1 Agilent Technologies and Sound Cards
21. Description Characteristics Values Specify the input coupling mode Coupling can beDC or AC If Coupling isDC the input is connected directly to theamplifier If Coup ing ISAC a series capacitor is inserted between the input connector and the amplifier For source channels Coup ing is generally not used since it is usually not possible to AC couple the output of a source After a hardware reset Coupling is automatically set to DC Vendor Usage Access Data type Read only while Running DC AC Agilent Technologies Al Channel Read write String Yes The input is connected directly to the amplifier A series capacitor is inserted between the input connector and the amplifier 11 9 DriveAlSenseToGround Purpose Specify if AISENSE is driven to onboard ground Purpose DriveAlSenseToGround canbeOn orOff IfDriveAl SenseToGround is0ff then AISENSE is not driven to onboard ground If Dri veAl SenseToGround isOn then AISENSE is driven to onboard ground AISENSE serves as the hardware reference node when channels are configured in nonreferenced single ended NRSE mode Channels are configured with the nput Type property IfI nputType is NonReferencedSi ngl eEnded then the hardware device uses AI SE NSE for the negativeinput of theamplifier regardless oftheDriveAl SenseToGround value IfinputType isDifferential orSi ngl eEnded then the hardware device drives AISENSE to onboard ground only if Dri veAl S
22. Properties RunTimeErrorAction TimerAction Purpose Specify the M file action function to execute whenever a predefined period of time passes Description A timer event is generated whenever the time specified by theTi mer Peri od property passes This event executes the action function specified for Ti mer Action Timeis measured relative to when the device object starts running Some timer events may not be processed if your system is significantly slowed or iftheTi mer Period valueis too small For example a common application for timer events is to display data However since displaying data is a CPU intensive task some of these events may be dropped To guarantee that events are not dropped you may want tousetheSamplesAcqui redAction property analog input or theSamp es Out put Acti on property analog output For digital O objects timer events are typically used to update and display the state of the device object Timer event information is not stored in theEventLog property Characteristics Usage Al AO DIO Common Access Read write Data type String Read only No when running Values The default value is an empty string See Also Properties EventLog Sampl esAcquiredAction Sampl esOutputAction Ti mer Period 10 81 TimerPeriod Purpose Description Characteristics Values See Also 10 82 Specify the period of time between timer events Ti mer Period specifies the time in seconds that mus
23. SampleRate 11025 set Al SamplesPerTrigger 22050 4 Acquire data Start Al wait until the requested samples are acquired and extract all the data from the engine Beforestart is issued you may want to begin inputting data from a microphone or a CD player start Al while strcmp Al Running On end data getdata Al Plot the data and label the figure axes plot data xl abel Samples ylabel Signal Volts 5 Clean up When you no longer need Al you should remove it from memory and from the MATLAB workspace delete Al clear Al 3 3 3 The Data Acquisition Session 3 4 Creating a Device Object Device objects are the toolbox components you use to access your hardware device They provide a gateway tothe functionality of your hardware and allow you to control the behavior of your data acquisition application Each device object is associated with a specific hardware subsystem To create a device object you call M file functions called object creation functions or object constructors These M files are implemented using MATLAB s object oriented programming capabilities which are described in MATLAB Classes and Objects in the Help browser The device object creation functions are listed below Table 3 1 Device Object Creation Functions Function Description anal ogi nput Create an analog input object analogoutput Create an analog output object di gitalio Create a digi
24. addchannel Al 0 For NI and CBI 3 Configure property values Repeat the trigger three times find the time for the acquisition to complete and define daqacti on as the M file to execute when a trigger run time error or stop event occurs set Al TriggerRepeat 3 time Al SamplesPerTrig Al SampleRate Al TriggerRepeat 1 set Al TriggerAction dagaction set Al RuntimeErrorAction dagaction set Al StopAction daqaction 5 53 5 Doing More with Analog Input 5 54 4 Acquire data Start Al and wait for it to stop running Thepaus e command allows the output from daqacti on to be displayed start Al pause ti me l 5 Clean up When you no longer need A you should remove it from memory and from the MATLAB workspace delete Al clear Al Passing Additional Parameters to an Action Function This example illustrates how additional arguments are passed to the action function Timer events are generated every 0 5 second todisplay data using the action function daqdoc5 7plot You can run this example by typingdaqdoc5_ 7 atthe MATLAB command line 1 Create a device object Create the analog input object Al for a sound card The installed adaptors and hardware IDs are found with daghwi nfo Al analoginput winsound Al analoginput nidag 1 Al analoginput cbi 1 2 Add channels Add one hardware channel toAl chan addchannel Al 1 chan addchannel Al 0 For NI and
25. clear Al The data is shown below Preview Data 0 2 T T Signal Level Volts 5 a o 0 2 4 0 3 i 1 L L 1 1 i 0 100 200 300 400 500 600 700 800 Samples All Acquired Data 0 3 T T T 0 2 2 01 o 2 D 0 3 3 701 5 H 70 2 0 3 0 4 1 L L 1 i 1 0 1 2 3 4 5 6 7 8 Samples x 10 5 17 5 Doing More with Analog Input Returning Time Information You can return relative time and absolute time information with theget data function Relative time is associated with the extracted data Absolute time is associated with the first trigger executed Relative Time To return data and relative time information for the analog input object ai data time getdata ai ti me is an m by 1 array of relative time values where m is the number of samples returned t i me O corresponds to the first sample logged by the data acquisition engine and time is measured continuously until the acquisition is stopped The relationship between the samples acquired and the relative time for each sample is shown below for m samples and n channels Data array Each column Relative time array represents one channel d11 012 din ti do da don t2 d31 d32 Ap t3 le dm1 dm2 dmn tm 5 18 Managing Acquired Data Absolute Time Toreturn data relative time information and the absolute time of the first trigger for the analog input object ai data time abstime getdata ai
26. daqschool Interface for displaying toolbox tutorials Y Y Y dagregister Register or unregister a hardware driver adaptor Y Y Y daqreset Remove device objects and data acquisition DLLs from Y Y Y memory dec2binvec Convert decimal value to binary vector Y delete Remove device objects channels or lines from the data Y Y Y acquisition engine disp Display summary information for device objects Y Y Y channels or lines ischannel Check for channels isdioline Check for lines Y Y Y Functions Grouped by Category General Purpose Continued Al AO DIO isvalid Determine if device objects channels or lines are valid Y Y Y length Return the length of a device object channel group or Y Y Y line group load Load device objects channels or linesintothe MATLAB v Y Y workspace makenames Generate a list of descriptive channel or line names Y Y Y muxchanidx Return multiplexed scanned channel index Y obj2mfile Convert device objects channels or lines to MATLAB Y Y Y code save Save device objects to a MAT file Y Y Y showdagevents Display event log information Y Y size Return the size of a device object channel group or line Y Y Y group 9 7 9 Function Reference Functions Listed Alphabetically This section contains detailed descriptions of all toolbox functions Each function reference page contains some or all of this information e The function name e The purpose of the function e The f
27. 0 1 1x1 analogout put Channel 1 2 1x1 analogoutput Channel To reference individual channels you must specify either MATLAB indices or descriptive channel names Refer to Referencing Individual Hardware Channels on page 4 6 for more information 6 5 6 Analog O utput 6 6 Configuring Analog Output Properties After hardware channels are added to the analog output object you should configure property values As described in Configuring and Returning Properties on page 3 12 the Data Acquisition Toolbox supports two basic types of properties for analog output objects common properties and channel properties Common properties apply to all channels contained by the device object while channel properties apply to individual channels The properties you configure depend on your particular analog output application For many common applications there is a small group of properties related to the basic setup that you will typically use These basic setup properties control the sampling rate and define the trigger type Analog output properties related tothe basic setup are given below Table 6 3 Analog Output Basic Setup Properties Property Name Description SampleRate Specify the per channel rate at which digital data is converted to analog data TriggerType Specify the type of trigger to execute Setting the Sampling Rate Y ou control the rate at which an analog output subsystem convert
28. 0 5980 5 35 5 Doing More with Analog Input 5 36 How Many Triggers Occurred You can find out how many triggers occurred with theTri ggersExecuted property value The trigger number for each trigger executed is also recorded by theEvent Log property A convenient way to access event log information is with thes howdagevents function For example suppose you create the analog input object ai for a sound card and add one channel toit ai is configured to acquire 40 000 samples with five triggers using the default sampling rate of 8000 Hz al analoginput winsound ch addchannel ai 1 set ai TriggerRepeat 4 start ai TriggersExecuted returns the number of triggers executed ai TriggersExecuted ans 5 showdaqevents returns information for all the events that occurred while ai was executing showdagevents ai 1 Start 10 22 04 0 2 Trigger 1 10 22 04 0 Channel N A 3 Trigger 2 10 22 05 8000 Channel N A 4 Trigger 3 10 22 06 16000 Channel N A 5 Trigger 4 10 22 07 24000 Channel N A 6 Trigger 5 10 22 08 32000 Channel N A 7 Stop 10 22 09 40000 For more information about recording and retrieving events refer to Recording and Retrieving Event Information on page 5 49 Configuring Analog Input Triggers When Did the Trigger Occur You can find the absolute time of the first trigger event with the InitialTriggerTi me property value The absolute time is ret
29. 10 Base Property Reference for these device specific values e Device independent triggers e Device specific hardware triggers Trigger types are grouped into two main categories The trigger types shown above are device independent triggers since they are available for all supported hardware F or these trigger types the action that initiates the trigger event involves satisfying a trigger condition in the engine software trigger type or issuing a toolbox function start ortrigger Configuring Analog Input Triggers Conversely device specific hardware triggers depend on the specific hardware device you are using For these trigger types the action that initiates the trigger event involves an external analog or digital signal Device specific hardware triggers for National Instruments ComputerBoards and Agilent Technologies devices are discussed in Device Specific Hardware Triggers on page 5 37 Device independent triggers are discussed below Immediate Trigger If Tri ggerType iS mmedi ate the default value the trigger occurs immediately after thest art function is issued You can configure an analog input object for continuous acquisition by use an immediate trigger and setting Sampl esPerTrigger orTriggerRepeat toi nf Trigger repeats are discussed in Repeating Triggers on page 5 30 Manual Trigger If Tri gger Type isManual thetrigger occurs just after you issue thet rigger function A manual tri
30. 5 33 5 Doing More with Analog Input 5 34 The figure below illustrates the data stored by the engine during a multiple trigger acquisition The data acquired for each trigger is given by the SamplesPerTrigger property value The relative trigger times are shown on theTi me axis where first trigger time corresponds tot 0 seconds by definition the second trigger time corresponds tot and so on Logging Trigger 1 Trigger 2 Trigger n SamplesPerTrigger On FP ty E Data stored in engine The following code modifies daqdoc5_5 sothat multiple trigger data is extracted from the engine with one call togetdata returndata Actual Rate duration Al Voice TriggerRepeat 1 start AlVoice d t getdata AlVoice returndata Plot the data plot t d xlabel Time sec ylabel Signal Level Volts title Voice Activation for Both Triggers grid on Configuring Analog Input Triggers The multiple trigger data is shown below Voice Activation for Both Triggers 0 3 0 2 0 1 o Signal Level Volts 0 4 l l l l l i 0 0 2 0 4 0 6 0 8 1 1 2 1 4 Time sec You can find the relative trigger times by searching for NaNs in the returned data You can find the index location of the NaN ind ort using thei snan function index find isnan d index 22051 With this information you can find the relative time for the second trigger t2time t index 1 t2time
31. 5 53 Linearly Scaling the Data Engineering Units 5 56 Example Performing a Linear Conversion 5 57 Analog Output 6 OVERVIEW 21554545825 woth she Gaede hood ods Ola hele Noes as 6 2 Getting Started with Analog Output 6 3 Creating an Analog Output Object oooococccooocoo 6 3 Adding Channels to an Analog Output Object 6 4 Configuring Analog Output Properties o o ooo 6 6 OutputtingData oooccoccocccccococ 6 9 Analog Output Examples o oococcccccc ee 6 10 Evaluating the Analog Output Object Status 6 14 vi Contents Managing Output Data 0 cee eee 6 17 Queuing Data with putdata 0 000 6 17 Example Queuing Data with putdata 6 19 Configuring Analog Output Triggers 6 21 Defining a Trigger Trigger Types sssusa saanane 6 22 Executing the Trigger 0 0 eee ee eee 6 23 How Many Triggers Occurred 0 000 e eee eee 6 23 When Did the Trigger Occur 0 00 cece eee 6 24 Device Specific Hardware TriggerS 000 ea ee 6 25 Configuring Events and Actions 6 27 Event TY PGS nati ar ade 6 27 Recording and Retrieving Event Information 6 29 Examples Using Action Properties and Action Functions 6 31 Linearly Scaling the Data Engineering Units 6 34 Example Performing a L
32. AO Running On end 5 Clean up When you no longer need A0 you should remove it from memory and fromthe MATLAB workspace delete A0 clear AO Outputting Data with a National Instruments Board In this example sine wave data is generated in MATLAB output to the D A converter on a National Instruments board and displayed with an oscilloscope The setup is shown below Data Source D A Converter Scope MATLAB ITDA variable D A A 0000 Y ou can run this example by typing daqdoc6_2 atthe MATLAB command line 1 Create a device object Create the analog output object A0 for a National Instruments board The installed adaptors and hardware Ds are found with daqhwi nfo AO analogoutput nidaq 1 2 Add channels Add one channel toA0 chan addchannel AO 0 G etting Started with Analog O utput 3 Configure property values Define an output time of four seconds assign values tothe basic setup properties generate data to be queued and queuethe data with one call toputdata duration 4 set A0 SampleRate 10000 set A0 TriggerType Manual Actual Rate get A0 SampleRate len Actual Rate durati on data sin linspace 0 2 pi len put data A0O data 4 Output data Start A0 issuea manual trigger and wait for the device object to stop running s
33. Al Voice 1 chan addchannel AlVoice 0 For NI and CBI 3 Configure property values Define a 2 second acquisition and configure a software trigger The source of the trigger is chan and the trigger executes when a rising voltage level has a value of at least 0 2 volt duration 2 two second acquisition set AlVoice SampleRate 44100 ActualRate get AlVoice SampleRate set AlVoice SamplesPerTrigger Actual Rate dur ati on set AlVoice TriggerChannel chan set AlVoice TriggerType Software set AlVoice TriggerCondition Rising set AlVoice TriggerConditionValue 0 2 4 Acquire data Start Al Voi ce acquire the specified number of samples and extract the first 1000 samples from the engine as sample time pairs Display the number of samples remaining in the engine start AlVoice while strcmp Al Voice Running On end data time getdata Al Voice 1000 remsamp num2str Al Voice Sampl esAvai l able disp Number of samples remaining in engine remsamp Plot all extracted data plot time data drawnow xl abel Time sec y g abel Signal Level Volts rid on 5 Clean up When you no longer need Al Voi ce you should remove it from memory and from the MATLAB workspace del ete Al Voi ce clear Al Voice Configuring Analog Input Triggers Note that when using software triggers you must specify theTri ggerType value before theTri gge
34. Example See Also 11 16 Specify how the value held by the analog output subsystem is determined When queued data is output to the analog output AO subsystem the hardware typically holds a value For National Instruments and ComputerBoards devices the value held is determined by Out Of Dat aMode Out Of DataMode can beHold or Default Value If Out Of Dat aMode iSHold then the last value output is held by the AO subsystem If Out Of Dat aMode is Def aul tVal ue then the value specified by the Def aul t Channel Val ue property is held by the AO subsystem Vendor National Instruments ComputerB oards Usage AO Common Access Read write Data type String Read only Yes while Running Hol d Hold the last output value Default Value Hold the value specified by Def aul t Channel Value Create the analog output object ao and add two channels to it ao analogoutput nidaq 1 addchannel ao 0 1 Y ou can configureao sothat when queued data is finished being output a value of 1 volt is held for both channels ao OutOfDataMode DefaultValue ao Channel DefaultChannel Value 1 0 Properties Def aul t Channel Val ue RampRate Purpose Specify the source ramp up and ramp down rate Purpose For input channels RampRat e is not generally used For source channels RampRate iS usually used to ensure that the source signal starts and stops smoothly Characteristics Vendor Agilent Technologies Usage AO Cha
35. Gat eNegHys Gat ePoshys Gat eAbove Gat eBel ow Gatel nWindow Gat eOut Window The trigger occurs when the analog signal makes a transition from below the specified value to above The trigger occurs when the analog signal makes a transition from above the specified value to below The trigger occurs when the analog signal is more than the specified high value The acquisition stops if the analog signal is less than the specified low value The trigger occurs when the analog signal is less than the specified low value The acquisition stops if the analog signal is more than the specified high value The trigger occurs as long as the analog signal is more than the specified value The trigger occurs as long as the analog signal is less than the specified value The trigger occurs as long as the analog signal is within the specified range of values The trigger occurs as long as the analog signal is outside the specified range of values Agilent Technologies The following trigger conditions are available when Trigger Type isHwDigital PositiveEdge NegativeEdge The trigger occurs when the positive rising edge of a digital signal is detected The trigger occurs when the negative falling edge of a digital signal is detected 10 87 TriggerCondition See Also 10 88 The following trigger conditions are available when Trigger Type iSHwAnal og Rising The trigger occurs when the analog sig
36. SamplesPerTrigger duration Actual Rate set ai TriggerRepeat 3 set ai LogFileName file00 daq set ai LoggingMode Disk amp Memory Logging Information to Disk 4 Acquire data Start ai wait forai tostop running and extract all the data stored in the log file as sample time pairs start ai while strcmp ai Running On end data time dagread file00 daq Plot the data and label the figure axes subplot 211 plot data title Logging and Retrieving Data xlabel Samples ylabel Signal Volts subplot 212 plot time data xlabel Time seconds ylabel Signal Volts 5 Clean up When you no longer need ai you should remove it from memory and fromthe MATLAB workspace delete ai clear al Retrieving Data Based on Samples Y ou can retrieve data based on samples usingtheSampl es property Toretrieve samples 1000 to 2000 for both sound card channels data time dagread file00 daq Samples 1000 2000 Plot the data and label the figure axes subplot 211 plot data xlabel Samples ylabel Signal Volts subplot 212 plot time data xlabel Time seconds ylabel Signal Volts Retrieving Data Based on Channels Y ou can retrieve data based on channels using the Channels property To retrieve samples 1000 to 2000 for the second sound card channel data time dagread file00 daq Samples 1000 2000 Channels 2 8 11 8 Savi
37. Syntax Arguments Description 9 32 Display data acquisition hardware information out daqhwinfo out daghwinfo adaptor out daghwi nf o obj out daghwinfo obj Fiel dName adaptor Name of the hardware driver adaptor The supported adaptors areni dag cbi hpel432 and wi nsound obj A device object or array of device objects FieldName A single field name or a cell array of field names out A structure containing the requested hardware information out daqhwinfo returns general hardwarerelated information as a structure toout The returned information includes installed adaptors the toolbox and MATLAB version and the toolbox name out daghwinfo adaptor returns hardware related information for the specified adapt or The returned information includes the adaptor DLL name the board names and Ds and the device object constructor syntax out daghwinfo obj returns hardwarerelated information for the device object obj Ifobj isan array of device objects then out is a 1 by n cell array of structures where n is the length of obj The returned information depends on the device object type and may include the maximum and minimum sampling rates the channel gains the hardware channel or line IDs and the vendor driver version out daghwinfo obj FieldName returns the hardware related information specified by Fi el dNa me for the device object obj Fi el dName can be a single field name
38. The following example illustrates how to configure a hardware digital trigger ai analoginput nidaq 1 addchannel ai 0 7 set ai TriggerType HwDi gital The diagram below illustrates how you connect a digital trigger signal to an MIO 16E Series board PF10 TRIG1 corresponds to pin 11 TTL signal PFIO TRIG1 A D MIO 16E Series board Hardware Analog Triggering If Tri gger Type isHwAnal ogPin the trigger is given by a low range analog signal typically between 10 to 10 volts For example totrigger your acquisition when the trigger signal is between 4 volts and 4 volts ai analoginput nidaq 1 addchannel ai 0 7 set ai TriggerType HwAnal ogPin set ai TriggerCondition InsideRegion set ai TriggerConditionValue 4 0 4 0 IfTriggerType isHwAnal ogChannel the trigger is given by an analog signal and the trigger channel is defined as the first channel in the channel group MATLAB index of one The valid range of the analog trigger signal is given by the full scale range of thetrigger channel The following exampleillustrates how to configure such a trigger where the trigger channel is assigned the 5 39 5 Doing More with Analog Input 5 40 descriptive nametTri gChan and the default Trigger Condi ti on property value is used al analoginput nidag 1 addchannel ai 0 7 set ai Channel 1 Channel Name Tri
39. VendorDriverVersion winsound 1 6 AC Coupled Audi oPCl Record E beled 44100 8000 i nt16 Bipolar Si mult aneousSampl e 1 2 Anal ogl nput 2 Windows Multimedia Driver 1 0 Among other things this information tells you that the minimum sampling rate is 8 kHz the maximum sampling rate is 44 1 kHz and there are two hardware channels that you can add to the analog input object 2 19 2 G etting Started with the Data Acquisition Toolbox Getting Help 2 20 The Data Acquisition Toolbox provides you with these help resources e The HTML and PDF versions of this guide and the Quick Reference Guide which are available through the Help browser e M file function help which you can display with thehel p command since some toolbox functions are overloaded you may need to specify the appropriate pathname as well e Thedaghel p function e Thepr opi nfo function The daghelp Function You can use the daghel p function to e Display command line help for functions and properties e List all the functions and properties associated with a specific device object A device object need not exist for you to obtain this information F or example to display all the functions and properties associated with an analog input object as well as the constructor M file help daqhelp anal oginput To display help for the Sampl eRat e property daqhelp SampleRate Y ou can also dis
40. al analoginput winsound addchannel ai 1 2 To capture all property information for all common ai properties out propinfo ai To display the default value for the Samp eRate property out SampleRate DefaultValue ans 8000 To display all the property information for the nput Range property propinfo ai Channel Input Range ans Type double Constraint Bounded ConstraintValue 1 1 DefaultValue 1 1 ReadOnly 0 ReadOnl yRunning 1 DeviceSpecific 0 Functions daghel p 9 79 putdata Purpose Syntax Arguments Description Remarks 9 80 Queue data in the engine for eventual output putdata obj data obj An analog output object data The data to be queued in the engine putdata obj data queues the data specified by data in the engine for eventual output to the analog output subsystem dat a must consist of a column of data for each channel contained by 0bj More About Queueing Data e Data must be queued in the engine beforeobj is executed e put data isa blocking function since it returns execution control to the MATLAB workspace only when the requested number of samples are queued in the engine for each channel group member e If the value of the Repeat Out put property is greater than 0 then all queued data is automatically requeued until the Repeat Out put valueis reached Repeat Out put must be configured beforestart is issued e After obj executes you can continue t
41. contain only letters numbers and underscores and must begin with a letter Create the analog input object ai for a sound card and add two channels to it al analoginput winsound addchannel ai 1 2 To assign a descriptive name to the first channel contained by ai Chanl ai Channel 1 set Chanl Channel Name Joe Y ou can now reference this channel by name instead of by index set ai Joe Units Decibels Functions addchannel ChannelSkew Purpose Description Characteristics Values See Also Specify the time between consecutive scanned hardware channels Channel Skew applies only to scanning hardware and not to simultaneous sample and hold SS H hardware For scanning hardware Channel Skew is configurable only when Channel SkewMode is set toManual If Channel SkewMode is Set toMi ni mum or Equisample then Channel Skew is automatically set to the appropriate device specific read only value For SS H hardware the only valid Channel Skew valueis zero SS H hardware includes Agilent Technologies devices and sound cards TheChannel Skew value is specified in seconds Usage Al Common Access Read write depends on Channel SkewMode value Data type Double Read only Yes when running For all supported hardware the default value is zero For SS H hardware the only valid value is zero For scanning hardware the value depends on Channel SkewMode Properties Channel SkewMode 10 21
42. for a sound card lt Toolbox device objects lt Hardware subsystems al analoginput winsound ao analogoutput winsound Y ou can now create a device object array consisting of ai andao using the usual MATLAB syntax To create the row array x x ai ao Index Subsystem Na me 1 Analog Input wi nsound0 Al 2 Analog Output wi nsound0 AO 3 5 3 The Data Acquisition Session 3 6 To create the column array y y ai ao Notethat you cannot createa matrix of device objects For example you cannot create the matrix z ai ao ai ao 27 Error using gt analoginput vertcat Only a row or column vector of device objects can be created Depending on your application you may want to pass an array of device objects toa function For example using one call tothes et function you can configure both ai andao tothe same property value set x SampleRate 44100 Refer to Chapter 9 Function Reference to see which functions accept a device object array as an input argument Where Do Device Objects Exist When you create a device object it exists in both the MATLAB workspace and the data acquisition engine For example suppose you create the analog input object ai for a sound card and then make a copy of ai al analoginput winsound newai ai The copied device object newai is identical to the original device object
43. information by typing help daq TheReadme HTML file contains toolbox modifications and bug fixes You can display this information by typing whatsnew daq Documentation Examples This guide provides detailed examples that show you how to acquire or output data These examples are collected in the example index which is available through the Help browser Some examples are constructed as mini applications that illustrate one or two important features of the toolbox and serve as templates so you can see how to build applications that suit your specific needs These examples are included as toolbox M files and are treated as demos Y ou can list all Data Acquisition Toolbox demos by typing help daqdemos All documentation example M files begin with daqdoc Torun an example type the M file name at the command line Note that most analog input Al and analog output AO examples are written for sound cards To use these examples with your hardware device you should modify the adaptor name and the device ID supplied to the creation function as needed Understanding the Toolbox Capabilities Additionally most documentation examples are written for clocked subsystems However some supported hardware devices particularly ComputerBoards devices do not possess onboard clocks Ifthe Al or AO subsystem of your hardware device does not have an onboard clock then these examples will not work To use the documentation examples you can
44. nidaq 1 chans addchannel ai 0 2 Toreturn the parent for channel 2 parent ai Channel 2 Parent parent iS an exact copy of ai isequal ai parent ans 1 Port Purpose Description Characteristics Values Example See Also Specify the port ID Hardware lines are often grouped together as a port Digital 1 0 subsystems can consist of multiple ports and typically have eight lines per port When adding hardware lines to a digital I O object with add i ne you can specify the port ID The port ID is stored in the Port property If the port ID is not specified then the smallest port ID value is automatically used Usage DIO Line Access Read only Data type Double Read only N A when running The port ID is defined when line are added to the digital 1 O object with addline Create the digital O object di o and add two hardware channels to it dio digitalio nidaq 1 addline dio 0 1 In You can usePort property to return the port Ds associated with the lines contained by dio dio Line Port ans 0 0 Functions addline 10 59 RepeatO utput Purpose Description Characteristics Values Example See Also 10 60 Specify the number of additional times queued data is output Tosend data to an analog output subsystem it must first be queued in the data acquisition engine with the put dat a function If you want to continuously output the same data you can
45. obj showdaqevents obj index showdagevents struct showdagevents struct index out showdaqevents obj index struct out showdaqevents showdaqevents index for obj showdaqevents structurestruc showdaqevents index stored in An analog input or analog output object The event index An event structure A one column cell array of event information obj displays a summary of the event log for obj obj index displays a summary of the events specified by struct displays a summary of the events stored in the t struct index displays a summary of the events specified by thestructurestruct out showdagevents outputstheevent information toa one column cell array out Each element of out is a string that contains the event information associated with that index value Y ou can pass a structure of event information tos howdaqevents This structure can be obtained from the get dat a function thedaqread function or the EventLog property show daqevents Example See Also Create the analog input object ai for a sound card add two channels to it and configure ai to execute three triggers ai analoginput winsound ch addchannel ai 1 2 set ai TriggerRepeat 2 Start ai and display the trigger event information with showdaqevents start ai showdagevents ai 2 4 2 Trigger 1 17 07 06 0 Channel N A 3 Trigger 2 17 07 07 8000 Channel N A 4 Trigger 3 1
46. out length obj Channel out length obj Line obj A device object or array of device objects obj Channel The channels contained by obj obj Line The lines contained by obj out A double out length obj returns the length of the device object obj toout out length obj Channel returns the length of the channel group contained by obj out length obj Line returns the length of the line group contained by obj Create the analog input object ai for a National Instruments board and add eight channels to it al analoginput nidaq 1 aich addchannel ai 0 7 Create the analog output object ao for a National Instruments board add one channel to it and create the device object array ai ao ao analogoutput nidaq 1 aoch addchannel ao 0 aiao ai ao Index Subsystem Name 1 Analog Input nidagl Al 2 Analog Output ni daql AO 9 67 length See Also 9 68 To find the length of ai ao lengt h ai ao ans 2 To find the length of the analog input channel group lengt h ai ch ans 8 Functions size load Purpose Syntax Arguments Description Remarks Load device objects channels or lines into the MATLAB workspace load file load file obj1l obj2 out load file obj1 obj2 file The MAT file name obj 1 obj 2 Device objects an array of device objects channels or lines out A structure containing the loaded device objects
47. peekdata Al 1000 set P ydata data set T String sprintf Number of peekdata calls num2str 1 drawnow Pose Ds end while strcemp Al Running On end 5 Clean up When you no longer need A you should remove it from memory and from the MATLAB workspace delete Al clear Al As you run this example you may not preview all 80 000 samples stored in the engine This is because the engine may store data faster than it can be displayed and peekdat a does not guarantee that all requested samples are processed Managing Acquired Data Extracting Data from the Engine Many data acquisition applications require that data is acquired at a fixed often high rate and that the data is processed in some way immediately after it is collected For example you may want to perform an FFT on the acquired data and then save it to disk When processing data you must extract it from the engine If acquired data is not extracted in a timely fashion it may be overwritten Data is extracted from the engine with theget dat a function For example to extract 1000 samples for the analog input object ai data getdata ai 1000 In addition to returning acquired data get dat a can return relative time absolute time and event information As shown below dat a isan m by n array containing acquired data where m is the number of samples and n is the number of channels d11 dy2 da 0 dm dm2 da dz dmn
48. the associated hardware driver adaptor is automatically registered so that the data acquisition engine can make use of its services The hardware driver adaptors included with the toolbox are all located in the daq private directory The full name for each adaptor is shown below Table A 1 Supported Vendors and Full Adaptor Names Vendor Full Adaptor Name National Instruments mwni daq dl ComputerB oards mwcbi dl Agilent Technologies mwhpe1432 dil Windows sound cards mwwinsound dl If for some reason a toolbox adaptor is not automatically registered then you need to register it manually using thedagqregister function For example to manually register the sound card adaptor dagregister winsound If you are using a third party adaptor then you may need to register it manually If so you must supply the full pathname to da qr egi ster For example to register the third party adaptor myadaptor dl daqregister D MATLABR12 tool box daq myadaptors myadaptor dll Note You must install the associated hardware driver before adaptor registration can occur A 19 A Troubleshooting Your Hardware A 20 Contacting The MathWorks If you need support from The MathWorks visit our Web site at http www mathworks com support or e mail us at support mat hworks com Before contacting The MathWorks you should run thedaqsupport function This function returns diagnostic information such as e T
49. you should remove the object from the MATLAB workspace To remove device objects and other variables from the MATLAB workspace use the cl ear command clear al If you usecl ear on a device object that is connected to hardware the object is removed from the workspace but remains connected to the hardware You can restore cleared device objects to MATLAB with thedagfi nd function 3 25 3 The Data Acquisition Session 3 26 Getting Started with Analog Input Overview Creating an Analog Input Object Adding Channels to an Analog Input Object Referencing Individual Hardware Channels Example Adding Channels for a Sound Card Configuring Analog Input o The Sampling Rate Trigger Types The Samples to Acquire per Trigger Acquiring Data Starting the Analog Input Object Logging Data Stopping the Analog nput Object Analog Input Examples Acquiring Data with a Sound Card Acquiring Data with a National Instruments Board Evaluating the Analog id PREE Status Status Properties The Display Summary 4 G etting Started with Analog Input 4 2 Overview Analog input Al subsystems convert real world analog input signals from a sensor into bits that can be read by your computer Perhaps the most important of all the subsystems commonly available Al subsystems are typically multi channel devices offering 12 or 16 bits of resolution The Data Acquisition Toolbox provides access t
50. 32 39 and 48 55 ComputerBoards Devices For ComputerBoards devices nput Type canbeDif ferential orSingleEnded Channels configured for differential input are not connected to a fixed reference such as earth and the input signals are measured as the difference between two terminals Channels configured for single ended input are connected toa common ground and input signals are measured with respect to this ground Agilent Technologies Devices For Agilent Technologies devices the only valid nput Type valueis Differential Channels configured for differential input are not connected to a fixed reference such as earth and the input signals are measured as the difference between two terminals Sound Cards For sound cards the only valid nput Type valueisAC Coupl ed When input channels are AC coupled they are connected so that constant DC signal levels are suppressed and only nonzero AC signals are measured 5 5 5 Doing More with Analog Input 5 6 Sampling Rate The sampling rate is defined as the per channel rate in samples second that an analog input subsystem converts analog data to digital data Y ou specify the sampling rate with the Samp eRate property The maximum rate at which channels are sampled depends on the type of hardware you are using If you are using simultaneous sample and hold SS H hardware such as a sound card then the maximum sampling rate for each channel is given by the maximum board
51. 5 27 5 Doing More with Analog Input 5 28 Capturing Postrigger Data In some circumstances you may want to capture data after the trigger occurs Such data is called postrigger data When capturing postrigger data the SamplesPerTrigger property value and the number of postrigger samples are equal Capturing postrigger data is illustrated below Postrigger samples Trigger occurs I Data stored in engine SamplesPerTrigger Y ou can capture postrigger using any supported trigger type Example Voice Activation and Pretriggers This example modifies daqdoc5_3 such that 500 pretrigger samples are acquired Y ou can run this example by typing daqdoc5_4 at the MATLAB command line 1 Create a device object Createthe analog input object Al Voi ce for a sound card The installed adaptors and hardware I Ds are found with daqhwi nfo AlVoice analoginput winsound Al Voice analoginput nidaq 1 Al Voice analoginput cbi 1 2 Add channels Add one hardware channel toAl Voi ce chan addchannel Al Voice 1 chan addchannel AlVoice 0 For NI and CBI Configuring Analog Input Triggers 3 Configure property values Define a 2 second acquisition and configure a software trigger The source of the trigger ischan and the trigger executes when a rising voltage level has a value of at least 0 2 volt Additionally 500 pretrigger samples are collected duration 2 two secon
52. 6 6 Analog Output Data Management Properties Property Name Description MaxSampl esQueued Indicate the maximum number of samples that can be queued in the engine Repeat Out put Specify the number of additional times queued data is output Ti meout Specify an additional waiting time to queue data Queuing Data with putdata Before data can be sent to the analog output hardware you must queue it in the engine Queuing data is managed with the put dat a function One column of data is required for each channel contained by the analog output object F or example to queue one second of data for each channel contained by the analog output object ao ao analogoutput winsound addchannel ao 1 2 data sin linspace 0 2 pi 8000 putdata ao data data 6 17 6 Analog O utput A data source consisting of m samples and n channels is illustrated below d11 012 din d21 d22 d n d31 d32 dap Data source Each column represents a separate output channel dm dm2 dmn Rules for Using putdata Using put data to queue data in the engine follows these rules e You must queue data in the engine before starting the analog output object e f the value of theRepeat Out put property is greater than 0 then all queued data is automatically requeued until theRepeat Out put valueis reached You must configureRepeat Out put beforestart is issued e While the analog output object is running you can continue t
53. 8 7 M makenames 9 71 managing data acquired 5 9 output 6 17 manual trigger Al object 5 23 AO object 6 22 mapping channels to hardware Ds 3 9 MAT file device objects saving to 8 5 properties saving to 8 3 maximum samples queued 10 51 MaxSamplesQueued 6 18 Measurement and Automation Explorer A 3 hardware configuration 2 17 memory resources B 2 mono mode 4 7 most significant bit DIO 7 8 multifunction boards 1 6 multiple device objects array 3 5 starting 6 37 stopping 6 38 multiplexing 1 12 mux board adding channels 9 17 channel indices 9 72 muxchani dx 9 72 Index N Name Al object 4 3 AO object 6 4 DIO object 7 3 National Instruments hardware AISENSE 11 10 channel configuration 5 5 data transfer mechanisms 11 25 driver A 3 properties 11 3 trigger types Al object 5 38 AO object 6 25 troubleshooting A 3 native data getdata 9 57 offset 10 53 putdata 9 80 scaling 10 55 NI DAQ driver A 3 noise 1 33 Nyquist frequency 4 16 Nyquist theorem 1 35 0 obj2mfile 8 3 object constructor 3 4 onboard clock 1 23 one shot acquisition 5 30 online help 2 20 output range 6 34 outputting data 3 22 continuous 6 22 holding the last value 11 16 single point 9 82 overloaded functions 9 2 overrange condition 1 22 P PC dock 1 23 peekdata 5 9 polarity 1 22 engineering units Al 5 56 polling the data block 5 11 port characteristics 7 5 port configurable device 7 5 postriggers 5 28 precision 1 31 pretrig
54. 9 11 addchannel Example 9 12 thenamesLeft for thefirst channel andRi ght for the second channel You can change these default channel names when the device object is created or any time after the channel is added National Instruments Suppose you create the analog input object Al 1 for a National Instruments board and add the first four hardware channels channels 0 3 to it All analoginput nidaq 1 addchannel Al 1 0 3 Thechannels are automatically assigned the indices 1 4 If you want to add the first four hardware channels toAl 1 and assign descriptive names to the channels addchannel Al1 0 3 chanl chan2 chan3 chan4 Note that you can use the makena mes function to create a cell array of channel names If you add channels 4 5 and 7 to the existing channel group addchannel A11 4 5 7 the new channels are automatically assigned the indices 5 7 Suppose instead you add channels 4 5 and 7 tothe channel group and explicitly assign them indices 1 3 addchannel All 4 5 7 1 3 The new channels are assigned the indices 1 3 and the previously defined channels are reindexed as indices 4 7 However if you assigned channels 4 5 and 7 to indices 6 8 an error is returned since there is a gap in the indices index 5 has no associated hardware channel addchannel See Also Sound Card Suppose you create the analog input object Al 1 for a sound card Most sound cards have only two c
55. AO Common Access Read only Data type Six element vector of doubles Read only N A when running The value is automatically updated when the trigger executes The default value is a vector of zeros Create the analog input object ai for a sound card and add two hardware channels to it al analoginput winsound chans addchannel ai 1 2 After starting ai the trigger immediately executes and the trigger time is recorded start ai abstime ai InitialTriggerTi me abstime 1 0e 003 1 9990 0 0020 0 0190 0 0130 0 0260 0 0208 To convert the clock vector to a more convenient form t fix abstime sprintf d d d t 4 t 5 t 6 ans 13 26 20 InitialTriggerTime See Also Functions getdata Properties EventLog Logging Sending 10 37 InputOverRangeAction Purpose Description Characteristics Values See Also 10 38 Specify the M file action function to execute when acquired data exceeds the valid hardware range An input overrange event is generated immediately after an overrange condition is detected for any channel group member This event executes the action function specified for nput OverRangeAction An overrange condition occurs when an input signal exceeds the range specified by the nput Range property Overrange detection is enabled only if the analog input object is running and an action function is specified for Input OverRangeAction Input overrange event infor
56. Additionally reading and writing line values are not clocked at a specific ratein the way that data is sampled by an analog input or analog output subsystem nstead values areeither written directly to digital lines with put val ue or read directly from digital lines with get value Therefore the concept of a running digital I O object does not make sense in the same way that it does for analog input and analog output objects H owever you can run a digital I O object to perform one task generate timer events Y ou can use ti mer events to update and display the state of the digital I O object For an example of this refer tothedi opanel demo Timer Events The only event supported by digital I O objects is a timer event Timer events occur after a specified period of time has passed Properties associated with generating timer events are given below Table 7 3 Digital I O Timer Event Properties Property Name Description Running Indicates if the device object is running Timer Action Specifies the M file action function to execute whenever a predefined period of time passes Timer Period Specifies the period of time between timer events A timer event is generated whenever thetime specified byTi mer Peri od passes This event executes the action function specified for Ti mer Acti on Timeis measured relative to when the device object starts running Running is On Starting a digital I O object is discussed in th
57. Cards The Recording Control panel is shown below You enable the CD or microphone for recording when the Select check box is checked for the CD Balance or Microphone Balance controls respectively E Recording Control Big Options Help CD Microphone Line Balance Balance Balance e F H 9 54 0 8 Volume Volume Volume tp ot T Select I Select AudioPCI Mixer Microphone and Sound Card Types Y our microphone will be one of two possible types powered or unpowered Y ou can use powered microphones only with Sound Blaster or Sound Blaster compatible microphone inputs You can use unpowered microphones with any sound card microphone input Many laptops must use unpowered microphones since they do not have Sound Blaster compatible sound cards As shown below you can easily identify these two microphone types by their jacks m U npowered microphone jack Powered microphone jack Y ou can find out which sound card brand you have installed by selecting the Devices tab on the Multimedia Properties dialog box Refer to Troubleshooting Sound Cards on page A 12 for a picture of this dialog box A 15 A Troubleshooting Your Hardware A 16 Testing with a Microphone To test your sound card with a microphone follow these steps 1 Plug the microphone into the appropriate sound card jack For a Sound Blaster sound card this jack is labeled MIC IN Record audio da
58. However the toolbox does not preserve configuration information that is not directly associated with your hardware For example channel name information is not preserved Refer to Appendix A Troubleshooting Y our Hardware for more information about using vendor tools General Toolbox Information To display general information about the Data Acquisition Toolbox out daghwinfo out Tool boxName Data Acquisition Tool box Tool boxVersion 1x39 char Matl abVersion 6 0 0 74976 R12 InstalledAdaptors 4x1 cell Thel nstalledAdaptors field lists the hardware driver adaptors installed on your system To display the installed adaptors out InstalledAdaptors ans chi hpel432 nidaq winsound 2 17 2 G etting Started with the Data Acquisition Toolbox 2 18 This information tells you that an adaptor is available for ComputerBoards Agilent Technologies National Instruments and sound card devices Note Toolbox adaptors are available to you only if the associated hardware driver is installed on your platform Adaptor Specific Information To display hardware information for a particular vendor you must supply the adaptor name as an argument todaqhwi nf o The supported vendors and adaptor names are given in The Hardware Driver Adaptor on page 2 7 F or example to display hardware information for the wi nsound adaptor out daqhwinfo winsound out Adaptor DII Name d v6 tool box daq
59. Instruments Board 4 19 Evaluating the Analog Input Object Status 4 22 Status Properties oooooococococo 4 22 The Display Summary 00 000 c eee ee 4 23 Doing More with Analog Input 9 Overview cias es 5 2 Configuring and Sampling Input Channels 5 3 Input Channel Configuration 000 0 eee o 5 4 Sampling Rate 0 ccccccococo 5 6 iv Contents Channel Skew oh ade ola Fi dock hha i ok aoe Peak hae Bbw ae 5 7 Managing Acquired Data 0000 e eee 5 9 Previewing Data s ileur are perean ea a ai Pabean NRS 5 9 Extracting Data from the Engine 0 0005 5 13 Returning Time Information ssa sssaaa aaaea 5 18 Configuring Analog Input Triggers 5 20 Defining a Trigger Trigger Types and Conditions 5 21 Executing the Trigger 0 0 cece ee eee ee 5 26 Trigger Delays orian ore Mat a oe eden eee 5 26 Repeating TriggerS 0 cece ect eee 5 30 How Many Triggers Occurred auraa eee eee 5 36 When Did the Trigger Occur 0 000 e eee eee 5 37 Device Specific Hardware TriggerS 00 0 ee 5 37 Configuring Events and Actions 5 46 EVENT TY PGS sie ona a shh a bid aa a a 5 46 Recording and Retrieving Event Information 5 49 Creating and Executing Action Functions 5 52 Examples Using Action Properties and Functions
60. Interrupt signals can be generated when one sample is acquired or when multiple samples are acquired A component of a digital O subsystem that you can read digital values from or write digital value to The collection of lines contained by a digital I O object Line properties Logging Noise Onboard clock Output range Postrigger data Precision Pretrigger data Properties Quantization Queuing data Running Sample rate Sampling Properties that are configured for individual lines A state of the Data Acquisition Toolbox where an analog input object stores acquired data to memory or a log file Any measurement that is not part of the phenomena of interest A timer chip on the hardware board which is programmed to generate a pulse train at the desired rate n most cases the onboard clock controls the sampling rate of the board The span of output values for which a D A conversion is valid Data that is acquired and stored in the engine after the trigger event occurs A determination of how exactly a result is determined without reference to what the result means Data that is acquired and stored in the engine before the trigger event occurs A characteristic of the tool box or the hardware driver that you can configure to suit your needs The property types supported by the toolbox include base properties device specific properties common properties and channel or line properties The process
61. Rules for Using peekdata e You can call peekdata before a trigger executes Therefore peekdata is useful for previewing data before it is logged to the engine or to a disk file e In most cases you will call peekdat a while the device object is running However you can call peekdat a once after the device object stops running e Ifsamples is greater than the number of samples currently acquired all available samples are returned with a warning message stating that the requested number of samples were not available peekdata Example See Also Create the analog input object ai for a National Instruments board add eight input channels and configure ai for a two second acquisition al analoginput nidaq 1 addchannel ai 0 7 set ai SampleRate 2000 set ai SamplesPerTrigger 4000 After issuing thest art function you can preview the data start ai data peekdata ai 100 peekdata returns 100 samples todata for all eight channel group members If 100 samples are not available then whatever samples are available will be returned and a warning message is issued The data is not removed from the data acquisition engine Functions getdata getsample Properties SamplesAvailable 9 77 propinfo Purpose Syntax Arguments Description 9 78 Return property characteristics for device objects channels or lines out propinfo obj out propinfo obj obj PropertyName out out pr
62. acquired from a microphone amplified digitized by a sound card and stored in MATLAB for subsequent analysis of frequency content 1 Introduction to Data Acquisition Data from a computer is converted into an analog signal and output to an actuator For example a vector of data in MATLAB is converted to an analog signal by a sound card and output to a loudspeaker Data Acquisition Hardware Data acquisition hardware is either internal and installed directly into an expansion slot inside your computer or external and connected to your computer through an external cable For example VXI modules are installed in an external VXI chassis and data is transferred between MATLAB and the module using an external link such as FireWire IEEE 1394 At the simplest level data acquisition hardware is characterized by the subsystems it possesses A subsystem is a component of your data acquisition hardware that performs a specialized task Common subsystems include e Analog input e Analog output e Digital input output e Counter timer Hardware devices that consist of multiple subsystems such as the one depicted below are called multifunction boards Analoginput Analogoutput subsystem subsystem Digital 1 O Counter timer subsystem subsystem The Data Acquisition System Analog Input Subsystems Analog input subsystems convert real w
63. ai with thewhos command whos ai Name Size Bytes Class al 1x1 1332 analoginput object Grand total is 52 elements using 1332 bytes Once the analog input object is created the properties listed below are automatically assigned values These general purpose properties provide descriptive information about the object based on ts class type and adaptor Table 4 1 Descriptive Analog Input Properties Property Name Description Na me Specify a descriptive name for the device object Type Indicate the device object type Y ou can display the values of these properties for ai with theget function get ai Name Type ans nidaql Al Analog Input 4 3 4 G etting Started with Analog Input 4 4 Adding Channels to an Analog Input Object After creating the analog input object you must add hardware channels to it As shown by the figure in Adding Channels or Lines on page 3 8 you can think of a device object as a container for channels The collection of channels contained by the device object is referred to as a channel group As described in Mapping Hardware Channel I Ds to MATLAB Indices on page 3 9 a channel group consists of a mapping between hardware channel Ds and MATLAB indices see below When adding channels to an analog input object you must follow these rules e The channels must reside on the same hardware device Y ou cannot add channels from different devices or from dif
64. analoginput objects the data is scaled whileit is extracted from the engine with theget dat a function according to the formula scaled value A D value units range sensor range The A D value is constrained by the nput Range property which reflects the gain and polarity of your analog input channels The sensor range is given by the SensorRange property which reflects the range of data you expect from your sensor For analog output objects t he data is scaled when it is queued in the engine with the put data function according to the formula scaled value original value output range units range The output range is constrained by the Out put Range property which specifies the gain and polarity of your analog output channels For both objects you can also use the Uni ts property to associate a meaningful label with your data Usage Al AO Channel Access Read write Data type Two element vector of doubles Read only No when running The default value is determined by the default value of the nput Range or the Out put Range property Functions getdata putdata Properties InputRange Output Range SensorRange Units UserData Purpose Description Characteristics Values Example Store data that you want to associate with a device object UserData stores data that you want to associate with the device object Usage Al AO DIO Common Access Read write Data type Any type Read only No when
65. analogoutput nidaq 1 addchannel ao 0 1 OutputRange See Also You can return the output ranges supported by the board with the Out put Ranges field of thedaghwi nf o function out daqhwinfo ao out Output Ranges ans 0 0000 10 0000 10 0000 10 0000 Toconfigure both channels contained by ao to output signals between 10 volts and 10 volts ao Channel OutputRange 10 10 Alternatively you can use thes et veri fy function to configure and return the Out put Range value Actual Range setverify ao Channel OutputRange 10 10 Functions daqhwinfo setverify Properties Units UnitsRange 10 57 Parent Purpose Description Characteristics Values Example 10 58 Indicate the parent device object of a channel or line The parent of a channel line is defined as the device object that contains the channel line Y ou can create a copy of the device object containing a particular channel or line by returning the value of Parent You can treat this copy like any other device object For example you can configure property values add channels or lines to it and so on Usage Al AO Channel DIO Line Access Read onl y Data type Device object Read onl y N A when running The value is defined when channels or lines are added to the device object Create the analog input object ai for a National Instruments board and add three hardware channels to it al analoginput
66. ans l 0 0500 0 0500 0 5000 0 5000 5 0000 5 0000 10 0000 10 0000 To configure both channels contained byai to accept input signals between 10 volts and 10 volts ai Channel InputRange 10 10 Alternatively you can use theset verify function Actual Range setverify ai Channel InputRange 10 10 Functions daqhwinfo setverify Properties InputOverRangeAction SensorRange Units UnitsRange InputType Purpose Specify the analog input hardware channel configuration Description For National Instruments devices nput Type can beSingleEnded Differential orNonReferencedSi ngl eEnded For ComputerBoards devices Input Type can beSingl eEnded or Differential for Agilent Technologies devices nput Type can only beDi f ferential For sound cards nput Type can only beAC Coupled If channels have been added to a National Instruments or ComputerBoards analog input object and you changethe nput Type value then the channels are automatically deleted if the hardware reduces the number of available channels Characteristics Usage Al Common Access Read write Data type String Read only Yes when running Values National Instruments Differential Channels are configured for differential input SingleEnded Channels are configured for single ended input NonReferenced This channel configuration is used when the input SingleEnded signal has its own ground reference which is tied tothe negative i
67. are automatically defined when lines are added to the digital O object with theadd i ne function The default value is one Suppose you create the digital I O object di o and add four hardware lines toit dio digitalio nidaq 1 addline dio 0 3 out addline automatically assigns theindices 1 4 tothese hardware lines You can swap the hardware lines associated with index 1 and index 2 with HwLi ne dio Line 1 HwLine 1 dio Line 2 HwLine 0 Functions addline Properties Line Index 10 33 Index Purpose Description Characteristics Values 10 34 Indicate the MATLAB index of a hardware channel or line Every hardware channel line contained by a device object has an associated MATLAB index that is used to reference that channel line For example to configure property values for an individual channel you must reference the channel through the Channel property using the appropriate ndex value Likewise to configure property values for an individual line you must reference the line through theLi ne property using the appropriate ndex value For channels lines you can assign indices automatically with theaddchanne add i ne function Channel line indices always begin at 1 and increase monotonically up to the number of channels lines contained by the device object For channels index assignments can also be made manually with the addchannel function For scanning hardware the scan order
68. by the Data Acquisition Toolbox include analog input Al analog output AO and digital 1 O DIO objects Access whether the property is read write or read only Read write property values can be returned with the get command and configured with thes et command Read only property values can be returned with theget command but cannot be configured with thes et command Data type the property data type The supported data types include action function double string Channel Line and any Read only when running whether a property value can be configured while the device object is running Valid property values including the default value When property values are given by an enumerated list the default value is usually indicated by Default values for some properties are calculated by the data acquisition engine while others are determined by the hardware driver If there are device specific enumerated values they are listed separately e An example using the property e Related properties and functions BitsPerSample Purpose Description Characteristics Values Specify the number of bits the sound card uses to represent each sample BitsPerSampl e can be8 or16 I1fBitsPerSample is8 thesound card represents each sample with 8 bits This means that each sample can be represented by any number between O and 255 If Bi tsPer Sampl e is16 the sound card represents each sample with 16 bits This means that ea
69. by the run time error event to storethe descriptive message that is generated when a run time error occurs This message is also displayed at the MATLAB command line Example Retrieving Event Information Suppose you want to examine the events logged for the example given by Example Queuing Data with putdata on page 6 19 You can do this by accessing the EventLog property events AQ EventLog events 3x1 struct array with fields Type Data By examining the contents of the Ty pe field you can list the events that were recorded while A0 was running events Type ans Start Trigger Stop Configuring Events and Actions To display information about the trigger event you must access the Dat a field which stores the absolute time the trigger occurred and the number of samples output when the trigger occurred trigdata events 2 Data trigdata AbsTime 1999 4 16 9 53 19 9508 Rel Sample 0 Alternatively you can usetheshowdaqevents function to display event information showdagevents events 2 2 Trigger 09 53 19 0 Examples Using Action Properties and Action Functions Examples showing how to create action functions and configure action properties are given below Displaying the Number of Samples O utput This example illustrates how to generate samples output events You can run this example by typing daqdoc6_4 at the MATLAB command line The dagdoc6_4disp action function displays t
70. by typingdaqdoc4_1 at the MATLAB command line 1 Create a device object Create the analog input object Al for a sound card The installed adaptors and hardware IDs are found with daghwi nfo Al analoginput winsound 2 Add channels Add one channel toA chan addchannel Al 1 3 Configure property values Assign values to the basic setup properties and create the variables bl ocksi ze andFs which are used for subsequent analysis The actual sampling rate is retrieved sinceit may beset by the engine to a value that differs from the specified value duration 1 l second acquisition set Al SampleRate 8000 Actual Rate get Al SampleRate set Al SamplesPerTrigger duration Actual Rate set Al TriggerType Manual blocksize get Al SamplesPerTrigger Fs Actual Rate 4 Acquire data Start Al issue a manual trigger and extract all data from the engine Beforestart is issued you should begin inputting data from the tuning fork into the sound card start Al trigger Al data getdata Al 4 16 Analog Input Examples 5 Clean up When you no longer need Al you should remove it from memory and from the MATLAB workspace delete Al clear Al Analyzing the Data For this example analysis consists of finding the frequency components of the tuning fork and plotting the results To do so the function daqdocf ft was created This function calculates the FFT of dat a and requires the
71. can invokedi sp by typing the device object at the MATLAB command line or by excluding the semicolon when creating a device object when adding channel or lines or when configuring property values using the dot notation All the commands shown below produce summary information for the device object Al or the channels contained by Al Al anal oginput winsound chans addchannel Al 1 2 Al SampleRate 44100 Al Channel 1 Channel Name CH1 chans flushdata Purpose Syntax Arguments Description Example Remove data from the data acquisition engine flushdata obj flushdata obj mode obj An analog input object or array of analog input objects mode Specifies how much data is removed from the engine ushdata obj removes all data from the data acquisition engine and resets heSamplesAvailable property to zero ro flushdata obj mode removes data from the data acquisition engine depending on the value of mode If mode isal all data is removed from the engine and theSamp es Avail able property is set to O This is the same as flushdata obj Ifmode istri ggers then data is removed from the engine only when the data corresponds to an integral number of triggers triggers is a valid choice only when theTri gger Repeat property is greater than O and the Sampl esPerTrigger property is noti nf Create the analog input object ai for a National Instruments board and add hardware channel
72. can output a single sample with the put samp e function Cha racteristics Usage Access Data type Read only when running Values Off On See Also Functions putsample Properties Running 10 74 AO Common Read only String N A Data is not being sent to the analog output hardware Data is being sent to the analog output hardware SensorRange Purpose Description Characteristics Values See Also Specify the range of data you expect from your sensor You useSensor Range to scale your data to reflect the range you expect from your sensor You can find the appropriate sensor range from your sensor s specification sheet F or example an accelerometer might have a sensor range of 5 volts which corresponds to 50 g s 1 g 9 80 m s s The data is scaled while it is extracted from the engine with the get dat a function according to the formula scaled value A D value units range sensor range The A D value is constrained by the nput Range property which reflects the gain and polarity of your hardware channels The units range is given by the UnitsRange property Usage Al Channel Access Read write Data type Two element vector of doubles Read only No when running The default value is determined by the default value of the nput Range property Functions getdata Properties InputRange Units UnitsRange 10 75 StartAction Purpose Specify the M file action function to
73. channels setting property values and using specific functions to acquire data 3 Analyze the acquired data using MATLAB Simple data acquisition applications using a sound card and a National Instruments board are given below Acquiring Data with a Sound Card Suppose you must verify that the fundamental lowest frequency of a tuning fork is 440 Hz To perform this task you will use a microphone and a sound card to collect sound level data You will then perform a fast Fourier transform FFT on the acquired data tofind the frequency components of thetuning fork The setup for this task is shown below Data Source Sensor Sound Card Data Sink A wim A D J MATLAB workspace 4 15 4 G etting Started with Analog Input Configuring the Data Acquisition Session For this example you will acquire 1 second of sound level data on one sound card channel Sincethe tuning fork vibrates at a nominal frequency of 440 Hz you can configure the sound card to its lowest sampling rate of 8000 Hz Even at this lowest rate you should not experience any aliasing effects since the tuning fork will not have significant spectral content above 4000 Hz which is the Nyquist frequency After you set thetuning fork vibrating and place it near the microphone you will trigger the acquisition one time using a manual trigger Y ou can run this example
74. cleared from the workspace you can usedaqfind andtheTag value to identify and retrieve the device object clear al aicell daqfind Tag Sound ai aicell 1 Functions daqfind 10 79 Timeout Purpose Description Characteristics Values See Also 10 80 Specify an additional waiting time to extract or queue data TheTi meout value in seconds is added to the time required to extract data from the engine or queue data to the engine Since data is extracted with the get data function and queued with theput dat a function Ti meout is associated only with these two blocking functions If the requested data is not extracted or queued after waiting the required time then a timeout condition occurs and control is immediately returned to MATLAB A timeout is one of the conditions for stopping an acquisition When a timeout occurs the action function specified by Runt i meErrorAction is called Ti meout iS not associated with hardware timeout conditions Possible hardware timeout conditions include e Triggering on a voltage level and that level never occurs e Externally docking an acquisition and the external clock signal never occurs e Losing the hardware connection Tocheck for hardware timeouts you may need to poll the appropriate property value Usage Al AO Common Access Read write Data type Double Read only Yes when running The default value is one second Functions getdata putdata
75. command to display my ai m at the command line Loading the Device Object To load a device object that was saved as an M file into the MATLAB workspace type the name of the M file at the command line For example to load ai fromthe M filemyai m ai myai Note that the read only properties such as Sampl esAcqui red and Sampl esAvai lable are restored to their default values get ai SamplesAcquired SamplesAvailable ans 0 0 When loadingai into the workspace the MAT file my ai mat is automatically loaded and theTriggerAction property value is restored ai TriggerAction ans myaction 7 3071e 005 Saving and Loading Device O bjects Saving Device Objects to a MAT File You can save a device object toa MAT file just as you would any workspace variable using thes ave command For example to save the analog input objectai andthevariablet i me defined in the preceding section tothe MAT file myai 1 mat save myail ai time Read only property values are not saved Therefore read only properties use their default values when you load the device object into the MATLAB workspace To determine if a property is read only usethe propi nf o function or examine the property reference pages Loading the Device O bject To load a device object that was saved to a MAT file into the MATLAB workspace use the oad command For example toload ai and ti me from MAT filemyai 1 mat load myail 8 5 8 Saving a
76. daq private mwwinsound dll AdaptorDI Version Version 2 0 R12 05 Oct 2000 AdaptorName winsound BoardNames AudioPCl Record InstalledBoardilds 0 Obj ect ConstructorName anal oginput winsound 0 1x26 char The obj ect ConstructorName field lists the subsystems supported by the installed sound cards and the syntax for creating a device object associated with a given subsystem To display the device object constructor names available for theAudioPC l Record board out Obj ectConstruct orName ans anal oginput winsound 0 anal ogoutput winsound 0 This information tells you that the sound card supports analog input and analog output objects To create an analog input object for the sound card al analoginput winsound To create an analog output object for the sound card ao analogoutput winsound Examining Your Hardware Resources Device Object Information To display hardware information for a specific device object you must supply the device object as an argument todaqhwi nf o The hardware information for the analog input object ai created in the preceding section is given below out daghwi nf o ai out Adapt or Name Bits Coupling Devi ceName Differential Ds Gains D Input Ranges MaxSampl eRate MinSampl eRate NativeDataType Polarity Sampl eType Si ngl eEndedl Ds Subsystemlype Total Channels VendorDriverDescription
77. e Line configurable devices You can address the lines associated with a line configurable device individually This means that you can configure individual lines for either input or output Additionally you can read and write values on a line by line basis Note that for National Instruments E Series hardware port 0 is always line configurable while all other ports are port configurable Y ou can return the line and port characteristics with the daqhwi nf o function For example National Instruments AT MI O 16DE 10 board has four ports and eight digital I O lines per port Toreturn the digital I O characteristics for this board hwinfo daqhwinfo dio To display the line and port characteristics for the first port hwinfo Port 1 ans ID 0 LinelDs 0 123 45 6 7 Direction in out Config line To display the line and port characteristics for the second port hwinfo Port 2 ans ID 2 LinelDs 0 123 45 6 7 Direction in out Config port Adding Lines to a Digital l O O bject To display the line and port characteristics for the third port hwi nfo Port 3 ans 1D 3 LinelDs 0 123 45 6 7 Direction in out Config port To display the line and port characteristics for the fourth port hwi nfo Port 4 ans ID 4 LinelDs 0 123 45 6 7 Direction in out Config port This information tells you that you can configure all 32 lines for either input or output and that the fir
78. error occurs or ast op function is issued When Logging is Off you can still preview data with thepeekdat a function provided Runni ng is On However peekdata does not guarantee that all the requested data is returned Toguaranteethat acquired data contains no gaps is must be logged to memory or toa disk file Data stored in memory is extracted with theget dat a function while data stored to disk is returned with thedagread function The destination for logged data is controlled with the Loggi ngMode property Usage Al Common Access Read only Data type String Read only N A when running Of f Data is not logged to memory or a disk file On Data is logged to memory or a disk file Functions daqgread getdata peekdata stop Properties LoggingMode Running LoggingMode Purpose Description Characteristics Values See Also Specify the destination for acquired data LoggingMode can beset toDisk Memory orDisk amp Memory IfLoggingMode is set toDi sk then acquired data as well as device object and hardware information is streamed to a disk file If Loggi ngMode is set to Me mor y then acquired data is stored in the data acquisition engine If Loggi ngMode issettoDisk amp Memory then acquired data is stored in the data acquisition engine and is streamed to a disk file When logging to the engine you must extract the data with the get data function If the data is not extracted it may be overwritten When logg
79. esQueued with the daq me m function The value of MaxSampl esQueued can affect the behavior of put data For example if the queued data exceeds the value of MaxSampl es Queued then put dat a becomes a blocking function until there is enough space in the queue to add the additional data Characteristics Usage AO Common Access Read only Data type Double Read only N A when running Values The value is calculated by the data acquisition engine See Also Functions daqmem putdata 10 51 Name Purpose Specify a descriptive name for the device object Description When a device object is created a descriptive nameis automatically generated and stored in Name This nameis produced by concatenating the name of the adaptor the device ID and the device object type You can change the value of Name at any time Characteristics Usage Al AO DIO Common Access Read write Data type String Read only No when running Values The value is defined after the device object is created Example Create the analog input object ai for a sound card al analoginput winsound The descriptive name for ai is given by ai Name ans winsound0 Al 10 52 NativeOffset Purpose Description Characteristics Values Example Indicate the offset to use when converting data from native format to doubles NativeOffset along with Nati veScaling is used to convert data from your hardware s native format to doubles using th
80. follows the MATLAB index Therefore the hardware channel associated with index 1 is sampled first the hardware channel associated with index 2 is sampled second and so on To change the scan order you can assign the channel Ds to different indices using the HwChannel orChannel property Index provides a convenient way to access channels and lines programmatically Usage Al AO Channel DIO Line Access Read onl y Data type Double Read only N A when running Values are automatically defined when channels lines are added to the device object with theaddchannel addline function The default value is one Index Example See Also Create the analog input object ai for asound card and add two hardware channels to it al analoginput winsound chans addchannel ai 1 2 Y ou can access the MATLAB indices for these channels with ndex ndexl chans 1 Index Index2 chans 2 Index Functions addchannel addline Properties Channel HwChannel HwLine Line 10 35 InitialTriggerTime Purpose Description Characteristics Values Example 10 36 Indicate the absolute time of the first trigger For all trigger types ni tial Tri ggerTi me records the time when Loggi ng or Sending is set to0n The absolute time is recorded as ac ock vector You can return the nitialTriggerTi me value with theget data function or with theDat a AbsTi me field of theEventLog property Usage Al
81. function index assignments can be made automatically or manually n either case the channel indices start at 1 and increase monotonically up to the number of channel group members For example the analog input object ai created in the preceding section had the MATLAB indices 1 and 2 automatically assigned to the hardware channels O and 1 respectively To manually swap the hardware channel order you supply the appropriate index tochans and usetheHwChannel property chans 1 HwChannel 1 chans 2 HwChannel 0 Alternatively you can use the Channel property le 0 ai Channel 1 HwChannel ai Channel 2 HwChannel Note that you can also useaddchannel to specify the required channel order chans addchannel ai 1 0 Descriptive Channel Names Choosing a unique descriptive name can be a useful way to identify and reference channels particularly for large channel groups Y ou can associate descriptive names with hardware channels using theaddchannel function For example Suppose you want to add 16 single ended channels toai and you want to associate the nameTri gChan with the first channel in the group ai I nputType SingleEnded addchannel ai 0 TrigChan addchannel ai 1 15 Adding Channels to an Analog Input O bject Alternatively you can use the Channel Name property ai I nputType SingleEnded addchannel ai 0 15 ai Channel 1 Channel Name TrigChan Y ou can now use the channel na
82. higher rate or perhaps you need to add an antialias filter to remove unwanted frequency components These real world effects act as obstacles between you and a precise accurate measurement To overcome these obstacles you need to experiment with different hardware and software configurations In other words you need to perform multiple data acquisition trials 1 Introduction to Data Acquisition 1 4 The Data Acquisition System As a user of MATLAB and the Data Acquisition Toolbox you areinterested in measuring and analyzing physical phenomena The purpose of any data acquisition system is to provide you with the tools and resources necessary to do so You can think of a data acquisition system as a collection of software and hardware that connects you to the physical world A typical data acquisition system consists of these components Data acquisition hardware At the heart of any data acquisition system lies the data acquisition hardware The main function of this hardware is to convert analog signals to digital signals and to convert digital signals to analog signals Sensors and actuators transducers Sensors and actuators can both be transducers A transducer is a device that converts input energy of one form into output energy of another form F or example a microphoneis a sensor that converts sound energy in the form of pressure into electrical energy while a loudspeaker is an actuator that converts electrical
83. in the next section If you think your driver is incompatible with the Data Acquisition Toolbox then you should verify that your hardware is functioning properly before updating drivers If your hardware is functioning properly then you are probably using unsupported drivers Visit the Agilent Web site at http agilent com for the latest drivers For a list of the HP E1432 driver versions that are compatible with the Data Acquisition Toolbox refer to the product page on the MathWorks Web site at http www mathworks com products daq A 9 A Troubleshooting Your Hardware Is Your Hardware Functioning Properly To troubleshoot your Agilent hardware you should use the HP E1432 Soft Front Panel The Soft Front Panel allows you to test each module supported by the HP E1432 driver software and is installed as part of this software You can access the Soft Front Panel through the Windows Start button Start gt Programs gt hpel432 gt HP E 1432 Soft Front Panel For example suppose you want to verify that the HP E1432 moduleis operating correctly To do this you should connect a known signal such as that produced by a function generator to the module Y ou then configure the input parameters as shown below A 1 7 All Channels Identical InputMode vOLT y Chan Number p 5 Trigger OFF Range po Trig Mode leva y Coupling DC Couping Trig Level cc Grounding On Breakout Box 5 Hysteresis fo Digital
84. mn size obj Channel returns the length of the first n dimensions of the channel groupobj Channel toseparate output variables F or example m n size obj Channel returns the number of rows tom and the number of columns ton m size obj Channel di m returns the length of the dimension specified by the scalar di m For example si ze obj Channel 1 returns the number of rows d size obj Line returnsthetwo element row vector d m n containing the number of rows and columns in the line group obj Line ml m2 m3 mn size obj Line returns the length of the first n dimensions of the line group obj Line to separate output variables For example m n size obj Line returns the number of rows tom and the number of columns ton m size obj Line dim returns thelength of the dimension specified by the scalar di m For example si ze obj Line 1 returns the number of rows Create the analog input object ai for a National Instruments board and add eight channels to it al analoginput nidaq 1 ch addchannel ai 0 7 To find the size of the device object size ai ans 1 1 Tofind the size of the channel group size ch ans 8 1 Functions length 9 93 start Purpose Syntax Arguments Description Remarks See Also 9 94 Start a device object start obj obj A device object or an array of device objects start obj initiates the execution of the device object ob
85. n whole This vector represents the polynomial p x 2x 3 MATLAB responds with A 5 Choose the File menu An array is an ordered collection of information sysc d2c sysd method xxiii Preface xxiv Introduction to Data Acquisition Overview Anatomy of a Data Acquisition Experiment The Data Acquisition System Data Acquisition Hardware Sensors Signal Conditioning The Computer Software The Analog Input In Sampling Quantization Channel Configuration Transferring Data from H ardware to System Memory Making Quality Measurements Accuracy and Precision Noise Matching the Sensor Range and AID Converter Range How Fast Should a Signal be Sampled Selected Bibliography 1 11 1 13 1 39 1 Introduction to Data Acquisition Overview Before you set up any data acquisition system you should understand the physical quantities you want to measure the characteristics of those physical quantities the appropriate sensor to use and the appropriate data acquisition hardware to use The purpose of this chapter is to provide you with some general information about making measurements with a data acquisition system The topics covered should assist you in understanding the above considerations and understanding the specification sheet associated with your hardware Topics include e Anatomy of a data acquisition experiment e The data acquisition
86. not set to their default values are written tofi le obj 2mfile obj file syntax converts obj tothe equivalent MATLAB code usings yntax and savesthecodetof e Thevaluesforsyntax can beset dot Ornamed set uses the set syntax dot uses subscripted assignment dot notation and named uses named referencing if defined obj 2mfile obj file all convertsobj tothe equivalent MATLAB code using theset syntax and saves the code tof i e al l specifies that all properties are written tofile obj 2mfile obj file syntax all convertsobj including all of obj s properties to the equivalent MATLAB code usings ynt ax and saves the code to file obj2mfile Remarks Example IfUserDat a isnot empty or if any of the action properties are set to a cell array of values then the data stored in those properties is written toa MAT file when the object is converted and saved The MAT file has the same name as the M file containing the object code see the example below You can recreate the saved device objects by typing the name of the M file at the command line You can also recreate channels or lines by typing the name of the M file with a device object as the only input Create the analog input object ai for a sound card add two channels and set values for several properties al analoginput winsound addchannel ai 1 2 set ai Tag myai TriggerRepeat 4 set ai StartAction myaction 2 magic 10
87. ockSource valueof nternal is analogous to a value of Update 10 24 ClockSource ComputerBoards Internal The internal hardware clock is used Al only Software The computer clock is used External Externally control the channel clock Al only Agilent Technologies Internal The internal hardware clock is used External The external sample clock positive true Inverted The external sample clock negative true External VXI Bus 3 The VXI bus clock divided by 3 provided by some other clock master VXI BusSampl e The VXI bus sample clock Sound Cards Internal The internal hardware clock is used See Also Properties Channel Skew Samp eRate 10 25 Data MissedAction Purpose Description Characteristics Values See Also 10 26 Specify the M file action function to execute when data is missed A data missed event is generated immediately after acquired data is missed This event executes the action function specified for Dat aMi ssedAction The default value for Dat aMissedAction isdagaction which displays the event type and the device object name In most cases data is missed because e The engine cannot keep up with the rate of acquisition e The driver wrote new data into the hardware s FIFO buffer before the previously acquired data was read You can usually avoid this problem by increasing the size of the memory block with the Buff eringConfig property Data missed event inform
88. of converting an infinitely precise analog signal toa binary number This process is performed by an A D converter The process of storing data in the engine for eventual output to an analog output subsystem A state of the Data Acquisition Toolbox where a device object is executing The per channel rate in samples second that an analog input or analog output subsystem converts data The process whereby an A D converter or a D A converter takes a snapshot of the data at discrete times For most applications the time interval between samples is kept constant e g sample every millisecond unless externally clocked C G lossary Scanning hardware Sending Sensor Signal conditioning Single ended input SS H hardware Subsystem Trigger event Data acquisition hardware that samples a single input signal converts that signal to a digital value and then repeats the process for every input channel used A state of the Data Acquisition Toolbox where an analog output object is outputting sending data from the engine to the hardware A device that converts a physical variable into a signal that you can input into your data acquisition hardware The process of making a sensor signal compatible with the data acquisition hardware Signal conditioning includes amplification filtering electrical isolation and multiplexing Input channel configuration where there is one signal wire associated with each inpu
89. out For a source channel Span specifies the maximum frequency at which the output signal will correctly track the signal that the source is attempting to generate The valid values for Span depend of the current clock frequency Y ou should set the clock frequency before setting Span Normally the maximum valid span is the clock frequency divided by 2 56 Valid spans are given by the maximum span divided by powers of two and the maximum span divided by five and by powers of two The ratio between the span and the maximum span is called the decimation factor For the E1432 module the maximum number of decimate by two passes allowed is nine Therefore the maximum decimation factor is 5 29 and the minimum valid span is clock frequency 2 56 5 29 If the dock frequency is larger than 51 2 kHz then the module is unable to do a decimation factor of one In this case the minimum decimation factor is two and the maximum valid span is clock frequency 5 12 For the E1433 module the maximum number of decimate by two passes allowed is 12 so the maximum decimation factor is 5 212 Dueto limits in the module s DSP processor when the clock frequency is set higher than 102 400 Hz it is unable to do any decimation In this case the only valid span is clock frequency 2 56 If you attempt to use decimation when the clock frequency is above 102 400 Hz then an error may occur when the measurement starts For the Option 1D4 source board the ma
90. port configurable device then the data acquisition engine writes to all port configurable lines even if they are not contained by the device object e When writing decimal values If the value is too large to be represented by the lines contained by the device object then an error is returned You can write to a maximum of 32 lines To write to more than 32 lines you must use a binvec value e When writing binvec values You can writeto any number of lines There must be an element in the binary vector for each line you write to e You can always read from a line configured for output Reading values is discussed on Reading Digital Values on page 7 12 e An error is returned if you write a negative value or if you write to a line configured for input 7 11 7 Digital input O utput 7 12 Reading Digital Values Y ou can read values from one or more digital I O lines with the get val ue function get val ue requires the digital I O object as an input argument Y ou can optionally specify an output argument which represents the returned values as a binary vector Binary vectors are described in Writing Digital Values on page 7 10 For example suppose you create the digital O object di o and add eight input lines to it from port 0 dio digitalio nidaq 1 addline dio 0 7 in Toread the current value of all the lines contained by di o and return the result toout portval getvalue dio
91. properly then you are probably using unsupported drivers Visit the ComputerBoards Web site at http www computerboards com for the latest drivers Suppose you are using InstaCal software with your hardware You can access this software through the Windows Start button Start gt P rograms gt C omputerB oards gt nstaCal The driver version is available through the Help menu Help gt About InstaCal Troubleshooting C omputerBoards Hardware For example the version of InstaCal used by a PCI DAS4020 12 board is shown below Instacal el Es File Install Calibrate Test Help Pra ae al PC Board List lt a lt a gt ISA Bus lt PCI Primary bus 0 P BBd 1 PCI D About Instacal Lx Ready Version 1 10 Instacal for Windows 95 98 NT Copyright 1998 99 ComputerBoards Inc 16 Commerce Boulevard Middleboro MA 02346 USA phone 508 946 5100 fax 508 946 9500 internet site http www computerboards com e mail info computerboards com A 7 A Troubleshooting Your Hardware A 8 Is Your Hardware Functioning Properly To troubleshoot your ComputerBoards hardware you should use the test feature provided by InstaCal To access this feature select the board you want to test from the PC Board List and select Analog from the Test menu For example suppose you want to verify that the analog input subsystem on your PCI DAS4020 12 board is operating correctly To
92. simultaneous sampling of all channels Simultaneous sample and hold hardware is discussed in the next section 1 18 The Analog Input Subsystem Simultaneous Sample and Hold Hardware Simultaneous sample and hold SS H hardware samples all input signals at the same time and holds the values until the A D converter digitizes all the signals For high end systems there can be a separate A D converter for each input channel For example suppose you need to simultaneously measure the acceleration of multiple accelerometers to determine the vibration of some device under test Todothis you must useSS H hardware since it does not have a channel skew In general you may need to use SS H hardware if your sensor signal changes significantly in a time that is less than the channel skew or if you need to use a transfer function or perform a frequency domain correlation The sample period for a multichannel configuration using SS H hardware is shown below Note that there is no channel skew A Group Group Group scan 1 scan 2 scan n O o O O ie O Y o O o E E Oo O Oo 2 8 O o o O o O Sample period gt Time 1 19 1 Introduction to Data Acquisition 1 20 Quantization As discussed in the previous section sampling takes a snapshot of the input signal at an instant of time When the snapshot is taken the sampled analog signal must be converted from a voltage value to a binary number that the c
93. supports a hardware digital trigger For a description of device specific trigger types refer to Device Specific Hardware Triggers on page 6 25 or theTri ggerType reference pages in Chapter 10 Base Property Reference G etting Started with Analog O utput Outputting Data After you configure the analog output object you can output data Outputting data involves these three steps 1 Queuing data 2 Starting the analog output object 3 Stopping the analog output object Queuing Data in the Engine Before you can start the device object data must be queued in the engine Data is queued in the engine with the put dat a function For example to queue one second of data for each channel contained by the analog output object ao ao analogoutput winsound addchannel ao 1 2 data sin linspace 0 2 pi 8000 putdata ao data data put data is a blocking function and will not return execution control to MATLAB until the specified data is queued put dat a is described in detail in Managing Output Data on page 6 17 and in Chapter 9 Function Reference Starting the Analog Output O bject You start an analog output object with thest art function For example to start the analog output object ao start ao After start isissued theRunni ng property is automatically set to0n and both the device object and hardware device execute according to the configured and default property values While the devic
94. system e The analog input subsystem e Making quality measurements e Selected bibliography Anatomy of a Data Acquisition Experiment Anatomy of a Data Acquisition Experiment For each new data acquisition experiment you need to perform these tasks e System setup e Calibration e Trials System Setup Thefirst step in any data acquisition experiment is toinstall the hardware and software Hardware installation consists of plugging a board into your computer or installing modules into an external chassis Software installation consists of loading hardware drivers and application software onto your computer After the hardware and software are installed you can attach your sensors Calibration After the hardware and software are installed and the sensors are connected the data acquisition hardware should be calibrated Calibration consists of providing a known input to the system and recording the output F or many data acquisition devices calibration can be easily accomplished with software provided by the vendor Trials After the hardwareis set up and calibrated you can begin to acquire data Y ou may think that if you completely understand the characteristics of the signal you are measuring then you should be able to configure your data acquisition system and acquire the data In the real world however your sensor may be picking up unacceptable noise levels and require shielding or you may need to run the device at a
95. the source mode AO SourceOut put Specify the source output AO 11 4 Properties Listed by Vendor Property Name Description Device Objects Span Specify the measurement bandwidth in Hz Al AO Sum Specify whether the source sum input is AO enabled or disabled Sound Card Properties The device specific sound card properties for analog input Al and analog output AO objects are given below Property Name Description Device Objects BitsPerSample Specify the number of bits the sound card Al AO uses to represent each sample StandardSample Specify whether the valid sample rates Al AO Rates snap to a small set of standard values or if you can set the sample rate to any value within the allowed bounds 11 5 11 Device Specific Property Reference 11 6 Properties Listed Alphabetically This section contains detailed descriptions of all toolbox device specific properties Each property reference page contains some or all of this information e The property name e A description of the property e The property characteristics including Vendor the vendors that support the property U sage whether it is a common property or a channel or line property and which device objects the property is associated with Common properties apply to all channels or lines contained by the device object Channel line properties can be set on a per channel per line basis The device objects supported
96. to each sample Property help The value of BitsPerSample cannot ke modified while the object is See Also Functions daqfind daghelp get propinfo set 9 38 daqread Purpose Syntax Arguments Description Read a Data Acquisition Toolbox da q file data dagread file data dagread file PropertyName PropertyValue data time dagread data time abstime dagread data time abstime events dagread data time abstime events daqinfo daqread daginfo dagread file info file A Data Acquisition Toolbox da q file PropertyName A daqread property name PropertyValue A daqr ead property value info Specifies that device object and hardware information are to be returned data An m by n array where m is the number of samples and nis the number of channels t i me An m by 1 array of relative time values where m is the number of samples absti me The absolute time of the first trigger events A structure containing event information daqi nfo A structure containing device object and hardware information data daqread file reads all the data fromfile data isan m by n data matrix where mis the number of samples and n is the number of channels If data includes data from multiple triggers then m is increased by the number of triggers due to the addition of NaN s 9 39 daqread data daqread file PropertyName Propert
97. use multiple calls toput dat a However since each put data call consumes memory a long output sequence can quickly bring your system to halt As an alternative to put dat a you can continuously output previously queued data using Repeat Out put SinceRepeat Out put requeues the data additional memory resources are not consumed While the data is being output you cannot add additional data to the queue Usage AO Common Access Read write Data type Double Read only Yes when running The default value is zero Create the analog output object ao for a sound card and add one channel to it ao analogoutput winsound chans addchannel ao 1 To queue one second of data data sin linspace 0 10 8000 putdata ao data To continuously output data for 10 seconds set ao Repeat Output 9 Functions putdata Running Purpose Description Characteristics Values See Also ndicate if the device object is running Along with theLogging or Sending property Runni ng reflects the state of an analog input or analog output object Running can beOn or Off Running is automatically set to 0n oncethest art function is issued When Running iSOn you can acquire data from an analog input device or send data to an analog output device after the trigger occurs For digital O objects Running is typically used to indicate if time based events are being generated Running is automatically set to 0f f oncet
98. used to specify index as long as the numbers are positive names An m by 1 cell array of channel names where m is the length of index names makenames prefix index generates a cell array of descriptive channel or line names by concatenating prefix andindex You can pass names as an input argument totheaddchannel oraddline function Ifnames contains more than one descriptive name then the size of names must agree with the number of hardware channels specified in addchannel or the number of hardware lines specified in addline If the channels or lines are to be referenced by name then pr ef i x must begin with a letter and contain only letters numbers and underscores Otherwise the names can contain any character Create the analog input object Al You can usemakenames to define descriptive names for each channel that is to be added toAl Al analoginput nidaq 1 names makenames chan 1 8 names iS an eight element cell array of channel nameschanl chan2 chang You can now pass na mes aS an input argument to theaddchannel function addchannel Al 0 7 names Functions addchannel addline 9 71 mux chanidx Purpose Syntax Arguments Description Remarks 9 72 Return multiplexed scanned channel index scanidx muxchanidx obj muxboard muxi dx scanidx muxchanidx obj absmuxi dx obj An analog input object associated with a National Instruments board muxboard The multiple
99. values of SampleRate andSamplesPerTrigger as well asdata asinputs f mag daqdocfft data Fs blocksize daqdocfft outputs the frequency and magnitude of data which you can then plot daqdocfft is shown below function f mag daqdocfft data Fs bl ocksize F MAG DAQDOCFFT X FS BLOCKSIZE calculates the FFT of X using sampling frequency FS and the SamplesPerTrigger provided in BLOCKSIZE xfft abs fft data mag 20 loglO xfft mag mag 1 blocksize 2 f 0 length mag 1 Fs blocksize f f The results are given below plot f mag grid on ylabel Magnitude dB xlabel Frequency Hz 4 17 4 G etting Started with Analog Input title Frequency Components of Tuning Fork Frequency Components of Tuning Fork 60 T T T T T 30 F E y 4 20 Magnitude dB f L L 1 L 1 0 500 1000 1500 2000 2500 3000 3500 4000 Frequency Hz The plot shows the fundamental frequency around 440 Hz and the first overtone around 880 Hz A simple way tofind actual fundamental frequency is y max maxindex max mag maxi ndex maxindex 441 The answer is 441 Hz Note The fundamental frequency is not always the frequency component with the largest amplitude A more sophisticated approach involves fitting the observed frequencies to a harmonic series to find the fundamental frequency 4 18 Analog Input Examples Acquiring Data wi
100. you with these options Save all property values or save only those property values that differ from their default values Read only property values are not saved Therefore read only properties use their default values when you load the device object into the MATLAB workspace To determine if a property is read only use the pr opi nf o function or examine the property reference pages Save property values using thes et syntax the dot notation or named referencing if defined If theUser Dat a property is not empty or if action properties are set to a cell array of values then the data stored in these properties is written toa MAT file when the device object is saved The MAT file has the same name as the M file containing the device object code For example suppose you create the analog input object ai for a sound card add two channels to it and configure several property values al analoginput winsound addchannel ai 1 2 Templ Temp2 time now set ai SampleRate 11025 TriggerRepeat 4 set ai TriggerAction myaction time start ai 8 3 8 Saving and Loading the Session 8 4 The following command saves ai andthe modified property values tothe M file myai m SincetheTriggerAction property is set toa cell array of values its value is automatically written to the MAT file myai mat obj 2mfile ai myai m Created d v6 myfiles myai m Created d v6 myfiles myai mat Use thet ype
101. 040 0 0170 0 0100 0 0430 0 0252 Toconvertthec ock vector toa more convenient form you can usethes pri nt f function t fix absti me sprintf d d d t 4 t 5 t 6 ans 10 43 25 As shown in the preceding section you can also evaluate the absolute time of the trigger event with thes howdaqevents function Configuring Analog O utput Triggers Device Specific Hardware Triggers Most data acquisition devices possess the ability to accept a hardware trigger Hardware triggers are processed directly by the hardware and are typically transistor transistor logic TTL signals Hardware triggers are used when speed is required since a hardware device can process an input signal much faster than software The device specific hardware triggers are presented to you as additional property values Hardware triggers for National Instruments and Agilent Technologies devices are discussed below and in Chapter 10 Base Property Reference Note that the available hardware trigger support depends on the board you are using Refer to your hardware documentation for detailed information about its triggering capabilities National Instruments When using National Instruments hardware there is an additional analog output trigger type available to you digital triggering IfTriggerType is set toHwDi gi tal the trigger is given by an external TTL signal that is input directly into the hardware device The following example illu
102. 10 28 Even EOG iis aie A A A 10 29 EWChHaNelysioia a A Grae waters 10 31 A kihoa tte ee aid A a aa bial 24 10 33 TOOK st ite eds o Fats ACN eto Acs edo 10 34 InitialTriggerTime 0 0 0 eee 10 36 InputOverRangeACtion oooocccccccccc ee 10 38 INPUERANGE 3 5 eee PAS eee a aS eke oles 10 39 NPUETY PE sareta eet E eet eee oe ee 10 41 ING eet ee ei eho eee ea a Pe be ee ee 10 43 x Contents EINON AIMCO curia a ook le Ged da 10 44 LOQFIIEN AMG cucuta peed hans oOo eee hed ede ed 10 45 LOQQING iii Sebel eae Depa bee be eee de Peed oa 10 46 LOQGINOM ode seruata yeas eed eee A oa eR 10 47 LogloDiskMode 0 ccc cee 10 48 ManualTrigger HWON 00 cece tees 10 49 MaxSamplesQueued 00 00 10 51 Name ia a PAR ae ee A ak dee a 10 52 NiativeOn set uti weeks ee eaters he Sek wee ey dere eed 10 53 NativeScaling Anaa su creed asad tiras a e 10 55 OQUEDPUER ANGE cid whale m beads GR Ga tc 10 56 Parent a A A eth Aha A ee WR Sede 10 58 PORE Seed Peat a at att eed eae 10 59 RepeatOutput 2 00 10 60 RUHNING salt a dr 10 61 RuntimeErrorAction ooococcccoccccoc eee 10 62 SampleRate yie ces eee ate ae ee dG ee 10 64 SamplesAcquired 0 ccc cect ee 10 66 SamplesAcquiredACtion 0 0 cece eee ee 10 67 SamplesAcquiredActionCount 00 cc cence ee eee 10 68 SamplesAvailable 0 0 00 cece 10 69 SamplesOutput 0000 cece 10 70 SamplesOutputAction 0 0 0 0 ee 10 71
103. 11 Device Specific Property Reference For example only analog input and analog output objects associated with a sound card have a BitsPerSampl e property The additional property values are also device specific but are included in this chapter For example all supported devices have an Input Type property but the valueAC Coupl ed is unique to analog input objects associated with a sound card Analog Input Properties Analog input base properties are divided into two main categories common properties and channel properties Common properties apply to every channel contained by the analog input object while channel properties can be configured for individual channels Common Properties The analog input common properties are grouped into the following categories based on usage Analog Input Basic Setup Properties Sampl esPer Specify the number of samples to acquire for each Trigger channel group member for each trigger that occurs Sampl eRate Specify the per channel rate at which analog data is converted to digital data TriggerType Specify the type of trigger to execute 10 3 10 Base Property Reference Analog Input Logging Properties LogFil eName Specify the name of the disk file to which information is logged Logging Indicate if data is being logged to memory or toa disk file LoggingMode Specify the destination for acquired data LogToDiskMode Specify whether data events and hardware infor
104. 212 This means that the converter can detect voltage differences at the level of 0 00244 volts 2 44 mV How Are Range Gain and Measurement Precision Related When you configure the input range and gain of your analog input subsystem the end result should maximize the measurement resolution and minimize the chance of an overrange condition The actual input range is given by the formula Actual input range I nput range Gain Therelationship between gain actual input range and precision for a unipolar and bipolar signal having an input range of 10 V is shown below Table 1 2 Relationship Between Input Range Gain and Precision Input Range Gain Actual Input Range Precision 12 Bit A D 0to10V 1 0 Oto10V 2 44 mV 2 0 Oto5V 1 22 mV 5 0 Oto2V 0 488 mV 10 0 0to1V 0 244 mV 5to5V 0 5 10to10V 4 88 mV 1 0 5to5V 2 44 mV 2 0 2 5 to 2 5 V 1 22 mV 5 0 1 0 to 1 0 V 0 488 mV 10 0 0 5 to 0 5 V 0 244 mV M aking Q uality M easurements As shown in the table the gain affects the precision of your measurement If you select a gain that decreases the actual input range then the precision increases Conversely if you select a gain that increases the actual input range then the precision decreases This is because the actual input range varies but the number of bits used by the A D converter remains fixed Note With the Data Acquisition Toolbox you do not haveto specify the range and gain Instead you simply spec
105. 5 Testing with a Microphone 000 cece eee eee A 16 Testing with a CD Player 00 e eee ee A 16 Running in Full Duplex Mode 00000e eee eee A 18 Other ThingstoTry 00 c cece eee A 19 Registering the Hardware Driver Adaptor A 19 ContactingTheMathWorks 0 0 cece eee A 20 Managing Your Memory Resources OVER VI CW io A ee es B 2 How Much Memory Do You Need B 3 Example Managing Memory Resources B 4 xii Contents Glossary C xiii xiv Contents Preface What Is the Data Acquisition Toolbox Exploring the Toolbox Related Products System Requirements Associated Products Using This Guide Expected Background Using the Documentation Examples i How This Guide is Organized Installation Information Toolbox Installation y Hardware and Driver Installation Typographical Conventions xvi xvi xvii xvii Xvii xix xix XX XX XX adi XX XX Preface What Is the Data Acquisition Toolbox xvi The Data Acquisition Toolbox is a collection of M file functions and MEX file dynamic link libraries DLLs built on the MATLAB Technical Computing Environment The toolbox provides you with these main features e A framework for bringing live measured data into MATLAB using PC compatible plug in data acquisition hardware Support for t
106. 5 5 decimation factor 11 21 driver A 9 properties 11 4 trigger types Al object 5 44 AO object 6 26 troubleshooting A 9 AISENSE 11 10 alias 1 37 AMUX 64T adding channels 9 17 channel indices 9 72 analog input object acquisition continuous 5 23 single point 9 61 adding channels 4 4 creating 4 3 display summary 4 23 engineering units 5 56 events and actions 5 46 extracting data 5 13 logging data 4 14 information to disk 8 6 previewing data 5 9 properties basic setup 4 9 channel 10 7 common 10 3 configuring 3 18 sampling rate 4 9 starting 4 13 Index status evaluation 4 22 stopping 4 14 triggers configuring 5 20 types 4 11 analog output object adding channels 6 4 creating 6 3 display summary 6 15 engineering units 6 34 events and actions 6 27 output continuous 6 22 single point 9 82 properties basic setup 6 6 channel 10 11 common 10 8 configuring 3 18 queueing data for output 6 9 sampling rate 6 6 starting 6 9 status evaluation 6 14 stopping 6 10 triggers configuring 6 21 types 6 8 analog triggers Agilent hardware 5 45 CBI hardware 5 43 NI hardware 5 39 analoginput 4 3 Agilent hardware 9 19 NI hardware 4 19 sound card 4 16 analogoutput 6 3 Agilent hardware 9 22 NI hardware 6 12 sound card 6 11 antialiasing filter 1 34 array data returned by get data 5 13 device object 3 5 B bandwidth 1 10 base properties 3 13 binary vector 7 10 binvec2dec 7 12 block See data block blocking functio
107. 500 samples acquired by each channel contained by ai data peekdata ai 500 Since previewing data is usually a low priority task peekdat a does not guarantee that all requested data is returned You can preview data at any time while the device object is running However you cannot usepeekdata in conjunction with hardware triggers since the device is idle until the hardware trigger is received 4 13 4 G etting Started with Analog Input 4 14 Logging Data While the analog input object is running you can log acquired data to the engine memory or to a disk file However before you can log data a trigger must occur You configure an analog input trigger with theTriggerType property For a detailed description of triggers refer to Configuring Analog Input Triggers on page 5 20 When the trigger occurs the Logging property is automatically set to 0n and data acquired from the hardware is logged to the engine or a disk file Y ou extract logged data fromthe engine with theget data function For example to extract all logged samples for each channel contained by ai data getdata ai getdata blocks the MATLAB command line until all the requested data is returned to the workspace You can extract data any time after the trigger occurs You can also return sample time pairs with get data For example to extract 500 sample time pairs for each channel contained by ai data time getdata ai 500 ti me isan m by 1 arr
108. 7 07 08 16000 Channel N A Functions dagread getdata Properties EventLog 9 91 size Purpose Return the size of a device object channel group or line group Syntax d size obj ml m2 m3 mn size obj m size obj dim d size obj Channel ml m2 m3 mn size obj Channel m size obj Channel di m d size obj Line ml m2 m3 mn size obj Line m size obj Line dim Arguments obj A device object or array of device objects dim The dimension obj Channel The channels contained by obj obj Line The lines contained by obj d A two element row vector containing the number of rows and columns in obj ml m2 m3 mn Each dimension ofobj is captured in a separate variable m The length of the dimension specified by di m Description d size obj returns the two element row vector d m n containing the number of rows and columns in obj m m m mn size obj returns the length of the first n dimensions of obj toseparate output variables For example m n size obj returns the number of rows tom and the number of columns ton m size obj dim returns the length of the dimension specified by the scalar di m For example si ze obj 1 returns the number of rows d size obj Channel returns the two element row vector d m n containing the number of rows and columns in the channel groupobj Channel 9 92 size Example See Also ml m2 m3
109. 9 1 Time sec 1 21 1 Introduction to Data Acquisition 1 22 Input Range and Polarity The input range of the analog input subsystem is the span of input values for which a conversion is valid You can change the input range by selecting a different gain value For example National Instruments AT MIO 16E 1 board has eight gain values ranging from 0 5 to 100 Many boards include a programmable gain amplifier that allows you to change the device gain through software When an input signal exceeds the valid input range of the converter an overrange condition occurs In this case most devices saturate to the largest representable value and the converted data is almost definitely incorrect The gain setting affects the precision of your measurement the higher lower the gain value the lower higher the precision Refer to How Are Range Gain and Measurement Precision Related on page 1 32 for more information about how input range gain and precision are related to each other An analog input subsystem can typically convert both unipolar signals and bipolar signals A unipolar signal contains only positive values and zero while a bipolar signal contains positive values negative values and zero Unipolar and bipolar signals are depicted below Refer to the figure in Quantization on page 1 20 for an example of a unipolar signal 10 Volts 5 Volts 0 Volts 5 Volts NE U
110. A0 anal ogoutput nidaq 1 A0 anal ogoutput cbi 1 2 Add channels Add one channel to Ao chans addchannel AO 1 chans addchannel A0 0 For NI and CBI 3 Configure property values Define an output time of one second assign values to the basic setup properties generate data to be queued and issue two put data calls Since the queued data is repeated four times and two put data calls are issued a total of 10 seconds of data is output duration 1 set A0 SampleRate 8000 Actual Rate get A0 Sampl eRate len Actual Rate durati on set A0 Repeat Output 4 data sin linspace 0 2 pi len putdata A0 data putdata A0 data 6 19 6 Analog O utput 4 Output data Start A0 and wait for the device object to stop running start A0 while strcmp A0 Running On end 5 Clean up When you no longer need A0 you should remove it from memory and fromthe MATLAB workspace delete A0 clear AO 6 20 Configuring Analog O utput Triggers Configuring Analog Output Triggers An analog output trigger is defined as an event that initiates the output of data As shown in thefigure below when a trigger occurs theSendi ng property is automatically set to 0n and queued data is output from the engine to the hardware subsystem Sending Off Sending On AS gt Time Queue data Trigger occurs Output data in engine to hardware Properties associated with analog outp
111. Al objects usetheSamplesAcqui red property to find out how many samples have been acquired sincethest art function was issued For AO objects use the Sa mpl es Out put property to find out how many samples have been output since thest art function was issued Usage Al AO Common Access Read only Data type Double Read only N A when running The value is automatically updated based on the number of samples acquired analog input or sent analog output The default value is zero Functions start Properties Sampl esAcquired SamplesOut put 10 69 SamplesO utput Purpose Description Characteristics Values See Also 10 70 ndicate the number of samples output per channel from the engine Sampl es Out put is continuously updated to reflect the current number of samples output by an analog output object It is reset to zero after the device objects stops and data has been queued with the put dat a function Use theSamp es Available property to find out how many samples are available to be output from the engine Usage AO Common Access Read only Data type Double Read only N A when running The value is continuously updated to reflect the current number of samples output The default value is zero Functions putdata Properties SamplesAvailable SamplesOutputAction Purpose Description Characteristics Values See Also Specify the M file action function to execute every time a pred
112. Anti Alias jon y Trig Slope Pos Exit Analog Anti Alias Not Adjustable 5 OK Cancel A 10 Troubleshooting Agilent Technologies Hardware The result of such a test is shown below for channel 1 ig HP E1432A Soft Front Panel olx AA Meas Input Source Display Chan 1 gt If the Soft Front Panel does not provide you with the expected results for the module under test and you are sure that your test setup is configured correctly then the problem is probably with the hardware To get support for your Agilent Technologies hardware visit their Web site at http www agilent com A 11 A Troubleshooting Your Hardware Troubleshooting Sound Cards You can verify that your sound card is functioning properly by recording data and then playing back the recorded data Recording data uses the sound card s analog input subsystem while playing back data uses the sound card s analog output subsystem Successful completion of these two tasks indicates your sound card works properly The data to be recorded can come from two sources e A microphone e ACD player The first thing you should do is enable your sound card s ability to record and play data This is done using the Microsoft Windows Multimedia Properties dialog box You can access this dialog box using the Windows Start button Start gt Settings gt Control Panel gt Multimedia The Multimedia Proper
113. CBI 3 Configure property values Define a 10 second acquisition and execute the M filedaqdoc5_7plot every 0 5 seconds Note that the variablesbsize P and T are passed to the action function duration 10 Ten second duration set Al SampleRate 22050 Actual Rate get Al SampleRate set Al SamplesPerTrigger duration Actual Rate set Al TimerPeriod 0 5 bsize Al SampleRate Al Ti mer Period figure P plot zeros bsize 1 T title Number of action functions calls num2str 0 Configuring Events and Actions xlabel Samples ylabel Signal Volts grid on set gcf doublebuffer on set Al TimerAction daqdoc5 7plot bsize P T 4 Acquire data Start Al Thedrawnow command indagdoc5_7pl ot forces MATLAB to update the display start Al pause duration 0 5 5 Clean up When you no longer need Al you should remove it from memory and from the MATLAB workspace delete Al clear Al 5 55 5 Doing More with Analog Input Linearly Scaling the Data Engineering Units The Data Acquisition Toolbox provides you with a way to linearly scale analog input signals from your sensor Y ou can associate this scaling with specific engineering units such as volts or Newtons that you may want to apply to your data When specifying engineering units there are three important considerations e The expected data range produced by your sensor This range depends on the physical p
114. Check for channels out ischannel obj Channel index obj Channel index Oneor more channels contained by obj out A logical value out ischannel obj Channel index returns a logical 1toout if obj Channel index isa channel Otherwise a logical 0 is returned ischannel does not determine if channels are valid associated with hardware To check for valid channels use thei s valid function Typically you usei schannel directly only when you are creating your own Miles Suppose you create the function my func for use with the Data Acquisition Toolbox If myf unc is passed one or more channels as an input argument then the first thing you should do in the function is check if the argument is a channel function myfunc chan Determine if a channel was passed if ischannel chan error The argument passed is not a channel end You can examine the Data Acquisition Toolbox M files for examples that use ischannel Functions isvalid 9 63 isdioline Purpose Syntax Arguments Description Remarks Example See Also 9 64 Check for lines out isdioline obj Line index obj Line index One or more lines contained by obj out A logical value out isdioline obj Line index returns a logical 1toout if obj Line index isa line Otherwise a logical O is returned i sdi ol i ne does not determine if lines are valid associated with hardware To check for valid lines use thei sv
115. Configure and return the specified property Actual setverify obj PropertyName PropertyVal ue Actual setverify obj Channel index PropertyName PropertyVal ue Actual setverify obj Line index PropertyName PropertyVal ue obj A device object or array of device objects Property Name A property name PropertyValue A property value obj Channel index One or more channels contained by obj obj Line index One or more lines contained by obj Actual The actual value for the specified property Actual setverify obj PropertyName PropertyValue sets PropertyName toPropert yVal ue forobj and returns the actual property value toActual Actual setverify obj Channel index PropertyName PropertyValue sets PropertyName toPropertyVal ue for the channels specified by index and returns the actual property valuetoActual Actual setverify obj Line index PropertyName PropertyVal ue sets PropertyName toPropertyVal ue for thelines specified byi ndex and returns the actual property value toActual set verify is equivalent to the commands set obj PropertyName PropertyVal ue Actual get obj PropertyName Usingset verify isnot required for setting property values but it does provide a convenient way to verify the actual property value set by the data acquisition engine setverify Example See Also setverify is particularly useful when setting the SampleRate l nput Range and Out put Rang
116. D adaptor Name of the hardware driver adaptor The supported adaptors areni dag cbi hpel432 and wi nsound 1D The hardware device identifier D is optional if the device object is associated with a sound card having an D of 0 Al The analog input object Al analoginput adaptor creates the analog input object Al for a sound card having an D of O adaptor must bewi ns ound This is the only case where D is not required Al analoginput adaptor 1 D creates the analog input object Al for the specified adapt or and for the hardware device with device identifier D 1 D can be specified as an integer or a string More About Creating Analog Input O bjects e When an analog input object is created it does not contain any hardware channels To execute the device object hardware channels must be added with theaddchannel function Y ou can create multiple analog input objects that are associated with a single analoginput subsystem However you can typically execute only one of them at a time The analog input object exists in the data acquisition engine and in the MATLAB workspace If you create a copy of the device object it references the original device object in the engine If D is a numeric value then you can specify it as an integer or a string If D contains any non numeric characters then you must specify it as a string see the Agilent Technologies example below e TheName property is automatically
117. Data Acquisition Toolbox For Use with MATLAB Computation T Visualization A Programming T The DOES WOR User s Guide SS Version 2 How to Contact The MathW orks 508 647 7000 Phone 508 647 7001 Fax The MathWorks Inc Mail 3 Apple Hill Drive Natick MA 01760 2098 http www mathworks com Web ftp mathworks com Anonymous FTP server comp soft sys matlab Newsgroup support mathworks com Technical support suggest mathworks com Product enhancement suggestions bugs mat hworks com Bug reports doc mathworks com Documentation error reports subscribe mathworks com Subscribing user registration service mathworks com Order status license renewals passcodes inf o mathworks com Sales pricing and general information Data Acquisition Toolbox User s Guide O COPYRIGHT 1999 2000 by The MathWorks Inc The software described in this document is furnished under a license agreement The software may be used or copied only under the terms of the license agreement No part of this manual may be photocopied or repro duced in any form without prior written consent from The MathWorks Inc FEDERAL ACQUISITION This provision applies to all acquisitions of the Program and Documentation by or for the federal government of the United States By accepting delivery of the Program the government hereby agrees that this software qualifies as commercial computer software within the meaning of FAR Part 12 212 DFARS Par
118. E board is shown below Internet Explorer Network Neighborhood Measurement amp Automation Data Neighborhood Devices and Interfaces The NI DAQ device number OxADEFSC The serial number of the device CVI Run Time Ey Measurement amp Automation E NI Spy NI PAL Software 5 10 4 4 Version 1 1 Build 51 Version 1 3 1 Troubleshooting N ational Instruments Hardware Is Your Hardware Functioning Properly Totroubleshoot your National Instruments hardware you should use the Test Panel The Test Panel allows you to test each subsystem supported by your board and is installed as part of the NI DAQ driver software You can access the Test Panel by right clicking on the appropriate device in the Measurement amp Automation Explorer and choosing Test Panel For example suppose you want to verify that the analog input subsystem on your PCI 6024E board is operating correctly To do this you should connect a known signal such as that produced by a function generator to one or more channels using a screw terminal panel The result of such a test is shown below for channel 1 Test Panel 1 1x einstrumes Device Name Device Number INSTRUMENTS PCI B024E i Analog Input Analog Output Counter 1 0 Digital 1 0 Channel fT w Input Limits High fro 0000 59 Last Error Low jo 0000 0 0000 T Sample Rate Hz y Fatal 10000 0 AB 4 0000 l Erro
119. Hardware Troubleshooting National Instruments Hardware If you are having trouble using the Data Acquisition Toolbox with a supported National Instruments board the reason may be that e You are using a hardware driver that is incompatible with the toolbox e Your hardware is not functioning properly What Driver Are You Using The Data Acquisition Toolbox is compatible only with specific versions of the NI DAQ driver and is not guaranteed to work with any other versions For a list of the NI DAQ driver versions that are compatible with the Data Acquisition Toolbox refer to the product page on the MathWorks Web site at http www mathworks com products daq If you think your driver is incompatible with the Data Acquisition Toolbox then you should verify that your hardware is functioning properly before updating drivers If your hardware is functioning properly then you are probably using unsupported drivers Visit the National Instruments Web site at http www natinst com for the latest NI DAQ drivers You can find out which version of NI DAQ you are using with National Instruments Measurement amp Automation Explorer You should be able to access this program through the Windows Desktop The driver version is available through the Help menu Help gt About Measurement amp Automation Explorer gt System Info gt Software A Troubleshooting Your Hardware A 4 For example the version of NI DAQ used by a PCI 6024
120. Hz title Frequency Output by Function Generator Frequency Output by Function Generator 80 T T T T T 40h 4 20 7 Magnitude dB L L L L 1 il L L 1 0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000 Frequency Hz This plot shows the nominal frequency around 1000 Hz A simple way to find actual frequency is shown below y max maxi ndex max mag maxindex maxindex 994 The answer is 994 Hz 4 21 4 G etting Started with Analog Input 4 22 Evaluating the Analog Input Object Status Y ou can evaluate the status of an analog input object by e Returning the values of certain properties e Invoking the display summary Status Properties The properties associated with the status of your analog input object allow you to evaluate e If the device object is running e If data is being logged to the engine or to a disk file e How much data has been acquired e How much data is available to be extracted from the engine The analog input status properties are given below Table 4 5 Analog Input Status Properties Property Name Description Logging Indicate if data is being logged to memory or to a disk file Running Indicate if the device object is running SamplesAcquired Indicate the number of samples acquired per channel SamplesAvailable Indicate the number of samples available per channel in the data acquisition engine When you issuethestart function Ru
121. MATLAB Installation Guidefor your platform If you experience installation difficulties and have Web access look for the license manager and installation information at the MathWorks Web site http www mat hworks com Hardware and Driver Installation Installation of your hardware device hardware drivers and any other device specific software is described in the documentation provided by your hardware vendor Note You need to install all necessary device specific software provided by your hardware vendor in addition to the Data Acquisition Toolbox Typographical C onventions Typographical Conventions This guide uses the following typographical conventions Item Convention to Use Example Example code Function names syntax Keys Literal string in syntax descriptions in Reference chapters Mathematical expressions MATLAB output Menu names menu items and controls New terms String variables from a finite list Monospace font Monospace font Boldface with an initial capital letter Usemonospace bold for literals Variables in italics Functions operators and constants in standard text Monospace font Boldface with an initial capital letter Italics Monospace italics To assign the value 5 toA enter A 5 Thecos function finds the cosine of each array element Syntax line example is MLGetVar ML var_name Press the Return key f freqspace
122. None ClockSource Internal DataMissedAction dagaction Eventlog InitialTriggerTime 0 0000 0 InputOverRangeAction InputType AC Coupled LogFileName logfile daq Logging Off LoggingMode Memory LogToDiskMode Overwrite 3 15 3 The Data Acquisition Session Manual TriggerHwOn Start Name winsound0 A Running Off RuntimeErrorAction dagaction SampleRate 8000 SamplesAcquired 0 Sampl esAcquiredAction Sampl esAcquiredActionCount 1024 Sampl esAvailable 0 SamplesPerTrigger 8000 StartAction StopAction Thane Timeout 1 TimerAction TimerPeriod 0 1 riggerAction riggerChannel 1x0 aichannel riggerCondition None riggerConditionValue 0 riggerDelay 0 riggerDelayUnits Seconds riggerRepeat 0 riggersExecuted 0 riggerType Immediate Type Analog Input UserData WINSOUND specific properties BitsPerSample 16 StandardSampleRates On To display the current value for one property you supply the property name to get get ai Sampl eRate 8000 Todisplay the current values for multiple properties you include the property names as elements of a cell array 3 16 Configuring and Returning Properties get ai StandardSampleRates Running ans On off Y ou can also use the dot notation to display a single property value al TriggerType ans mmedi ate Channel and Line Properties Toreturn all configurab
123. None This is the only supported value for SS H hardware Properties Channel Skew Samp eRate 10 23 ClockSource Purpose Specify the clock used to govern the hardware conversion rate Description For all supported hardware except ComputerBoards analog output subsystems Cl ockSource can beset tol nternal which specifies that the acquisition rate is governed by the internal hardware clock For subsystems without a hardware clock you must use software clocking to govern the sampling rate Software clocking allows a maximum sampling rate of 500 Hz and a minimum sampling rate of 0 0002 Hz An error is returned if more than 1 sample of jitter is detected Note that you may not be able to attain rates over 100 Hz on all systems especially Windows 9X Characteristics Usage Al AO Common Access Read write Data type String Read only Yes when running Values National Instruments Internal Externa External Sampl e Ctrl External Scan Ctrl External Sample AndScanCtrl The internal hardware clock is used Externally control the channel clock AO only Externally control the channel clock This value overrides the Channel Skew property value Al only Externally control the scan clock This value overrides theSamp leRate property value Al only Externally control the channel and scan clocks This value overrides the Channel Skew and SampleRate property values Al only For an analog output object a Cl
124. Pressure Resistance temperature Temperature device RTD Strain gauge Force Thermocouple Temperature The Data Acquisition System When choosing the best analog sensor to use you must match the characteristics of the physical variable you are measuring with the characteristics of the sensor The two most important sensor characteristics are e The sensor output e The sensor bandwidth Sensor O utput The output from a sensor can be an analog signal or a digital signal and the output variable is usually a voltage although some sensors output current Current Signals Current is often used totransmit signals in noisy environments because it is much less affected by environmental noise The full scale range of the current signal is often either 4 20 mA or 0 20 mA A 4 20 mA signal has the advantage that even at minimum signal value there should be a detectable current flowing The absence of this indicates a wiring problem Before conversion by the analog input subsystem the current signals are usually turned into voltage signals by a current sensing resistor The resistor should be of high precision perhaps 0 03 or 0 01 depending on the resolution of your hardware Additionally the voltage signal should match the signal to an input range of the analog input hardware For 4 20 mA signals a 50 ohm resistor will give a voltage of 1 V for a 20 mA signal by Ohm s law Voltage Signals The most commonly interfaced signal is a vo
125. Properties Sampl eRate StandardSampleRates Purpose Description Characteristics Values Specify whether the valid sample rates snap to a small set of standard values or if you can set the sample rate to any value within the allowed bounds StandardSampl eRates canbeOn of Off IfStandardSampl eRates isOff thenit is possible to set the sample rate to any value within the bounds supported by the hardware For most sound cards the lower bound is 8 000 kHz while the upper bound is 44 0 kHz For newer sound cards an upper bound of 96 0 kHz may be supported The specified sample rate is rounded up to the next integer value IfStandardSampleRates isOn then the available sample rates snap to a small set of standard values The standard values are 8 000 kHz 11 025 kHz 22 050 kHz and 44 100 kHz If you specify a sampling rate that is within one percent of a standard value then the sampling rate snaps tothat standard value If you specify a sampling rate that is not within one percent of a standard value then the sampling rate rounds up to the closest standard value Regardless of theSt andardSampl eRates value if you specify a sampling rate that is outside the allowed limits then an error is returned Vendor Sound cards Usage Al AO Common Access Read write Data type String Read only Yes when running 0n The sample rate can be set only to a small set of standard values off If supported by the hardware the sample r
126. SamplesOutputActionCount 00 0 eee eee ee 10 72 SamplesPerTrigger 0 0 c cece e eee eee 10 73 A ehi wie tet apenas oe eee 10 74 Sensor RANJE wesc ee a ee a ae 10 75 StartAction cia RA ee eee eee 10 76 StOPACtiON ic ia hee Pie deeds Dea i ed ee 10 77 RAG vores T RR 10 79 TM ES seca ae teeth ial Mathie ei Aretha trad 10 80 TIMEA CEL ONT 15 sch are ih hho A AA yl e 10 81 Timer Period goas e ceed ara te da ee arate ao oa ay age ke 10 82 Trigg AON si eo ee APSO eS Ee eek 10 83 TriggerChannel 000s cece eee 10 84 TriggerCondition 0 cece eee 10 85 TriggerConditionValue 0 00 eee eee 10 89 TriggerDelay 0 0 2 cc cece tees 10 90 TriggerDelayUnits 0 0 0 c eee ee 10 91 TriggerRepeat 6 tees 10 92 TriggersE xecuted 0 cece ee 10 93 TE gg TYPE axa geet Aten A 10 94 Type iras A a il Oe ee nates he ee A 10 96 UNIS osas ia eee ee eee oe A 10 97 UnitsRange io cece eevee ie eee eee ee OE E 10 98 User Data cos rra oe Sees EEP eee oad 10 99 1 OVERVIEW cunas oak AGA aa rod ds 11 2 Getting Command Line Property HelP o 11 2 Properties Listed by Vendor 4 11 3 National Instruments Properties o oo cococcocoooo 11 3 ComputerBoards Properties 0 0 0 cece eee 11 4 Agilent Technologies Properties 00 e eee eee 11 4 Sound Card Properties 0 000 cece eee ee tenes 11 5 Properties Listed Alph
127. See Also Create the analog input object ai for a National Instruments board that is connected to four AMUX 64T multiplexers and add 256 channels toai using addmuxchannel ai analoginput nidaq 1 ai I nputType SingleEnded ai NumMuxBoards 4 addmuxchannel ai The following two commands return a scanned index value of 14 scanidx muxchanidx ai 4 1 scanidx muxchanidx ai 193 Functions addmuxchannel 9 73 obj2mfile Purpose Syntax Arguments Description 9 74 Convert device objects channels or lines to MATLAB code obj 2mfile obj file obj 2mfile obj file syntax obj 2mfile obj file all obj 2mfile obj file syntax all obj A device object array of device objects channels or lines file The file that the MATLAB code is written to The full pathname can be specified If an extension is not specified the m extension is used syntax Syntax of the converted MATLAB code By default thes et syntax is used If dot is specified then the subscripted referencing syntax is used If named is specified then named referencing is used if defined all Ifall is specified all properties are written tofile Ifall is not specified only properties that are not set to their default values are written tofile obj 2mfile obj file convertsobj tothe equivalent MATLAB code using theset syntax and saves the code tof i e By default only those properties that are
128. Testing with a Microphone Testing with a CD Player Running in Full Duplex Mode Other ThingstoTry Registering the Hardware Driver Adaptor Contacting The MathWorks A A 2 A 3 AB S A 6 A 6 A 8 A 9 AY A 10 A 12 A 15 A 16 A 16 A 18 A 19 A 19 A 20 A Troubleshooting Your Hardware Overview This appendix describes simple tests you can perform to troubleshoot your National Instruments ComputerBoards Agilent Technologies and Windows sound card hardware The tests involve using software provided by the vendor or the operating system sound cards and does not involve using the Data Acquisition Toolbox To accurately test your hardware you should use these tools to match the requirements of your data acquisition session For example you should select the appropriate sampling rate number of channels acquisition mode continuous or single point and input range Note If you cannot access your board using the vendor s software then you will not be able to do so with the Data Acquisition Toolbox If these tests do not help you then you may need to register the hardware driver adaptor or contact The MathWorks for support Contact information is provided in Contacting The MathWorks on page A 20 as well as in the beginning of this guide If the problem is with your hardware then you should contact the hardware vendor Troubleshooting N ational Instruments
129. The following command writes MATLAB codetothe files myai mandmyai mat obj 2mfile ai myai m dot my ai m contains code that recreates the analog input code shown above using the dot notation for all properties that have their default values changed Since Start Action isset toa cell array of values this property appears in myai mas ai StartAction startacti on and is Saved in myai mat as startaction myaction 2 magic 10 Torecreateai and assign the device object to a new variableai new ainew myai The associated MAT file myai mat is automatically loaded 9 75 peekdata Purpose Syntax Arguments Description Remarks 9 76 Preview most recent acquired data data peekdata obj sampl es obj An analog input object samples The number of samples to preview for each channel contained by obj data An m by n matrix where m is the number of samples and n is the number of channels data peekdata obj samples returns the latest number of samples specified by samples todata More About Using peekdata e Unlikegetdata peekdata is a nonblocking function that immediately returns control to MATLAB Sincepeekdata does not block execution control data may be missed or repeated e peekdata takes a snapshot of the most recent acquired data and does not remove samples from the data acquisition engine Therefore the SamplesAvailable property value is not affected when peekdata is called
130. This is also referred to as a DIO subsystem Direct memory access DMA is a system of transferring data whereby samples are automatically stored in system memory whilethe processor does something else A MEX file dynamic link library DLL file that stores the device objects and associated property values that control your data acquisition application controls the synchronization of events and controls the storage of acquired or queued data Channel properties that allow you to linearly scale input or output data An event occurs at a particular time after a condition is met and may result in one or more actions Many event types are automatically generated by the toolbox while others are generated only after you configure specific properties The process of starting the device object and hardware device While an analog input object is executing you can acquire data While an analog output object is executing you can output data Thefirst in first out FI FO memory buffer which is used by data acquisition hardware to temporarily store data A system that can send and receive information simultaneously For sound cards full duplex means that the device can acquire input data via an analog input subsystem while outputting data via an analog output subsystem at the same time The span of input values for which an A D conversion is valid The slowest but most common method to move acquired data from the hardware to system memory
131. You canissuetrigger onlyifTriggerType issettoManual Running iSOn and Logging isOff You can specify trigger as the value for an action property ai StartAction trigger Functions start stop Properties Initial TriggerTi me Logging Running Sending TriggerAction TriggerType 9 97 waittlstop Purpose Syntax Arguments Description Remarks 9 98 Wait for the device object to stop running waittilstop obj waitti me obj A device object or an array of device objects waitti me The maximum time to wait for obj to stop running waittilstop obj waittime blocks the MATLAB command line and waits for obj to stop running You specify the maximum waiting time in seconds with wai ttime waittime overrides the value specified for theTi meout property Ifobj isan array of device objects then wai ttil stop may wait up to the specified time for each device object in the array waittilstop is particularly useful if you want to guarantee that the specified data is acquired before another task is performed Ifobj isnot running when wai ttilstop is issued or if an error occurs while obj iS running then waittilstop immediately relinquishes control of the command line When obj stops running its Running property is automatically set to Of f obj can stop running under one of the these conditions e The requested number of samples is acquired analog input or sent out analog output e Thestop function is issu
132. a run time error occurs This message is also displayed at the MATLAB command line The Trigger Field Tri gger is used by the trigger event to indicate the trigger number For example if three trigger events occur thenTrigger is3 for the third trigger event The total number of triggers executed is given by the TriggersExecuted property Configuring Events and Actions Example Retrieving Event Information Suppose you want to examine the events logged for the example given by Example Voice Activation Using a Software Trigger on page 5 23 You can do this by accessing the Event Log property events AlVoice EventLog events 3x1 struct array with fields Type Data By examining the contents of the Type field you can list the events that occurred while Al Voi ce was running events Type ans Start Trigger Stop To display information about the trigger event you must access the Dat a field which stores the absolute time the trigger occurred the number of samples acquired when the trigger occurred the index of the trigger channel and the trigger number trigdata events 2 Data trigdata AbsTime Rel Sample 0 Channel 1 Trigger 1 1999 4 15 18 12 5 8615 Alternatively you can usetheshowdaqevents function to display event information showdagevents events 2 2 Trigger 1 18 12 05 0 Channel 1 5 51 5 Doing More with Analog Input 5 52 Creating and Executing Actio
133. abetically 11 6 BitsPerSample tsean eee fae ita Race 11 7 COLA si ees o Se oae eT ARS Cee BE cae Pace 11 8 GOUPO col o ele eden need Gaede nad ee Aube tue ek d 11 9 DriveAlSenseToGround 00 0c cece eee 11 10 GroundingMode 00 c eee eee eee 11 11 NputM ode wis ieen ees edie ee ES ee ee be Pee ees 11 12 INPUESQUICS sche ek eee dee a gee 11 14 NumMuxBoards 00000 eee eee 11 15 QutOfDataM ode occ eee ee be a a 11 16 RaMPRate iii a E GRE wera AE we 11 17 Source ode it a ean es 11 18 SOUFCOQUEPUE a ets i i ace dba doce 11 19 Span Yaraa A noi oD 11 21 StandardSampleRates 0000 e ee ee 11 23 SUM ssid ia eek a eee ee a Sh a 11 24 Transfer Mode o a Es ance ets 11 25 Troubleshooting Your Hardware A OVOP Vi eW eane Gin week ES a sents Ge Hanae ale A 2 Troubleshooting National Instruments Hardware A 3 What Driver Are You USing 2 000 cece eee A 3 Is Your Hardware Functioning Properly A 5 Troubleshooting ComputerBoards Hardware A 6 What Driver Are You USing 0 00 cece ee A 6 Is Your Hardware Functioning Properly A 8 Troubleshooting Agilent Technologies Hardware A 9 What Driver Are You USing 2 00 cee eee A 9 Is Your Hardware Functioning Properly A 10 Troubleshooting Sound Cards o A 12 Microphone and Sound Card Types oocococccccc o A 1
134. added to a device object constitute a channel group while the lines added to a device object constitute a line group The functions associated with adding channels or lines to a device object are listed below Table 3 2 Functions Associated with Adding Channels or Lines Functions Description addchannel Add hardware channels to an analog input or analog output object addline Add hardware lines to a digital 1 O object addmuxchannel Add channels when using a National Instruments AMUX 64T multiplexer For example to add two channels to an analog input object associated with a sound card you must supply the appropriate hardware channel identifiers IDs toaddchannel al analoginput winsound addchannel ai 1 2 Note You cannot acquire or output data with a device object that does not contain channels or lines Similarly you cannot acquire or output data with channels or lines that are not contained by a device object You can think of a device object as a channel or line container that reflects the common functionality of a particular device The common functionality of a device applies to all channels or lines that it contains For example the sampling rate of an analog input object applies to all channels contained by Adding Channels or Lines that object In contrast the channels and lines contained by the device object reflect the functionality of a particular channel or line For example you ca
135. ai You can verify this by setting a property valuefor ai and returning the value of the same property from ne wai set ai SampleRate 22050 get newai SampleRate ans 22050 Creating a Device O bject As shown below ai andnewai return the same property value because they both reference the same device object in the data acquisition engine copy MATLAB al gt newai Data Acquisition Engine al If you delete either the original device object or a copy then the engine device object is also deleted In this case you cannot use any copies of the device object that remain in the workspace since they are no longer associated with any hardware Device objects that are no longer associated with hardware are called invalid objects The example below illustrates this situation delete ai newai newai Invalid Data Acquisition object This object is not associated with any hardware and should be removed from your workspace using CLEAR Y ou should remove invalid device objects from the workspace with the c ear command 3 7 3 The Data Acquisition Session 3 8 Adding Channels or Lines Channds and lines are the basic hardware device elements with which you acquire or output data After you create a device object you must add channels or lines toit Channels are added to analog input and analog output objects while lines are added to digital O objects The channels
136. ak out box is attached to the specified channel Your can set nput Mode toMi c or 200Volt Mic only if a microphone break out box is attached to the specified channel For each input mode the full scale setting is configured with the nput Range property Thereis nol CP current sourceinsidethe E 1432 device Instead you can attach a break out box containing an ICP current source to the input When this ICP break out box is attached setting nput Mode tol CP enables the ICP current source in the break out box If there is no ICP break out box attached to the input then setting nput Mode tol CP does nothing Note Ifa channel is not connected to a smart break out box then changing its input mode causes the input mode for all channels within the device to change If there is a smart break out box present then you can set the input mode on a per channel basis Characteristics vendor Agilent Technologies Usage Al Channel Access Read write Data Type String Read onl y Yes while Running 11 12 InputMode Values Voltage The input mode is set to volts ICP The input mode is set to ICP Charge The input mode is set to charge amp Mic The input mode is set to microphone 200Volt Mic The input mode is set to microphone with 200 volt supply turned on See Also Properties Coupling I nputRange nputType 11 13 InputSource Purpose Specify the input to the A D converter Description For input channels nput Source c
137. al id function Typically you usei sdi ol ine directly only when you are creating your own M files Suppose you create the function my f unc for use with the Data Acquisition Toolbox If myf unc is passed one or more lines as an input argument then the first thing you should doin the function is check if the argument is a line function myfunc line Determine if a line was passed if isdioline line error The argument passed is not a line end You can examine the Data Acquisition Toolbox M files for examples that use isdioline Functions isvalid isvalid Purpose Syntax Arguments Description Remarks Example Determine if device objects channels or lines are valid out isvalid obj out isvalid obj Channel index out isvalid obj Line index obj A device object or array of device objects obj Channel index Oneor more channels contained by obj obj Line index One or more lines contained by obj out A logical array out isvalid obj returns a logical 1toout ifobj isa valid device object Otherwise a logical 0 is returned out isvalid obj Channel index returns a logical 1toout ifthe channels specified by obj Channel index are valid Otherwise a logical Ois returned out isvalid obj Line index returns a logical 1toout ifthe lines specified by obj Li ne index are valid Otherwise a logical O is returned Invalid device objects channels and lines are no l
138. alog Input 5 38 National Instruments When using National Instruments NI hardware there are additional trigger types and trigger conditions available to you These device specific property values fall into two categories hardware digital triggering and hardware analog triggering Thedevice specifictrigger types and trigger conditions are described below and in Chapter 10 Base Property Reference Table 5 8 Analog Input TriggerType and TriggerCondition Property Values for NI Hardware TriggerType TriggerCondition Description Value Value HwDi gi tal None The trigger occurs when the falling edge of a digital HwAnal ogChannel or HwAnal ogPin AboveHi ghLevel Bel owLowLevel HighHysteresis I nsideRegi on LowHysteresis TTL signal is detected Thetrigger occurs when the analog signal is above the specified value Thetrigger occurs when the analog signal is below the specified value The trigger occurs when the analog signal is greater than the specified high value with hysteresis given by the specified low value The trigger occurs when the analog signal is inside the specified region Thetrigger occurs when the analog signal is less than the specified low value with hysteresis given by the specified high value Configuring Analog Input Triggers Hardware Digital Triggering IfTri gger Type isHwDi git al thetrigger occurs when the falling edge of a digital TTL signal is detected
139. also present then these two signals cannot be distinguished In other words the 1 Hz sine wave produces the same samples as the 5 Hz sine wave when the sampling rate is 4 S s This situation is shown below 0 8 F e e ES o T T oS N Amplitude 0 2 0 4 0 6 0 8 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 Time sec Sample period In a real world data acquisition environment you may need to condition the signal by filtering out the high frequency components 1 36 M aking Q uality M easurements Even though the samples appear to represent a sine wave with a frequency of one fourth the sampling rate the actual signal could be any sine wave with a frequency of n 0 25 x Sampling rate where n is zeroor any positive integer For this example the actual signal may be at a frequency of 3 Hz 5 Hz 7 Hz 9 Hz and soon The relationship 0 25 x Sampling rate is called the alias of a signal that may be at another frequency In other words aliasing occurs when one frequency assumes the identity of another frequency If you sample the input signal at least twice as fast as the highest frequency component then that signal may be uniquely characterized but this rate would not mimic the waveform very closely As shown below to get an accurate picture of the waveform you need a sampling rate of roughly 10 to 20 times the highest frequency
140. alues refer to Chapter 7 Digital Input Output 1 Create a device object Create the digital O object di o for a National Instruments PCI 6024E board with hardware ID 1 dio digitalio nidaq 1 2 Add lines Add eight hardware lines to di o and configure them for output addline dio 0 7 out Accessing Your Hardware 3 Read and write values Create an array of output values and write the values to the digital I O subsystem Note that reading and writing digital O line values typically does not require that you configure specific property values pval 1111010 1 putval ue dio pval gval getvalue dio 4 Clean up When you nolonger need di o you should remove it from memory and from the MATLAB workspace del ete dio clear dio Note Digital line values are usually not transferred at a specific rate Although some specialized boards support clocked I O the Data Acquisition Toolbox does not support this functionality 2 11 2 G etting Started with the Data Acquisition Toolbox 2 12 Understanding the Toolbox Capabilities In addition to the printed and online documentation the Data Acquisition Toolbox provides these resources to help you understand the product capabilities e TheContents and Readme files e Documentation examples e The Quick Reference Guide e Demos The Contents and Readme Files TheContents M filelists the toolbox functions and demos Y ou can display this
141. an beSwitchBox CALIN Ground and BOBCALIN TheBOBCALIN valueis valid only when a smart break out box BoB is connected to the input Smart BoB s include a charge break out box or a microphone break out box When a smart break out box is attached to an E1432 or E1433 module additional input modes are available These additional input modes are available through the nput Mode property After a hardware reset nput Source iS automatically set toSwitchBox Characteristics Vendor Usage Access Data Type Read only while Running Values SwitchBox CALIN Ground BOBCALIN See Also Properties nput Mode 11 14 Agilent Technologies Al Channel Read write String Yes Select the front panel connector Select the module s CALIN line Ground the input Select the module s CALIN line via the CAL connection in a break out box NumMux Boards Purpose Description Characteristics Values Specify the number of external multiplexer devices connected NumMux Boards specifies the number of AMUX 64T multiplexer devices connected to your hardware NumMuxBoards can be0 1 2 or4 Ifyou are using a 1200 Series board then NumMux Boards can only be0 Vendor Usage Access Data type Read only when running 0 1 2 or4 National Instruments Al Common Read write Double No The number of AMU X 64T multiplexer devices connected 11 15 OutOfDataMode Purpose Description Characteristics Values
142. analog input objects are logged to separate files You can return data stored in a disk filetothe MATLAB workspace with thedaqr ead function If an error occurs during data logging an error message is returned and data logging is stopped Usage Al Common Access Read write Data type String Read only Yes when running Index Multiple log files are written each with an indexed filename based on the LogFi eName property Overwrite The log fileis overwritten Functions dagread Properties LogFileName LoggingMode ManualTriggerHwOn Purpose Description Characteristics Values Example Specify that the hardware device starts when a manual trigger is issued Manual Tri ggerHwOn can beset toStart orTrigger IfManual Tri ggerHwOn is Start then the hardware device associated with your device object starts running after you issuethest art function If Manual Tri ggerHwOn iSTrigger then the hardware device associated with your device object starts running after you execute a manual trigger with thet ri gger function You can use trigger only when you configure theTri ggerType property toManual Y ou should configure Manual Trigger HwOn toTri gger when you want to synchronize the input and output of data or you require more control over when an analog input device starts Note that you cannot use peekdata or acquire pretrigger data when you use this value Additionally you should not use this value with repeated triggers sinc
143. annel or line Base properties are displayed first followed by device specific properties If you use thehe l p command to display the M file help for get then you must supply the pathname shown below help daq daqdevice get Create the analog input object ai for a sound card and configure it to operate in stereo mode ai analoginput winsound addchannel ai 1 2 The commands shown below are some of the ways you can use get to return property values chan get ai Channel out get ai SampleRate TriggerDel ayUnits out get ai get chan 1 Units get chan I ndex HwChannel Channel Name Functions set setverify getdata Purpose Syntax Arguments Description Extract data time and event information from the data acquisition engine data getdata obj data getdata obj samples data getdata obj type data getdata obj samples type data time getdata data time abstime getdata data time abstime events getdata obj An analog input object samples The number of samples to extract If sampl es is not specified the number of samples extracted is given by the Sampl esPer Trigger property type Specifies the format of the extracted data as doubl e the default or as native data An m by n array where m is the number of samples extracted and n is the number of channels contained by obj ti me An m by 1 array of relative tim
144. annel 1 NativeScaling offset get ai Channel 1 NativeOffset data double nativedata scaling offset Functions daghwinfo daqread getdata putdata Properties I nputRange NativeScaling SensorRange UnitsRange NativeScaling Purpose Description Characteristics Values See Also Indicate the scaling to use when converting data from native format to doubles NativeScaling along with Nati veOffset is used to convert data from your hardware s native format to doubles using the formula data native data native scaling native offset For analog input objects you return data from the engine in native format using the get dat a function Additionally if you log native data toa daq file then you can read back that data usingthedaqr ead function For analog output objects you queue native data in the engine using the put dat a function You may want to return or queue data in native format to conserve memory and to increase speed TheNativeScaling value for a given channel may change if you change the UnitsRange SensorRange Or nput Range property values for that channel You can return the native data type of your hardware device with the daghwi nf o function Usage Al AO Channel Access Read only Data type Double Read only N A when running The default value is device specific Functions daqhwinfo daqread getdata putdata Properties InputRange NativeOffset SensorRange UnitsRange 10 55 Ou
145. aqsupport A 20 data extracting from engine 5 13 previewing 5 9 queuing for output 6 17 data acquisition session 3 2 acquiring data Al 4 13 adding channels Al object 4 4 AO object 6 4 adding lines 7 4 Index cleaning up 3 25 configuring properties Al object 4 9 AO object 6 6 creating a device object Al object 4 3 AO object 6 3 DIO object 7 3 loading 8 3 outputting data AO 6 9 saving 8 3 data block B 2 polling 5 11 data flow acquired data 2 4 output data 2 6 data missed event 5 47 Dat aMissedAction 5 47 debugging your hardware A 20 daqsupport A 20 dec2binvec 7 10 delete 3 25 demos 2 13 descriptive names channels 4 6 lines 7 8 device ID 4 3 device object 3 4 array 3 5 simultaneous input and output 6 37 configuring property values 3 18 copying 3 6 creating Al object 4 3 AO object 6 3 DIO object 7 3 invalid 3 7 loading 8 3 saving 8 3 specifying property names 3 19 starting 3 23 stopping 3 24 device specific properties 3 13 Agilent hardware 11 4 CBI hardware 11 4 NI hardware 11 3 sound cards 11 5 differential inputs 1 24 digital 1 O object adding lines 7 4 creating 7 3 display summary 7 18 port types 7 5 properties common 10 12 line 10 13 reading values 7 12 starting 7 16 status evaluation 7 18 stopping 7 16 writing values 7 10 digital triggers Agilent hardware Al object 5 45 AO object 6 26 CBI hardware Al 5 42 NI hardware Al object 5 39 AO object 6 25 digital values reading 7 12 writin
146. aranteed to complete execution until sometime after the device object and hardware device stop running and the Running property is set toOff Timer Event A timer event is generated whenever the time specified by the Ti mer Period property passes This event executes the action function specified for Ti mer Action Time is measured relative to when the device object starts running Some timer events may not be processed if your system is significantly slowed or iftheTi mer Peri od valueis toosmall For example a common application for Configuring Events and Actions timer events is to display data However since displaying data is a CPU intensive task some of these events may be dropped To guarantee that events are not dropped you may want to usethe Sampl es Out put Action property Trigger Event A trigger event is generated immediately after a trigger occurs This event executes the action function specified for Tri gger Acti on Under most circumstances the action function is not guaranteed to complete execution until sometime after Sending is set toOn Recording and Retrieving Event Information Whilethe analog output object is running certain information is automatically recorded in the Event Log property for some of the event types listed in the preceding section Event Log iS a structure that contains two fields Type and Data TheType field contains the event type The Dat a field contains event specific information Even
147. ardware channel ID as input arguments You can optionally specify MATLAB indices descriptive channel names and an output argument For example to add two hardware channels to the device object ao created in the preceding section chans addchannel ao 0 1 G etting Started with Analog O utput The output argument chans is a channel object that reflects the channel array contained by ao You can display the class of chans with thewhos command whos chans Name Size Bytes Class chans 2x1 512 aochannel object Grand total is 7 elements using 512 bytes Y ou can usechans to easily access channels For example you can easily configure or return property values for one or more channels As described in Referencing Individual Hardware Channels on page 4 6 you can also access channels with the Channel property Once you add channels to an analog output object the properties listed below are automatically assigned values These properties provide descriptive information about the channels based on their class type and ID Table 6 2 Descriptive Analog Output Channel Properties Property Name Description HwChannel Specify the hardware channel ID Index Indicatethe MATLAB index of a hardware channel Parent Indicate the parent device object of a channel Type Indicate a channel Y ou can display the values of these properties for chans with theget function get chans HwChannel Index Parent Type ans
148. arent Indicate the parent device object of a channel Type Indicate a channel Y ou can display the values of these properties for chans with theget function get chans HwChannel Index Parent Type ans 0 1 1x1 analoginput Channel 1 2 1x1 analogi nput Channel If you are using scanning hardware then the MATLAB indices define the scan order index 1 is sampled first index 2 is sampled second and so on Note The number of channels you can add to a device object depends on the specific board you are using Some boards support adding channels in any order and adding the same channel multiple times while other boards do not Additionally each channel may have its own input range which is verified with each acquired sample The collection of channels you add to a device object is sometimes referred to as a channel gain list or a channd gain queue For scanning hardware these channels define the scan order 4 5 4 G etting Started with Analog Input 4 6 Referencing Individual Hardware Channels As described in the preceding section you can access channels with the Channel property or with a channel object To reference individual channels you must specify either MATLAB indices or descriptive channel names MATLAB Indices Every hardware channel contained by an analog input object has an associated MATLAB index that is used to reference the channel When adding channels with theaddchannel
149. arying signals For example suppose you are measuring temperature once a minute If your acquisition system is picking up a 60 Hz hum from an a c power supply then that hum will appear as constant noise level if you are sampling at 30 Hz Aliasing occurs when the sampled signal contains frequency components greater than one half the sampling rate The frequency components could originate from the signal of interest in which case you are undersampling and should increase the sampling rate The frequency components could also originate from noise in which case you may need to condition the signal using a filter The rule used to prevent aliasing is given by the Nyquist theorem which states that e An analog signal can be uniquely reconstructed without error from samples taken at equal time intervals e The sampling rate must be equal to or greater than twice the highest frequency component in the analog signal A frequency of one half the sampling rate is called the Nyquist frequency However if your input signal is corrupted by noise then aliasing can still occur 1 35 1 Introduction to Data Acquisition For example suppose you configure your A D converter to sample at a rate of 4 samples per second 4 S s or 4 Hz and the signal of interest is a 1 Hz sine wave Since the signal frequency is one fourth the sampling rate then according to the Nyquist theorem it should be completely characterized However if a5 Hz sine wave is
150. assigned a descriptive name that is produced by concatenatingadaptor D and Al You can changethis name at any time analoginput Example More About the Hardware Device Identifier When data acquisition devices are installed they are assigned a unique number which identifies the device in software The device identifier is typically assigned automatically and can usually be manually changed using a vendor supplied device configuration utility National Instruments refers to this number as the device number while Agilent Technologies refers to it is as the device ID For sound cards the device identifier is typically not exposed to you through the Microsoft Windows environment However the Data Acquisition Toolbox automatically associates each sound card with an integer D value There are two cases to consider e f you have one sound card installed then D is O You are not required to specify D when creating an analog input object associated with this device e f you have multiple sound cards installed the first one installed has an D of 0 the second one installed has an D of 1 and so on You must specify D when creating analog input objects associated with devices not having an D of 0 There are two ways you can determine the D for a particular device e Typedaqhwinfo adaptor e Execute the vendor supplied device configuration utility National Instruments Tocreate an analog input object for a Nationa
151. ast sampling rate is required To make high quality measurements you should follow these rules e Maximize the precision and accuracy e Minimize the noise e Match the sensor range to the A D range Accuracy and Precision Whenever you acquire measured data you should make every effort to maximize its accuracy and precision The quality of your measurement depends on the accuracy and precision of the entire data acquisition system and can be limited by such factors as board resolution or environmental noise In general terms the accuracy of a measurement determines how close the measurement comes to thetrue value Therefore it indicates the correctness of the result The precision of a measurement reflects how exactly the result is determined without reference to what the result means The re ative precision indicates the uncertainty in a measurement as a fraction of the result For example suppose you measure a table top with a meter stick and find its length to be 1 502 meters This number indicates that the meter stick and your eyes can resolve distances down to at least a millimeter Under most circumstances this is considered to be a fairly precise measurement with a relative precision of around 1 1500 However suppose you perform the measurement again and obtain a result of 1 510 meters After careful consideration you discover that your initial technique for reading the meter stick was faulty because you did not read it from di
152. ate can be set to any value within the allowed bounds up to a maximum of 96 0 kHz 11 23 Sum Purpose Description Characteristics Values 11 24 Specify whether the source sum input is enabled or disabled Sum can be Off or On If Sumis Of f the sum input is disabled If Sum is On the sum input is enabled The signal on the sum input is internally added to the output that the source would otherwise produce For the Option 1D4 single channel source the source sum input is shared with the source COLA output Only one of thesetwo may be enabled at any onetime For prototype Option 1D4 sources one of the two must be enabled at all times By default the constant level output is enabled and the sum input is disabled Vendor Agilent Technologies Usage AO Channel Access Read write Data Type String Read only No while Running off Disable the source sum input On Enable the source sum input TransferMode Purpose Description Specify how data is transferred from the data acquisition device to system memory For National Instruments hardware Transfer Mode can bel nterrupts or Si ngl eDMA for both analog input and analog output subsystems If TransferMode iSi nterrupts then data is transferred from the hardware first in first out memory buffer FI FO to system memory using interrupts If Transfer Mode iSSi ngl eDMA then data is transferred from the hardware FIFO to system memory using a single dire
153. ation is stored in theType and Data fields of the EventLog property TheType field valueis Dat aMissed TheData field valueis Rel Sampl e which is the last sample acquired when the event occurred When a data missed event occurs the analog input object is automatically stopped Usage Al Common Access Read write Data type String Read onl y No when running The default valueisdagaction Functions dagaction Properties EventLog DefaultChannelValue Purpose Description Characteristics Values Example See Also Specify the value held by the analog output subsystem Def aul t Channel Val ue specifies the value to write to the analog output AO subsystem when data is finished being output from the engine Def aul tChannel Val ue is used only when Out Of Dat aMode is set to Def aul t Val ue This property guarantees that a known valueis held by the AO subsystem if a run time error occurs Note that sound cards do not have an Out Of Dat aMode property Usage AO Channel Access Read write Data type Double Read only Yes when running The default value is zero Create the analog output object ao and add two channels to it ao analogoutput nidaq 1 addchannel ao 0 1 Y ou can configureao so that when it stops outputting data a value of 1 volt is held for both channels ao Out Of DataMode DefaultValue ao Channel DefaultChannel Value 1 0 Properties Out Of Dat aMode 10 27 Di
154. ay containing relative time values for all m samples Time is measured relative to the time the first sample is logged and is measured continuously until the acquisition stops get dat a is described in more detail in Chapter 9 Function Reference You can log data to disk with theLoggi ngMode property You can replay data saved todisk with thedaqr ead function Refer to Logging nformation to Disk on page 8 6 for more information about Loggi ngMode and daqread Stopping the Analog Input Object An analog input object can stop under one of these conditions e You issue thest op function e The requested number of samples is acquired e A run time hardware error occurs e A timeout occurs When the device object stops the Running andLogging properties are automatically set to Of f At this point you can reconfigure the device object or immediately issue another st art command using the current configuration Analog Input Examples Analog Input Examples This section illustrates how to perform basic data acquisition tasks using analog input subsystems and the Data Acquisition Toolbox F or most data acquisition applications you must follow these basic steps 1 Install and connect the components of your data acquisition hardware At a minimum this involves connecting a sensor to a plug in or external data acquisition device 2 Configure your data acquisition session This involves creating a device object adding
155. ays mono mode or stereo mode For mono mode hwch must be1 For stereo mode the first hwch value specified must be 1 Note If you are using National Instruments AMUX 64T multiplexer boards you must use theaddmuxchannel function to add channels More About MATLAB Indices Every hardware channel contained by a device object has an associated MATLAB index that is used to reference the channel Index assignments are made either automatically by addchannel or explicitly with thei ndex argument and follow these rules e If index is not specified and no hardware channels are contained by the device object then the assigned indices automatically start at one and increase monotonically If hardware channels have already been added to the device object then the assigned indices automatically start at the next highest index value and increase monotonically e Ifi ndex is specified but the indices are previously assigned then the requested assignment takes precedence and the previous assignment is reindexed to the next available values If the lengths of hwch andi ndex are addchannel not equal then an error is returned and no channels are added to the device object e Theresulting indices begin at one and increase monotonically up to the size of the channel group e f you are using scanning hardware then the indices define the scan order e Sound cards cannot be reindexed Rules for Adding Channels to National Instruments 1200 S
156. basic data acquisition session using an analog input object Channels introduces adding and configuring analog input channels Triggers illustrates how data can be acquired using an immediate manual and software trigger Data Logging illustrates how to configure an analog input object for data logging Introduction Channels Triggers Data Logging Common Demos Thecommon demos illustrate features that are common toall supported device objects These demos are listed below Demo Name Description demodag_action Introduction to action functions demodaq_intro Introduction to the Data Acquisition Toolbox demodaq save Save and load device objects daqtimerplot Example action function that plots acquired data Understanding the Toolbox Capabilities Analog Input Demos The analog input demos are listed below Demo Name Description dagrecord daqscope demoai_ channel demoai_fft demoai_intro demoai_logging demoai_trig Record data from the specified adaptor Example oscilloscope Introduction to analog input channels Fast Fourier transform FFT of an incoming signal Introduction to analog input objects Demonstrate logging data to a disk file Demonstrate the use of immediate manual and software triggers Analog Output Demos The analog output demos are listed below Demo Name Description daqfcngen daqpl ay daqsong demoao_ channel demoao_intro demoa
157. ber of hardware channels you use e The number of samples you need to store in the engine e The data type size of each sample The memory required for data storage is given by the formula memory required samples stored x channel number x data type Of course the number of samples you need to store in the engine at any time depends on your particular needs The memory used by a device object is given by the formula memory used block size x block number x channel number x data type The block size and block number is given by the Buf f eri ngConfig property The data type is given by the Nati veDat aType field of thedaghwi nf o function Y ou can display the memory resources used by and available to a device object with the da q me m function For analog input objects memory is used when channels are added For analog output objects memory is used when data is queued in the engine For both device objects the memory used can dynamically change based on the number of samples acquired or queued B Managing Your Memory Resources Example Managing Memory Resources Suppose you create the analog input object ai for a sound card add two channels to it and configure a four second acquisition using a sampling rate of 11 025 kHz al analoginput winsound addchannel ai 1 2 set ai SampleRate 11025 set ai SamplesPerTrigger 44100 You return the default block size and number of blocks with the BufferingConfig proper
158. box function st art or trigger Conversely device specific hardware triggers depend on the specific hardware device you are using For these trigger types the action that initiates the trigger event involves an external digital signal Device specific hardware triggers for National Instruments and Agilent Technologies devices are discussed in Device Specific Hardware Triggers on page 6 25 Device independent triggers are discussed below Immediate Trigger If Tri gger Type is mmedi ate the default value the trigger occurs immediately after thest art function is issued You can configure an analog output object for continuous output by using an immediate trigger and setting Repeat Output toinf Manual Trigger If Tri ggerType is Manual the trigger occurs immediately after thetrigger function is issued Configuring Analog O utput Triggers Executing the Trigger For an analog output trigger to occur you must follow these steps 1 Queue data in the engine 2 Configure the appropriate trigger properties 3 Issuethestart function 4 Issuethetrigger function ifTriggerType iSManual Oncethetrigger occurs queued data is output tothe hardware and the device object stops executing when all the queued data is output Note Only one trigger event can occur for analog output objects How Many Triggers Occurred For analog output objects only one trigger can occur You can determine if the trigger event occurred b
159. cbi hpel432 and wi nsound unload Specifies that the hardware driver adaptor is to be unloaded out Captures the message returned by daqregister daqregister adaptor registers the hardware driver adaptor specified by adaptor For third part adaptors adaptor must include the full pathname daqregister adaptor unload unregisters the hardware driver adaptor specified by adapt or For third part adaptors adaptor must include the full pathname out dagregister captures the resulting message in out A hardware driver adaptor must be registered sothe data acquisition engine can make use of its services Unless an adaptor is unloaded registration is required only once For adaptors that are included with the toolbox registration occurs automatically when you first create a device object However you may need to register third party adaptors manually In either case you must install the associated hardware driver before registration can occur The following command registers the sound card adaptor provided with the toolbox dagregister winsound The following command registers thethird party adaptor my adaptor dl Note that you must supply the full pathname to daqregi ster daqregister D MATLABR12 toolbox daq myadaptors myadaptor dll 9 43 daqreset Purpose Syntax Description See Also 9 44 Remove device objects and data acquisition DLLs from memory dagreset daqreset removes a
160. ch sample can be represented by any number between 0 and 65 535 For older Sound Blaster cards configured for full duplex operation you may not be able to set Bi tsPer Sampl e to 16 bits for both the analog input and analog output subsystems Instead you need to set one subsystem for 8 bits and the other subsystem for 16 bits Note Sound cards with greater than 16 bits are not supported by the toolbox Vendor Usage Access Data type Read only when running 16 Sound cards Al AO Common Read write Double Yes Represent data with 8 bits Represent data with 16 bits 11 7 COLA Purpose Description Characteristics Values 11 8 Specify whether the source constant level output is enabled or disabled COLA can beoff or On If COLA is Of f the source constant level output is disabled If COLA is ON the source constant level output is enabled For the Option 1D4 single channel source the source COLA output is shared with the source sum input Only one of these two may be enabled at any one time For prototype Option 1D4 sources only one of the two must be enabled at all times and the default is for the constant level output to be enabled Vendor Usage Access Data Type Read only while Running Of f On Agilent Technologies AO Channel Read write String Yes The source constant level output is disabled The source constant level output is enabled Coupling Purpose
161. cified byobj Line index More About Writing Values to Lines e You can specify dat a as either a decimal value or a binary vector A binary vector or binvec is constructed with the least significant bit LSB in the first column and the most significant bit MSB in the last column F or example the decimal number 23 is written as the binary vector 1110 1 e Ifobj contains lines from a port configurable device then all lines will be written to even if they are not contained by the device object e An error will be returned if data is written to an input line e An error is returned if you attempt to write a negative value e f a decimal value is written to a digital O object and the value is too large to be represented by the hardware then an error is returned Create the digital O object di o and add four output lines to it dio digitalio nidaq 1 lines addline dio 0 3 out Write the value 8 as a decimal value and as a binary vector putvalue dio 8 putvalue dio 0 0 0 1 9 83 Save Purpose Syntax Arguments Description Remarks See Also 9 84 Save device objects to a MAT file save file save file obj1 obj2 file The MAT file name obj 1 obj 2 One or more device objects or an array of device objects save file saves all MATLAB variables to the MAT filef il e If an extension is not specified for f i e then a MAT extension is used save file obj1 obj2 Saves the specif
162. cify the range of the analog output hardware subsystem Parent Indicate the parent device object of a channel Type Indicate a channel Units Specify the engineering units label UnitsRange Specify the range of data as engineering units Digital I O Properties Digital I O base properties are divided into two main categories common properties and line properties Common properties apply to every line contained by the digital I O object while line properties can be configured for individual lines Common Properties The digital I O common properties are given below Digital I O Common Properties Line Contain hardware lines added tothe device object Na me Specify a descriptive name for the device object Running Indicate if the device object is running Tag Specify a device object label Ti merAction Specify the M file action function to execute whenever a predefined period of time passes Ti mer Period Specify the period of time between timer events Properties Grouped by Category Digital I O Common Properties Continued Type Indicate the device object type UserData Store data that you want to associate with a device object Line Properties The digital I O line properties are given below Digital I O Line Properties Direction Specify whether a line is used for input or output HwLine Specify the hardware line ID Index Indicate the MATLAB index of a hardware line LineName Speci
163. clocked For most digital converters sampling is performed by a sample and hold S H circuit An S H circuit usually consists of a signal buffer followed by an electronic switch connected to a capacitor The operation of an S H circuit follows these steps 1 Ata given sampling instant the switch connects the buffer and capacitor to an input 2 Thecapacitor is charged to the input voltage 3 Thecharge is held until the A D converter digitizes the signal 4 For multiple channels connected multiplexed to one A D converter the previous steps are repeated for each input channel 5 Theentire process is repeated for the next sampling instant The Analog Input Subsystem A multiplexer S H circuit and A D converter are illustrated in the next section Hardware can be divided into two main categories based on how signals are sampled scanning hardware which samples input signals sequentially and simultaneous sample and hold SS H hardware which samples all signals at the same time These two types of hardware are discussed below Scanning Hardware Scanning hardware samples a single input signal converts that signal toa digital value and then repeats the process for every input channel used In other words each input channel is sampled sequentially A scan occurs when each input in a group is sampled once As shown below most data acquisition devices have one A D converter that is multiplexed to multiple input channels
164. ct memory access DMA channel Some boards also support aTransferMode of Dual DMA for analog input subsystems For example the AT MIO 16E 1 board supports this transfer mode If Transfer Mode iS Dual DMA then data is transferred from the hardware FIFO to system memory using two DMA channels Depending on your system resources data transfer via interrupts can significantly degrade system performance For ComputerBoards hardware Transfer Mode can beDefault InterruptPerPoint DMA orl nterruptPerBlock IfTransferMode iSDefault the transfer mode is automatically selected by the driver based on the board type and the sampling rate If TransferMode isinterruptPerPoint asingle conversion is transferred for each interrupt You should use this property value if your sampling rate is less the 5 kHz or you specify a small block size for memory buffering as defined by the Buf f eri ngConfig property If TransferMode iSDMA data is transferred using a single DMA channel If TransferMode iSI nterruptPerBl ock a block of data is transferred for each interrupt You should use this property value if your sampling rate is greater than 5 kHz and you are using a board that has a fast maximum sampling rate Note that a data block is defined by the board and usually corresponds to half the FIFO size Note If your sampling rate is greater than around 5 kHz you should avoid using interrupts if possible The recommended Transfer Mode setting for your application
165. ct todaqhwi nfo and examine the Di ff erential Ds field out daqhwinfo ai out Differentiall Ds ans 0 1 2 3 4 5 6 7 The first three differential channels have Ds0 1 and2 respectively addchannel ai 0 2 The index assigned to a hardware channel depends on the order in which you add it to the device object In the above example the channels are automatically assigned the MATLAB indices 1 2 and 3 respectively You can change the hardware channels associated with the MATLAB indices using the HwChannel property For example to swap the order of the second and third hardware channels al Channel 2 HwChannel 2 al Channel 3 HwChannel l Adding Channels or Lines The original and modified index assignments are shown below Hardware channel ID MATLAB index O lt gt 1 Original index assignment lt gt 2 2 lt gt 3 O lt gt 1 Modified index aru i a 2 3 Note If you are using scanning hardware then the MATLAB indices define the scan order index 1 is sampled first index 2 is sampled second and so on For digital 1 O objects the diagram would look the same except that lines would be substituted for channels 3 11 3 The Data Acquisition Session Configuring and Returning Properties Y ou define and evaluate the behavior of your data acquisition application with device object properties You define your application behavior by assigning values to properties with thes et fu
166. ction displays the absolute time and relative sample associated with the start trigger and stop events 1 Create a device object Createthe analog output object A0 for a sound card The installed adaptors and hardware IDs are found with daqhwi nfo AO analogoutput winsound A0 analogoutput nidaq 1 A0 analogoutput cbi 1 2 Add channels Add one channel toA0 chan addchannel AO 1 chan addchannel A0 0 For NI and CBI Configuring Events and Actions 3 Configure property values Specify daqdoc6_5disp as the M file action function to execute when the start trigger and stop events occur generate data to be queued and queue the data with one call toput data set A0 SampleRate 8000 Actual Rate get A0 SampleRate set A0 StartAction dagdoc6_5disp set A0 TriggerAction dagdoc6_5disp set A0 StopAction dagdoc6_5disp data sin linspace 0 2 pi ActualRate data data data data time length data A0O SampleRate putdata AO data 4 Output data Start A0 start A0 5 Clean up When you no longer need A0 you should remove it from memory and fromthe MATLAB workspace delete A0 clear AO 6 33 6 Analog O utput Linearly Scaling the Data Engineering Units The Data Acquisition Toolbox provides you with a way tolinearly scale data as it is being queued in the engine You can associate this scaling with specific engineering units such as volts
167. ctions daqmem Properties BufferingConfig Al AO Common Read write String Yes Memory is allocated by the data acquisition engine Memory is allocated manually 10 17 Channel Purpose Description Characteristics Values Example 10 18 Contain hardware channels added to a device object Channel isa vector of all the hardware channels contained by an analog input Al or analog output AO object Since a newly created Al or AO object does not contain hardware channels Channel is initially an empty vector The size of Channel increases as channels are added with theaddchannel function and decreases as channels are removed using the del et e function Channel is used to reference one or more individual channels To reference a channel you must know its MATLAB index which is given by the ndex property For example you must use Channel with the appropriate indices when configuring channel property values For scanning hardware the scan order follows the MATLAB index Therefore the hardware channel associated with index 1 is sampled first the hardware channel associated with index 2 is sampled second and so on To change the scan order you can specify a permutation of the indices with Channel Usage Al AO Common Access Read write Data type Vector of channels Read only Yes when running Values are automatically defined when channels are added to the device object with theaddchannel function T
168. ctions getdata peekdata 9 61 getvalue Purpose Syntax Arguments Description Remarks Example See Also 9 62 Read values from lines out getval ue obj out getvalue obj Line index obj A digital 1 O object obj Line index One or more lines contained by obj out A binary vector out getvalue obj returns the current value from all lines contained by obj asa binary vector toout out getvalue obj Line index returns the current value from the lines specified by obj Line index More About Reading Values from Lines e By default out is returned as a binary vector binvec A binvec value is constructed with the least significant bit LSB in the first column and the most significant bit MSB in the last column For example the decimal number 23 is written as the binvec value 1110 1 e You can convert a binvec value to a decimal value with the bi nvec2dec function e If obj contains lines from a port configurable device the data acquisition engine will automatically read from all the lines even if they are not contained by the device object Create the digital I O object di o and add eight input lines to it dio digitalio nidaq 1 lines addline dio 0 7 in Toreturn the current values from all lines contained by di o as a binvec value out getvalue dio Functions binvec2dec ischannel Purpose Syntax Arguments Description Remarks Example See Also
169. cute whenever a predefined period of time passes Specify the period of time between timer events Specify the M file action function to execute when a trigger occurs 10 6 Properties G rouped by Category Analog Input General Purpose Properties BufferingConfig BufferingMode Channel EventLog Name Tag Ti meout Type UserData Specify the per channel allocated memory Specify how memory is allocated Contain hardware channels added to the device object Store information for specific events Specify a descriptive name for the device object Specify a device object label Specify an additional waiting time to extract data Indicate the device object type Store data that you want to associate with a device object Channel Properties The analog input channel properties are given below Analog Input Channel Properties Channel Name HwChannel Index Input Range NativeOffset NativeScaling Specify a descriptive channel name Specify the hardware channel ID Indicate the MATLAB index of a hardware channel Specify the range of the analog input subsystem Indicate the offset to use when converting data from native format to doubles Indicate the scaling to use when converting data from native format to doubles 10 7 10 Base Property Reference 10 8 Analog Input Channel Properties Continued Parent Indicate the parent device object of a channel S
170. d 2 residing in VXI chassis 0 AO analogoutput hpel432 vxid 1 2 instr Alternatively you can use the syntax AO analogoutput hpel432 1 2 0 See Also Functions addchannel daqhwi nfo Properties Name 9 23 binvec2dec Purpose Syntax Arguments Description Remarks Example See Also 9 24 Convert binary vector to decimal value out binvec2dec bin bin A binary vector out A double array out binvec2dec bin converts the binary vector bi n tothe equivalent decimal number and stores the result in out All nonzero binary vector elements are interpreted as a 1 A binary vector binvec is constructed with the least significant bit LSB in the first column and the most significant bit MSB in the last column F or example the decimal number 23 is written as the binvec value 1110 1 To convert the binvec value 1 1 1 0 1 toa decimal value binvec2dec 1 1 1 0 1 ans 23 Functions dec2binvec clear Purpose Syntax Arguments Description Remarks Remove device objects from the MATLAB workspace clear obj clear obj Channel i ndex clear obj Line index obj A device object or array of device objects obj Channel index Oneor more channels contained by obj obj Line index One or more lines contained by obj clear obj removesobj and all associated channels or lines from the MATLAB workspace but not from the data acquisition engine clear obj Cha
171. d acquisition set Al Voice SampleRate 44100 Actual Rate get AlVoice SampleRate set Al Voice SamplesPerTrigger Actual Rate duration set AlVoice TriggerChannel chan set AlVoice TriggerType Software set Al Voice TriggerCondition Rising set Al Voice TriggerConditionValue 0 2 set AlVoice TriggerDelayUnits Samples set AlVoice TriggerDelay 500 4 Acquire data Start Al Voi ce acquire the specified number of samples and extract the first 1000 samples from the engine as sample time pairs start Al Voi ce while strcmp Al Voice Running On end data time getdata Al Voice 1000 Plot all the extracted data plot time data xlabel Time sec ylabel Signal Level Volts grid on 5 Clean up When you no longer need Al Voi ce you should remove it from memory and from the MATLAB workspace delete Al Voice clear AlVoice 5 29 5 Doing More with Analog Input 5 30 The output from this example is shown below Note that the pretrigger data constitutes half of the 1000 samples extracted from the engine Additionally pretrigger data has negative time associated with it since time 0 corresponds to the time the trigger event occurs and data logging is initiated Voice Activation with Pretriggering 0 3 T T T 0 1 F 4 O i ae Signal Level Volts 0 4 L 1 i 1 1 0 015 0 01 0 005 0 0 005 0 01 0 015 Time sec Re
172. d immediately after a trigger occurs This event executes the action function specified for the Trigger Action property Under most circumstances the action function is not guaranteed to complete execution until sometime after Logging is set to 0n Configuring Events and Actions Recording and Retrieving Event Information While the analog input object is running certain information is automatically recorded in the Event Log property for some of the event types listed in the preceding section Event Log iS a structure that contains two fields Type and Data TheType field contains the event type TheData field contains event specific information Events are recorded in the order in which they occur The first Event Log entry reflects the first event recorded the second Event Log entry reflects the second event recorded and so on The event types recorded in Event Log for analog input objects as well as the values for theType and Data fields are given below Table 5 12 Analog Input Event Information Stored in EventLog Event Type Type Field Value Data Field Value Data missed DataMissed Rel Sample Input overrange OverRange Rel Sample Channel OverRange Run time error Error AbsTi me Rel Sample String Start Start AbsTi me Rel Sample Stop Stop AbsTi me Rel Sample Trigger Trigger AbsTi me Rel Sample Channel Trigger 5 49 5 Doing More with Analog Input 5 50 Samples acquired events and timer events are not s
173. data as sample time pairs and returns the absolute time of the trigger The absolute time is returned as aclock vector and is identical to the value stored by the ni ti al Tri ggerTi me property data time abstime events getdata extracts data as sample time pairs returns the absolute time of the trigger and returns a structure containing a list of events that occurred up totheget data call The possible events that can be returned are identical to those stored by the Event Log property More About getdata e n most circumstances get dat a returns all requested data and does not miss any samples In the unlikely event that the engine cannot keep pace with the hardware device it is possible that data is missed If data is missed the Dat aMi ssedActi on property is called and the device object is stopped e get data isa blocking function since it returns execution control to the MATLAB workspace only when the requested number of samples are extracted from the engine for each channel group member e You can issue C Control C whileget data is blocking This will not stop the acquisition but will return control to MATLAB e The amount of data that you can extract from the engine is given by the Sampl esAvail able property getdata Example More About Extracting Data From the Engine e Once the requested data is extracted fromtheengine theSampl esAvail able property value is automatically reduced by the number of sampl
174. ddchannel ai 0 3 set ai SampleRate 1000 Actual Rate get ai SampleRate set ai SamplesPerTrigger Actual Rate set ai LoggingMode Disk amp Memory set ai LogFileName data daq start ai After the data has been collected and saved to a disk file you can retrieve the data and other acquisition related information using daqr ead To read all the sample time pairs from data daq data time dagread data daq 9 41 daqread See Also 9 42 To read samples 500 to 1000 for all channels from data daq data dagread data daq Samples 500 1000 To read the first 0 5 seconds of data for channels 1 and 2 from data daq data dagread data daq Time 0 0 5 Channels 1 2 To obtain the channel property information from data daq daginfo dagread data daq info chaninfo daqinfo Obj Info Channel To obtain a list of event types and event data contained by data daq daginfo dagread data daq info events daginfo Obj Info EventLog event type events Type event _ data events Data Functions getdata Properties EventLog LogFileName LoggingMode LogToDiskMode daqregister Purpose Syntax Arguments Description Remarks Example Register or unregister a hardware driver adaptor dagregister adaptor dagregister adaptor unload out dagregister adaptor Name of the hardware driver adaptor The supported adaptors areni daq
175. do this you should connect a known signal such as that produced by a function generator to one of the channels using a BNC cable The result of such a test is shown below for channel 0 Board Test PCI DAS4020 12 at b400h Lx Analog Loop Back Test Advanced Scan Test ChO Avg Yal 0 1995 volts 5 0 5 0 Input Ch Signal Source A D Range JEXTERNAL BV Connect a low frequency signal lt 100Hz as shown and verfiy the proper waveform BNI CHO EXT JE If InstaCal does not provide you with the expected results for the subsystem under test and you are sure that your test setup is configured correctly then the problem is probably with the hardware To get support for your ComputerBoards hardware visit their Web site at http www computerboards com Troubleshooting Agilent Technologies Hardware Troubleshooting Agilent Technologies Hardware If you are having trouble using the Data Acquisition Toolbox with a supported Agilent Technologies device the reason may be that e You are using a hardware driver that is incompatible with the tool box e Your hardware is not functioning properly What Driver Are You Using The Data Acquisition Toolbox is compatible only with specific versions of the HP E1432 driver and is not guaranteed to work with any other versions Y ou can find out which driver version you are using with the Soft Front Panel which is described
176. e For example to queue 8000 samples in the engine for each channel contained by the analog output object ao ao analogoutput winsound addchannel ao 1 2 data sin linspace 0 2 pi 8000 putdata ao data data Before the queued data can be output you must start the analog output object start ao When a trigger occurs theSendi ng property is automatically set to0n andthe queued data is sent to the hardware Stopping the Device Object An analog input Al or analog output AO object can stop under one of these conditions e You issue thest op function e The requested number of samples is acquired Al or sent AO e A run time hardware error occurs e A timeout occurs When the device object stops the Running Logging and Sendi ng properties are automatically set to0ff At this point you can reconfigure the device object or immediately issue another st art command using the current configuration Cleaning Up Cleaning Up When you no longer need a device object you should clean up the MATLAB environment by removing the object from memory the engine and from the workspace These are the steps you take to end a data acquisition session Y ou remove device objects from memory with the del et e function For example to delete the analog input object ai created in the preceding section delete ai A deleted device object is invalid which means that you cannot connect it tothe hardware In this case
177. e 2 4 The Hardware Driver Adaptor 0 00 cece eee 2 7 Accessing Your Hardware 0 0 0 ee eeee 2 8 Acquiring Data 2 0 ete 2 8 OQULPULTING Data zos orase senie west tea nt ee ees 2 9 Reading and Writing Digital Values o o o 2 10 Understanding the Toolbox Capabilities 2 12 The Contents and Readme Files o oococcccocccoco o 2 12 Documentation Examples 000 0c cee eee eee 2 12 The Quick Reference Guide 00 00 e eee ee 2 13 DAMOS rs E E ee ok EE 2 13 Examining Your Hardware Resources 2 17 General Toolbox Information o oooocccocococoo 2 17 ii Contents Adaptor Specific Information 0 00 cece eee ees 2 18 Device Object Information 0 000 cece ee 2 19 Getting Help stos ie Ave 2 20 Thedaghelp Function oooccccccocc ee 2 20 The propinfo Function ococcccoccc dadan wii 2 21 3 Overview cias PI ae AR E dos 3 2 Example The Data Acquisition Session 04 3 3 Creating a Device Object 00 0 eee 3 4 Creating an Array of Device Objects 0 00 3 5 Where Do Device Objects Exist 0 2 0 0 00 cece eee 3 6 Adding Channels or Lines 0 0000 3 8 Mapping Hardware Channel IDs to MATLAB Indices 3 9 Configuring and Returning Properties 3 12 Property TYP 5 2 vba coe e OP a eb Oe ed eb ees 3 12 Returning P
178. e IDs are found with daqhwi nfo dio digitalio nidaq 1 2 Add lines Add eight output lines from port 0 line configurable addline dio 0 7 out 3 Read and write values Write a value of 13 tothe first four lines as a decimal number and as a binary vector and read back the values data 13 putval ue dio Line 1 4 data vall getvalue dio bvdata dec2binvec data putvalue dio Line 1 4 bvdata val2 getvalue dio 7 13 7 Digital input O utput 7 14 Write a value of 3 tothe last four lines as a decimal number and as a binary vector and read back the values data 3 putvalue dio Li ne 5 8 data val3 getvalue dio Line 5 8 bvdata dec2binvec data 4 putval ue dio Line 5 8 bvdata val4 getvalue dio Line 5 8 Read values from the last four lines but switch the most significant bit MSB and the least significant bit LSB val5 getvalue dio Line 8 1 5 4 Clean up When you nolonger need di o you should removeit from memory and from the MATLAB workspace delete dio clear dio Generating Timer Events Generating Timer Events The fact that analog input and analog output objects make use of data stored in the engine and clocked I O leads to the concept of a running device object and the generation of events However since the Data Acquisition Toolbox does not support buffered digital I O operations digital O objects do not store data in the engine
179. e circumstances e A device object is cleared from the MATLAB workspace and it needs to be retrieved from the data acquisition engine e You need to locate device objects channels or lines that have particular property names and property values Rules for Specifying Property Names and Property Values e You can use property name property value string pairs structures and cell array pairs in thesame call todaqf ind However in asingle call todagfind you can specify only device object properties or channel line properties e You must use the same format as returned by get For example if get returns the Channel Name property value as Left you must specify Left as the property valuein daqf ind case matters However case does not matter when you specify enumerated property values For example daqf ind will find a device object with a Runni ng property value of On oron You can usedaqfi nd toreturn a cleared device object al analoginput winsound ch addchannel ai 1 2 set ch Channel Name Joe Jack clear al ainew dagfind Toreturn the channel associated with the descriptive name ack ch2 daqfind ainew Channel Name Jack Toreturn the device object with a sampling rate of 8000 Hz and the descriptive namewi nsound0 Al you can pass a structuretodaqfind S Name winsound0 Al S SampleRate 8000 daqobj daqfind S Functions clear get propinfo 9 29 daghelp Purpose S
180. e event occurred Rel Sample The acquired Al or output AO sample number when the event occurred String The descriptive error message Run time errors include hardware errors and timeouts Run time errors do not include configuration errors such as setting an invalid property value Usage Al AO Common Access Read write Data type String Read only No when running The default valueis dagaction RuntimeErrorAction See Also Functions daqaction Properties EventLog Ti meout 10 63 SampleRate Purpose Description Characteristics Values 10 64 Specify the per channel rate at which analog data is converted to digital data or digital data is converted to analog data Sampl eRate specifies the per channel rate in samples second that an analog input Al or analog output AO subsystem converts data Al subsystems convert analog data to digital data while AO subsystems convert digital data to analog data Al and AO subsystems have a finite though often large number of valid sampling rates If you specify a sampling rate that does not match one of the valid values then the data acquisition engine automatically selects the next highest supported sampling rate that is within 1 of the requested rate If there is no valid sampling rate within this tolerance the next highest value is selected If a higher value is not available then an error is returned Sincethe engine can set the sampling ratet
181. e for measuring several signals with a single measuring device is multiplexing Signal conditioning devices for analog signals often provide multiplexing for use with slowly changing signals such as temperature This is in addition to any built in multiplexing on the DAQ board The A D converter samples one channel switches to the next channel and samples it switches to the next channel and so on Because the same A D converter is sampling many channels the effective sampling rate of each individual channel is inversely proportional to the number of channels sampled You must take care when using multiplexers so that the switched signal has sufficient time to settle Refer to Noise on page 1 33 for more information about settling time The Data Acquisition System Excitation Source Some sensors require an excitation source to operate For example strain gauges and resistive temperature devices RTDs require external voltage or current excitation Signal conditioning modules for these sensors usually provide the necessary excitation RTD measurements are usually made with a current source that converts the variation in resistance to a measurable voltage The Computer The computer provides a processor a system clock a bus to transfer data and memory and disk space to store data The processor controls how fast data is accepted by the converter The system clock provides time information about the acquired data Knowing t
182. e formula data native data native scaling native offset For analog input objects you return data from the engine in native format using the get dat a function Additionally if you log native data toa daq file then you can read back that data usingthedaqr ead function For analog output objects you queue native data in the engine using the put dat a function You may want to return or queue data in native format to conserve memory and to increase speed Thenative0ffset value for a given channel may change if you change the UnitsRange SensorRange Or nput Range property values for that channel You can return the native data type of your hardware device with the daghwi nfo function Usage Al AO Channel Access Read only Data type Double Read only N A when running The default value is device specific Create the analog input object ai for a National Instruments board and add eight channels to it al analoginput nidaq 1 addchannel ai 0 7 Start ai collect one second of data for each channel and extract the data from the engine using the native format of the device start ai nativedata getdata ai 1000 native 10 53 NativeOffset See Also 10 54 Y ou can return the native data type of the board with the daqhwi nf o function out daghwi nf o ai out NativeDataType ans int 16 Convert the data to doubles using theNativeScaling andNati veOffset properties scaling get ai Ch
183. e hardware channels specified by hwch to the device object obj i ndex specifies the MATLAB indices to associate with the added channels chans addchannel obj hwch names adds the hardware channels specified by hwch tothe device object obj The MATLAB indices associated with the added channels are assigned automatically names is a descriptive channel name or cell array of descriptive channel names chans addchannel obj hwch index names addsthehardwarechannels specified by hwch tothe device object obj i ndex specifies the MATLAB indices to associate with the added channels names is a descriptive channel name or cell array of descriptive channel names 9 9 addchannel Remarks 9 10 Rules for Adding Channels e Thenumeric values you supply for hwch depend on the hardware you access For National Instruments and ComputerBoards hardware channels are zero based begin at zero For Agilent Technologies hardware and sound cards channels are one based begin at one Hardware channel IDs are stored in the HwChannel property and the associated MATLAB indices are stored in the ndex property You can add individual hardware channels to multiple device objects For for sound cards and Agilent Technologies devices you cannot add a hardware channel multiple times to the same device object For Agilent Technologies devices added channels must bein increasing order e You can configure sound cards in one of two w
184. e it is digitized Signal amplification allows you to reduce noise and to make use of the full range of your hardware thereby increasing the resolution of the measurement 1 11 1 Introduction to Data Acquisition 1 12 Filtering Filtering removes unwanted noise from the signal of interest A noise filter is used on slowly varying signals such as temperature to attenuate higher frequency signals that can reduce the accuracy of your measurement Rapidly varying signals such as vibration often require a different type of filter known as an antialiasing filter An antialiasing filter removes undesirable higher frequencies that may lead to erroneous measurements Electrical Isolation If the signal of interest may contain high voltage transients that could damage the computer then the sensor signals should be electrically isolated from the computer for safety purposes You can also use electrical isolation to make sure that the readings from the data acquisition hardware are not affected by differences in ground potentials For example when the hardware device and the sensor signal are each referenced to ground problems occur if thereis a potential difference between the two grounds This difference can lead to a ground loop which may lead to erroneous measurements Using electrically isolated signal conditioning modules eliminates the ground loop and ensures that the signals are accurately represented Multiplexing A common techniqu
185. e maximum accelerometer range in volts and UnitsRange is set to the corresponding range in g s set chan SensorRange 5 5 set chan InputRange 0 5 0 5 set chan UnitsRange 50 50 set chan Units g s 1g 9 80 m s s 4 Acquire data Start the acquisition and wait until all the data is acquired start Al while strcmp Al Running On end linearly Scaling the Data Engineering Units Extract and plot all the acquired data data getdata Al subplot 2 1 1 plot data Calculate and display the frequency information Fs Actual Rate blocksize duration Actual Rate f mag daqdocfft data Fs blocksize subplot 2 1 2 pl ot f mag 5 Clean up When you no longer need Al you should remove it from memory and from the MATLAB workspace delete Al clear Al 5 59 5 Doing More with Analog Input 5 60 Analog Output Overview Getting Started with Analog Output Creating an Analog Output Object Adding Channels to an Analog Output Object Configuring Analog Output dicots i Outputting Data Analog Output Examples Evaluating the Analog Output Object Status Managing Output Data Queuing Data with putdata Example Queuing Data with putdata Configuring Analog Output Triggers Defining a Trigger Trigger Types Executing the Trigger a How Many Triggers Occurred When Did the Trigger Occur Device Specific Hardware Triggers Configuri
186. e next section 7 15 7 Digital Input O utput 7 16 Some timer events may not be processed if your system is significantly slowed oriftheTi mer Peri od valueis toosmall For example a common application for timer events is to display data However since displaying data can be a CPU intensive task some of these events may be dropped For digital I O objects timer events aretypically used to display the state of the device object Refer tothe di opanel demofor an example that generates timer events to update the state of a digital 1 O object To see how to construct an action function refer to Creating and Executing Action Functions on page 5 52 or the example below Starting and Stopping a Digital I O Object You usethest art function to start a digital O object For example to start the digital 1 O object di o start dio After start is issued theRunni ng property is automatically set to 0n and timer events can be generated If you attempt to start a digital I O object that does not contain any lines or that is already running then an error is returned A digital 1 O object will stop executing under these conditions e Thest op function is issued e An error occurred in the system When the device object stops Running is automatically set to Off Generating Timer Events Example Generating Timer Events This example illustrates how to generate timer events for a digital I O object Theaction functio
187. e object is running you can continue to queue data However running does not necessarily mean that data is being output from the engine to the analog output hardware For that to occur a trigger must execute When the trigger executes the Sending property is automatically set to0n Analog output triggers are described on Defining a Trigger on page 6 8 and Configuring Analog Output Triggers on page 6 21 6 9 6 Analog O utput 6 10 Stopping the Analog Output O bject An analog output object can stop under one of these conditions e You issue thest op function e The queued data is output e A run time hardware error occurs e A timeout occurs When the device object stops the Running and Sendi ng properties are automatically set to Of f At this point you can reconfigure the device object or immediately queue more data and issue another st art command using the current configuration Analog Output Examples This section illustrates how to perform basic data acquisition tasks using analog output subsystems and the Data Acquisition Toolbox For most data acquisition applications using analog output subsystems you must follow these basic steps 1 Install and connect the components of your data acquisition hardware At a minimum this involves connecting an actuator to a plug in or external data acquisition device 2 Configure your data acquisition session This involves creating a device object adding channe
188. e properties since these properties can only be set to specific values accepted by the hardware You can use the pr opi nf o function to obtain information about the valid values for these properties If a property value is specified but does not match a valid value then e f the specified value is within the range of supported values FortheSampl eRat e and nput Range properties the valueis automatically rounded up to the next highest supported value For all other properties the value is automatically selected to be the nearest supported value e f the valueis not within the range of supported values an error is returned and the current property value remains unchanged Createthe analog input objectai for a National Instruments AT M O 16DE 10 board add eight hardware channels to it and set the sample rate to 10 000 Hz usingsetverify ai analoginput nidaq 1 ch addchannel ai 0 7 Actual Rate setverify ai SampleRate 10000 Suppose you uses et veri f y toset theinput range for all channels contained by ai to 8 to 8 volts ActuallnputRange setverify ai Channel InputRange 8 8 Thel nput Range value was actually rounded up to 10 to 10 volts Actual l nputRange 1 ans 10 10 Functions get propinfo set Properties InputRange Out putRange Sampl eRate 9 89 show daqevents Purpose Syntax Arguments Description Remarks 9 90 Display event log information showdaqevents
189. e range Triggers Specify the trigger range Channel s Specify the channel range Channel names can be specified as a cell array DataFormat Specify the data format asdoubles ornative TimeFor mat Specify the time format asvector ormatrix TheSamples Time andTriggers properties are mutually exclusive If none of these three properties is specified then all the data is returned Retrieving Event Device O bject Channel and Hardware Information Y ou can retrieve event device object channel and hardware information along with data and time information using the syntax shown below data time abstime events daqinfo dagread file P1 V1 P2 V2 events iS a structure containing event information associated with the logged data The events retrieved depend on the value of the Sampl es Ti me or Triggers property At a minimum the trigger event associated with the selected data is returned The entire event log is returned toevents only if Samples Time or Triggers is not specified daqi nf o isa structure that stores device object channel and hardware information in two fields Obj nfo and Hwi nfo Obj Inf o isa structure containing property values for the device object and any channels it contains The property values are returned in the same format as returned by get Hwi nf o is a structure containing hardware information The hardware information is identical to the information returned by daqhwi nf o obj
190. e the power and flexibility of your analog output application by utilizing events An event occurs at a particular time after a condition is met and may result in one or more actions While the analog output object is running you can use events to display a message display data analyze data or perform just about any other action Actions are controlled through action properties and action functions All event types have an associated action property Action functions are M file functions that you construct to suit your specific data acquisition needs You execute an action when a particular event occurs by specifying the name of the M file action function as the value for the associated action property Refer to Creating and Executing Action Functions on page 5 52 to learn how to create action functions Note that daqacti on is the default value for some action properties Event Types The analog output event types and associated action properties are described below Table 6 9 Analog Output Action Properties Event Type Property Name Run time error RuntimeErrorAction Samples output SamplesOutputAction Sampl esOutputActionCount Start StartAction Stop StopAction Timer Timer Action Ti mer Period Trigger TriggerAction 6 27 6 Analog O utput 6 28 Run time Error Event A run time error event is generated immediately after a run time error occurs This event executes the action function specified for Run
191. e the subsequent behavior is undefined Usage Al Common Access Read write Data type String Read only Yes when running Start Start the hardware after thes tart function is issued Trigger Start the hardware after thet ri gger function is issued Create the analog input object ai and the analog output object ao for a sound card and add two channels to each device object al analoginput winsound addchannel ai 1 2 ao analogoutput winsound addchannel ao 1 2 10 49 ManualTriggerHwOn See Also 10 50 To operate the sound card in full duplex mode and to minimize the time between when ai starts andao starts you configure Manual Tri ggerHwOn to Trigger forai andTriggerType toManual for bothai andao set ai ao TriggerType Manual al Manual TriggerHwOn Trigger Theanalog input and analog output hardware devices will both start after you issue thet rigger function For a detailed example that uses Manual Tri ggerHwOn refer to Starting Multiple Device Objects on page 6 37 Functions peekdata start trigger Properties TriggerType Max SamplesQueued Purpose ndicate the maximum number of samples that can be queued in the engine Description MaxSampl es Queued indicates the maximum number of samples allowed in the analog output queue The default value is calculated by the engine and is based on the memory resources of your system You can override the default value of MaxSampl
192. e values where m is the number of samples extracted Relative time is measured with respect to the first sample logged by the engine absti me The absolute time of the first trigger returned as acl ock vector This value is identical to the value stored by the Initial TriggerTi me property events A structure containing a list of events that occurred up to the time of theget data call data getdata obj extracts the number of samples specified by the Sampl esPer Trigger property for each channel contained by obj data isan m by n array where m is the number of samples extracted and n is the number of channels data getdata obj samples extracts the number of samples specified by sampl es for each channel contained by obj 9 57 getdata Remarks 9 58 data getdata obj type extracts data in the specified format Ift ype is specified as nat i ve the data is returned in the native data format of the device Ift ype iS specified as doub e the default the data is returned as doubles data getdata obj samples type extracts the number of samples specified bys a mp es in theformat specified by t y pe for each channel contained by obj data time getdata returns data as sampletime pairs ti me is an m by 1 array of relative time values where m is the number of samples returned Relative time is measured with respect to the first sample logged by the engine data time abstime getdata extracts
193. each input channel serving as a trigger source Al only Trigger Thetrigger number Al only Usage Al AO Common Access Read write Data type String Read only No when running The default value is an empty string Functions trigger Properties EventLog Logging 10 83 TriggerChannel Purpose Description Characteristics Values Example See Also 10 84 Specify the channels serving as trigger sources Tri ggerChannel specifies the channels serving as trigger sources The trigger channel s must be specified before the trigger type You may need to configure theTriggerCondition andTriggerConditionVal ue properties in conjunction with Trigger Channel For all supported vendors if Tri ggerType iS Software then you must acquire data from the channel being used for the trigger source For National Instruments hardware ifTriggerType isHwAnalogChannel then Tri ggerChannel must bethe first element of the channel group The exception is if you are using the PCI 6110 or PCI 6111 board In this case you can specify any channel for theTriggerChannel value Usage Al Common Access Read write Data type Vector of channels Read only Yes when running The default value is an empty vector Create the analog input object ai add two channels and define the trigger source as channel 2 al analoginput winsound ch addchannel ai 1 2 set ai TriggerChannel ch 2 set ai TriggerType Software
194. ead However you will probably use daqread in one of these two ways e Retrieving data and time information e Retrieving event device object channel and hardware information Retrieving Data and Time Information Y ou can characterize logged data by the sample number or thetimethe sample was acquired To retrieve data and time information you use the syntax shown below data time abstime daqread file P1 V1 P2 V2 where e data is the retrieved data Data is returned as an m by n matrix where mis the number of samples and n is the number of channels e ti me optional is the relative time associated with the retrieved data Time is returned as an m by 1 matrix where m is the number of samples e absti me optional is the absolute time of the first trigger Absolute time is returned as acl ock vector e file isthe name of the log file e P1 V2 P2 V2 optional are the property name property value pairs which allow you to select the amount of data to retrieve among other things see below daqread returns data and time information in the same format as get data If data from multiple triggers is retrieved each trigger is separated by a NaN Logging Information to Disk Y ou select the amount of data returned and the format of that data with the properties given below Table 8 2 daqread Properties Property Name Description Samples Specify the sample range Ti me Specify the relative tim
195. ect Y Y Y trigger Manually execute a trigger Y Y waittilstop Wait for the device object to stop running Y Y Working with Data Al AO DIO flushdata Remove data from the data acquisition engine Y getdata Extract data time and event information from the data v acquisition engine getsample Immediately acquire one sample Y getvalue Read values from lines Y peekdata Preview most recent acquired data Y putdata Queue data in the engine for eventual output Y putsample Immediately output one sample Y putvalue Write values to lines Y Getting Information and Help Al AO DIO daqhelp Display help for device objects constructors adaptors Y Y Y functions and properties daqhwi nfo Display data acquisition hardware information Y Y Y 9 5 9 Function Reference 9 6 Getting Information and Help Continued Al AO DIO daqpropedit Invoke the property editor graphical user interface Y Y Y propinfo Return property characteristics for device objects Y Y Y channels or lines General Purpose Al AO DIO binvec2dec Convert binary vector to decimal value Y clear Remove device objects from the MATLAB workspace Y Y Y daqaction An action function that displays event information for Y Y Y the specified event daqfind Return device objects channels or lines from the data Y Y Y acquisition engine to the MATLAB workspace daqmem Allocate or display memory resources Y Y daqread Read a Data Acquisition Toolbox daq file Y
196. ed e A run time error occurs e TheTi meout property value is reached wai tti me Supersedes this value It is not guaranteed that theStopAction property is called before waittilstop returns The stop action event is recorded by the Event Log property waittilstop Example See Also Create the analog input object ai for a National Instruments board add eight channels to it and configure a 25 second acquisition ai analoginput nidaq 1 ch addchannel ai 0 7 al SampleRate 2000 ai TriggerRepeat 4 ai SamplesPerTrigger 10000 You can usewaittilstop toblock the MATLAB command line until all the requested data is acquired Since the expected acquisition time is 25 seconds thewaittime argument is 26 If the acquisition does not complete within this time then a timeout occurs start ai waittilstop ai 26 Properties EventLog Running StopAction Ti meout 9 99 waittilstop 9 100 Base Property Reference Overview 2 ee a 10 2 Getting Command LinePropertyHelp 10 2 Properties Grouped by Category 10 3 Analog Input Properties 10 3 Analog Output Properties 0 10 8 Digital I O Properties 10 12 Properties Listed Alphabetically 10 14 10 Base Property Reference Overview 10 2 This section provides descriptions of all toolbox base properties Base properties apply to all suppo
197. efined number of samples is output for each channel group member A samples output event is generated immediately after the number of samples specified by theSamplesOutputActionCount property is output for each channel group member This event executes the action function specified for Sampl esOutputAction Samples output event information is not storedin theEventLog property Usage AO Common Access Read write Data type String Read only No when running The default value is an empty string Properties EventLog Sampl esOutputActionCount 10 71 SamplesOutputActionCount Purpose Specify the number of samples to output for each channel group member before a samples output event is generated Description A samples output event is generated immediately after the number of samples specified by Samp esQut putActionCount is output for each channel group member This event executes the action function specified by the SamplesOutputAction property Characteristics Usage AO Common Access Read write Data type Double Read onl y Yes when running Values The default value is 1024 See Also Properties SamplesOut putActi on 10 72 SamplesPerTrigger Purpose Description Characteristics Values Example See Also Specify the number of samples to acquire for each channel group member for each trigger that occurs Sampl esPer Trigger specifies the number of samples to acquire for each analog input channel group
198. el and Hardware Information You can retrieve event object channel and hardware information by specifying the appropriate arguments todaqr ead For example to retrieve all event information you must return all the logged data data time abstime events info daqread file00 daq events Type ans Start Trigger Trigger Trigger Trigger Stop If you retrieve part of the data then only the events associated with the requested data are returned data time abstime events info dagread file00 daq Trigger 1 3 events Type ans Trigger Trigger Trigger You can retrieve the entire event log as well as object and hardware information by includingi nfo as an input argument todaqread daginfo dagread file00 daq info daqinfo Objl nfo 1x1 struct Hwi nfo 1x1 struct Toreturn the event log information eventinfo daqinfo Obj Info EventLog eventinfo 6x1 struct array with fields Type Data 8 13 8 Saving and Loading the Session 8 14 Function Reference Overview 2 2 ee 9 2 Getting Command LineFunctionHelp 9 2 Functions Grouped by Category 9 4 Functions Listed Alphabetically 9 8 9 Function Reference 9 2 Overview This section provides descriptions of all toolbox functions that you can use directly In Functions Grouped by Category on page 9 4 the functions are summarized according
199. en specifying property names Additionally you need use only enough letters to identify the property name uniquely so you can abbreviate most property names For example you can configure thes amp eRate property any of these ways set ai SampleRate 44100 set ai samplerate 44100 set ai sampler 44100 However when you include property names in an M file you should use the full property name This practice can prevent problems with future releases of the Data Acquisition Toolbox if a shortened nameis no longer unique because of the addition of new properties Default Property Values If you do not explicitly define a value for a property then the default value is used All configurable properties have default values However the default value for a given property may vary based on the hardware you are using Additionally some default values are calculated by the engine and depend on the values set for other properties If the hardware driver adaptor specifies a default value for a property then that value takes precedence over the value defined by the toolbox 3 19 3 The Data Acquisition Session 3 20 If a property has a finite set of string values then the default value is enclosed by curly braces For example the default value for the Loggi ngMode property is Me mor y set ai LoggingMode Disk Memory Disk Memor y Y ou can alsousethepropi nfo function or refer to Chapter 10 Base Pr
200. energy into sound energy Signal conditioning hardware Sensor signals are often incompatible with data acquisition hardware To overcome this incompatibility the signal must be conditioned F or example you may need to condition an input signal by amplifying it or by removing unwanted frequency components Output signals may need conditioning as well However only input signal conditioning is discussed in this chapter The computer The computer provides a processor a system clock a bus to transfer data and memory and disk space to store data Software Data acquisition software allows you to exchange information between the computer and the hardware For example typical software allows you to configure the sampling rate of your board and acquire a predefined amount of data The Data Acquisition System The data acquisition components and their relationship to each other are shown below Physical phenomena Data Acquisition System Computer L 7 Software Signal aie conditioning Ls Acquisition hardware Actuator K Es dimt e ee ee ee ee Physical phenomena Data analysis The figure depicts the two important features of a data acquisition system e Signals are input to a sensor conditioned converted into bits that a computer can read and analyzed to extract meaningful information For example sound level data is
201. enseToGround isOn Characteristics Vendor National Instruments Usage Al Common Access Read write Data type String Read only Yes when running Values Off Do not drive AISENSE to onboard ground On Drive AISENSE to onboard ground See Also Properties InputType 11 10 GroundingMode Purpose Description Characteristics Values Specify the input channel grounding mode GroundingMode can beGrounded orFloating IfGroundingMode isGrounded the low side of the channel is grounded IfGroundi ngMode isFloating thelow side of the channel floats thereby making the input a differential input Groundi ngMode can be set only for input channels Source channels are never floating and are always grounded If a smart break out box is attached to the channel then the grounding mode is automatically set to the appropriate value If a dumb break out box or no break out box is attached to the channel the grounding mode is given by the GroundingMode value In this case no hardware settings are changed and no errors are generated Vendor Usage Access Data type Read only while Running Grounded Floating Agilent Technologies Al Channel Read write String Yes The input channel is grounded The input channel is floating 11 11 InputMode Purpose Specify the channel input mode Description Input Mode can besettoVoltage CP Charge Mic or200Vol t Mic You can set nput Mode toChar ge only if a charge bre
202. ensorRange Specify the range of data you expect from your sensor Type Indicate a channel Units Specify the engineering units label UnitsRange Specify the range of data as engineering units Analog Output Properties Analog output base properties are divided into two main categories common properties and channel properties Common properties apply to every channel contained by the analog output object while channel properties can be configured for individual channels Common Properties The analog output common properties are grouped into the following categories based on usage Analog Output Basic Setup Properties SampleRate Specify the per channel rate at which digital data is converted to analog data TriggerType Specify the type of trigger to execute Analog Output Trigger Properties Initial Trigger Indicate the absolute time of the first trigger Ti me TriggerAction Specify the M file action function to execute when a trigger occurs Properties Grouped by Category Analog Output Trigger Properties Continued TriggersExecuted Indicate the number of triggers that execute TriggerType Specify the type of trigger to execute Analog Output Status Properties Running Indicate if the device object is running Sampl esAvailable Indicatethe number of samples available per channel in the engine Sampl es Out put Indicate the number of samples output per channel from the en
203. eout where each field nameis the nameof a channel property of 0bj and each field contains the value of that property out get obj Line index returns the structureout where each field name is the name of a line property of obj and each field contains the value of that property out get obj PropertyName returns the value of the property specified by PropertyName toout IfPropertyName is replaced by a 1 by n or n by 1 cell array of strings containing property names then get returns a 1 by n cell array of values toout Ifobj isan array of data acquisition objects then out will be an m by n cell array of property values where mis equal to the length of obj and nis equal tothe number of properties specified out get obj Channel index PropertyName returns the value of PropertyName toout for the specified channels contained by obj If multiple 9 55 get Remarks Example See Also 9 56 channels and multiple property names are specified then out is an m by n cell array where m is the number of channels and n is the number of properties out get obj Line index PropertyName returns the value of PropertyName toout for the specified lines contained by obj If multiple lines and multiple property names are specified then out is an m by n cell array where m is the number of lines and n is the number of properties get displays all property names and their current values for the specified device object ch
204. er required to represent the number dec2bi nvec 23 4 ans 1 1 1 0 1 Functions binvec2dec 9 47 delete Purpose Syntax Arguments Description Remarks 9 48 Remove device objects channels or lines from the data acquisition engine del ete obj del ete obj Channel index delete obj Line index obj A device object or array of device objects obj Channel index One or more channels contained by obj obj Li ne index One or more lines contained by obj del ete obj removes the device object specified by obj fromthe engine If obj contains channels or lines they are removed as well If obj is the last object accessing the driver then the driver and associated adaptor are unloaded del ete obj Channel index removes the channels specified by i ndex and contained by obj from the engine As a result the remaining channels may be reindexed del ete obj Line index removes thelines specified byi ndex and contained by obj fromthe engine As a result the remaining lines may be reindexed Deleting device objects channels and lines follows these rules e del ete removes device objects channels or lines from the data acquisition engine but not from the MATLAB workspace To remove variables from the workspace use the c ear function If multiple references to a device object exist in the workspace then removing one device object from the engine invalidates the remaining references These
205. er while Agilent Technologies refers toit is as the device ID For sound cards the device identifier is typically not exposed to you through the Microsoft Windows environment However the Data Acquisition Toolbox automatically associates each sound card with an integer D value There are two cases to consider e f you have one sound card installed then D is 0 You are not required to specify D when creating an analog output object associated with this device e f you have multiple sound cards installed the first one installed has an D of 0 the second one installed has an D of 1 and so on You must specify D when creating analog output objects associated with devices not having an D of 0 There are two ways you can determine the D for a particular device e Typedaqhwinfo adaptor e Execute the vendor supplied device configuration utility National Instruments To create an analog output object for a National Instruments board defined as device number 1 AO anal ogoutput nidaq 1 Agilent Technologies To create an analog output object for an Agilent Technologies module with device identifier 1 residing in VXI chassis 0 AO analogoutput hpel432 vxi0 l i instr Alternatively you can use the syntax AO anal ogout put hpel432 1 0 analogoutput The HP driver allows you to span multiple hardware devices To create an analog output object that spans two HP devices with device identifiers 1 an
206. ergoing a vibration test Y our job is to measure the acceleration and the frequency components of the device while it is vibrating The accelerometer has a range of 50 g s a voltage sensitivity of 99 7 mV g and a resolution of 0 00016 g 5 57 5 Doing More with Analog Input 5 58 The accelerometer signal is input toa Tektronix TDS 210 digital oscilloscope and to channel 0 of the data acquisition board By observing the signal on the scope the maximum expected range of data from the sensor is 200 mV which corresponds to approximately 2 g s Given this constraint you should configure the board s input range to the 500 mV which is the closest input range that encompasses the expected data range Y ou can run this example by typing daqdoc5_8 atthe MATLAB command line 1 Create a device object Create the analog input object Al for a National Instruments board The installed adaptors and hardware Ds are found with daqhwinfo Al analoginput nidaq 1 2 Add channels Add one hardware channel toAl chan addchannel Al 0 3 Configure property values Configure the sampling rate to 200 kHz and define a two second acquisition duration 2 Actual Rate setverify Al SampleRate 200000 set Al SamplesPerTrigger duration Actual Rate Configure the engineering units properties This example assumes you are using a National Instruments PCI 6024E board or an equivalent hardware device SensorRange is set toth
207. eries Boards When using National Instruments 1200 Series hardware you need to modify the above rules in these ways e Channel I Ds aregivenin reverseorder withaddchannel For example toadd eight single ended channels to the analog input object ai addchannel ai 7 1 0 e The scan order is from the highest ID to the lowest ID which must be 0 e There cannot be any gaps in the channel group e When channels are configured in differential mode the hardware IDs are O 2 4 and 6 More About Descriptive Channel Names You can assign hardware channels descriptive names which are stored in the Channel Name property Choosing a unique descriptive name can be a useful way to identify and reference channels For a single call toaddchannel you can e Specify one channel name that applies to all channels that are to be added e Specify a different name for each channel to be added If the number of names specified in a singleaddchannel call is more than one but not equal tothe number of channels to be added then an error is returned If a channel is to be referenced by its name then that name must not contain symbols If you are naming a large number of channels then the make na mes function may be useful If a channel is not assigned a descriptive name then it must be referenced by index A sound card configured in mono mode is automatically assigned the name Mono while a sound card configured in stereo mode is automatically assigned
208. erring data via DMA is given below 1 When data is ready for transfer the board directs the system DMA controller to put it into in system memory as soon as possible 2 Assoon as the CPU is able which is usually very quickly it stops interacting with the data acquisition hardware and the DMA controller moves the data directly into memory 3 TheDMA controller gets ready for the next sample by pointing to the next open memory location 4 Theprevious steps are repeated indefinitely with data going to each open memory location in a continuously circulating buffer No interaction between the CPU and the board is needed Your computer supports several different DMA channels Depending on your application you can use one or more of these channels For example simultaneous input and output with a sound card requires one DMA channel for the input and another DMA channel for the output M aking Q uality M easurements Making Quality Measurements For most data acquisition applications you need to measure the signal produced by a sensor at a specific rate In many cases the sensor signal is a voltage level that is proportional to the physical phenomena of interest for example temperature pressure or acceleration If you are measuring slowly changing quasi static phenomena like temperature a slow sampling rate usually suffices If you are measuring rapidly changing dynamic phenomena like vibration or acoustic measurements a f
209. erty is set toAuto SinceBufferingConfig indicates the memory used by the engine you should monitor this property closely Channel Skew Many data acquisition devices have one A D converter that is multiplexed toall input channels If you sample multiple input channels from scanning hardware then each channel is sampled sequentially following this procedure 1 Asingleinput channel is sampled 2 Theanalog signal is converted toa digital value 3 The process is repeated for every input channel being used Since these channels cannot be sampled simultaneously a time gap exists between consecutively sampled channels This time gap is called the channd skew The channel skew and the sample period is illustrated below A Channels Group Group Group scan 1 scan 2 scan n _ a O O O O O O O O O O O O O gt Sample period gt Channel skew gt Time 5 7 5 Doing More with Analog Input As shown in the preceding figure a scan occurs when all channels in a group are sampled once and the scan rate is defined as the rate at which every channel in the group is sampled The properties associated with configuring the channel skew are given below Table 5 3 Channel Skew Properties Property Name Description Channel Skew Channel SkewMode Specify the time between consecutive scanned hardware channels Specify how the channel skew s determined Channel Skew and Cha
210. es returned If the requested number of samples is greater than the samples to be acquired then an error is returned If the requested data is not returned in the expected amount of time an error is returned The expected timeto return data is given by thetimeit takes the engine to fill one data block plus the time specified by the Ti meout property If multiple triggers are included in asingleget data call a NaN is inserted into the returned data and time arrays and the absolute time returned is given by the first trigger MATLAB supports math operations only for the double data type Therefore to use math functions on native data you must convert it to doubles Create the analog input object ai for a National Instruments board and add hardware channels 0 3 to it al analoginput nidaq 1 addchannel ai 0 3 Configure a one second acquisition with Samp eRat e set to 1000 samples per second and Sampl esPer Trigger set to 1000 samples per trigger set ai SampleRate 1000 set ai SamplesPerTrigger 1000 start ai Thefollowingget dat a command blocks execution control until all sample time pairs the absolute time of the trigger and any events that occurred duringthe getdata Call are returned data time abstime events getdata ai data is returned as a 1000 by 4 array of doubles ti me is returned as a 1000 by 1 vector of relative times absti me is returned as aclock vector and events is returned as a 3 by 1 s
211. escription Characteristics Values See Also 10 66 ndicate the number of samples acquired per channel SamplesAcqui red is continuously updated to reflect the current number of samples acquired by an analog input object It is reset to zero after astart function is issued UsetheSamp esAvail able property to find out how many samples are available to be extracted from the engine Usage Al Common Access Read only Data type Double Read only N A when running The value is continuously updated to reflect the current number of samples acquired The default value is zero Functions start Properties SamplesAvailable SamplesAcquiredAction Purpose Specify the M file action function to execute every time a predefined number of samples is acquired for each channel group member Description A samples acquired event is generated immediately after the number of samples specified by the Sampl esAcquiredActionCount property is acquired for each channel group member This event executes the action function specified for Sampl esAcquiredAction You should useSa mpl es AcquiredActi on if you must access each sample that is acquired If you do not have this requirement you may want to use the Ti mer Action property Samples acquired event information is not stored in theEvent Log property Characteristics Usage Al Common Access Read write Data type String Read only No when running Values The default value is an emp
212. esponding function header is function myaction obj event ti me If you pass additional parameters to the action function then they must be included in the function header after the two required arguments Configuring Events and Actions Specifying a Toolbox Function as an Action In addition to specifying your own action function you can specify thest art stop ortrigger toolbox functions as actions For example to configureai to stop running when an overrange condition occurs ai nputOverRangeAction stop Examples Using Action Properties and Functions This section provides examples that show you how to create action functions and configure action properties Displaying Event Information with an Action Function This example illustrates how action functions allow you to easily display event information The example uses dagacti on to display information for trigger run time error and stop events The default Samp eRate and Sampl esPer Trigger values areused which results in a 1 second acquisition for each trigger executed Y ou can run this example by typingdagdoc5_6 at the MATLAB command line 1 Create a device object Createthe analog input object Al for a sound card The installed adaptors and hardware Ds are found with daghwi nfo Al analoginput winsound Al analoginput nidaq 1 Al analoginput cbi 1 2 Add channels Add one hardware channel toAl chan addchannel Al 1 chan
213. etail Getting Command Line Property Help To get command line property help you should use the daghe p function For example to get help for the sound card s Bi ts Per Sampl e property daqhelp BitsPerSample Note You can usedaghel p without creating a device object You can also get property characteristics such as the default property value usingthepr opi nf o function For example suppose you create the analog input object ai for a sound card and want to find the default value for the BitsPerSample property ai analoginput winsound out propinfo ai BitsPerSample out Default Value ans 16 Properties Listed by Vendor Properties Listed by Vendor This section contains brief descriptions of all toolbox device specific properties The properties are grouped according to these supported vendors e National Instruments properties e ComputerBoards properties e Agilent Technologies properties e Sound card properties multi vendor Y ou can display device specific properties with the set function The device specific properties are displayed after the base properties Note Some device specific property values are not available for all devices Refer to your hardware documentation for detailed information about device specific behavior National Instruments Properties The device specific National Instruments properties for analog input Al and analog output AO objects are given below
214. ete listing of the device object s functions and properties is displayed along with a brief description of each function and property The help for the device object s constructor is also displayed e You can display object specific function information by specifying na me as object function F or example to display the help for an analog input object s getdata function name isanaloginput getdata e You can display object specific property information by specifying name as obj property For example to display the help for an analog input object s Sampl eRate property name iSanaloginput SampleRate For thedaqghel p obj name syntax e Ifname is the name of a device object constructor and the m extension is included the constructor help is displayed e Ifname is the name of a function or property the function or property help is displayed The following commands are some of the ways you can use daghel p to obtain help on device objects constructors adaptors functions and properties daqhelp analogoutput out daghelp analogoutput m daqhelp set daqhelp anal oginput peekdata daqhelp analoginput TriggerDelayUnits The following commands are some of the ways you can usedaghel p to obtain information about functions and properties for an existing device object al analoginput winsound daghel p ai InitialTriggerTi me out daqhelp ai getsample Functions propinfo 9 31 daqhw info Purpose
215. evice Specific 7 rue fonos BITSPERSAMPLE 16 BitsPerSample specifies the number of bits the sound card uses to each sample Property help The value of BitsPerSample cannot ke modified while the object is 3 21 3 The Data Acquisition Session 3 22 Acquiring and Outputting Data After you configure the device object you can acquire or output data Acquiring and outputting data involves these three steps 1 Starting the device object 2 Logging data or sending data 3 Stopping the device object As data is being transferred between MATLAB and your hardware you can think of the device object as being in a particular state Two types of states are defined for the Data Acquisition Toolbox Running For analog input objects running means that data is being acquired from an analog input subsystem H owever the acquired data is not necessarily saved to memory or a disk file For analog output objects running means that data queued in the engine is ready to be output to an analog output subsystem Therunning state is indicated by theRunni ng property for both analog input and analog output objects Running can beOn or Off Logging or Sending For analog input objects logging means that data acquired from an analog input subsystem is being stored in the engine or saved to a disk file The logging state is indicated by the Logging property Logging can beOn or Off For analog output objects sendi
216. execute just before the device object starts running Description A start event is generated immediately after thes tart function is issued This event executes the action function specified for St art Action When the action function has finished executing Runni ng is automatically set to 0n and the device object and hardware device begin executing Start event information is stored in theType and Data fields of theEventLog property TheType field valueis St art TheData field values are given below Data Field Value Description AbsTi me The absolute time as ac ock vector the event occurred Rel Sample The acquired Al or output AO sample number when the event occurred Characteristics Usage Al AO Common Access Read write Data type String Read only No when running Values The default value is an empty string See Also Functions start Properties EventLog Runni ng 10 76 StopAction Purpose Specify the M file action function to execute just after the device object stops running Description A stop event is generated immediately after the device object and hardware device stop executing This occurs when e Astop function is issued e For analog input Al objects the requested number of samples to acquire was reached or data was missed For analog output AO objects the requested number of samples to output was reached e A run time error occurred A stop event executes the action functio
217. falling edge of an external digital signal Pretrigger data cannot be captured HwAnalogChannel Thetrigger sourceis an external analog signal Al only HwAnalogPin The trigger source is a low range external analog signal Al only For 1200 Series hardware HwDi gi tal isthe only device specificTrigger Type value for analog input subsystems Analog output subsystems do not support any device specificTriggerType values ComputerBoards HwDi gital The trigger source is an external digital signal Al only Pretrigger data cannot be captured HwAnal og The trigger source is an external analog signal Al only Agilent Technologies HwDi gital The trigger source is an external digital signal Al only Pretrigger data cannot be captured HwAnal og The trigger source is an external analog signal Al only HwDi git al Pos The trigger source is the positive edge of an external digital signal AO only HwDi git al Neg The trigger source is the negative edge of an external digital signal AO only Functions start trigger Properties Logging Sending TriggerCondition TriggerConditionValue 10 95 Type Purpose Description Characteristics Values 10 96 ndicate the device object type a channel or a line Type is associated with device objects channels and lines For device objects Type can beAnal og Input Analog Output orDigital 1 0 Once a device object is created the value of Ty pe is automatically de
218. ferent subsystems on the same device e The channels must be sampled at the same rate Y ou add channels to an analog input object with theaddchannel function addchannel requires the device object and at least one hardware channel ID as input arguments You can optionally specify MATLAB indices descriptive channel names and an output argument For example to add two hardware channels tothe device object ai created in the preceding section chans addchannel ai 0 1 The output argument chans is a channel object that reflects the channel array contained by ai You can display the class of chans with the whos command whos chans Name Size Bytes Class chans 2x1 512 aichannel object Grand total is 7 elements using 512 bytes Y ou can usechans to easily access channels For example you can easily configure or return property values for one or more channels As described in Referencing Individual Hardware Channels on page 4 6 you can also access channels with the Channel property Adding Channels to an Analog Input O bject Once you add channels toan analog input object the properties listed below are automatically assigned values These properties provide descriptive information about the channels based on their class type and ID Table 4 2 Descriptive Analog Input Channel Properties Property Name Description HwChannel Specify the hardware channel ID Index Indicatethe MATLAB index of a hardware channel P
219. fined For channels the only value of Type is Channel For lines the only value of Type isLi ne The value is automatically defined when channels or lines are added to the device object Usage Al AO Common Channel DIO Common Line Access Read only Data type String Read only N A when running Device Objects For device objects Type has these possible values Analog Input The device object type is analog input Analog Output The device object type is analog output Digital 10 The device object type is digital I O The value is automatically defined after the device object is created Channels and Lines For channels the only value of Type is Channel For lines the only value of Type isLi ne The value is automatically defined when channels or lines are added to the device object Units Purpose Description Characteristics Values See Also Specify the engineering units label Units is astring that specifies the engineering units label to associate with your data You should use Uni ts in conjunction with theUni tsRange property Usage Al AO Channel Access Read write Data type String Read only No when running The default valueis Volts Properties UnitsRange 10 97 UnitsRange Purpose Description Characteristics Values See Also 10 98 Specify the range of data as engineering units You use Uni ts Range to scale your data to reflect particular engineering units For
220. fy a descriptive line name Parent Indicate the parent device object of a line Port Specify the port ID Type Indicate a line 10 13 10 Base Property Reference Properties Listed Alphabetically This section contains detailed descriptions of all toolbox device specific properties Each property reference page contains some or all of this information e The property name e A description of the property e The property characteristics including 10 14 Usage the device objects the property can be used with and whether it is a common property or a channel or line property Common properties apply to all channels or lines contained by the device object while channel line properties can be set on a per channel per line basis The device objects supported by the Data Acquisition Toolbox include analog input Al analog output AO and digital I O DIO objects Access whether the property is read write or read only Read write property values can be returned with the get command and configured with thes et command Read only property values can be returned with the get command but cannot be configured with thes et command Data type the property data type The supported data types include action function double string Channel Line and any Read only when running whether a property value can be configured when the device object is running Valid property values including the default value When proper
221. fy a different name for each line to be added If the number of names specified in a singleadd i ne call is more than one but differs from the number of lines to be added then an error is returned If a line is to be referenced by its name then that name must not contain symbols If you are naming a large number of lines then the makenames function may be useful If a line is not assigned a descriptive name then it must be referenced by index Create the digital I O object di o and add the first four hardware lines line IDs 0 3 from port O dio digitalio nidaq 1 addline dio 0 3 in These lines are automatically assigned the indices 1 4 If you want to add the first four hardware lines to di o and assign descriptive names to the lines addline dio 0 3 in linel line2 line3 line4 Note that you can use the make na mes function to create a cell array of line names Y ou can add the first four hardware lines line Ds 0 3 from port 1 to the existing line group addline dio 0 3 1 out The new lines are automatically assigned the indices 5 8 Functions delete makenames Properties HwLine Index LineName addmux channel Purpose Syntax Arguments Description Remarks See Also Add hardware channels when using a multiplexer board addmuxchannel obj addmuxchannel obj chani ds chans addmuxchannel obj An analog input object associated with a National Instruments board c
222. g 7 10 digitalio 7 3 disk logging 10 47 Index display summary Al object 4 23 AO object 6 15 DIO object 7 18 DMA 1 28 NI hardware 11 25 documentation examples 2 12 dot notation configuring property values 3 18 returning property values 3 17 saving property values to an M file 8 3 driver Agilent hardware A 9 CBI hardware A 6 NI hardware A 3 E E1432 driver A 9 engine 2 4 extracting data from 5 13 queuing data to 6 17 engineering units Al object 5 56 AO object 6 34 event types data missed Al 5 47 input overrange Al 5 47 run time error Al object 5 47 AO object 6 28 samples acquired Al 5 47 samples output AO 6 28 start Al object 5 48 AO object 6 28 stop Al object 5 48 AO object 6 28 timer Al object 5 48 AO object 6 28 trigger Al object 5 48 AO object 6 29 EventLog Al object 5 49 AO object 6 29 events 2 3 Al object 5 46 AO object 6 27 displaying with showdaqevents Al object 5 36 AO object 6 24 example index 2 12 examples acquiring data NI hardware 4 19 sound card 4 15 adding lines 7 9 generating timer events DIO 7 17 logging and retrieving information Al 8 10 outputting data with a sound card 6 11 6 12 performing a linear conversion Al object 5 57 AO object 6 35 polling the data block Al 5 11 previewing and extracting data 5 15 reading and writing DIO values 7 13 retrieving event information Al object 5 51 AO object 6 30 using action properties Al object 5 53 Index AO objec
223. gChan set ai TriggerType HwAnal ogChannel set ai TriggerConditionValue 0 2 The diagram below illustrates how you can connect anal og trigger signals to an MIO 16E Series board Analog channel Analog trigger ACHO A D PFIO TRIG1 K MIO 16E Series board Configuring Analog Input Triggers ComputerBoards When using ComputerB oards Measurement Computing Corporation hardware thereare additional trigger types and trigger conditions availableto you These device specific property values fall into two categories hardware digital triggering and hardware analog triggering Thedevice specific trigger types and trigger conditions are described below and in Chapter 10 Base Property Reference Table 5 9 Analog Input TriggerType and TriggerCondition Values for CBI Hardware TriggerType TriggerCondition Description Value Value HwDi gital GateHi gh The trigger occurs as long as the digital signal is high GateLow The trigger occurs as long as the digital signal is low TrigHigh The trigger occurs when the digital signal is high Triglow The trigger occurs when the digital signal is low TrigPosEdge Tri gNegEdge The trigger occurs when the positive rising edge of the digital signal is detected The trigger occurs when the negative falling edge of the digital signal is detected 5 41 5 Doing More with Analog Input
224. gers 5 27 previewing data 5 9 properties BitsPerSample 11 7 BufferingConfig 10 15 Buf feringMode 10 17 Channel 10 18 Channel Name 10 20 Channel Skew 10 21 Channel SkewMode 10 22 ClockSource 10 24 COLA 11 8 Coupling 11 9 DataMi ssedAction 10 26 Default Channel Value 10 27 Direction 10 28 DriveAl SenseToGround 11 10 EventLog 10 29 GroundingMode 11 11 HwChannel 10 31 HwLine 10 33 Index 10 34 Initial TriggerTime 10 36 Index 1 10 nput Mode 11 12 nput OverRangeAction 10 38 nputRange 10 39 nputSource 11 14 nputType 10 41 Line 10 43 LineName 10 44 Logging 10 46 LoggingMode 10 47 LogToDiskMode 10 48 anual Trigger HwOn 10 49 axSamplesQueued 10 51 ame 10 52 ativeOffset 10 53 ativeScaling 10 55 umMuxBoards 11 15 Out Of DataMode 11 16 Out put Range 10 56 Parent 10 58 Port 10 59 RampRate 11 17 Repeat Out put 10 60 Running 10 61 SampleRate 10 64 SamplesAcquired 10 66 SamplesAcquiredAction 10 67 SamplesAcquiredActionCount 10 68 SamplesAvailable 10 69 p p p Sampl esOut put 10 70 SamplesOutput Action 10 71 SamplesOutputActionCount 10 72 SamplesPerTrigger 10 73 Sending 10 74 SensorRange 10 75 SourceMode 11 18 SourceQut put 11 19 Span 11 21 StandardSampleRates 11 23 StartAction 10 76 StopAction 10 77 Sum 11 24 Tag 10 79 Ti meout 10 80 Ti mer Action 10 81 Ti mer Period 10 82 TransferMode 11 25 TriggerAction 10 83 TriggerChannel 10 84 TriggerCondition 10 85 Trigge
225. gger may provide you with more control over the data that is logged For example if the acquired data is noisy you can preview the data using peek dat a and then manually execute the trigger after you observe that the signal is well behaved Software Trigger If Tri ggerType isSoft ware the trigger occurs when a signal satisfying the specified condition is detected on one of the hardware channels specified by theTri ggerChannel property The trigger condition is specified as either a voltage value and slope or a range of voltage values using the TriggerCondition andTriggerConditionVal ue properties Example Voice Activation Using a Software Trigger This example demonstrates how to configure an acquisition with a sound card based on voice activation The sample rate is set to 44 1 kHz and data is logged after an acquired sample has a value greater than or equal to 0 2 volt and a rising positive slope A portion of the acquired data is then extracted from the engine and plotted Y ou can run this example by typing daqdoc5_ 3 at the MATLAB command line 1 Create a device object Create the analog input object Al Voi ce for a sound card The installed adaptors and hardware I Ds are found with daghwi nfo Al Voice analoginput winsound Al Voice analoginput nidaq 1 Al Voice analoginput cbi 1 5 23 5 Doing More with Analog Input 5 24 2 Add channels Add one hardware channel to Al Voice chan addchannel
226. gine Sending Indicate if data is being sent to the hardware device Analog Output Hardware Configuration Properties ClockSource Specify the clock used to govern the hardware conversion rate Sampl eRate Specify the per channel rate at which digital data is converted to analog data Analog Output Data Management Properties MaxSamplesQueued Indicate the maximum number of samples that can be queued in the engine 10 9 10 Base Property Reference Analog Output Data Management Properties Continued Repeat Out put Ti meout Specify the number of additional times queued data is output Specify an additional waiting time to queue data Analog Output Action Properties RuntimeError Action Sampl es Out put Action Sampl es Out put Acti onCount StartAction StopAction Ti merAction Ti mer Period TriggerAction Specify the M file action function to execute when a run time error occurs Specify the M file action function to execute every time a predefined number of samples is output for each channel group member Specify the number of samples to output for each channel group member before a samples output event is generated Specify the M file action function to execute just before the device object starts running Specify the M file action function to execute just after the device object stops running Specify the M file action function to execute whene
227. gine Y Input overrange A signal exceeds the hardware input range Y Run time error A run time error is encountered Run time Y errors include timeouts and hardware errors Start Thestart function is issued Y Y Stop The device object stops executing Trigger A trigger executes Y Y Timer events samples available events Al and samples output events AO are not logged Dat a stores event specific information associated with the event type in several fields For all stored events Dat a contains the Rel Sample field which returns the input or output sample number at the time the event occurred For the start stop run time error and trigger events Data contains theAbsTi me field which returns the absolute time as a c ock vector the event occurred Other event specific fields are included in Dat a For a description of these fields refer to Configuring Events and Actions in Chapter 5 for analog input objects Configuring Events and Actions in Chapter 6 for analog output objects or the appropriate reference pages in this chapter Event Log can store a maximum of 1000 events If this value is exceeded then the most recent 1000 events are stored You can usetheshowdagevents function to easily display stored event information 10 29 EventLog Characteristics Values Example See Also 10 30 Usage Al AO Common Access Read only Data type Structure array Read only N A when running Va
228. gital set ai TriggerCondition TrigPosEdge Configuring Analog Input Triggers The diagram below illustrates how you connect a digital trigger signal toa PCI DAS1602 16 board A D External Trigger corresponds to pin 45 TTL signal A D External Trigger A D K PCI DAS1602 16 board Hardware Analog Triggering If Tri gger Type isHwAnal og the trigger is given by an analog signal For example to trigger your acquisition when the trigger signal is between 4 volts and 4 volts ai analoginput cbi 1 addchannel ai 0 7 set ai TriggerType HwAnal og set ai TriggerCondition Gatel nWindow set ai TriggerConditionValue 4 0 4 0 The diagram below illustrates how you connect an analog trigger signal to a PCI DAS1602 16 board Al Ch 0 7 corresponds to pins 2 17 while Analog Trigger In corresponds to pin 43 Analog channels Analog trigger 7 Al Ch 0 7 A D Analog Trigger In lt PCI DAS1602 16 board 5 43 5 Doing More with Analog Input Agilent Technologies When using Agilent Technologies hardware there are additional trigger types and trigger conditions available to you These device specific property values fall into two categories hardware digital triggering and hardware analog triggering Thedevice specifictrigger types and t
229. grateto2 kHz configurethetrigger to repeat two times and scale the data to cover the full output range of the D A converter Sincethe peak to peak amplitude of the queued data is 4 UnitsRange issetto 2 2 which scales the output data to 20 volts peak to peak set A0 SampleRate 2000 set A0 Repeat Out put 2 set chan UnitsRange 2 2 Queue the data with one call toput data putdata A0 data 4 Output data Start A0 and wait until all the data is output start AQ while strcmp AO Running On end 5 Clean up When you nolonger need A0 you should remove it from memory and from the MATLAB workspace del et e AQ clear AO Starting Multiple Device O bjects Starting Multiple Device Objects With the Data Acquisition Toolbox you can start multiple device objects Y ou may find this feature useful when simultaneously using your hardware s analog output AO and analog input Al subsystems For example suppose you create the analog input object ai and the analog output object ao for a sound card and add one channel to each device object al analoginput winsound addchannel ai 1 ao analogoutput winsound addchannel ao 1 Y ou should use manual triggers when starting multiple device objects since this trigger type executes faster than other trigger types with the exception of hardware triggers Additionally to synchronize the input and output of data you should configure the Man
230. gure property values Define a 1 second total acquisition time and configure a software trigger The source of the trigger ischan and the trigger executes when a rising voltage level has a value of at least 0 2 volt Additionally the trigger is repeated once when the trigger condition is met duration 0 5 One half second acquisition for each trigger set Al Voice SampleRate 44100 Actual Rate get AlVoice SampleRate set Al Voice Timeout 5 set Al Voice SamplesPerTrigger Actual Rate durati on set AlVoice TriggerChannel chan set Al Voice TriggerType Software set Al Voice TriggerCondition Rising set Al Voice TriggerConditionValue 0 2 set AlVoice TriggerRepeat 1 5 31 5 Doing More with Analog Input 5 32 4 Acquire data Start Al Voi ce acquire the specified number of samples extract all the data from the first trigger as sample time pairs and extract all the data from the second trigger as sample time pairs Note that you can extract the data acquired from both triggers with the command getdata Al Voice 44100 start Al Voice while strcmp Al Voice Running On end d1 t1 getdata Al Voice d2 t2 getdata Al Voice Plot the data for both triggers ubplot 211 plot t1 d1 grid on hold on xis t1 1 0 05 tl end 0 05 0 8 0 8 abel Time sec ylabel Signal level Volts itle Voice Activation First Trigger ubplot 212
231. hani ds The hardware channel Ds chans The channels that are added to obj addmuxchannel obj adds as many channels toobj asis physically possible based on the number of National Instruments AMU X 64T multiplexer mux boards specified by the NumMux Boards property For one mux board 64 channels are added F or two mux boards 128 channels are added F or four mux boards 256 channels are added addmuxchannel obj chanids adds the channels specified by chani ds toobj chani ds refers to the hardware channel Ds of the data acquisition board The actual number of channels added toobj depends on the number of mux boards used For example suppose you are using a data acquisition board with 16 channels connected to one mux board If chanid is O then addmuxchannel adds four channels Refer tothe AM U X 64T User Manual for more information about adding mux channels based on hardware channel Ds and the number of mux boards used chans addmuxchannel returns the channels added tochans Before using addmuxchannel you must set theNumMuxBoards property to the appropriate value You can use as many as four mux boards with one analog input object addmuxchannel deletes all channels contained by obj before new channels are added Functions muxchani dx 9 17 analoginput Purpose Syntax Arguments Description Remarks 9 18 Create an analog input object Al analoginput adaptor Al analoginput adaptor 1
232. hannel mapping e The channel name e The engineering units 6 15 6 Analog O utput The display summary shown below is for the example given in Outputting Data with a Sound Card on page 6 11 prior to issuing thestart function Display Summary of Analog Output AO Object Using AudioPCI Playback Output Parameters 8000 samples per second on each channel General display Trigger Parameters 1 Immediate trigger on START summary Engine status Waiting for START 0 total sec of data currently queued for START 0 samples currently queued by PUTDATA 0 samples sent to output device since START AO object contains channel s Channel display summary Index Channel Name HwChannel OutputRange UnitsRange Units 1 Mono 1 1 1 1 1 Volts You can usetheChannel property to display only the channel summary information AO Channel 6 16 Managing O utput Data Managing Output Data At the core of any analog output application lies the data you want to send from a computer to an output device such as an actuator The role of the analog output subsystem is to convert digitized data to analog data for subsequent output Before you can output data to the analog output subsystem it must be queued in the engine Queuing data is managed with theput dat a function In addition to this function there are several properties associated with managing output data These properties are given below Table
233. hannels that can be added to a device object To configure the sound card to operate in mono mode you must specify hwch as1 All analoginput winsound addchannel All 1 TheChannel Name property is automatically assigned the value Mono You can now configure the sound card to operate in stereo mode by adding the second channel addchannel Al1 2 TheChannel Name property is assigned the values Left and Ri ght for the two hardware channels Alternatively you can configure the sound card to operate in stereo mode with one call toaddchannel addchannel All 1 2 Functions delete makenames Properties Channel Name HwChannel ndex 9 13 addline Purpose Syntax Arguments Description 9 14 Add hardware lines to a digital I O object lines addline obj hwline direction lines addline obj hwline port direction lines addline obj hwline direction names lines addline obj hwline port direction names obj A digital 1 O object hwl ine The numeric IDs of the hardware lines added to the device objet Any MATLAB vector syntax can be used direction Thelinedirections can bel n or Out and can be specified as a single value or a cell array of values port The numeric IDs of the digital I O port names A descriptive line name or cell array of descriptive line names lines A row vector of lines with the same length as hwl i ne lines addline obj hwline direct
234. hat you recorded a sensor reading is generally not enough Y ou also need to know when that measurement occurred Data is transferred from the hardware to system memory via dynamic memory access DMA or interrupts DMA is hardware controlled and therefore extremely fast Interrupts may be slow due to the latency time between when a board requests interrupt servicing and when the computer responds The maximum acquisition rate is also determined by the computer s bus architecture Refer to How Are Acquired Samples Clocked on page 1 23 for more information about DMA and interrupts Softw are Regardless of the hardware you are using you must send information to the hardware and receive information from the hardware You send configuration information to the hardware such as the sampling rate and receive information from the hardware such as data status messages and error messages You may also need to supply the hardware with information so that you can integrate it with other hardware and with computer resources This information exchange is accomplished with software 1 13 1 Introduction to Data Acquisition There are two kinds of software e Driver software e Application software For example suppose you are using the Data Acquisition Toolbox with a National Instruments AT MI O 16E 1 board and its associated NI DAQ driver The relationship between you the driver software the application software and the hardware is
235. he default value is an empty column vector Create the analog input object ai for a National Instruments card and add three hardware channels to it al analoginput nidaq 1 addchannel ai 0 2 To set a property value for the first channel added ID 0 you must reference the channel by its index using the Channel property chans ai Channel 1 set chans I nputRange 10 10 Channel Based on the current configuration the hardware channels are scanned in order from 0 to 2 To swap the scan order of channels 0 and 1 you can specify the appropriate permutation of the MATLAB indices with Channel ai Channel 1 2 3 ai Channel 2 1 3 See Also Functions addchannel delete Properties HwChannel Index 10 19 ChannelN ame Purpose Description Characteristics Values Example See Also 10 20 Specify a descriptive channel name Channel Na me specifies a descriptive name for a hardware channel If a channel name is defined then you can reference that channel by its name If a channel name is not defined then the channel must be referenced by its index Channel names are not required to be unique Y ou can also define descriptive channel names when channels are added to a device object with theaddchannel function Usage Al AO Channel Access Read write Data type String Read onl y Yes when running The default value is an empty string To reference a channel by name it must
236. he engine to the hardware Additionally G etting Started with Analog O utput Sampl esAvail abl e tells you how many samples per channel arestill queued in the engine and ready to be output to the hardware When all the queued data is output from the engine both Running andSendi ng are automatically set to Off SamplesAvailable is O andSampl es Out put reflects the total number of samples per channel that was output The Display Summary You can invoke the display summary by typing the analog output object at the command line The information displayed reflects many of the basic setup properties described in Configuring Analog Output Properties on page 6 6 and is designed so you can quickly evaluate the status of your data acquisition session The display is divided into two main sections general summary information and channel summary information General Summary Information Thegeneral display summary includes the device object type and the hardware device name followed by this information e Output parameters The sampling rate e Trigger parameters The trigger type e The engine status Whether the engine is sending data waiting to start or waiting to trigger Thetotal time required to output the queued data The number of samples queued by put dat a Thenumber of samples sent to the hardware device Channel Summary Information The channel display summary includes property values associated with e The hardware c
237. he number of blocks used results in a per channel memory that is somewhat greater than the Sampl esPer Trigger value When you manually allocate memory the number of blocks is not dynamic and care must be taken to ensure there is sufficient memory to store the acquired data If the number of samples acquired or queued exceeds the allocated memory then an error is returned Y ou can easily determine the memory allocated and available memory for each device object with the daqmem function Usage Al AO Common Access Read write Data type Two element vector of doubles Read only Yes when running 10 15 BufferingConfig Values Example See Also 10 16 The default value is determined by the engine and is based on the number of channels contained by the device object and the sampling rate The Buf feri ngMode value determines whether the values are automatically updated as data is acquired For analog output objects the default number of blocks is zero Create the analog input object ai for a sound card and add two channels to it al analoginput winsound addchannel ai 1 2 The block size and number of blocks are given by Buff eringConfig while the native data type for the sound card is given by daqhwi nfo ai BufferingConfig ans 512 30 out daghwi nf o ai out NativeDataType ans int 16 With this information the total allocated memory is calculated to be 61 440 bytes This number is stored b
238. he number of events that were output from the engine whenever the samples output event occurred 1 Create a device object Createthe analog output object A0 for a sound card The installed adaptors and hardware Ds are found with daghwi nfo AO analogoutput winsound A0 anal ogoutput nidaq 1 A0 analogoutput cbi 1 2 Add channels Add two channels toA0 chans addchannel A0 1 2 chans addchannel A0 0 1 For NI and CBI 6 31 6 Analog O utput 6 32 3 Configure property values Configure the trigger to repeat four times specify daqdoc6_4disp as the M file action function to execute whenever 8000 samples are output generate data to be queued and queue the data with one call toputdata set A0 SampleRate 8000 Actual Rate get A0 SampleRate set A0 RepeatOutput 4 set A0 SamplesO0utputActionCount 8000 freq get A0 SamplesOutputActionCount set A0 SamplesOutputAction daqdoc6 4disp data sin linspace 0 2 pi 3 freq putdata AO data data 4 Output data Start A0 start A0 5 Clean up When you no longer need A0 you should remove it from memory and fromthe MATLAB workspace delete A0 clear AO Displaying EventLog Information This example illustrates how action functions allow you to easily display information stored in theEvent Log property You can run this example by typing daqdoc6_5 at the MATLAB command line Thedaqdoc6_5disp action fun
239. he versions of the MathWorks products you are using e Your MATLAB path e The characteristics of your hardware Theoutputfromdaqsupport isautomatically saved to a text file which you can use to help troubleshoot your problem For example if you are having trouble with your sound card type dagsupport winsound Managing Y our Memory Resources Overview 2 ee a B 2 How Much Memory Do You Need B 3 Example Managing Memory Resources B 4 B Managing Your Memory Resources Overview When data is acquired from an analog input subsystem or output to an analog output subsystem it must be temporarily stored in computer memory The Data Acquisition Toolbox allocates memory in terms of data blocks A data block is defined as the smallest slice of memory that the data acquisition enginecan usefully manipulate For example acquired data is logged to a disk file using an integral number of data blocks A representation of allocated memory using n data blocks is shown below block 1 block 2 block 3 lee block n The Data Acquisition Toolbox strives to make memory allocation as simple as possible For this reason the data block size and number of blocks are automatically calculated by the engine This calculation is based on the parameters of your acquisition such as the sampling rate and is meant to apply to most common data acquisition applications Additionally as da
240. he volume control for your sound card For example suppose Out put Range is 10 10 andUnitsRange is 5 5 If a queued value is 2 5 then the scaled value is 2 5 20 10 or 5 in the appropriate units Note The data acquisition engine always clips out of range values Clipping means that an out of range value is fixed to either the minimum or maximum value that is representable by the hardware Clipping is equivalent to saturation Example Performing a Linear Conversion This example illustrates how to configure the engineering units properties for an analog output object connected to a National Instruments PCI 6024E board The queued data consists of a 4 volt peak to peak sine wave The Uni t sRange property is configured so that queued data is scaled to the Out put Range property value which is fixed at 10 volts This scaling utilizes the maximum dynamic range of the analog output hardware You can run this example by typing daqdoc6_6 at the MATLAB command line 1 Create a device object Create the analog output object A0 for a National Instruments board The installed adaptors and hardware IDs are found with daqhwinfo AO analogoutput nidaq 1 2 Add channels Add one hardware channel toA0 chan addchannel A0 0 3 Configure property values Create the data to be queued freq 2 w 2 pi freg t linspace 0 10 10000 data 2 sin w t 6 35 6 Analog O utput 6 36 Configurethesamplin
241. henomena you are measuring and the maximum output range of the sensor e The range of your analog input hardware For many devices this range is specified by the gain and polarity You can return valid input ranges with the daghwi nfo function e The engineering units associated with your acquisition By default most analog input hardware converts data to voltage values However after the data is digitized you may want to define a linear scaling that represents specific engineering units when data is returned to MATLAB The properties associated with engineering units and linearly scaling acquired data are given below Table 5 13 Analog Input Engineering Units Properties Property Name Description SensorRange Specify the range of data you expect from your sensor InputRange Specify the range of the analog input subsystem Units Specify the engineering units label UnitsRange Specify the range of data as engineering units Note If supported by the hardware you can set the engineering units properties on a per channel basis Therefore you can configure different engineering unit conversions for each hardware channel 5 56 linearly Scaling the Data Engineering Units Linearly scaled acquired data is given by the formula scaled value A D value units range sensor range Note Theabove formula assumes you are using symmetric units range and sensor range values and represents the simplest scenario If yo
242. her tasks until the next interrupt occurs For example the data can be processed or saved to a disk file As long as the average rates of storing and extracting data are equal acquired data will not be missed and your application should run smoothly Interrupts The slowest but most common method to move acquired data to system memory is for the board to generate an interrupt request IRQ signal This signal can be generated when one sample is acquired or when multiple samples 1 27 1 Introduction to Data Acquisition 1 28 are acquired The process of transferring data to system memory via interrupts is given below 1 When data is ready for transfer the CPU stops whatever it is doing and runs a special interrupt handler routinethat saves the current machine registers and then sets them to access the board 2 The data is extracted from the board and placed into system memory 3 Thesaved machine registers are restored and the CPU returns tothe original interrupted process The actual data move is fairly quick but there is a lot of overhead time spent saving setting up and restoring the register information Therefore depending on your specific system transferring data by interrupts may not be a good choice when the sampling rate is greater than around 5 kHz DMA Direct memory access DMA is a system whereby samples are automatically stored in system memory while the processor does something else The process of transf
243. hese popular hardware devices National Instruments E Series and 1200 Series boards ComputerBoards Measurement Computing Corporation boards Agilent Technologies E 1432A 33A 34A VXI modules Microsoft Windows sound cards Additionally you can use the Data Acquisition Toolbox Adaptor Kit to interface unsupported hardware devices to the toolbox Support for analog input Al analog output AO and digital I O DIO subsystems including simultaneous Al and AO conversions Data buffering for background acquisitions Data logging Event driven acquisitions Ex ploring the Toolbox A list of the toolbox functions is available to you by typing help daq You can view the code for any function by typing type function _name You can view the help for any function by typing daqhelp function name You can change the way any toolbox function works by copying and renaming the M file then modifying your copy Y ou can also extend the toolbox by adding your own M files or by using it in combination with other products such as the Signal Processing Toolbox or the Instrument Control Toolbox Related Products Related Products System Requirements The Data Acquisition Toolbox is a multiplatform product that you install on a host computer running Microsoft Windows 95 Windows 98 Windows 2000 or Windows NT 4 0 The toolbox requires e MATLAB 6 0 Release 12 e A supported data acquisition device for a complete listing of all
244. hest op function is issued the specified data is acquired or sent or a run time error occurs When Running is Of f you cannot acquire or send data However you can acquire one sample with thegets amp e function or send one sample with the put samp e function Usage Al AO DIO Common Access Read only Data type String Read only N A when running off The device object is not running On The device object is running Functions getsample putsample start Properties Logging Sending 10 61 RuntimeErrorAction Purpose Description Characteristics Values 10 62 Specify the M file action function to execute when a run time error occurs A run time error event is generated immediately after a run time error occurs This event executes the action function specified for Runt i meErrorAction Additionally a toolbox error message is automatically displayed to the MATLAB workspace If an error occurs that is not explicitly handled by the toolbox then the hardware specific error message is displayed The default value for RunTi meErrorAction isdagaction which displays the event type the time the event occurred and the device object name along with the error message Run time error event information is stored in the Type and Data fields of the EventLog property TheType field valueisError TheData field values are given below Data Field Value Description AbsTi me The absolute time as ac ock vector th
245. hys Avail Phys Total PageFile Avail PageFile Total Virtua Specifies a number between 0 and 100 that gives a general idea of current memory utilization 0 indicates no memory use and 100 indicates full memory use Indicates the total number of bytes of physical memory Indicates the number of bytes of physical memory available Indicates the total number of bytes that can be stored in the paging file Notethat this number does not represent the actual physical size of the paging file on disk Indicates the number of bytes available in the paging file Indicates the total number of bytes that can be described in the user mode portion of the virtual address space of the calling process daqmem Remarks Example Field Description Avail Virtual Indicates the number of bytes of unreserved and uncommitted memory in the user mode portion of the virtual address space of the calling process UsedDaq The total memory used by all device objects Note that all the above fields except for UsedDaq are identical to the fields returned by Windows Me mor ySt atus function out daqmem obj returns a 1 by N structureout containing two fields UsedBytes and MaxBytes for the device object obj N isthe number of device objects specified by obj UsedBytes returns the number of bytes used by obj Max Bytes returns the maximum number of bytes that can be used by obj daqmem obj maxmem sets the maximum mem
246. i ggerType can bel mmediate Manual orSoftware IfTriggerType is mmedi ate the trigger occurs immediately after thest art function is issued If TriggerType iS Manual thetrigger occurs immediately after thet rigger function is issued If Tri gger Type isSoft ware the trigger occurs when the associated trigger condition is satisfied Al only For a given hardware device additional trigger types may be available Some trigger types require trigger conditions and trigger condition values Trigger conditions are specified with theTri gger Condition property while trigger condition values are specified with the Tri ggerConditionValue property When a trigger occurs for an analog input object data logging is initiated and theLoggi ng property is automatically set to 0n When a trigger occurs for an analog output object data sending is initiated and theSendi ng property is automatically set to 0n Usage Al AO Common Access Read write Data type String Read only Yes when running All Supported Hardware mmedi ate The trigger executes immediately after st art is issued Pretrigger data cannot be captured Manual The trigger executes immediately after thet ri gger function is issued Software The trigger executes when the associated trigger condition is satisfied Trigger conditions are given by the TriggerCondition property Al only TriggerType See Also National Instruments HwDi gital The trigger source is the
247. i oat eek 9 72 Obj ZIM Giese a tera leas Areata lee ee id 9 74 peck dataset dds Gitte take dated ll 9 76 DFODINTO assure era aa See 9 78 putdatay ur A heeds 9 80 putsamplS is lee theta aes Getta hue de bleed 9 82 DUtVAIUS chick aoe arts hte he anata nas 9 83 SAVE dt Sais a aeeanetndle ache etek eae tes 9 84 A a ln ets Bon does 9 85 SetVerify os candies ied ee ete ees ten ea 9 88 ShowdageventS 0 0 cece ete eee 9 90 Starte o n oe A nate Ors ee See ee ws 9 94 SCOP isin Hees Tape alate dikes Slee Ges aah eae ets 9 95 trigga ie ee Gate ea A 9 97 WaittilStop sc 2 de bee eden a a cee 9 98 10 OVErVICW En E EE EE E E A EEE 10 2 Getting Command Line Property HelP o 10 2 Properties Grouped by Category 10 3 Analog Input Properties 0 0 0 0 cece eee 10 3 Analog Output Properties 00 00 e eee eee ee 10 8 Digital 1 O PropertieS 1 0 0 0 c ccc eee 10 12 Properties Listed Alphabetically 10 14 BufferingConfig cece ee eee 10 15 BufferingMode 0 0 c cece ett 10 17 Channeli Aasra stein naa a tah a aA A ayaa aes are bze 10 18 ChannelName 1 0 2 00 cette 10 20 Channa SK OW cio eed wees ee bein yu dered 10 21 ChannelSkewMode ccc eee tees 10 22 CIOCKSOUNGE cir ta Sale 10 24 DataMissedACtioOn 0 000 cect tees 10 26 DefaultChannelValue ocooococcccccn 10 27 a essre rrene ces of cece Eee ee mee ee ee
248. ic values For example the nput Type property has a different set of values for each supported hardware vendor The relationship between common properties channel line properties base properties and device specific properties is shown below Device object Base properties Device specific properties Hardware channels lines Base properties Device specific properties Common properties Channel line properties For acomplete description of all properties refer toChapter 10 BaseProperty Reference or Chapter 11 Device Specific Property Reference 3 13 3 The Data Acquisition Session 3 14 Returning Property Names and Property Values Once the device object is created you can use thes et function to return all configurable properties to a variable or to the command line Additionally if a property has a finite set of string values thenset also returns these values Y ou can usetheget function toreturn one or more properties and their current values to a variable or to the command line The syntax used to return common and channel line properties is described below The examples are based on the analog input object ai created for a sound card and containing two channels al analoginput winsound addchannel ai 1 2 Common Properties Toreturn all configurable common property names and their possible values for a device ob
249. ied device objects tof i e Saving device objects follows these rules You can usesave in the functional form as well as the command form shown above When using the functional form you must specify the filename and device objects as strings Samples associated with a device object are not stored in the MAT file Y ou can bring these samples into the MATLAB workspace with the get dat a function and then save them to the MAT file using a separate variable name You can also log samples to disk by configuring theLoggi ngMode property toDisk or Di sk amp Me mory Values for read only properties are restored to their default values upon loading For example theEvent Log property is restored to an empty vector Use the pr opi nf o function to determine if a property is read only Values for theBuf f eri ngConf i g property when theBuf feringMode property isset toAuto andtheMaxSamp es Queued property may not be restored tothe same value since both these property values are based on available memory If you use thehel p command to display the M file help for s av e then you must supply the pathname shown below help daq private save Functions getdata load propinfo set Purpose Syntax Arguments Description Configure or display device object properties set obj props set obj set obj PropertyName props set obj PropertyName set obj PropertyName PropertyValue set obj PN PV set obj S
250. ier to work with than decimal values since there is a clear association between a given line and the value 1 or 0 that is written to it You can convert decimal values to binvec values with thedec2bi nvec function For example suppose you create the digital I O object di o and add eight output lines to it from port 0 dio digitalio nidaq 1 addline dio 0 7 out To write a value of 23 to the eight lines contained by di o you can write to the device object data 23 putvalue dio data 7 10 W riting and Reading Digital l O Line Values Alternatively you can write to individual lines through theLi ne property putvalue dio Line 1 8 data Towritea binary vector of values using the device object and the Li ne property bvdata dec2binvec data 8 putvalue dio bvdata putval ue dio Line 1 8 bvdata Thesecond input argument supplied todec2bi nvec specifies thenumber of bits used torepresent the decimal value Sincethe preceding commands writetoall eight lines contained by di o an eight element binary vector is required If you do not specify the number of bits then the minimum number of bits needed to represent the decimal value is used Alternatively you can create the binary vector without using dec2binvec bvdata logical 1 11010 0 0 putvalue dio bvdata Rules for Writing Digital Values Writing values to digital 1 0 lines follows these rules e If the digital O object contains lines from a
251. ies Property Name Description Sampl eRate Specify the per channel rate at which analog data is converted to digital data SamplesPerTrigger Specify the number of samples to acquire for each channel group member for each trigger that occurs TriggerType Specify the type of trigger to execute The Sampling Rate You control the rate at which an analog input subsystem converts analog data to digital data with theSamp eRat e property Samp eRat e must be specified as samples per second For example to set the sampling rate for each channel of your National Instruments board to 100 000 samples per second 100 kHz ai analoginput nidaq 1 addchannel ai 0 1 set ai SampleRate 100000 4 9 4 G etting Started with Analog Input 4 10 Data acquisition boards typically have predefined sampling rates that you can set If you specify a sampling rate that does not match one of these predefined values there are two possibilities e Iftherateis within the range of valid values then the engine automatically selects a valid sampling rate The rules governing this selection process are described in theSamp eRat e reference pages in Chapter 10 Base Property Reference e If the rate is outside the range of valid values then an error is returned Note For some sound cards you can set the sampling rate to any value between the minimum and maximum values defined by the hardware You can enable this featu
252. ify the actual input range desired Noise Noise is considered to be any measurement that is not part of the phenomena of interest Noise can be generated within the electrical components of the input amplifier internal noise or it can be added to the signal as it travels down the input wires tothe amplifier external noise Techniques that you can use to reduce the effects of noise are described below Removing Internal Noise Internal noise arises from thermal effects in the amplifier Amplifiers typically generate a few microvolts of internal noise which limits the resolution of the signal to this level The amount of noise added to the signal depends on the bandwidth of the input amplifier Toreduce internal noise you should select an amplifier with a bandwidth that closely matches the bandwidth of the input signal Removing External Noise External noise arises from many sources F or example many data acquisition experiments are subject to 60 Hz noise generated by a c power circuits This type of noise is referred to as pick up or hum and appears as a sinusoidal interference signal in the measurement circuit Another common interference source is fluorescent lighting These lights generate an arc at twice the power line frequency 120 Hz Noise is added to the acquisition circuit from these external sources because the signal leads act as aerials picking up environmental electrical activity 1 33 1 Introduction to Da
253. ignal A slowly varying signal has a low bandwidth while a The Data Acquisition System rapidly varying signal has a high bandwidth To properly measurethe physical phenomena of interest the sensor bandwidth must be compatible with the measurement bandwidth Y ou may want to use sensors with the widest possible bandwidth when making any physical measurement This is the one way to ensure that the basic measurement system is capable of responding linearly over the full range of interest However the wider the bandwidth of the sensor the more you must be concerned with eliminating sensor response to unwanted frequency components Signal Conditioning Sensor signals are often incompatible with data acquisition hardware To overcome this incompatibility the sensor signal must be conditioned Thetype of signal conditioning required depends on the sensor you are using F or example a signal may havea small amplitude and require amplification or it may contain unwanted frequency components and require filtering Common ways to condition signals include e Amplification e Filtering e Electrical isolation e Multiplexing e Excitation source Amplification Low level signals less than around 100 millivolts usually need to be amplified High level signals may also require amplification depending on the input range of the analog input subsystem For example the output signal from a thermocouple is small and must be amplified befor
254. iguration consists of two steps adding channels or lines and setting property values to establish the desired behavior H ardware that is used for event counting frequency and period measurement and pulse train generation This subsystem is not supported by the Data Acquisition Toolbox A digital to analog subsystem A process that encompasses all the steps you must take to acquire data using an analog input object output data using an analog output object or read values from or write values to digital 1 0 lines These steps are broken down into initialization configuration execution and termination The smallest slice of memory that the data acquisition engine can usefully manipulate A MATLAB object that allows you to access a hardware device A property that applies only for specific hardware devices For example the BitsPerSampl e property is supported only for sound cards Input channel configuration where there are two signal wires associated with each input signal one for the input signal and one for the reference return signal The measurement is the difference in voltage between the two wires which helps reduce noise and any voltage common to both wires C G lossary Digital 1 0 subsystem DMA Engine Engineering units properties Event Execution FIFO buffer Full duplex Input range Interrupts Line Line group Hardware that sends or receives digital values logic levels
255. ill not stop the acquisition but will return control to MATLAB TheSamplesAcqui red property keeps a running count of the total number of samples per channel that have been acquired TheSamplesAvailable property tells you how many samples you can extract from the engine per channel MATLAB supports math operations onl y for the double data type Therefore if you extract data using the native data type of your hardware typically int16 you must convert the data to doubles before performing math operations For more information about get dat a refer to its reference pages in Chapter 9 Function Reference Example Previewing and Extracting Data Suppose you have a data acquisition application that is particularly time consuming By previewing the data you can ascertain whether the acquisition is proceeding as expected without acquiring all the data If it is not then you can abort the session and diagnose the problem This example illustrates how you might usepeekdata andget dat a together in such an application You can run this example by typingdaqdoc5_2 at the MATLAB command line 1 Create a device object Create the analog input object Al for a sound card The installed adaptors and hardware Ds are found with daghwi nfo Al analoginput winsound Al analoginput nidaq 1 Al analoginput cbi 1 5 15 5 Doing More with Analog Input 5 16 2 Add channels Add one hardware channel toAl cha
256. in the same call toset set obj PN PV sets the properties specified in the cell array of strings PN to the corresponding values in the cell array PV PN must be a vector PV can be m by n where m is equal to the specified number of device objects channels or lines and n is equal to the length of PN set obj S wheres is a structure whose field names are device object properties sets the properties named in each field name with the values contained in the structure If you use thehe p command to display the M file help for s et then you must supply the pathname shown below help daq daqdevice set Create the analog input object ai for a sound card and configure it to operate in stereo mode ai analoginput winsound addchannel ai 1 2 To display all of ai s configurable properties and their valid values set ai To set the value for the Samp eRat e property to 10000 set ai SampleRate 10000 The following two commands set the value for theSampl eRate and nput Type properties using one call toset set ai SampleRate 10000 TriggerType Manual set ai Sampl eRate TriggerType 10000 Manual set You can also set different channel property values for multiple channels ch ai Channel 1 2 set ch UnitsRange ChannelName 1 1 Namel 2 2 Name2 See Also Functions get setverify 9 87 setverify Purpose Syntax Arguments Description Remarks 9 88
257. inear Conversion 6 35 Starting Multiple Device Objects 6 37 7 Overview a ped ieee a edie be 7 2 Creating a Digital I O Object 7 3 Adding Lines to a Digital I O Object 7 4 Line and Port Characteristics 000 c eee eee 7 5 Referencing Individual Hardware Lines 7 8 Writing and Reading Digital I O Line Values 7 10 Writing Digital Values 000 00 c eee 7 10 Reading Digital Values 0 0 0 0 eee eee ee 7 12 Example Writing and Reading Digital Values 7 13 Generating Timer Events 0000 0c eeee 7 15 Time Events ia Got og OAR ae ew Sd orkid ed 7 15 Starting and Stopping a Digital I O Object 7 16 Example Generating Timer Events 0 0005 7 17 Evaluating the Digital I O Object Status 7 18 The Display Summary 0000 ee 7 18 Saving and Loading the Session 8 Overview ocio ets ace wale in a Adal erect A 8 2 Saving and Loading Device Objects 8 3 Saving Device Objects to an M File ooo oooooo 8 3 Saving Device Objects toa MAT File oo o oooooo o 8 5 Logging Information to Disk 8 6 Specifying a Filename o ooocoocccocoo 8 7 Retrieving Logged Information ocococcocococco 8 8 Example Logging and Retrieving Information
258. ing frequency and period measurement and pulse train generation 1 7 1 Introduction to Data Acquisition Sensors A sensor converts the physical phenomena of interest into a signal that is input into your data acquisition hardware There are two main types of sensors based on the output they produce digital sensors and analog sensors Digital sensors produce an output signal that is a digital representation of the input signal and has discrete values of magnitude measured at discrete times A digital sensor must output logic levels that are compatible with the digital receiver Some standard logic levels include transistor transistor logic TTL and emitter coupled logic ECL Examples of digital sensors include switches and position encoders Analog sensors produce an output signal that is directly proportional to the input signal and is continuous in both magnitude and in time Most physical variables such as temperature pressure and acceleration are continuous in nature and are readily measured with an analog sensor F or example the temperature of an automobile cooling system and the acceleration produced by a child on a swing all vary continuously The sensor you use depends on the phenomena you are measuring Some common analog sensors and the physical variables they measure are listed below Table 1 1 Common Analog Sensors Sensor Physical Variable Accelerometer Acceleration Microphone Pressure Pressure gauge
259. ing to disk you can specify the log filename with the LogFi eName property and you can control the number of log files created with the LogToDiskMode property You can return data stored in a disk file to the MATLAB workspace with thedaqread function Usage Al Common Access Read write Data type String Read only Yes when running Disk Acquired data is logged to a disk file Me mor y Acquired data is logged to memory Di sk amp Me mor y Acquired data is logged to a disk file and to memory Functions dagread getdata Properties LogFileName LogToDiskMode 10 47 LogToDiskMode Purpose Description Characteristics Values See Also 10 48 Specify whether data events and hardware information are saved to one disk file or to multiple disk files LogToDiskMode can beset toOverwrite orl ndex IfLogToDiskMode is set to Over write then the log file is overwritten each timestart is issued If LogToDiskMode is set tol ndex a different disk file is created each times t art is issued and these rules are followed e The first log filename is specified by the initial value of LogFi eName e If the specified file already exists it is overwritten and no warning is issued e LogFil eName is automatically updated with a numeric identifier after each fileis written For example ifLogFil eName isinitially specified asdata daq then data daq isthe first filename data01 daq is the second filename and so on Separate
260. ion adds the hardware lines specified by hwl i ne tothedigital 1 O object obj di rection configures the lines for either input or output ines is a row vector of lines lines addline obj hwline port direction adds the hardware lines specified by hwl i ne fromthe port specified by port tothedigital I O object obj lines addline obj hwline direction names adds the hardware lines specified by hwl i ne tothedigital I O object obj names isadescriptiveline name or cell array of descriptive line names lines addline obj hwline port direction names adds the hardware lines specified by hwl i ne from the port specified by port tothedigital I O object obj di rection configures the lines for either input or output names is a descriptive line name or cell array of descriptive line names addline Remarks Rules for Adding Lines e The numeric values you supply for hwl i ne depend on the hardware you access For National Instruments and ComputerBoards hardware line IDs are zero based begin at zero e You can add a line only once to a given digital I O object e Hardware line IDs are stored in the HwLi ne property and the associated MATLAB indices are stored in the ndex property e For a single call toadd ine you can add multiple lines from one port or the same line ID from multiple ports You cannot add multiple lines from multiple ports e Ifaport D is not explicitly referenced lines are added first f
261. ion obj event obj A device object event A variable that captures the event information contained by theEventLog property daqaction obj event iS an example action function that displays information tothe MATLAB command window For all events the information includes the event type and the name of the device object that caused the event to occur For events that record the absolute time in Event Log the event time is also displayed For run time error events the error message is also displayed You specify daqacti on asthe action function to be executed for any event by specifying it as the value for the associated action property For analog input objects daqacti on isthe default value for the Dat aMi ssedAction and RuntimeErrorAction properties For analog output objects daqacti on isthe default value for the Runt i meErrorAction property You can usetheshowdaqevents function to easily display event information captured by the Event Log property Create the analog input object ai and call the action function dagacti on when a trigger event occurs al analoginput winsound addchannel ai 1 set ai TriggerRepeat 3 set ai TriggerAction daqaction start ai Functions showdaqevents Properties DataMissedAction EventLog RuntimeErrorAction 9 27 dagfind Purpose Syntax Arguments Description 9 28 Return device objects channels or lines from the data acquisition engine tothe MATLAB work
262. ire input data via an analog input subsystem while outputting data via an analog output subsystem at the same time Note that full tells you nothing about the bit resolution or the number of channels used in each direction Therefore sound cards can simultaneously receive and send data using 8 or 16 bits while in mono or stereo mode A common restriction of full duplex mode is that both subsystems must be configured for the same sampling rate If you try to run your card in full duplex mode and the following error is returned Error using gt dagdevice start Device Winsound already in use then your sound card is not configured properly it does not support this mode or you don t have the correct driver installed If your card supports full duplex mode then you may need to enable this feature through the Multimedia Properties dialog box Refer to Troubleshooting Sound Cards on page A 12 for a picture of this dialog box If you are unsure about the full duplex capabilities of your sound card refer toits specification sheet or user manual It is usually very easy to update your hardware drivers to the latest version by visiting the vendor s Web site O ther Things to Try Other Things to Try If troubleshooting your hardware does not help you then you may need to register the hardware driver adaptor or contact The MathWorks for support Registering the Hardware Driver Adaptor When you first create a device object
263. is stored temporarily because it can be overwritten The rate at which the data is overwritten depends on several factors including the available memory the rate at which data is acquired and the number of hardware channels from which data is acquired The stored data is not automatically available in the MATLAB workspace Instead you must explicitly extract data from the engine using the get dat a function Toolbox Components The flow of acquired data consists of these two independent steps 1 Data acquired from the hardware is stored in the engine 2 Datais extracted from the engine and stored in MATLAB or output toa disk file These two steps are illustrated below MATLAB 2 Extract data from the engine Data Acquisition Toolbox Data acquisition engine Acquired data 1 Fill engine with acquired data Hardware lt Sensors 2 G etting Started with the Data Acquisition Toolbox The Flow of Output Data Outputting data means that data is flowing from the data acquisition engineto the hardware device However before data is output you must queue it in the engine with the put dat a function The amount of data that you can queue depends on several factors including the available memory the number of hardware channels to which data is output and the size of each data sample The flow of out
264. is not extracted from the engine In other words peekdata provides a snapshot of the most recent requested samples This situation is illustrated below y a ___ Take a snapshot of the most recent requested data E Data stored in engine Ifanother peekdata call is issued then once again only the most recent requested samples are returned This situation is illustrated below Time gt ee Take another snapshot of the most recent requested data I Data stored in engine 5 10 Managing Acquired Data Rules for Using peekdata Using peekdata to preview data follows these rules e You can call peekdat a before a trigger executes Therefore peekdata is useful for previewing data before it is logged to the engine or a disk file e In most cases you will call peekdat a while the device object is running However you can call peekdata once after the device object stops running e f the specified number of preview samples is greater than the number of samples currently acquired all available samples are returned with a warning message stating that the requested number of samples were not available For more information about peekdat a refer to its reference pages in Chapter 9 Function Reference Example Polling the Data Block Under certain circumstances you may want to poll the data block Polling the data block is useful when calling peekdat a since this functio
265. j When st art is issued for an analog input or analog output object e The M file action function specified for St art Action is executed e TheRunni ng property is set to0n e The start event is recorded in theEventLog property e Data existing in the engine is flushed Although an analog input or analog output object may be executing data logging or sending is not necessarily initiated Data logging or sending requires a trigger event to occur and depends on theTri gger Type property value For any device object you can specify start as the valuefor an action property ai StopAction start Note You typically execute a digital I O object to periodically update and display its state Refer to thedi opanel demo for an example of this Functions stop trigger Properties EventLog Running Sending TriggerType Purpose Syntax Arguments Description Remarks Stop a device object stop obj obj A device object or an array of device objects stop obj terminates the execution of the device object obj An analog input object automatically stops when the requested samples are acquired or data is missed An analog output object automatically stops when the queued data is output These two device objects can also stop executing under one of these conditions e TheTi meout property value is reached e A run time error occurs For analog input objects st op must be used when theTri ggerRepeat property
266. ject you must supply the device object tos et For example all configurable common properties for ai are shown below The base properties are listed first followed by the device specific properties set ai BufferingConfig BufferingMode Auto Manual Channel Channel Skew Channel SkewMode None ClockSource Internal DataMissedAction Input OverRangeAction InputType AC Coupl ed LogFil eName LoggingMode Disk Memory Disk amp Memory LogToDiskMode Overwrite Index Manual TriggerHwOn Start Trigger Na me RuntimeErrorActi on Sampl eRate Sampl esAcquiredAction Sampl esAcquiredActionCount SamplesPerTrigger Configuring and Returning Properties StartAction StopAction ea Ti meout Ti merAction Ti mer Period riggerAction riggerChannel riggerCondition None riggerConditionValue riggerDelay riggerDelayUnits Seconds Samples riggerRepeat riggerType Manua ser Data I mmedi ate Software U WINSOUND specific properties BitsPerSample StandardSampleRates Off On Toreturn all common properties and their current values for a device object you must supply the device object to get For example all common properties for ai are shown below The base properties are listed first followed by the device specific properties get ai BufferingConfig 512 30 BufferingMode Auto Channel 2x1 aichannel Channel Skew 0 Channel SkewMode
267. l Using daqpropedit you can perform these tasks for device objects channels and lines e List all existing device objects as well as the channels or lines they contain This is identical to using thedaqfi nd function e Configure property values This is identical to using thes et function or the dot notation e Display the names and current values for configurable properties This is identical to using the get function or the dot notation e Display property characteristics This is identical to using the pr opi nfo function e Display property help This is identical to using thedaqhel p function Create the analog input object ai for a sound card and add one channel to it al analoginput winsound addchannel ai 1 2 To configure property values for ai usingdaqpropedit daqpropedit ai 9 37 daqpropedit The Data Acquisition Property Editor is shown below File Options Help List of device objects channels and lines la BitsPerS ample 16 Property to configure and its current value BufferingConfig 512 30 Bufferingtlode Auto lt n 0 namel List of configurable properties Inema and their current values DatallissedAction dagaction EventLog Default Value 36 Constraint Value Tete iii Read nw wben rr ff Property characteristics Device Specific 1 True BITSPERSAMPLE 16 BitsPerSample specifies the number of bits the sound card uses
268. l Ds ans 0 1 2 3 4 5 6 7 In contrast the single ended channel Ds would be numbered O through 15 Note Ifthe nput Type valueis changed and that change decreases the number of channels contained by the analog input object then a warning is returned and all channels are deleted Configuring and Sampling Input C hannels National Instruments Devices For National Instruments devices nputType can beDifferential Singl eEnded or NonRef erencedSi ngl eEnded Channels configured for differential input are not connected to a fixed reference such as earth and input signals are measured as the difference between twoterminals Channels configured for single ended input are connected toa common ground and input signals are measured with respect to this ground Channels configured for nonreferenced single ended input are connected to their own ground reference and input signals are measured with respect to this reference The ground reference is tied to the negative input of the instrumentation amplifier The number of channels that you can add to a device object depends on the nput Type property value Most National Instruments boards have 16 or 64 single ended inputs and 8 or 32 differential inputs which are interleaved in banks of 8 This means that for a 64 channel board with single ended inputs you can add all 64 channels However if the channels are configured for differential input you can only add channels 0 7 16 23
269. l Instruments board defined as device number 1 Al analoginput nidaq 1 Agilent Technologies Tocreate an analog input object for an Agilent Technologies module with device identifier 1 residing in VXI chassis 0 Al analoginput hpel432 vxid l instr Alternatively you can use the syntax Al analoginput hpel432 1 0 9 19 analoginput See Also 9 20 The HP driver allows you to span multiple hardware devices To create an analog input object that spans two HP devices with device identifiers 1 and 2 residing in VXI chassis 0 Al analoginput hpel432 vxi0 1 2 instr Alternatively you can use the syntax Al analoginput hpel432 1 2 0 Functions addchannel daqhwi nfo Properties Name analogoutput Purpose Syntax Arguments Description Remarks Create an analog output object AO analogoutput adaptor AO analogoutput adaptor 1D adaptor Name of the hardware driver adaptor The supported adaptors areni daq cbi hpel432 and wi nsound 1D The hardware device identifier D is optional if the device object is associated with a sound card having an D of O AO The analog output object AO analogoutput adaptor creates the analog output object A0 for a sound card having an D of O adapt or must bewi ns ound Thisisthe only case where D is not required AO analogoutput adaptor 1 D creates the analog output object A0 for the specified adapt or and f
270. l Rate get ao Sampl eRate Alternatively you can usethes et veri fy function which sets a property value and returns the actual value set Actual Rate setverify ao SampleRate 100000 You can find the range of valid sampling rates for your hardware with the propi nfo function ValidRates propinfo ao SampleRate ValidRates ConstraintValue ans 1 0e 005 0 0000 2 0000 6 7 6 Analog O utput 6 8 Defining a Trigger For analog output objects a trigger is defined as an event that initiates the output of data from the engine to the analog output hardware Defining a trigger for an analog output object involves specifying the trigger type Trigger types are specified with the Tri gger Type property The valid TriggerType values that are supported for all hardware are given below Table 6 4 Analog Output TriggerType Property Values TriggerType Values Description mmedi ate Thetrigger occurs just after you issuethestart function Manual The trigger occurs just after you manually issue the trigger function Most devices have hardware specific trigger types which are available to you through theTri ggerType property For example to see all the trigger types including hardware specific trigger types for the analog output object ao created in the preceding section set ao TriggerType Manual Immediate HwDigital This information tells you that the National Instruments board also
271. le channel line property names and their possible values for a single channel line contained by a device object you must use the Channel Line property For example to display the configurable channel properties for the first channel contained by ai set ai Channel 1 Channel Name HwChannel InputRange SensorRange Units UnitsRange All channel properties and their current values for the first channel contained by ai are shown below get ai Channel 1 Channel Name Left HwChannel 1 Index 1 InputRange 1 1 NativeOffset 1 5259e 005 NativeScaling 3 0518e 005 Parent 1x1 anal oginput SensorRange 1 1 Type Channe Units Volts UnitsRange 1 1 As described in the preceding section you can also return values for a specified number of channel properties with theget function or the dot notation 3 17 3 The Data Acquisition Session 3 18 Configuring Property Values You configure property values with thes et function or the dot notation In practice you can configure many of the properties at any time while the device object exists However some properties are not configurable while the object is running Use the pr opi nfo function or refer to Chapter 10 Base Property Reference for information about when a property is configurable The syntax used to configure common and channel line properties is described below The examples are based on the analog input object ai created in
272. le the device object is running Logging or Sending Data While the device object is running you can e Log data acquired from an analog input subsystem to the engine memory or toa disk file e Output data queued in the engine to an analog output subsystem However before you can log or send data a trigger must occur You configure an analog input or analog output trigger with theTri gger Type property All the examples presented in this section use the default Trigger Type value of mmedi ate which executes the trigger immediately after thest art function is issued For a detailed description of triggers refer to Configuring Analog Input Triggers on page 5 20 or Configuring Analog Output Triggers on page 6 21 3 23 3 The Data Acquisition Session 3 24 Extracting Logged Data When a trigger occurs for an analog input object the Logging property is automatically set to 0n and data acquired from the hardware is logged to the engine or a disk file Y ou extract logged data from the engine with theget data function F or example to extract 500 samples for each channel contained by ai data getdata ai 500 getdata blocks the MATLAB command line until all the requested data is returned to the workspace Y ou can extract data any time after the trigger occurs Sending Queued Data For analog output objects you must queue data in the engine with theput data function before it can be output to the hardwar
273. lication manually Start gt P rograms gt Accessories gt Multimedia gt CD Player The figure below shows how to play a CD with the CD Player application CD Player Mm E Disc View Options Help BOOS l Play button Title The Sun Years Track Folsom Prison Blues lt 0 3 Whilethe CD is playing record audio data by selecting the Record button on the Sound Recorder While recording the green line in the Sound Recorder should indicate that data is being captured If this is the case then the analog input subsystem on your sound card is functioning properly Note that the CD player converts digital audio data to analog audio data Therefore the CD sends analog data to the sound card 4 After recording the audio data save it to disk The data is automatically saved as a WAV file 5 Play the saved WAV file While playing the green line in the Sound Recorder should indicate that data is being captured If this is the case then the analog output subsystem on your sound card is functioning properly If you are not able to record or play data make sure that the sound card and input devices are enabled for recording and playback as described in the beginning of this section A 17 A Troubleshooting Your Hardware A 18 Running in Full Duplex Mode The term full duplex refers to a system that can send and receive information simultaneousl y For sound cards full duplex means that the device can acqu
274. ll device objects existing in the engine and unloads all data acquisition DLLs loaded by the engine including the adaptor and engine DLL files Y ou should usedaqreset to return MATLAB tothe known initial state of having no device objects and no data acquisition DLLs loaded in memory When MATLAB is returned to this state the data acquisition hardware is reset Functions clear delete daqschool Purpose Syntax Description Interface for displaying toolbox tutorials dagschool daqschool launches the Data Acquisition Toolbox Tutorials interface which is shown below Data Acquisition Toolbox Tutorials SBE Analog Input Analog Output Digital YO Common The buttons in this windew will launch the Data Acquisition Toolbox demos for analog input objects Introduction illustrates a basic data acquisition session using an analog input object Channels introduces adding and configuring analog input channels Triggers illustrates how data can be acquired using om imediate manual and software trigger Data Legging illustrates how to configure an analog input object for data logging Introduction Channels Triggers Data Logging Refer to Demos on page 2 13 for a list of demos included with daqschool 9 45 dec2binvec Purpose Syntax Arguments Description Remarks Example 9 46 Convert decimal value to binary vector out dec2bi nvec dec out dec2binvec dec bits
275. load file returns all variables from the MAT filef i e into the MATLAB workspace load file obj1 obj2 returns the specified device objects from the MAT filef ile intothe MATLAB workspace out load file obj1 obj2 returns the specified device objects from the MAT filefile asa structuretoout instead of directly loading them into the workspace The field names in out match the names of the loaded device objects If no device objects are specified then all variables existing in the MAT file are loaded Loading device objects follows these rules e Unique device objects are loaded into the MATLAB workspace as well as the engine e f a loaded device object already exists in the engine but not the MATLAB workspace the loaded device object automatically reconnects to the engine device object e f a loaded device object already exists in the workspace or the engine but has different properties than the loaded object then these rules are followed The read only properties are automatically reset to their default values All other property values are given by the loaded object and a warning is issued stating that property values of the workspace object have been updated 9 69 load Example See Also 9 70 If the workspace device object is running then it is stopped before loading occurs If identical device objects are loaded then they point to the same device object in the engine For example if you sa
276. low are automatically assigned values These general purpose properties provide descriptive information about the object based on its class type and adaptor Table 7 1 Descriptive Digital I O Properties Property Name Description Na me Specify a descriptive name for the device object Type Indicate the device object type Y ou can display the values of these properties for di o with theget function get dio Name Type ans nidagl DI0 Digital 10 7 3 7 Digital input O utput Adding Lines to a Digital I O Object After creating the digital I O object you must add lines to it As shown by the figure in Adding Channels or Lines on page 3 8 you can think of a device object as a container for lines The collection of lines contained by the device object is referred toas a linegroup A line group consists of a mapping between hardware line Ds and MATLAB indices see below When adding lines to a digital I O object you must follow these rules e The lines must reside on the same hardware device You cannot add lines from different devices or from different subsystems on the same device e You can add a line only onceto a given digital I O object However a line can be added to as many different digital I O objects as you desire e You can add lines that reside on different ports to a given digital 1 O object Y ou add lines to a digital I O object with theaddl i ne function addline requires
277. ls setting property values and using specificfunctions to output data Simple data acquisition applications using a sound card and a National Instruments board are given below G etting Started with Analog O utput Outputting Data with a Sound Card In this example sine wave data is generated in MATLAB output to the D A converter on the sound card and sent to a speaker The setup is shown below Data Source D A Converter Speaker MATLAB variable D A 3 Y ou can run this example by typing daqdoc6_1 at the MATLAB command line 1 Create a device object Createthe analog output object A0 for a sound card The installed adaptors and hardware IDs are found with daghwi nfo AO analogoutput winsound 2 Add channels Add one channel to Ao chan addchannel AO 1 3 Configure property values Define an output time of four seconds assign values to the basic setup properties generate data to be queued and queue the data with one call toput data duration 4 set A0 SampleRate 8000 set A0 TriggerType Manual Actual Rate get A0 SampleRate len ActualRate duration data sin linspace 0 2 pi len put data A0 data 6 11 6 Analog O utput 6 12 4 Output data Start A0 issue a manual trigger and wait for the device object to stop running start AQ trigger AO while strcmp
278. ltage signal F or example thermocouples strain gauges and accelerometers all produce voltage signals There are three major aspects of a voltage signal that you need to consider e Amplitude If the signal is smaller than a few millivolts you may need to amplify it If it is larger than the maximum range of your analog input hardware typically 10 V you will have to divide the signal down using a resistor network The amplitude is related to the sensitivity resolution of your hardware Refer to Accuracy and Precision on page 1 29 for more information about hardware sensitivity 1 9 1 Introduction to Data Acquisition 1 10 e Frequency Whenever you acquire data you should decide the highest frequency you want to measure The highest frequency component of the signal determines how often you should sample the input If you have more than one input but only one analoginput subsystem then the overall sampling rate goes up in proportion to the number of inputs Higher frequencies may be present as noise which you can remove by filtering the signal before it is digitized If you sample the input signal at least twice as fast as the highest frequency component then that signal will be uniquely characterized However this rate may not mimic the waveform very closely For a rapidly varying signal you may need a sampling rate of roughly 10 to 20 times the highest frequency to get an accurate picture of the waveform For slo
279. luding the number of triggers already executed e The engine status Whether the engine is logging data waiting to start or waiting to trigger Thenumber of samples acquired since starting Thenumber of samples available to be extracted with get data Channel Summary Information The channel display summary includes property values associated with e The hardware channel mapping e The channel name e The engineering units 4 23 4 G etting Started with Analog Input General display summary Channel display summary 4 24 The display summary for the example given in Acquiring Data with a Sound Card on page 4 15 beforestart is issued is shown below Display Summary of Analog Input AI Object Using AudioPCl Record Acquisition Parameters 8000 samples per second on each channel 8000 samples per trigger on each channel l sec of data to be logged per trigger Log data to Memory on trigger Trigger Parameters 1 Manual trigger s on TRIGGER Engine status Waiting for START 0 samples acquired since starting 0 samples available for GETDATA Al object contains channel s Index Channel Name HwChannel InputRange SensorRange UnitsRange Units 1 Mono 1 1 1 1 1 1 1 Volts You can usetheChannel property to display only the channel summary information Al Channel Doing More with Analog Input Overview Configuring and Sampling Input Channels Input Channel Configuratio
280. lues are automatically added as events occur The default value is an empty structure array Create the analog input object ai and add four channels to it al analoginput nidaq 1 chans addchannel ai 0 3 Acquire 1 second of data and display the logged event types start ai events ai EventLog events Type ans Start Trigger Stop To examine the data associated with the trigger event events 2 Data ans AbsTime 1999 2 12 14 54 52 5456 Rel Sample 0 Channel Trigger 1 Functions showdaqevents Hw Channel Purpose Description Characteristics Values Example Specify the hardware channel ID All channels contained by a device object have a hardware channel ID and an associated MATLAB index The channel 1D is given by HwChannel and the MATLAB indexis given by the ndex property TheHwChannel valueis defined when hardware channels are added to a device object with theaddchannel function Thebeginning channel ID value depends on the hardware device For National Instruments hardware channel Ds are zero based begin at zero For Agilent Technologies hardware and sound cards channel Ds are one based begin at one For scanning hardware the scan order follows the MATLAB index Therefore the hardware channel associated with index 1 is sampled first the hardware channel associated with index 2 is sampled second and so on To change the scan order you can assign the cha
281. mation are saved to one disk file or to multiple disk files Analog Input Trigger Properties Initial Trigger Indicate the absolute time of the first trigger Ti me Manual Trigger Specify that the hardware device starts when a HwOn manual trigger is issued TriggerAction Specify the M file action function to execute when a trigger occurs i gger Channel Specify the channels serving as trigger sources riggerCondition Specify the condition that must be satisfied before a trigger executes riggerCondition Specify one or more voltage values that must be Value satisfied before a trigger executes Trigger Delay Specify the delay value for data logging TriggerDelay Specify the units in which trigger delay data is Units measured 10 4 Properties Grouped by Category Analog Input Trigger Properties Continued TriggerRepeat TriggersExecuted TriggerType Specify the number of additional times the trigger executes Indicate the number of triggers that execute Specify the type of trigger to execute Analog Input Status Properties Logging Running Sampl esAcquired Sampl esAvail able Indicate if data is being logged to memory or toa disk file Indicate if the device object is running Indicate the number of samples acquired per channel Indicate the number of samples available per channel in the engine Analog Input Hardware Configuration Propertie
282. mation is stored in theType and Data fields of the EventLog property TheTy pe field valueisOver Range TheData field values are given below Data Field Value Description Rel Sample The acquired sample number when the event occurred Channel The index of the channel that experienced an overrange signal Over Range Indicates if the channel went from overrange to in range or from in range to overrange Usage Al Common Access Read write Data type String Read only No when running The default value is an empty string Properties EventLog InputRange InputRange Purpose Description Specify the range of the analog input subsystem Input Range isatwo element vector that specifies the range of voltages that can be accepted by the analog input Al subsystem You should configure nput Range so that the maximum dynamic range of your hardware is utilized If an input signal exceeds the nput Range value then an overrange condition occurs Overrange detection is enabled only if the analog input object is running and a value is specified for the nput Over RangeActi on property For many devices the input range is expressed in terms of the gain and polarity Al subsystems have a finite number of nput Range values that you can set If an input range is specified but does not match a valid range then the next highest supported range is automatically selected by the engine IfI nput Range exceeds the range of
283. me to reference the channel ai TrigChan I nputRange 10 10 Example Adding Channels for a Sound Card Suppose you create the analog input object ai for a sound card al analoginput winsound Most sound cards have just two hardware channels that you can add If one channel is added the sound card is said to be in mono mode If two channels are added the sound card is said to be in stereo mode However the rules for adding these two channels differ from those of other data acquisition devices These rules are described below Mono Mode If you add one channel toai the sound card is said to be in mono mode and the channel added must have a hardware ID of 1 addchannel ai 1 At the software level mono mode means that data is acquired from channel 1 At the hardware level you generally cannot determine the actual channel configuration and data can be acquired from channel 1 channel 2 or both depending on your sound card Channel 1 is automatically assigned the descriptive channel name Mono ai Channel Channel Name ans Mono 4 7 4 G etting Started with Analog Input 4 8 Stereo Mode If you add two channels toai the sound card is said to be in stereo mode Y ou can add two channels using two calls toaddchannel provided channel 1 is added first addchannel ai 1 addchannel ai 2 Alternatively you can use one call toaddchannel provided channel 1is specified as the first element of the hardwa
284. member for each trigger that occurs If Sampl esPerTrigger is Set tol nf then the analog input object continually acquires data until astop function is issued or an error occurs The default value of Sampl esPer Trigger is calculated by the data acquisition engine such that onesecond of data is acquired This calculation is based on the value of SampleRate Usage Al Common Access Read write Data type Double Read only Yes when running The default value is set by the engine such that one second of data is acquired Create the analog input object ai for a sound card and add two channels to it al analoginput winsound addchannel ai 1 2 By default a one second acquisition in which 8000 samples are acquired for each channel is defined To define a two second acquisition at the same sampling rate set ai SamplesPerTrigger 16000 Functions stop Properties SampleRate 10 73 Sending Purpose Indicate if data is being sent to the hardware device Description Alongwith theRunni ng property Sending reflects the state of an analog output object Sending can beOn or Off Sending is automatically set to0n when a trigger occurs When Sending isOn queued data is being output to the analog output subsystem Sending is automatically set to0f f when the queued data has been output an error occurs or ast op function is issued When Sendi ng is Off data is not being output to the analog output subsystem although you
285. mmary information and line summary information General Summary Information Thegeneral display summary includes the device object type and the hardware device name followed by the port parameters The port parameters include the port ID and whether the associated lines are configurable for reading or writing Line Summary Information The line display summary includes property values associated with e The hardware line mapping e Theline name e The port ID e The line direction Evaluating the Digital I O O bject Status The display summary for the example given in Example Writing and Reading Digital Values on page 7 13 is shown below Display Summary of DigitallO DIO Object Using PCI 6024E General display summary Port Parameters Port 0 is line configurable for reading and writing Engine status Engine not required DIO object contains line s Index LineName HwLine ort Direction Line display summary o u DD Oo A W N RR P 0 0 0 0 Tn 0 0 0 0 Y OD Wo Rh WwW N FY o You can use the Li ne property to display only the line summary information DIO Line 7 19 7 Digital Input O utput 7 20 Saving and Loading the Session Overview 2 2 ee a 8 2 Saving and Loading Device Objects 8 3 Saving DeviceObjectstoanM File 2 8 3 Saving Device Objects to a MAT File 8 5 Logging Information to Disk 8 6 Specif
286. n Sampling Rate i Channel Skew Managing Acquired Data Previewing Data yoa Extracting Data from the E ngine i Returning Time Information Configuring Analog Input Triggers Defining a Trigger Trigger ee and Conditions Executing the Trigger ah af Trigger Delays Repeating Triggers How Many Triggers Occurred y When Did the Trigger Occur Device Specific Hardware Triggers Configuring Events and Actions Event Types Recording and Retrieving Event Information Creating and Executing Action Functions Examples Using Action Properties and Functions Linearly Scaling the Data Engineering Units Example Performing a Linear Conversion 5 7 5 18 5 56 5 57 5 Doing More with Analog Input 5 2 Overview This chapter presents the complete analog input functionality available to you with the Data Acquisition Toolbox Properties and functions are presented ina way that reflects the typical procedures you will use to configure your analog input data acquisition session Topics include e Configuring and sampling input channels e Managing acquired data e Configuring analog input triggers e Configuring events and actions e Linearly scaling the data Configuring and Sampling Input C hannels Configuring and Sampling Input Channels The hardware you are using has characteristics that satisfy your specific application needs Some of the most important hardware characteris
287. n addchannel Al 1 chan addchannel Al 0 For NI and CBI 3 Configure property values Define a 10 second acquisition set up the plot and store the plot handle in the variable P The amount of data to display is given by preview duration 10 Ten second acquisition set Al Sampl eRate 8000 Actual Rate get Al SampleRate set Al SamplesPerTrigger duration Actual Rate preview duration Actual Rate 100 subplot 211 set gcf doublebuffer on P plot zeros preview 1 grid on xl abel Sampl es ylabel Signal Level Volts 4 Acquire data Start Al and update the display using peekdat a every time an amount of data specified by pr evi ew is stored in the engine by polling Sampl esAcquired Thedrawnow command forces MATLAB to update the plot After all data is acquired it is extracted from the engine Note that whenever peekdata is used all acquired data may not be displayed start Al while Al SamplesAcquired lt preview end while Al SamplesAcquired lt duration Actual Rate data peekdata Al preview set P ydata data drawnow end Extract all the acquired data from the engine and plot the data data getdata Al subplot 212 plot data grid on title All Acquired Data xl abel Samples ylabel Signal level volts Managing Acquired Data 5 Clean up When you nolonger need Al you should remove it from memory and from the MATLAB workspace delete Al
288. n action function is specified for nput Over RangeActi on and the analog input object is running Run time Error Event A run time error event is generated immediately after a run time error occurs Additionally a toolbox error message is automatically displayed to the MATLAB workspace If an error occurs that is not explicitly handled by the toolbox then the hardware specific error message is displayed This event executes the action function specified for Runt i meErrorAction The default value for Runt i meErrorAction isdagaction which displays the event type the time the event occurred the device object name and the error message Run time errors include hardware errors and timeouts Run time errors do not include configuration errors such as setting an invalid property value Samples Acquired Event A samples acquired event is generated immediately after a predetermined number of samples is acquired This event executes the action function specified for the Sampl esAcquiredActi on property every time the number of samples specified by Sampl esAcquiredActionCount is acquired for each channel group member 5 47 5 Doing More with Analog Input 5 48 You should useSampl esAcqui redActi on if you must access each sample that is acquired However if you are performing a CPU intensive task with the data then system performance may be adversely affected If you do not have this requirement you may want to usetheTi mer Actio
289. n configure the input range gain and polarity on a per channel basis The relationship between an analog input object and the channels it contains is shown below Analog Input Object Container device object Channel 1 Channel 2 Channel 3 Channel group hardware channels Channel n For digital 1 O objects the diagram would look the same except that lines would be substituted for channels Mapping Hardware Channel IDs to MATLAB Indices When you add channels to a device object the resulting channel group consists of a mapping between hardware channel IDs and MATLAB indices Hardware channel IDs are numeric values defined by the hardware vendor that uniquely identify a channel For National Instruments and ComputerBoards hardware the channel Ds are zero based begin at zero For Agilent Technologies hardware and sound cards the channel IDs are one based begin at one However when you reference channels you use the MATLAB indices and not the hardware Ds Given this you should keep in mind that MATLAB is one based You can return the vendor s hardware I Ds with thedaghwi nfo function 3 9 3 The Data Acquisition Session 3 10 For example suppose you create the analog input object ai for a National Instruments board and you want to add the first three differential channels ai analoginput nidaq 1 To return the hardware IDs supply the device obje
290. n getdata 5 13 putdata 6 9 board ID 4 3 buffer configuration 10 15 extracting data 5 14 previewing data 5 10 queuing data 6 17 C calibration 1 3 Channel 4 6 channel gain list 4 5 channel group Al object 4 4 AO object 6 4 channel names 4 7 channel properties 3 12 Al object 10 7 AO object 10 11 channel skew 5 7 Index Channel Name 4 7 channels 3 8 adding Al object 4 4 AO object 6 4 descriptive names 4 6 input configuration 5 4 mapping to hardware Ds 3 9 referencing 4 6 Channel Skew 5 8 Channel SkewMode 5 8 cleaning up the MATLAB environment clear 3 25 delete 3 25 with dagfind 9 48 clear 3 25 clipping 6 35 clock 5 37 clocked acquisition 1 23 common properties 3 12 Al object 10 3 AO object 10 8 DIO object 10 12 ComputerBoards hardware channel configuration 5 5 driver A 6 properties 11 4 trigger types Al 5 41 troubleshooting A 6 configuring property values dot notation 3 18 set 3 18 constructor 3 4 Contents 2 12 continuous acquisition example using Al and AO 6 37 samples per trigger 5 23 trigger repeats 5 30 continuous output 6 22 creation function 3 4 custom adaptors 2 7 D D A converter 1 7 output range 6 34 sampling rate 6 6 dagaction Al example 5 53 default property value data missed event Al 5 47 run time error event Al object 5 47 AO object 6 28 dagfind 3 25 daqhel p 2 20 daqhwi nfo 2 17 daqmem B 4 daqpropedit 3 20 dagread 8 8 daqregi ster A 19 daqreset 9 44 daqschool 2 13 d
291. n Functions When using action functions you should be aware of these execution rules e Action functions execute in the order in which they are issued e All action functions except those associated with timer events are guaranteed to execute e Action function execution may be delayed if the action involves a CPU intensive task such as updating a figure You can specify the action function to be executed when a specific event type occurs by including the name of the M file as the value for the associated action property For example to execute the action function myaction for the analog input object ai every time 1000 samples are acquired ai Sampl esAcquiredActionCount 1000 ai Sampl esAcquiredAction myaction M file action functions require at least two input arguments The first argument is the device object The second argument is a variable that captures the event information given in Table 5 12 Analog Input Event Information Stored in EventLog on page 5 49 This event information pertains only to the event that caused the action function to execute The function header for my action is shown below function myacti on obj event You can pass additional parameters to the action function by including them as elements of a cell array For example to pass the MATLAB variablet i me to myaction time datestr now 0 ai Sampl esAcquiredActionCount 1000 ai Sampl esAcquiredAction myaction ti me The corr
292. n daqacti on displays the event type and device object name Note that you must issue a stop command to stop the execution of the digital 1 O object Y ou can run this example by typing daqdoc7_2 at the MATLAB command line 1 Create a device object Create the digital 1 O object di o for a National Instruments board The installed adaptors and hardware IDs are found with daqhwinfo dio digitalio nidaq 1 2 Add lines Add eight input lines from port 0 line configurable addline dio 0 7 in 3 Configure property values Configure the timer event to call dagaction every five seconds set dio Ti merAction dagaction set dio TimerPeriod 5 0 Start the digital 1 O object You must issue as top command when you no longer want to generate timer events start dio 4 Clean up When you nolonger need di o you should remove it from memory and from the MATLAB workspace del ete dio clear dio 7 17 7 Digital input O utput Evaluating the Digital I O Object Status 7 18 At any time after a digital I O object is created you can evaluate its status by e Returning the value of theRunni ng property e Invoking the display summary The Display Summary You can invoke the display summary by typing the digital I O object at the command line The displayed information is designed so you can quickly evaluate the status of your data acquisition session The display is divided into two main sections general su
293. n does not block execution control For example you can issue peekdata calls based on the number of samples acquired by polling the Samp es Acquired property Y ou can run this example by typingdagdoc5_1 at the MATLAB command line 1 Create a device object Createthe analog input object Al for a sound card The available adaptors and hardware IDs are found with daqhwi nfo Al analoginput winsound Al analoginput nidaq 1 Al analoginput cbi 1 2 Add channels Add one hardware channel toAl addchannel Al 1 addchannel Al 0 For NI and CBI 3 Configure property values Define a 10 second acquisition set up a plot and storethe plot handleandtitle handlein the variables P andT respectively duration 10 Ten second acquisition Actual Rate get Al SampleRate set Al SamplesPerTrigger duration Actual Rate figure 5 11 5 Doing More with Analog Input 5 12 set gcf doublebuffer on Reduce plot flicker P plot zeros 1000 1 T title sprintf Number of peekdata calls num2str 0 xlabel Samples axis 0 1000 1 1 grid on 4 Acquire data Start Al and update the display for each 1000 samples acquired by polling Sampl es Acquired Thedr awnow command forces MATLAB to update the plot Since peekdat a is used all acquired data may not be displayed start Al Sl while Al SamplesAcquired lt Al SamplesPerTrigger while Al SamplesAcquired lt 1000 i end data
294. n in MATLAB in multiple output formats A comprehensive environment for neural network research design and simulation within MATLAB Tool for algorithm development signal and linear system analysis and time series data modeling Tool for analyzing historical data modeling systems developing statistical algorithms and learning and teaching statistics Tool for building accurate simplified models of complex systems from noisy time series data Tool for signal and image analysis compression and de noising Using This Guide Using This Guide Ex pected Background To use the Data Acquisition Toolbox you should have some familiarity with e The basic features of MATLAB e The capabilities of your hardware device e The basic concepts associated with acquiring live measured data If You Are a New User For a brief review of basic data acquisition concepts you should start with Chapter 1 Introduction to Data Acquisition Otherwise start with Chapter 2 Getting Started with the Data Acquisition Toolbox which provides simple examples that illustrate how to input and output data Then read the appropriate chapter based on the hardware subsystem you are using F or example if you are acquiring data with an analog input subsystem you should read Chapter 4 Getting Started with Analog Input After you have successfully transferred data between your hardware device and MATLAB you should read the appropria
295. n property Start Event A start event is generated immediately after thest art function is issued This event executes the action function specified for St artAction When theSt art Acti on M filehas finished executing Running is automatically set to0n and the device object and hardware device begin executing Stop Event A stop event is generated immediately after the device object and hardware device stop running This occurs when e Thest op function is issued e The requested number of samples is acquired e A run time error occurs A stop event executes the action function specified for St opActi on Under most circumstances the action function is not guaranteed to complete execution until sometime after the device object and hardware device stop running and the Running property is set toOff Timer Event A timer event is generated whenever the time specified by the Ti mer Period property passes This event executes the action function specified for Ti mer Acti on Time is measured relative to when the device object starts running Some timer events may not be processed if your system is significantly slowed or iftheTi mer Peri od valueis toosmall For example a common application for timer events is to display data However since displaying data isa CPU intensive task some of these events may be dropped To guarantee that events are not dropped usetheSamp esAcquiredActi on property Trigger Event A trigger event is generate
296. n specified for St opAct i on Under most circumstances the action function is not guaranteed to complete execution until sometime after the device object and hardware device stop and the Running property is set to Off Stop event information is stored in theType and Data fields of theEvent Log property TheType field value is St op The Data field values are given below Data Field Value Description AbsTi me The absolute time as ac ock vector the event occurred Rel Sample The acquired Al or output AO sample number when the event occurred Characteristics Usage Al AO Common Access Read write Data type String Read only No when running Values The default value is an empty string 10 77 StopAction See Also Functions stop Properties EventLog Runni ng 10 78 Tag Purpose Description Characteristics Values Example See Also Specify a device object label Tag provides a means to identify device objects with a label Using theda qf i nd function and theTag value you can identify and retrieve a device object that was cleared from the MATLAB workspace Usage Al AO DIO Common Access Read write Data type String Read only No when running The default value is an empty string Create the analog input object ai for a sound card and add two channels to it al analoginput winsound addchannel ai 1 2 Assign ai a label usingTag set ai Tag Sound Ifai is
297. nal has a positive slope when passing through the specified range of values Falling The trigger occurs when the analog signal has a negative slope when passing through the specified range of values Leaving Thetrigger occurs when the analog signal leaves the specified range of values Entering The trigger occurs when the analog signal enters the specified range of values Note that when Tri ggerType iSHwAnal og the trigger condition values are all specified as two element vectors Setting two trigger levels prevents the module from triggering repeatedly due to a noisy signal Properties TriggerChannel TriggerConditionValue TriggerType TriggerConditionValue Purpose Description Characteristics Values Example See Also Specify one or more voltage values that must be satisfied before a trigger executes TriggerConditionVal ue isusedwhenTriggerType isSoft ware andisignored whenTriggerCondition iSNone To execute a software trigger the values specified for Trigger Condition and Tri ggerConditionVal ue must besatisfied WhenTriggerConditionisRising orFalling TriggerConditionValue accepts a single value When TriggerCondition isEntering orLeaving TriggerConditionValue accepts a two element vector of values Usage Al Common Access Read write Data type Double or a two element vector of doubles Read only Yes when running The default value is zero Create the analog input object ai and add one channel t
298. nction or the dot notation You evaluate your application configuration and status by displaying property values with the get function or the dot notation Property Types Data Acquisition Toolbox properties are divided into two main types e Common properties Common properties apply to every channel or line contained by a device object e Channel Line properties Channel line properties are configured for individual channels or lines Therelationship between an analog input object the channels it contains and their properties is shown below Analog Input Object Common properties apply to all channels Channel 1 Channel 2 Channel 3 Channel properties are set on a per channel basis Channel n For digital I O objects the diagram would look the same except that lines would be substituted for channels 3 12 Configuring and Returning Properties Common properties and channel line properties are subdivided into these two categories Base properties Base properties apply to all supported hardware subsystems of a given type such as analog input For example the Samp eRat e property is supported for all analog input subsystems regardless of the vendor Device specific properties Device specific properties apply only to specific hardware devices For example theBitsPerSampl e property is supported only for sound cards Note that base properties can have device specif
299. nctions clear daqreset 9 49 digitalio Purpose Syntax Arguments Description Remarks 9 50 Create a digital I O object DIO digitalio adaptor 1D adaptor Name of the hardware driver adaptor The supported adaptors areni daq andcbi 1D The hardware device identifier DIO The digital I O object DIO digitalio adaptor 1D creates the digital I O object DI 0 for the specified adapt or and for the hardware device with device identifier D 1 D can be specified as an integer or a string More About Creating Digital I O Objects e When a digital I O object is created it does not contain any hardware lines Toexecutethe device object hardware lines must be added with theadd i ne function e You can create multiple digital I O objects that are associated with a single digital I O subsystem However you can typically execute only one of them at a time e The digital I O object exists in the data acquisition engine and in the MATLAB workspace If you create a copy of the device object it references the original device object in the engine e TheName property is automatically assigned a descriptive name that is produced by concatenatingadaptor D and DI 0 You can changethis name at any time More Aboutthe Hardware Device Identifier When data acquisition devices are installed they are assigned a unique number which identifies the device in software The device identifier is typically assigned a
300. nctions that are used refer to Chapter 9 Function Reference If you want detailed information about any properties that are used refer to Chapter 10 Base Property Reference Acquiring Data If you have a sound card installed you can run the following example which acquires one second of data from two analog input hardware channels and then plots the acquired data Y ou should modify this example to suit your specific application needs If you want detailed information about acquiring data refer to Chapter 5 Doing More with Analog Input 1 Create a device object Create the analog input object ai for a sound card ai analoginput winsound 2 Add channels Add two hardware channels toai addchannel ai 1 2 Accessing Your Hardware 3 Configure property values Configure the sampling rate to 44 1 kHz and collect 1 second of data 44 100 samples for each channel set ai SampleRate 44100 set ai SamplesPerTrigger 44100 4 Acquire data Start the acquisition When all the data is acquired ai automatically stops executing start ai data getdata ai plot data 5 Clean up When you no longer need ai you should remove it from memory and from the MATLAB workspace del ete ai clear al Outputting Data If you have a sound card installed you can run the following example which outputs 1 second of data to two analog output hardware channels You should modify this example to s
301. nd Loading the Session Logging Information to Disk While an analog input object is running you can log this information toa disk file e Acquired data e Event information e Device object and channel information e Hardware information Logging information to disk provides a permanent record of your data acquisition session and is an easy way to debug your application As shown below you can think of the logged information as a stream of data and events Start Trigger 1 Trigger 2 Trigger n Stop Time E Data logged to file The properties associated with logging information to a disk file are given below Table 8 1 Analog Input Logging Properties Property Name Description LogFil eName Specify the name of the disk file to which information is logged Logging Indicate if data is being logged 8 6 Logging Information to Disk Table 8 1 Analog Input Logging Properties Continued Property Name Description LoggingMode Specify the destination for acquired data LogToDiskMode Specify whether data device object information and hardware information is saved to one disk file or to multiple disk files Y ou can initiate logging by settingLoggingMode toDisk orDisk amp Memory A new log file is created each time you issue thest art function and each different analog input object must log information to a separate log file Writing to disk is performed as soon as possible after the curren
302. nd trigger condition value e The number of times to repeat the trigger e A trigger delay e An action function to execute when the trigger event occurs Properties associated with analog input triggers are given below Table 5 6 Analog Input Trigger Properties Property Name Description InitialTriggerTime Indicate the absolute time of the first trigger Manual Trigger HwOn Specify that the hardware device starts when a manual trigger is issued TriggerAction Specify the M file action function to execute when a trigger occurs Configuring Analog Input Triggers Table 5 6 Analog Input Trigger Properties Continued Property Name Description rigger Channel riggerCondition riggerCondition Value riggerDelay riggerDelayUnits riggerRepeat riggersExecuted riggerType Specify the channels serving as trigger sources Specify the condition that must be satisfied before a trigger executes Specify one or more voltage values that must be satisfied before a trigger executes Specify the delay value for data logging Specify the units in which trigger delay data is measured Specify the number of additional times the trigger executes Indicate the number of triggers that execute Specify the type of trigger to execute Except for Tri gger Acti on thesetrigger related properties are discussed in the following sections Tri gger Acti on is discussed in Configuring Events and
303. nected to the output IfSourceQut put iSCALOUT the source output is connected to the module s internal CALOUT line This allows the module s CALOUT line to be driven by an external signal applied at the source output connector IfSourceOut put isSRC amp CALOUT the source output is connected to the module s internal CALOUT line and the source D A converter is also connected to the CALOUT line This is a combination of theGr ounded andCALOUT values and is useful for multi mainframe calibration Vendor Agilent Technologies Usage AO Channel Access Read write Data Type String Read only Yes while Running 11 19 SourceOutput Values 11 20 Nor mal Grounded Open CALOUT SRC amp CAL OUT Normal source output The source output connector remains grounded while the source D A converter is internally connected to the CALOUT linein the module The source remains open circuited even when the source is started The source output is connected to the module s internal CALOUT line The source output connector remains grounded while the source D A converter is internally connected to the CALOUT linein the module The source output is also connected to the module s internal CALOUT line Span Purpose Description Specify the measurement bandwidth in Hz For an input channel span specifies the maximum frequency at which valid alias protected data is received Frequencies above this value are filtered
304. ng Events and Actions Event Types Recording and Retrieving Event Information Examples Using Action Properties and Action F unctions Linearly Scaling the Data E ngineering Units Example Performing a Linear Conversion Starting Multiple Device Objects 6 2 6 3 6 4 6 6 6 10 6 14 6 17 67 6 19 6 21 6 22 6 81 6 34 6 35 6 37 6 Analog O utput 6 2 Overview Analog output subsystems convert digital data stored on your computer to a real world analog signal These devices perform the inverse conversion of analog input subsystems Typical plug in acquisition boards offer two output channels with 12 bits of resolution with special hardware available to support multiple channel analog output operations The Data Acquisition Toolbox provides access to analog output subsystems through an analog output object The purpose of this chapter is to show you how to perform data acquisition tasks using your analog output hardware Topics include e Getting started with analog output e Managing output data e Configuring analog output triggers e Configuring events and actions e Linearly scaling the data e Starting multiple device objects G etting Started with Analog O utput Getting Started with Analog Output The purpose of this section is to show you how to use the Data Acquisition Toolbox to perform basic tasks with your analog output AO hardware This is accomplished by describing
305. ng and Loading the Session 8 12 Plot the data and label the figure axes subplot 211 plot data xlabel Samples ylabel Signal Volts subplot 212 plot time data xlabel Time seconds ylabel Signal Volts Alternatively you can retrieve data for the second sound card channel by specifying the channel name data time daqread file00 daq Samples 1000 2000 Channels Right Retrieving Data Based on Triggers Y ou can retrieve data based on triggers using theTri ggers property To retrieve all the data associated with the second and third triggers for both sound card channels data time dagread file00 daq Triggers 2 3 Plot the data and label the figure axes subplot 211 plot data xlabel Samples ylabel Signal Volts subplot 212 plot time data xlabel Time seconds ylabel Signal Volts Retrieving Data Based on Time Y ou can retrieve data based on time using theTi me property Ti me must be specified in seconds and Ti me 0 corresponds to the first logged sample To retrieve the first 25 of the data acquired for the first trigger data time daqread file00 daq Time 0 0 5 Plot the data and label the figure axes subplot 211 plot data xlabel Samples ylabel Signal Volts subplot 212 plot time data xlabel Time seconds ylabel Signal Volts Logging Information to Disk Retrieving Event Object Chann
306. ng means the data queued in the engine is being output to an analog output subsystem The sending state is indicated by theSendi ng property Sendi ng can beOn or Off Running Logging andSendi ng areread only properties that are automatically set toOn or Of f bytheengine When Runni ng isOf f Logging andSendi ng must be off When Running isOn Logging andSendi ng are set to0n only when a trigger occurs Note Digital I O objects also possess a running state However since they do not store data in the engine the logging and sending states do not exist Acquiring and O utputting Data Starting the Device Object Y ou start a device object with thest art function For example to start the analog input object ai al analoginput winsound addchannel ai 1 2 start ai After start isissued theRunni ng property is automatically set to0n and both the device object and hardware device execute according to the configured and default property values While you are acquiring data with an analog input object you can preview the data with thepeekdata function peekdata takes a snapshot of the most recent data but does not remove data fromthe engine For example to preview the most recent 500 samples acquired by each channel contained by ai data peekdata ai 500 Since previewing data is usually a low priority task peekdat a does not guarantee that all requested data is returned You can preview data at any time whi
307. nge When sensor data is digitized by an A D converter you must be aware of these two issues e The expected range of the data produced by your sensor This range depends on the physical phenomena you are measuring and the output range of the sensor e The range of your A D converter For many devices the hardware range is specified by the gain and polarity M aking Q uality M easurements You should select the sensor and hardware ranges such that the maximum precision is obtained and the full dynamic range of the input signal is covered For example suppose you are using a microphone with a dynamic range of 20 dB to140dB and an output sensitivity of 50 mV Pa If you are measuring street noise in your application then you might expect that the sound level never exceeds 80 dB which corresponds to a sound pressure magnitude of 200 mPa and a voltage output from the microphone of 10 mV Under these conditions you should set the input range of your data acquisition card for a maximum signal amplitude of 10 mV or a little more How Fast Should a Signal be Sampled Whenever a continuous signal is sampled some information is lost The key objective is to sample at a rate such that the signal of interest is well characterized and the amount of information lost is minimized If you sample at a rate that is too slow then the signal is undersampled and aliasing can occur Aliasing can occur for both rapidly varying signals and slowly v
308. nipolar Bipolar Unipolar The Analog Input Subsystem In many cases thesignal polarity is a fixed characteristic of the sensor and you must configure the input range to match this polarity As you can see it is crucial to understand the range of signals expected from your sensor so that you can configure the input range of the analog input subsystem to maximize resolution and minimize the chance of an overrange condition How Are Acquired Samples Clocked Samples are acquired from an analog input subsystem at a specific rate by a clock Like any timing system data acquisition clocks are characterized their resolution and accuracy Timing resolution is defined as the smallest time interval that you can accurately measure The timing accuracy is affected by clock jitter J itter arises when a clock produces slightly different values for a given time interval For any data acquisition system there are typically three clock sources that you can use the onboard data acquisition clock the computer clock or an external clock The Data Acquisition Toolbox supports all of these clock sources depending on the requirements of your hardware The Onboard Clock The onboard clock is typically a timer chip on the hardware board that is programmed to generate a pulse stream at the desired rate The onboard clock generally has high accuracy and low jitter compared to the computer clock You should always use the onboard clock when the sampling
309. nnel Ds to different indices using HwChannel Usage Al AO Channel Access Read write Data type Double Read only Yes when running Values are automatically defined when channels are added to the device object with theaddchannel function The default value is one Createthe analog input object ai for a National Instruments board and add the first three hardware channels to it al analoginput nidaq 1 addchannel ai 0 2 10 31 Hw Channel See Also 10 32 Based on the current configuration the hardware channels are scanned in order from 0 to 2 To swap the scan order of channels 0 and 1 you can assign these channels to the appropriate indices using HwChannel ai Channel 1 HwChannel 1 ai Channel 2 HwChannel 0 Functions addchannel Properties Channel I ndex Hw Line Purpose Description Characteristics Values Example See Also Specify the hardware line ID All lines contained by a digital O object havea hardware ID and an associated MATLAB index The hardware ID is given by HwLi ne and the MATLAB index is given by the ndex property TheHwLi ne value is defined when hardware lines are added to a digital I O object with theadd i ne function The beginning line ID value depends on the hardware device For National Instruments hardware line Ds are zero based begin at zero Usage DIO Line Access Read write Data type Double Read only Yes when running Values
310. nnel Access Read write Data Type Double Read only Yes while Running Values Y ou can set RampRat e to any value between O and 100 seconds 11 17 SourceMode Purpose Specify the source mode Description If SourceMode is set toArbitrary the host program must provide the data to use for the arbitrary source signal Note that there is no Of f source mode To turn a source channel off you must make it inactive When the source is inactive it is normally low impedance to ground To make the source high impedance set theSourceQut put property to Open Characteristics Vendor Usage Access Data Type Read only while Running Values Arbitrary See Also Properties SourceQut put 11 18 Agilent Technologies AO Channel Read write String Yes An arbitrary source signal SourceOutput Purpose Description Characteristics Specify the source output SourceQutput can be Normal Grounded Open CALOUT or SRC amp CALOUT IfSourceQut put isNor mal the normal source output is used This output is defined by the source mode and other source parameters IfSourceOut put iSGrounded the source output connector remains grounded while the source D A converter is internally connected to the CALOUT linein the module IfSourceQut put iS Open the source remains open circuited even when the source is started The impedance on the output is only about 1 kilohm because the power fail decay circuit is still con
311. nnel index removes the specified channels contained by obj from the MATLAB workspace but not from the data acquisition engine clear obj Line index removes the specified lines contained by obj fromthe MATLAB workspace but not from the data acquisition engine Clearing device objects channels and lines follows these rules e clear does not remove device objects channels or lines from the data acquisition engine Use the de et e function for this purpose e f multiple references to a device object exist in the workspace clearing one reference will not invalidate the remaining references e You can restore cleared device objects to the MATLAB workspace with the dagfi nd function If you use thehel p command to display the M file help for cl ear then you must supply the pathname shown below help daq private clear 9 25 clear Example See Also 9 26 Create the analog input object ai copy ai to anew variableai copy and then clear the original device object from the MATLAB workspace al analoginput winsound ch addchannel ai 1 2 aicopy al clear al Retrieveai fromthe engine with daqfi nd anddemonstratethat ai is identical toai copy ainew daqfind isequal aicopy ai new ans 1 Functions daqfind delete daqaction Purpose Syntax Arguments Description Remarks Example See Also An action function that displays event information for the specified event dagact
312. nnel SkewMode are configurable only for scanning hardware and not for simultaneous sample and hold SS H hardware For SS H hardware Channel SkewMode can only beNone andChannel Skew can only be 0 The values for Channel SkewMode are given below Table 5 4 ChannelSkew Mode Property Values ChannelSkewMode Value Description None Equi sample Manual Minimum No channel skew is defined This is the only valid value for simultaneous sample and hold SS H hardware The channel skew is automatically calculated as sampling rate number of channels The channel skew must be set with the Channel Skew property The channel skew is given by the smallest value supported by the hardware If Channel SkewMode iSMi ni mumorEqui sampl e then Channel Skew indicates the appropriate read only value If Channel SkewMode iS set toManual you must specify the channel skew with Channel Skew 5 8 Managing Acquired Data Managing Acquired Data At the core of any analog input application lies the data you acquire from a sensor and input into your computer for subsequent analysis The role of the analog input subsystem is to convert analog data to digitized data that can be read by the computer There are two ways to manage acquired data e Preview the data with thepeekdat a function e Extract the data from the engine with the get dat a function After data is extracted from the engine you can analyze it save i
313. nning 1 17 setting up 1 4 simultaneous sample and hold 1 19 supported vendors 2 7 hardware D channel 4 4 device board 4 3 line 7 4 mapping to channels 3 9 port 7 4 hardware triggers Al object 5 37 AO object 6 25 help 2 20 holding the last output value 11 16 HP E1432 driver A 9 HwChannel Al object 4 5 AO object 6 5 HwLine 7 5 channel 4 4 HwChannel 4 6 device board 4 3 line 7 4 HwLine 7 8 mapping to channels 3 9 port 7 4 immediate trigger Al object 5 23 AO object 6 22 Index Al object 4 5 AO object 6 5 DIO object 7 5 indexing channel array 4 6 line array 7 8 initializing the hardware 9 44 InitialTriggerTime 5 19 input overrange event 5 47 input range 1 22 engineering units 5 57 InputOverRangeAction 5 47 InputType 5 4 InstaCal A 6 hardware configuration 2 17 Index internal clock 1 23 interrupts 1 27 NI hardware 11 25 invalid device object 3 7 ischannel 9 63 isdioline 9 64 isnan 5 35 isvalid 9 65 J jitter 1 23 L least significant bit DIO 7 8 Line 7 8 line group 7 4 line names 7 9 line object 7 4 line properties 3 12 line configurable device 7 6 LineName 7 9 lines 3 8 adding 7 4 descriptive names 7 8 referencing 7 8 load 8 5 loading device objects MAT file 8 5 M file 8 4 LogFileName 8 7 Logging 5 20 logging data to memory 3 22 information to disk Al 8 6 file name specification 8 7 multiple files 8 7 retrieving data with daqr ead 8 8 LoggingMode 8 7 LogToDi skMode
314. nning is automatically set to 0n When the trigger executes Logging is automatically set to0n and Sampl esAcquired keeps a running count of the total number of samples per channel that have been logged to the engine or a disk file Sampl esAvail abl e tells you how many samples per channel are available to be extracted from the engine with the getdata function Evaluating the Analog Input O bject Status When the requested number of samples are acquired Sampl esAcquired reflects this number and both Running and Loggi ng are automatically set to Of f When you extract all the samples from the engine Sampl esAvail able isO The Display Summary You can invoke the display summary by typing the analog input object at the command line The displayed information reflects many of the basic setup properties described in Configuring Analog Input Properties on page 4 9 and is designed so you can quickly evaluate the status of your data acquisition session The display is divided into two main sections general summary information and channel summary information General Summary Information Thegeneral display summary includes the device object type and the hardware device name followed by this information e Acquisition parameters Thesampling rate Thenumber of samples to acquire per trigger Theacquisition duration for each trigger The destination for logged data e Trigger parameters Thetrigger type Thenumber of triggers inc
315. nput of the instrumentation amplifier ComputerBoards Differential Channels are configured for differential input SingleEnded Channels are configured for single ended input 10 41 InputType Agilent Technologies Differential Channels are configured for differential input Sound Cards AC Coupled The input is coupled so that constant DC signal levels are suppressed 10 42 Line Purpose Description Characteristics Values Example See Also Contain hardware lines added to the device object Line isavector of all the hardwarelines contained by a digital 1 O DIO object Since a newly created DIO object does not contain hardware lines Li ne is initially an empty vector The size of Li ne increases as lines are added with the addline function and decreases as lines are removed with thede et e function Y ou can useLi ne toreference one or more individual lines To reference a line you must know ts MATLAB index and hardware ID The MATLAB index is given by the ndex property while the hardware ID is given by the HwLine property Usage DIO Common Access Read write Data type Vector of lines Read only Yes when running Values are automatically defined when lines are added tothe DIO object with theaddl ine function The default value is an empty column vector Create the digital 1 O object di o and add four input lines to it dio digitalio nidaq 1 addline dio 0 3 In To set a p
316. o a value that differs from the value you specify you should return the actual sampling rate using theget function or the device object display summary Alternatively you can usethes et veri f y function which sets theSamp eRat e value and then returns the actual value that is set Tofind out the range of sampling rates supported by your board use thepr opi nfo function Additionally since the actual sampling rate depends on the number of channels contained by the device object and the Channel Skew property value Al only Sampl eRat e should bethe last property you set before starting the device object Usage Al AO Common Access Read write Data type Double Read onl y Yes when running The default value is obtained from the hardware driver SampleRate Example Create the analog input object ai for a sound card and add two channels to it al analoginput winsound addchannel ai 1 2 Y ou can find out the range of valid sampling rates with theConstraintVal ue field of the propi nf o function rates propinfo ai Sampl eRate rates ConstraintValue ans 8000 48000 To configure the per channel sampling rate to 48 kHz set ai SampleRate 48000 Alternatively you can use thes et veri fy function to configure and return the Sampl eRate value Actual Rate setverify ai SampleRate 48000 See Also Functions propinfo setverify Properties Channel Skew 10 65 SamplesAcquired Purpose D
317. o analog input devices through an analog input object The purpose of this chapter is to show you how to perform simple analog input tasks using just a few functions and properties After reading this chapter you should be able to use the Data Acquisition Toolbox to configure your own analog input session Topics include e Creating an analog input object e Adding channels to an analog input object e Configuring analog input properties e Acquiring data e Analog input examples e Evaluating the analog input object status Creating an Analog Input O bject Creating an Analog Input Object Y ou create an analog input object with theanal ogi nput function anal ogi nput accepts the adaptor name and the hardware device D as input arguments F or a list of supported adaptors refer to The Hardware Driver Adaptor on page 2 7 The device ID refers tothe number associated with your board when it is installed Some vendors refer to the device D as the device number or the board number The device ID is optional for sound cards with an ID of 0 Use thedaqhwi nf o function to determine the available adaptors and device IDs Each analog input object is associated with one board and one analog input subsystem F or example to create an analog input object associated with a National Instruments board with deviceID 1 al analoginput nidaq 1 The analog input object ai now exists in the MATLAB workspace Y ou can display the class of
318. o queue data unless Repeat Out put iS greater than 0 e You can queue data in the engine until the value specified by the MaxSampl es Queued property is reached or the limitations of your hardware or computer are reached For moreinformation about put data refer toits reference pages in Chapter 9 Function Reference Rules for Queuing Data Data to be queued in the engine follows these rules e Data is output as soon as a trigger occurs e Anerror is returned if aNaN is included in the data stream 6 18 Managing O utput Data e You can use the native data type of the hardware Note that MATLAB supports math operations only for the double data type Therefore to use math functions on native data you must convert t to doubles e f the data is not within the range of the Uni ts Range property then itis clipped to the maximum or minimum value specified by Uni ts Range Refer to Linearly Scaling the Data Engineering Units on page 6 34 for more information about clipping Example Queuing Data with putdata This example illustrates how you can useput dat a to queue 8000 samples and then output the data a total of five times using the Repeat Out put property You can run this example by typing daqdoc6_3 at the MATLAB command line 1 Create a device object Createthe analog output object A0 for a sound card The installed adaptors and hardware Ds are found with daghwi nfo AO analogoutput winsound
319. o queue data unless Repeat Out put is greater than 0 e You can queue data in the engine until the value specified by the MaxSampl esQueued property is reached or the limitations of your hardware or computer are reached More About O utputting Data e Data is output as soon as a trigger occurs e An error is returned if aNaN is included in the data stream e You can specify dat a as the native data type of the hardware Note that MATLAB supports math operations only for the double data type Therefore to use math functions on native data you must convert it to doubles e f the output data is not within the range specified by the Out put Range property then the data is clipped putdata Example See Also e TheSampl esOutput property keeps a running count of the total number of samples that have been output per channel e TheSamp esAvail able property tells you how many samples are ready to be output from the engine per channel After data is output SamplesAvailable is automatically reduced by the number of samples sent to the hardware Create the analog output object ao for a National Instruments board add two output channels to it and generate 10 seconds of data to be output ao analogoutput nidaq 1 ch addchannel ao 0 1 set ao SampleRate 1000 data linspace 0 1 10000 Before you can output dat a it must be queued in the engine using put data putdata ao data data start ao Functions put
320. o_trig Example function generator Output data tothe specified adaptor Output data from HANDEL MAT to a sound card Introduction to analog output channels Introduction to analog output objects Demonstrate the use of immediate and manual triggers 2 15 2 G etting Started with the Data Acquisition Toolbox Digital I O Demos The digital O demos are listed below Demo Name Description demodio_intro Introduction to digital I O objects demodio_line Introduction to digital 1 O lines diopanel Example panel for transferring values between MATLAB and a digital I O subsystem 2 16 Examining Your Hardware Resources Examining Your Hardware Resources Y ou can examine the data acquisition hardware resources visible to the tool box with thedaghwi nf o function Hardware resources include installed boards hardware drivers and adaptors The information returned by daqhwi nf o depends on the supplied arguments and is divided into these three categories e General toolbox information e Adaptor specific information e Device object information If you configure hardware parameters using a vendor tool such as National Instruments Measurement and Automation Explorer or ComputerBoards InstaCal then daghwi nfo will return this configuration information For example if you configure your ComputerBoards device for 16 single ended channels using InstaCal then daqhwi nf o returns this hardware configuration
321. og Input Action Properties Event Type Property Name Data missed Input overrange Run time error Samples acquired Start Stop Timer Trigger DataMissedAction InputOverRangeAction RuntimeErrorAction Sampl esAcquiredAction SamplesAcquiredActionCount StartAction StopAction Ti merAction Ti merPeriod TriggerAction Configuring Events and Actions Data Missed Event A data missed event is generated immediately after acquired data is missed In most cases data is missed because e The engine cannot keep up with the rate of acquisition e The driver wrote new data into the hardware s FIFO buffer before the previously acquired data was read You can usually avoid this problem by increasing the size of the memory block with the Buf feringConfig property This event executes the action function specified for the Dat aMi ssedAction property The default value for Dat aMissedAction iSdagaction which displays the event type and the device object name When a data missed event occurs the analog input object is automatically stopped Input O verrange Event An input overrange event is generated immediately after an overrange condition is detected for any channel group member An overrange condition occurs when an input signal exceeds the range specified by thel nput Range property This event executes the action function specified for the Input Over RangeAction property Overrange detection is enabled only when a
322. oit al analoginput winsound ch addchannel ai 1 The trigger executes when a signal with a negative slope passing through 0 2 volts is detected on channel 1 set ai TriggerChannel ch set ai TriggerType Software set ai TriggerCondition Falling set ai TriggerConditionValue 0 2 Properties TriggerCondition TriggerType 10 89 TriggerDelay Purpose Description Characteristics Values Example See Also 10 90 Specify the delay value for data logging You can define both pretriggers and postriggers Pretriggers are specified with a negativeTrigger Delay value while postriggers are specified with a positive Tri ggerDel ay value You can delay a trigger in units of time or samples with theTriggerDelayUnits property Pretriggers are not defined for hardware triggers or whenTriggerType isl mmediate Pretrigger samples are included as part of the total samples acquired per trigger as specified by the Sampl esPerTrigger property If sampletime pairs are returned to the workspace with the get dat a function then the pretrigger samples are identified with negative time values Usage Al Common Access Read write Data type Double Read only Yes when running The default value is zero Create the analog input object ai and add one channel toit al analoginput winsound ch addchannel ai 1 Configureai to acquire 44 100 samples per trigger with 11 025 samples 0 25 seconds acquired as
323. olbox Installation 0 000 c eee eee xxii Hardware and Driver Installation o xxii Typographical Conventions xxiii Introduction to Data Acquisition 1 Overview nasema dC A E 1 2 Anatomy of a Data Acquisition Experiment 1 3 The Data Acquisition System oococccccoo o 1 4 Data Acquisition Hardware 00 cee eee eee 1 6 SENSORS i iG eee eS eb ad SKA eke a a Paes 1 8 Signal Conditioning 0 06 cee ee 1 11 The Computer s siewi edad whee det waded ome kee 1 13 Contents SoftWare wie a Be Ae a bd ek ORE a Rabie has 1 13 The Analog Input Subsystem 4 1 16 Sampling s Luis oe edad alata sees beer cee d 1 16 Quantization 0 0 tees 1 20 Channel Configuration 0 000 cece eee 1 24 Transferring Data from Hardware to System Memory 1 27 Making Quality Measurements 1 29 Accuracy and Precision 000 cece tees 1 29 NOISE souran an po Shee ool Phe da ety chews 1 33 Matching the Sensor Range and A D Converter Range 1 34 How Fast Should a Signal be Sampled 1 35 Selected Bibliography 0000 cee eaee 1 39 Getting Started with the Data Acquisition Toolbox 2 Toolbox Components 0 000 cece ene as 2 2 M File Functions 00 00 c eect eee 2 3 The Data Acquisition Engine 0 00 cece ee
324. olbox demos by typing help daqdemos All documentation example M files begin with da qdoc Torun an example type the M file name at the command line Note that most examples are written for specific hardware devices To use these examples with your hardware device you should modify the creation function input arguments and the device object property values as needed How This Guide is Organized The organization of this guide is described below Chapter Description Introduction to Data Provides you with general information about Acquisition making measurements with data acquisition hardware The topics covered should help you understand the specification sheet associated with your hardware Getting Started with Describes the toolbox components and shows you the Data Acquisition how to access your hardware examine your Tool box hardware resources and get command line help TheDataAcquisition Describes all the steps you are likely to take when Session acquiring or outputting data Getting Started with Shows you how to perform basic data acquisition Analog Input tasks using your analog input subsystem Using This Guide Chapter Description Doing More with Analog Input Analog Output Digital Input Output Saving and Loading the Session Function Reference Base Property Reference Device Specific Property Reference Troubleshooting Your Hardware Managing Your Memory Resources Glossa
325. omputer can read The conversion from an infinitely precise amplitude toa binary number is called quantization During quantization the A D converter uses a finite number of evenly spaced values to represent the analog signal The number of different values is determined by the number of bits used for the conversion Most modern converters use 12 or 16 bits Typically the converter selects the digital value that is closest to the actual sampled value The figure below shows a 1 Hz sine wave quantized by a 3 bit A D converter ESS ji Amplitude w T 0 1 j n f 1 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 Time sec The Analog Input Subsystem The number of quantized values is given by 23 8 the largest representable value is given by 111 2 21 20 7 0 and the smallest representable value is given by 000 0 0 Quantization Error There is always some error associated with the quantization of a continuous signal Ideally the maximum quantization error is 0 5 least significant bits LSBs and over the full input range the average quantization error is zero As shown below the quantization error for the previous sine wave is calculated by subtracting the actual signal from the quantized signal 0 55 AANA ALLL NM PIN AMAN Quantization error bits 15 f 1 1 1 1 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0
326. on the data MATLAB and the Data Acquisition Toolbox provide you with these capabilities and more 1 15 1 Introduction to Data Acquisition 1 16 The Analog Input Subsystem Many data acquisition hardware devices contain one or more subsystems that convert digitize real world sensor signals into numbers your computer can read Such devices are called analog input subsystems Al subsystems A D converters or ADCs After the real world signal is digitized you can analyze it store it in system memory or store it toa disk file The function of the analog input subsystem is to sample and quantize the analog signal using one or more channels You can think of a channel as a path through which the sensor signal travels Typical analog input subsystems have eight or 16 input channels available to you After data is sampled and quantized it must be transferred to system memory Analog signals are continuous in time and in amplitude within predefined limits Sampling takes a snapshot of the signal at discrete times while quantization divides the voltage or current value into discrete amplitudes Sampling quantization channel configuration and transferring data from hardware to system memory are discussed below Sampling Sampling takes a snapshot of the sensor signal at discrete times For most applications the time interval between samples is kept constant for example sample every millisecond unless externally
327. onger associated with any hardware and should be cleared from the workspace with thec ear function Typically you usei svali d directly only when you are creating your own M files Create the analog input object ai for a National Instruments board and add eight channels to it al analoginput nidaq 1 ch addchannel ai 0 7 To verify the device object is valid isvalid ai ans 1 9 65 isvalid See Also 9 66 To verify the channels are valid isvalid ch ans 1 1 1 1 1 1 1 1 If you delete a channel then i sval i d returns a logical O in the appropriate location del ete ai Channel 3 isvalid ch ans 1 1 0 1 1 1 1 1 Typically you will usei svalid directly only when you are creating your own M files Suppose you create the function myf unc for use with the Data Acquisition Toolbox If my f unc is passed the previously defined device object a i as an input argument myf unc ai the first thing you should do in the function is check if ai is a valid device object function myfunc obj Determine if an invalid handle was passed if isvalid obj error Invalid data acquisition object passed end You can examine the Data Acquisition Toolbox M files for examples that use isvalid Functions clear delete ischannel isdioline length Purpose Syntax Arguments Description Example Return the length of a device object channel group or line group out length obj
328. operty Reference or Chapter 11 Device Specific Property Reference to find the default value for any property daqpropedit A Graphical Property Editor Thetoolbox provides the Data Acquisition Property Editor which is a graphical user interface GUI for accessing properties You launch the property editor with thedaqpropedit function The GUI is designed so that you can e List all existing device objects as well as the channels or lines they contain e Configure property values e Display the names and current values for configurable properties e Display property characteristics e Display property help For example to configure property values for the analog input object ai using daqpropedit al analoginput winsound addchannel ai 1 2 daqpropedit ai Configuring and Returning Properties The Data Acquisition Property Editor is shown below Data Acquisition Property Editor olx Eile Options Help Listof device objects channels and lines Ed BitsPerS ample 16 Property to configure and its current value Buffering onfig 512 30 Bufferingllode Auto R eae ESE List of configurable properties ChammelSkewllode None ClockSource Internal and their current values DatallissedAction dagqaction EventLoy Type double Default Value 16 Constraint Bounded Constraint Value 816 Read On opi FeadOnywhen Pratap Property characteristics D
329. opinfo obj PropertyName A device object channels or lines A validobj property name A structure whose field names are the property names for obj ifPropertyName is not specified returns the structureout whose field names are the property names for obj Each property namein out contains the fields shown below Field Name Description Type The property data type Possible values areacti on function any double andstring Constraint The type of constraint on the property value Possible ConstraintValue DefaultValue ReadOnly ReadOnl yRunni ng DeviceSpecific values areaction function bounded enum andnone The property value constraint The constraint can be a range of valid values or a list of valid string values The property default value If the property is read only a 1 is returned Otherwise a 0 is returned If the property is read only while the device object is running a 1 is returned Otherwise a O is returned If the property is device specific a 1 is returned Ifa 0 is returned the property is supported for all device objects of a given type propinfo Example See Also out propinfo obj PropertyName returns the structureout for the property specified by PropertyName IfPropertyName sa cell array of strings a cell array of structures is returned for each property Create the analog input object ai for a sound card and configure it to operate in stereo mode
330. or Newtons that you may want to apply to your data The properties associated with engineering units and linearly scaling output data are given below Table 6 11 Analog Output Engineering Units Properties Property Name Description Out put Range Specify the range of the analog output hardware subsystem Units Specify the engineering units label UnitsRange Specify the range of data as engineering units For many devices the output range is expressed in terms of the gain and polarity Note You can set the engineering units properties on a per channel basis Therefore you can configure different engineering unit conversions for each hardware channel Linearly scaled output data is given by the formula scaled value original value output range units range Theunits range is given by the Unit sRange property while the output rangeis given by the Out put Range property Uni ts Range controls the scaling of data when it is queued in the engine with the put dat a function Out put Range specifies the gain and polarity of your D A subsystem You should choose an output range that encompasses the output signal and that utilizes the maximum dynamic range of your hardware 6 34 linearly Scaling the Data Engineering Units For sound cards you may have to adjust the volume control to obtain the full scale output range of the device Refer to Troubleshooting Sound Cards on page A 12 to learn how to access t
331. or Sampl esPer Trigger property is set toi nf For analog output objects st op must be used when theRepeat Out put property is set toi nf When stop is issued for either of these device objects e TheRunning property is set toOff e TheLogging property or Sending property is set to Off e The M file action function specified for St opActi on is executed e The stop event is recorded in theEvent Log property For any device object you can specify st op as the value for an action property ao TimerAction stop Note Issuingstop is the only way to stop an executing digital O object You typically execute a digital O object to periodically update and display its state Refer to the di opanel demo for an example 9 95 stop See Also Functions start trigger Properties EventLog Logging Repeat Out put Running SamplesPerTrigger Sending Timeout TriggerRepeat 9 96 trigger Purpose Syntax Arguments Description Remarks See Also Manually execute a trigger trigger obj obj An analog input or analog output object or an array of these device objects trigger obj manually executes a trigger After trigger is issued e The absolute time of the trigger event is recorded by the Initial TriggerTi me property e TheLogging property or Sending property is set to0n e The M file action function specified by Tri gger Acti on is executed e The trigger event is recorded in theEvent Log property
332. or a cell array of field names out is an m by n cell array where mis the length of obj and n is the length ofFi el dName You can return a list of valid field names with thedaqhwi nf o obj syntax daqhwinfo To display all installed adaptors out daghwinfo out I nstalledAdaptors ans heb hpel432 nidag winsound To display the device object constructor names for all installed wi ns ound devices out daghwinfo winsound out Obj ect ConstructorName ans analoginput winsound 0 analogoutput winsound 0 Create the analog input object ai for a sound card To display theinput ranges for ai al analoginput winsound out daqhwinfo ai out InputRanges ans 1 1 To display the minimum and maximum sampling rates for ai out daghwinfo ai MinSampleRate MaxSampl eRate out 8000 44100 9 33 daqmem Purpose Syntax Arguments Description 9 34 Allocate or display memory resources out daqmem out daqmem obj daqmem obj max mem obj A device object or array of device objects ma x me m The amount of memory to allocate out A structure containing information about memory resources out daqmem returns the structure out which contains several fields describing the memory resources associated with your platform and the Data Acquisition Toolbox The fields are described below Field Description MemoryLoad Total P
333. or the hardware device with device identifier D 1 D can be specified as an integer or a string More About Creating Analog Output O bjects e When an analog output object is created it does not contain any hardware channels To execute the device object hardware channels must be added with theaddchannel function e You can create multiple analog output objects that are associated with a single analog output subsystem H owever you can typically execute only one of them at a time e The analog output object exists in the data acquisition engine and in the MATLAB workspace If you create a copy of the device object it references the original device object in the engine e If D is a numeric value then you can specify it as an integer or a string If D contains any non numeric characters then you must specify it as a string see the Agilent Technologies example below e TheName property is automatically assigned a descriptive name that is produced by concatenating adaptor D and A0 You can change this name at any time 9 21 analogoutput Example 9 22 More About the Hardware Device Identifier When data acquisition devices are installed they are assigned a unique number which identifies the device in software The device identifier is typically assigned automatically and can usually be manually changed using a vendor supplied device configuration utility National Instruments refers to this number as the device numb
334. ore information about RSE and NRSE connections The Analog Input Subsystem Transferring Data from Hardware to System Memory The transfer of acquired data from the hardware to system memory follows these steps 1 Acquired data is stored in the hardware s first in first out FIFO buffer 2 Dataistransferred from theF IFO buffer to system memory using interrupts or DMA These steps happen automatically Typically all that s required from you is some initial configuration of the hardware device when it is installed The FIFO Buffer The FIFO buffer is used to temporarily store acquired data The data is temporarily stored until it can be transferred to system memory The process of transferring data into and out of an analog input FIFO buffer is given below 1 TheFIFO buffer stores newly acquired samples at a constant sampling rate 2 Before the FIFO buffer is filled the software starts removing the samples For example an interrupt is generated when the FIFO is half full and signals the software to extract the samples as quickly as possible 3 Since servicing interrupts or programming the DMA controller can take up toa few milliseconds additional data is stored in the FIFO for future retrieval For a larger FIFO buffer longer latencies can be tolerated 4 Thesamples are transferred to system memory via the system bus for example PCI bus or AT bus After the samples are transferred the software is free to perform ot
335. orld analog input signals from a sensor into bits that can be read by your computer Perhaps the most important of all the subsystems commonly available they are typically multichannel devices offering 12 or 16 bits of resolution Analoginput subsystems arealsoreferred toas Al subsystems A D converters or ADCs Analog input subsystems are discussed in detail beginning in The Analog Input Subsystem on page 1 16 Analog Output Subsystems Analog output subsystems convert digital data stored on your computer toa real world analog signal These subsystems perform the inverse conversion of analog input subsystems Typical acquisition boards offer two output channels with 12 bits of resolution with special hardware available to support multiple channel analog output operations Analog output subsystems are also referred to as AO subsystems D A converters or DACs Digital Input O utput Subsystems Digital input output DIO subsystems are designed toinput and output digital values logic levels to and from hardware These values are typically handled either as single bits or lines or as a port which typically consists of eight lines While most popular data acquisition cards include some digital I O capability it is usually limited to simple operations and special dedicated hardware is often necessary for performing advanced digital O operations Counter Timer Subsystems Counter timer C T subsystems are used for event count
336. ory that can be allocated for o bj to the value specified by ma x me m More About Allocating and Displaying Memory Resources e For analog output objects da q me m obj maxmem controls the value of the MaxSampl esQueued property e f you manually configure the Buf f eri ngConfig property then this value supersedes the values specified by da q me m obj maxmem and the MaxSamplesQueued property Create the analog input object ai wi n for a sound card and the analog input object ai ni for a National Instruments board and add two channels to each device object aiwin analoginput winsound addchannel aiwin 1 2 aini analoginput nidag 1 addchannel aini 0 1 9 35 daqmem See Also 9 36 To display the total memory used by all existing device objects out daqmem out UsedDaq ans 69120 To configure the maximum memory used by ai wi n to 640 KB daqmem ai win 640000 To configure the maximum memory used by each device object with one call to daqmem daqmem aiwin aini 640000 480000 Properties BufferingConfig MaxSampl esQueued daqpropedit Purpose Syntax Arguments Description Remarks Example Invoke the property editor graphical user interface daqpropedit daqpropedit obj obj A device object daqpropedit obj invokes the property editor graphical user interface GUI for the device object obj The channels or lines contained by obj are displayed as wel
337. ound0 A0 Stop event occurred at 13 00 25 for the object winsound0 Al Digital Input Output Overview Creating a Digital 1 O Object Adding Lines to a Digital 1 O Object Line and Port Characteristics Referencing Individual Hardware Lines Writing and Reading aes I O Line Values Writing Digital Values ee Reading Digital Values Example Writing and Reading Digital Values Generating Timer Events Timer Events Starting and Stopping a Digital 1 0 Object Example Generating Timer Events Evaluating the Digital I O rae Status The Display Summary 7 Digital input O utput Overview Digital 1 O DIO subsystems are designed to input and output digital values to and from hardware These values are typically handled either as single bits or lines or as a port which typically consists of eight lines While most popular data acquisition boards include some digital I O capability it is usually limited tosimple operations and special dedicated hardwareis required for performing advanced digital I O operations The Data Acquisition Toolbox provides access to digital I O subsystems through a digital I O object Note The Data Acquisition Toolbox does not directly support buffered digital I O or handshaking latching However you can write your own M code to support this functionality Buffered digital O means that the data associated with a digital I O subsystem is stored in the engine Handshaking allows you
338. peating Triggers Y ou can configure triggers to occur once one shot acquisition or multiple times You control trigger repeats with theTrigger Repeat property If TriggerRepeat is set to its default value of O then the trigger occurs once If TriggerRepeat is set to a positive integer value then the trigger is repeated the specified number of times If Tri gger Repeat is set toi nf then the trigger repeats continuously and you can stop the device object only by issuing the stop function Configuring Analog Input Triggers Example Voice Activation and Repeating Triggers This example modifies daqdoc5_3 such that two triggers are issued The specified amount of data is acquired for each trigger and stored in separate variables TheTi meout value is set to five seconds Therefore if get dat a does not return the specified number of samples in the time given by the Ti me Out property plus the time required to acquire the data the acquisition will be aborted You can run this example by typing daqdoc5_5 at the MATLAB command line 1 Create a device object Create the analog input object Al Voi ce for a sound card The installed adaptors and hardware I Ds are found with daghwi nfo Al Voice analoginput winsound AI Voice analoginput nidaq 1 Al Voice analoginput cbi 1 2 Add channels Add one hardware channel toAl Voi ce chan addchannel Al Voice 1 chan addchannel AlVoice 0 For NI and CBI 3 Confi
339. play help for an existing device object For example to display help for theBitsPerSampl e property for an analog input object associated with a sound card al analoginput winsound out daghelp ai BitsPerSample G etting Help The propinfo Function You can usethepropinfo function to return the characteristics of Data Acquisition Toolbox properties F or example you can find the default value for any property using this function pr opi nfo returns a structure containing the fields shown below Table 2 2 propinfo Fields Field Name Description Type The property data type Possible values areacti on function any double andstring Constraint The type of constraint on the property value Possible ConstraintValue Default Value ReadOnl y ReadOnl yRunni ng DeviceSpecific values areaction function bounded enum andnone The property value constraint The constraint can be a range of valid values or a list of valid string values The property default value If the property is read only a 1 is returned Otherwise a0 is returned If the property is read only while the device object is running a 1 is returned Otherwise a0 is returned If the property is device specific a1 is returned If a0 is returned the property is supported for all device objects of a given type 2 21 2 G etting Started with the Data Acquisition Toolbox For example toreturn the characteristics for all the
340. plesOutputActionCount 6 28 SamplesPerTrigger 4 12 postrigger data 5 28 pretrigger data 5 27 sampling 1 16 sampling rate Al subsystem 5 6 AO subsystem 6 6 saturation 6 35 save 8 5 saving device objects MAT file 8 5 M file 8 3 information to disk Al 8 6 property values toa MAT file 8 3 scaling the data Al object 5 56 AO object 6 34 p p p p p p p p 1 11 Index 1 12 scanning hardware 1 17 channel order channels scan order 4 5 Sending 6 21 sending data 3 22 sensors 1 8 range 10 75 session 3 2 loading 8 3 saving 8 3 set configuring property values 3 18 returning property values 3 14 saving property values to an M file 8 3 settling time 1 31 setverify 410 showdaqevents 5 36 Al object 5 51 AO object 6 31 signal conditioning 1 11 simultaneous input and output 6 37 simultaneous sample and hold hardware 1 19 single ended inputs 1 25 single point acquisition 9 61 output 9 82 skew 5 7 software clock 1 23 CBI hardware 10 24 software trigger 5 23 sound cards channel configuration 5 5 device specific properties 11 5 mono mode 4 7 standard sample rates 11 23 stereo mode 4 8 troubleshooting A 12 start 3 23 start event Al object 5 48 AO object 6 28 StartAction Al object 5 48 AO object 6 28 starting multiple device objects 6 37 state logging 3 22 running 3 22 sending 3 22 status evaluation Al object 4 22 AO object 6 14 DIO object 7 18 stereo mode 4 8 stop 3 24 stop e
341. plot t2 d2 grid on xis t2 1 0 05 t2 end 0 05 0 8 0 8 abel Time sec ylabel Signal level Volts itle Voice Activation Second Trigger r gt D O0 gt sx wun 5 Clean up When you no longer need Al Voi ce you should remove it from memory and from the MATLAB workspace del ete Al Voi ce clear Al Voice Configuring Analog Input Triggers The data acquired for both triggers is shown below Voice Activation First Trigger o D T 0 4 o mM T 1 e io T Signal level Volts o T a P T 0 6 f aa 0 8 i 1 1 1 J Time sec Voice Activation Second Trigger T T o D T 0 4 o N T f o o oh T Signal level Volts o T La 1 2 wm 0 0 5 0 6 0 7 0 8 0 9 1 Time sec As described in Extracting Data from the Engine on page 5 13 if you do not specify the amount of data to extract from the engine with get dat a then the amount of data returned is given bytheSamplesPerTrigger property You can return data from multiple triggers with one call toget data by specifying the appropriate number of samples When you return data that spans multiple triggers a Na N is inserted in the data stream between trigger events Therefore an extra sample the NaN is stored in the engine and returned by get data Identifying these NaNs allows you to locate where and when each trigger was issued in the data stream
342. portval 1 1 1 0 1 0 0 0 To read the current values of the first four lines contained by di o and return the result to out lineval getvalue dio Line 1 5 lineval 1 1 1 0 1 Y ou can convert a binvec to a decimal value with thebi nvec2dec function For example to convert the binary vector i neval toa decimal value out binvec2dec lineval out 23 W riting and Reading Digital l O Line Values Rules for Reading Digital Values Reading values from digital I O lines follows these rules e f the digital O object contains lines from a port configurable device then all lines are read even if they are not contained by the device object However only values from the lines contained by the digital I O object are returned e You can always read from a line configured for output e For National Instruments hardware lines configured for input return a value of 1 by default e getvalue always returns a binary vector binvec To convert the binvec to a decimal value usethebinvec2dec function Example Writing and Reading Digital Values This example illustrates how to read and write digital values using a line configurable subsystem With line configurable subsystems you can transfer values on a line by line basis Y ou can run this example by typing daqdoc7_1 at the MATLAB command line 1 Create a device object Create the digital I O object di o for a National Instruments board The installed adaptors and hardwar
343. pretrigger data set ai SampleRate 44100 set ai TriggerType Manual set ai SamplesPerTrigger 44100 set ai TriggerDelay 0 25 Properties SamplesPerTrigger TriggerDelayUnits TriggerDelay Units Purpose Description Characteristics Values See Also Specify the units in which trigger delay data is measured TriggerDelayUnits canbeSeconds orSamples IfTriggerDel ayUnits is Seconds then data logging is delayed by the specified time for each channel group member If Tri ggerDel ayUnits isSampl es then data logging is delayed by the specified number of samples for each channel group member The trigger delay value is given by theTr i gger Delay property Usage Al Common Access Read write Data type String Read only Yes when running Seconds The trigger is delayed by the specified number of seconds Samples The trigger is delayed by the specified number of samples Properties Trigger Delay 10 91 TriggerRepeat Purpose Description Characteristics Values See Also 10 92 Specify the number of additional times the trigger executes Y ou can configure a trigger to occur once one shot acquisition or multiple times If Tri ggerRepeat is set toits default value of zero then the trigger executes once If Tri ggerRepeat iS set toa positive integer value then the trigger executes the specified number of times If Tri gger Repeat is set toi nf then the trigger executes continuously
344. properties associated with the analog input object ai created in the preceding section Alinfo propinfo ai The characteristics for theTri gger Type property are displayed below Alinfo TriggerType ans Type string Constraint Enum ConstraintValue 3x1 cell DefaultValue Immedi ate ReadOnly 0 ReadOnl yRunning 1 DeviceSpecific 0 This information tells you that e The property value data type is a string e The property value is constrained as an enumerated list of values e There are three possible property values e The default valueis mmedi ate e The property is not read only e You cannot configure the property while the device object is running e The property is supported for all analog input objects To display the property value constraints Alinfo TriggerType ConstraintValue ans Manual mmedi at e Software 2 22 The Data Acquisition Session Overview Example The Data Acquisition Session Creating a Device Object Creating an Array of Device Objects a Where Do Device Objects Exist Adding Channels or Lines Mapping Hardware Channel IDs to MATLAB ndices Configuring and Returning Properties Property Types alk Returning Property Names and Property Values Configuring Property Values Wc dep Specifying Property Names Default Property Values i daqpropedit A Graphical Property Editor Acquiring and Outputting Data Starting the Device Object
345. put data consists of these two independent steps 1 Data from MATLAB is queued in the engine 2 Data queued in the engine is output to the hardware These two steps are illustrated below MATLAB 1 Queue data into the engine Data Acquisition Toolbox Data acquisition engine Queued data 2 Output data to the hardware Hardware gt Actuators Toolbox Components The Hardware Driver Adaptor The hardware driver adaptor or just adaptor is the interface between the data acquisition engine and the hardware driver The adaptor s main purpose is to pass information between MATLAB and your hardware device via the driver Hardware drivers are provided by your device vendor For example if you are acquiring data using a National Instruments E Series board then the appropriate version of the NI DAQ driver must be installed on your platform Note that hardware drivers are not installed as part of the Data Acquisition Toolbox Thesupported vendors and the adaptor names used by the toolbox are listed below Table 2 1 Supported Vendors and Adaptor Names Vendor Adaptor Name National Instruments ni daq ComputerBoards cbi Agilent Technologies hpel432 Windows sound cards wi nsound Note You can use the Data Acquisition Toolbox Adaptor Kit to interface unsupported hardware devices to the toolbox Refe
346. r digital I O subsystem to input or output data after receiving a digital pulse The purpose of this chapter is to show you how to perform data acquisition tasks using your digital O hardware Topics include e Creating a digital I O object e Adding lines toa digital I O object e Writing and reading digital I O line values e Generating timer events e Evaluating the digital I O object status Creating a Digital l O O bject Creating a Digital I O Object You create a digital I O object with thedi gi tal io function di git ali o accepts the adaptor name and the hardware device ID as input arguments For a list of supported adaptors refer to The Hardware Driver Adaptor on page 2 7 The device ID refers to the number associated with your board when it is installed Some vendors refer to the device ID as the device number or the board number Usethedaqhwi nf o function todeterminethe available adaptors and device Ds Each digital I O object is associated with one board and one digital I O subsystem For example to create a digital O object associated with a National Instruments board with device D 1 dio digitalio nidaq 1 The digital I O object di o now exists in the MATLAB workspace You can display the class of di o with the whos command whos dio Name Size Bytes Class dio 1x1 1308 digitalio object Grand total is 40 elements using 1308 bytes Once the digital I O object is created the properties listed be
347. r Codes Stop 0 999 Data Mode Strip Chart Y Scale Mode Average Reading ne Sho ButoScale 0 099336 Cont nua C Full Range If the Test Panel does not provide you with the expected results for the subsystem under test and you are sure that your test setup is configured correctly then the problem is probably with the hardware To get support for your National Instruments hardware visit their Web site at http www natinst com A 5 A Troubleshooting Your Hardware Troubleshooting ComputerBoards Hardware If you are having trouble using the Data Acquisition Toolbox with a supported ComputerBoards Measurement Computing Corporation board the reason may be that e You are using a hardware driver that is incompatible with the toolbox e Your hardware is not functioning properly What Driver Are You Using The Data Acquisition Toolbox is compatible only with specific versions of the the Universal Library drivers or the associated release of the I nstaCal software and is not guaranteed to work with any other versions For a list of the driver versions that are compatible with the Data Acquisition Toolbox refer to the product page on the MathWorks Web site at ht tp www mathworks com products daq If you think your driver is incompatible with the Data Acquisition Toolbox then you should verify that your hardware is functioning properly before updating drivers If your hardware is functioning
348. r Condition value The output from this example is shown below Voice Activation 0 3 T T 0 2 0 17 Signal Level Volts L 0 005 0 01 0 015 0 02 0 025 Time sec The first logged sample has a signal level value of at least 0 2 volt and this value corresponds to time 0 Note that after you issue the get dat a function 87 200 samples remain in the engine Al Voice SamplesAvailable ans 87200 5 25 5 Doing More with Analog Input 5 26 Executing the Trigger For an analog input trigger to occur you must follow these steps 1 Configure the appropriate trigger properties 2 Issuethestart function 3 Issuethet rigger function if TriggerType valueis Manual Once the trigger occurs data logging is initiated The device object and hardware device stop executing when the requested samples are acquired a run time error occurs or you issue thes t op function Note After a trigger occurs the number of samples specified by SamplesPerTrigger iS acquired for each channel group member before the next trigger can occur Trigger Delays Trigger delays allow you to control exactly when data is logged after a trigger occurs You can log data either before the trigger or after the trigger Logging data before the trigger occurs is called pretriggering while logging data after a trigger occurs is called postriggering You configure trigger delays with theTri ggerDel ay property Pret
349. r an error occurs M File Functions To perform any task with your data acquisition application you must call M file functions from the MATLAB environment Among other things these functions allow you to e Create device objects which provide a gateway to your hardware s capabilities and allow you to control the behavior of your application e Acquire or output data e Configure property values e Evaluate your acquisition status and hardware resources For a listing of all Data Acquisition Toolbox functions refer to Chapter 9 Function Reference Y ou can also display all the toolbox functions by typing help daq 2 G etting Started with the Data Acquisition Toolbox The Data Acquisition Engine The data acquisition engine or just engine is a ME X file dynamic link library DLL file that e Stores the device objects and associated property values that control your data acquisition application e Controls the synchronization of events e Controls the storage of acquired or queued data While the engine performs these tasks you can use MATLAB for other tasks such as analyzing acquired data In other words the engine and MATLAB are asynchronous The relationship between acquiring data outputting data and data flow is described below The Flow of Acquired Data Acquiring data means that data is flowing from your hardware device into the data acquisition engine where it is temporarily stored in memory The data
350. r to the MathWorks Web site at htt p www mat hworks com products daq for more information about the adaptor kit As described in Examining Your Hardware Resources on page 2 17 you can list the supported adaptor names with the daqhwi nfo function For a list of vendor driver requirements and limitations refer to Data Acquisition Toolbox 2 0 in the Release Notes 2 G etting Started with the Data Acquisition Toolbox 2 8 Accessing Your Hardware Perhaps the most effective way to get started with the Data Acquisition Toolbox is to connect to your hardware and input or output data This section provides simple examples that show you how to e Acquire data from analog input channels e Output data to analog output channels e Read values from and write values to digital I O lines Each example illustrates a typical data acquisition session The data acquisition session comprises all the steps you are likely to take when acquiring or outputting data using a supported hardware device Y ou should keep these steps in mind when constructing your own data acquisition applications Notethat the analog input and analog output examples use a sound card while the digital O example uses a National Instruments PCI 6024E board If you are using a different supported hardware device you should modify the adaptor name and the device I D supplied to the creation function as needed If you want detailed information about any fu
351. rConditionValue 10 89 TriggerDel ay 10 90 TriggerDel ayUnits 10 91 TriggerRepeat 10 92 TriggersExecuted 10 93 TriggerType 10 94 Type 10 96 Units 10 97 UnitsRange 10 98 UserData 10 99 property characteristics 2 21 property types base 3 13 channel 3 12 Al object 10 7 AO object 10 11 common 3 12 Al object 10 3 AO object 10 8 DIO object 10 12 device specific 3 13 Agilent hardware 11 4 CBI hardware 11 4 NI hardware 11 3 sound cards 11 5 Index line 3 12 DIO object 10 13 property values configuring 3 18 default 3 19 graphical property editor 3 20 saving 8 3 specifying names 3 19 propinfo 2 21 putdata 6 17 putsample 9 82 putvalue 7 10 quantization 1 20 queuing data for output 6 17 maximum number of samples 10 51 Quick Reference Guide 2 13 R reading digital values 7 12 Readme 2 12 read only properties 2 21 registering your adaptor A 19 relative time 5 18 repeating triggers 5 30 Repeat Out put 6 18 resetting the hardware 9 44 retrieving data from a log file 8 8 returning property values dot notation 3 17 get 3 15 set 3 14 Running 3 23 running device objects 3 22 run time error event Al object 5 47 AO object 6 28 RuntimeErrorAction 10 62 Al object 5 47 AO object 6 28 S Sampl eRate 5 6 samples acquired event 5 47 samples output event 6 28 SamplesAcquired 5 15 SamplesAcquiredAction 5 47 SamplesAcquiredActionCount 5 47 SamplesAvailable 5 15 SamplesOutput 6 14 Sampl esOutput Action 6 28 Sam
352. rate For example suppose you create the analog input objectai for a sound card and configureit for stereo operation If the device has a maximum rate of 48 0 kHz then the maximum sampling rate per channel is 48 0 kHz al analoginput winsound addchannel ai 1 2 set ai SampleRate 48000 If you are using scanning hardware such as a National Instruments board then the maximum sampling rate your hardware is rated at typically applies for one channel Therefore the maximum sampling rate per channel is given by the formula Maximum board rate Maximum sampling rate per channel _ _ ping p Number of channels scanned For example suppose you create the analog input object ai for a National Instruments board and add 10 channels toit If the device has a maximum rate of 100 kHz then the maximum sampling rate per channel is 10 kHz ai analoginput nidaq 1 set ai InputType SingleEnded addchannel ai 0 9 set ai Sampl eRate 10000 Typically you can achieve this maximum rate only under ideal conditions In practice the sampling rate depends on several characteristics of the analog input subsystem including the settling time the gain and the channel skew Channel skew is discussed in the next section Configuring and Sampling Input C hannels Note Whenever theSamp eRate value is changed the Buf feringConfig property value is recalculated by the engine if the Buf f eri ngMode prop
353. rateis high and when you require a fixed time interval between samples The onboard clock is referred to as the internal clock in this guide The Computer Clock The computer PC clock is used for boards that do not possess an onboard clock The computer clock is less accurate and has more jitter than the onboard clock and is generally limited to sampling rates below 500 Hz The computer clock is referred to as the software clock in this guide External Clock An external clock is often used when thesampling rateis low and not constant For example an external clock source is often used in automotive applications where samples are acquired as a function of crank angle 1 23 1 Introduction to Data Acquisition Channel Configuration You can configure input channels in one of these two ways e Differential e Single ended Y our choice of input channel configuration may depend on whether the input signal is floating or grounded A floating signal uses an isolated ground reference and is not connected tothe building ground As a result the input signal and hardware device are not connected to a common reference which can cause the input signal to exceed the valid range of the hardware device To circumvent this problem you must connect the signal to the onboard ground of the device Examples of floating signal sources include ungrounded thermocouples and battery devices A grounded signal is connected to the building ground As a
354. re ID vector addchannel ai 1 2 Stereo mode means that data is acquired from both hardware channels Channel 1 is automatically assigned the descriptive nameLeft and channel 2 is automatically assigned the descriptive name Ri ght ai Channel Channel Name ans Left Ri ght Whilein stereo mode if you want to delete one channel then that channel must be channel 2 If you try to delete channel 1 an error is returned delete ai Channel 2 The sound card is now in mono mode Configuring Analog Input Properties Configuring Analog Input Properties After hardware channels are added to the analog input object you should configure property values As described in Configuring and Returning Properties on page 3 12 the Data Acquisition Toolbox supports two basic types of properties for analog input objects common properties and channel properties Common properties apply to all channels contained by the device object while channel properties apply to individual channels The properties you configure depend on your particular analog input application For many common applications there is a small group of properties related to the basic setup that you will typically use These basic setup properties control the sampling rate define the trigger type and define the samples to be acquired per trigger Analog input properties related to the basic setup are given below Table 4 3 Analog Input Basic Setup Propert
355. re with theStandardSampleRates property Refer to Chapter 11 Device Specific Property Reference for more information For hardware that supports simultaneous sampling of channels sound cards and Agilent Technologies devices the maximum sampling rate for each channel is given by the maximum board rate For scanning hardware most National Instruments and ComputerBoards devices the per channel sampling rate is given by the maximum hardware rate divided by the number of channels contained by the device object After setting a value for Samp eRat e you should find out the actual rate set by the engine Actual Rate get ai SampleRate Alternatively you can usethes et veri f y function which sets a property value and returns the actual value set Actual Rate setverify ai SampleRate 100000 You can find the range of valid sampling rates for your hardware with the propinfo function ValidRates propinfo ai SampleRate Vali dRates ConstraintValue ans 1 0e 005 0 0000 2 0000 Configuring Analog Input Properties Trigger Types For analog input objects a trigger is defined as an event that initiates data logging to memory or to a disk file Defining an analog input trigger involves specifying the trigger type with theTriggerType property TheTri ggerType values that are supported for all hardware are given below Table 4 4 Analog Input TriggerType Property Values TriggerType Value Description
356. rection Purpose Description Characteristics Values Example See Also 10 28 Specify whether a line is used for input or output When adding hardware lines to a digital 1 O object with add ine you must configure the line direction The line direction can be n or Out and is automatically stored in Di rection Ifalinedirection is n you can only read a value from that line If a line direction is Out you can writeor read a linevalue For line configurable devices you can change individual line directions using Di rection For port configurable devices you cannot change individual line directions Usage DIO Line Access Read write Data type String Read only Yes when running in The line can be read from Out The line can be read from or written to Create the digital I O object di o and add two input lines and two output lines toit dio digitalio nidag 1 addline dio 0 3 f Iln In Out Out To configure all lines for output dio Line 1 2 Direction Out Functions addline EventLog Purpose Description Store information for specific events Event og isa structure array that stores information related to specific analog input Al or analog output AO events Event information is storedintheTy pe and Data fields of EventLog Type stores the event type The logged event types are shown below Event Type Description Al AO Data missed Data is missed by the en
357. rectly above Therefore the first measurement was not accurate 1 29 1 Introduction to Data Acquisition Precision and accuracy are illustrated below X X x Q x x x x Not precise Precise Not accurate Not accurate eN x a Not precise Precise Accurate Accurate For analog input subsystems accuracy is usually limited by calibration errors while precision is usually limited by the A D converter Accuracy and precision are discussed in more detail below Accuracy Accuracy is defined as the agreement between a measured quantity and the true value of that quantity Every component that appears in the analog signal path affects system accuracy and performance The overall system accuracy is given by the component with the worst accuracy M aking Q uality M easurements For data acquisition hardware accuracy is often expressed as a percent or a fraction of the least significant bit LSB Under ideal circumstances board accuracy is typically 0 5 LSB Therefore a 12 bit converter has only 11 usable bits Many boards include a programmable gain amplifier which is located just before the converter input To prevent system accuracy from being degraded the accuracy and linearity of the gain must be better than that of the A D converter The specified accuracy of a board is also affected by the sampling rate and the settling time of the amplifier The settling time is defined as the time required for the instrumen
358. remaining references should be cleared from the workspace with thec ear function If you delete a device object while it is running then a warning is issued before it is deleted You cannot delete a device object while it is logging or sending data Y ou should usedel ete at the end of a data acquisition session Y ou can quickly delete all existing device objects with the command del ete dagfind delete Example See Also If you use thehel p command to display the M file help for del et e then you must supply the pathname shown below help daq daqdevice delete National Instruments Create the analog input object ai for a National Instruments board add hardware channels 0 7 to it and make a copy of hardware channels 0 and 1 al analoginput nidaq 1 addchannel ai 0 7 ch ai Channel 1 2 To delete hardware channels O and 1 delete ch These channels are deleted from the data acquisition engine and are no longer associated with ai The remaining channels are reindexed such that the indices begin at 1 and increase monotonically to 6 To delete a i delete ai Sound Card Create the analog input object Al 1 for a sound card and configure it to operate in stereo mode All anal oginput winsound addchannel A11 1 2 Y ou can now configure the sound card for mono mode by deleting hardware channel 2 delete Al1 Channel 2 If hardware channel 1 is deleted instead an error is returned Fu
359. result the input signal and hardware device are connected to a common reference Examples of grounded signal sources include nonisolated instrument outputs and devices that are connected to the building power system Note For more information about channel configuration refer to your hardware documentation Differential Inputs When you configure your hardware for differential input there are two signal wires associated with each input signal one for the input signal and one for the reference return signal The measurement is the difference in voltage between the two wires which helps reduce noise and any voltage that is common to both wires As shown below the input signal is connected to the positive amplifier socket labeled and the return signal is connected to the negative amplifier socket The Analog Input Subsystem labeled The amplifier has a third connector that allows these signals to be referenced to ground Amplifier Input signal Return signal National Instruments recommends that you use differential inputs under any of these conditions e The input signal is low level less than 1 volt e The leads connecting the signal are greater than 10 feet e Theinput signal requires a separate ground reference point or return signal e Thesignal leads travel through a noisy environment Single Ended Inputs When you configure your hardware for single ended input there is one signal wire a
360. rigger conditions are described below and in Chapter 10 Base Property Reference Table 5 10 Analog Input TriggerType and TriggerCondition Property Values for Agilent Hardware TriggerType TriggerCondition Description Value Value HwDi gi tal PositiveEdge The trigger occurs when the positive rising edge of a digital signal is detected NegativeEdge The trigger occurs when the negative falling edge of a digital signal is detected HwAnal og Rising The trigger occurs when the analog signal has a Falling Leaving Entering positive slope when passing through the specified range of values The trigger occurs when the analog signal has a negative slope when passing through the specified range of values The trigger occurs when the analog signal leaves the specified range of values The trigger occurs when the analog signal enters the specified range of values 5 44 Note that when Tri ggerType isHwAnal og the trigger condition values are all specified as two element vectors Setting two trigger levels prevents the module from triggering repeatedly due to a noisy signal Configuring Analog Input Triggers Hardware Digital Triggering If Tri ggerType iSHwDi gi tal the trigger is given by a digital TTL signal For example to trigger your acquisition when the negative edge of a digital signal is detected al anal oginput hpel432 8 addchannel ai 1 16 set ai TriggerType HwDigital se
361. riggers are specified by a negativeTri gger Del ay value while postriggers are specified by a positive Trigger Del ay value You can delay data logging in time or in samples using theTri ggerDel ayUnits property WhenTri ggerDel ayUnits is set toSamp es data logging is delayed by the specified number of samples When theTri ggerDel ayUni ts property is set toSeconds data logging is delayed by the specified number of seconds Configuring Analog Input Triggers Capturing Pretrigger Data In some circumstances you may want to capture data before the trigger occurs Such data is called pretrigger data When capturing pretrigger data the Sampl esPer Trigger property valueincludes the data captured before and after the trigger occurs Capturing pretrigger data is illustrated in below i Pretrigger samples Trigger samples j Trigger occurs k Sampl esPerTrigger i I Data stored in engine You can capture pretrigger data for manual triggers and software triggers If TriggerType iSManual andthetri gger function is issued before the trigger delay passes then a warning is returned and the trigger is ignored the trigger event does not occur Y ou cannot capture pretrigger data for immediate triggers or device specific hardware triggers Note Pretrigger data has negative relative time values associated with it This is because time 0 corresponds to the time the trigger event occurs and data logging is initiated
362. rlow Essex UK 1988 Bevington Philip R Data Reduction and Error Analysis for the Physical Sciences McGraw Hill New York NY 1969 Carr J oseph J Sensors Prompt Publications Indianapolis Indiana 1997 TheMeasurement Instrumentation and Sensors Handbook edited by J ohn G Webster CRC Press Boca Raton FL 1999 PCI MIO E Series User Manual J anuary 1997 Edition Part Number 320945B 01 National Instruments Austin TX 1997 1 39 1 Introduction to Data Acquisition 1 40 Getting Started with the Data Acquisition Toolbox Toolbox Components M File Functions The Data Acquisition Engin ne The Hardware Driver Adaptor Accessing Your Hardware Acquiring Data Outputting Data Reading and Writing Digital Values i Understanding the Toolbox ma cies The Contents and Readme Files Documentation Examples The Quick Reference Guide Demos Examining Your Hardware Resources General Toolbox Information Adaptor Specific Information Device Object Information Getting Help i The daqhelp Funcion The propinfo F unction 2 7 2 G etting Started with the Data Acquisition Toolbox Toolbox Components The Data Acquisition Toolbox consists of three distinct components M file functions the data acquisition engine and hardware driver adaptors As shown below these components allow you to pass information between MATLAB and your data acquisition hardware MATLAB
363. rom port 0 then from port 1 and so on e You can specify the line directions as a single value or a cell array of values If a single direction is specified then all added lines have that direction If supported by the hardware you can configure individual lines by supplying a cell array of directions More About MATLAB Indices Every hardware line contained by a device object has an associated MATLAB index that is used to reference the line Index assignments are made automatically by add ine and follow these rules e f no hardware lines are contained by the device object then the assigned indices automatically start at one and increase monotonically If hardware lines have already been added to the device object then the assigned indices automatically start at the next highest index value and increase monotonically e The resulting indices begin at one and increase monotonically up to the size of the line group e The first indexed line represents the least significant bit LSB and the highest indexed line represents the most significant bit MSB 9 15 addline Example See Also 9 16 More About Descriptive Line Names You can assign hardware lines descriptive names which are stored in the Li neName property Choosing a unique descriptive name can bea useful way to identify and reference lines For a single call toadd ine you can e Specify one line name that applies to all lines that are to be added e Speci
364. roperty Names and Property Values 3 14 Configuring Property Values 0 000 eee eee 3 18 Specifying Property Names 0 000 e eee eee ee 3 19 Default Property Values 00 cece eee eee 3 19 daqpropedit A Graphical Property Editor 3 20 Acquiring and Outputting Data 3 22 Starting the Device Object 1 0 0 0 ee ee 3 23 Logging or Sending Data 0 0c eee ee 3 23 Stopping the Device Object 0 0 2 cee ee 3 24 Cleaning Up isis oe peas Heer a fede oia e epa 3 25 Getting Started with Analog Input 4 Overview 0 a week Gin ce Rtas ase ald ean 4 2 Creating an Analog Input Object 4 3 Adding Channels to an Analog Input Object 4 4 Referencing Individual HardwareChannels 4 6 Example Adding Channels for a Sound Card 4 7 Configuring Analog Input Properties 4 9 The Sampling Rate 0 0 ec ee 4 9 Trigger TYPES Mois ARO Soe Se Oden Oe eo ane a 4 11 The Samples to Acquire per Trigger oooocccocccoo 4 12 Acquiring Data 0 0 0 cece 4 13 Starting the Analog Input Object 2 0 005 4 13 Logging Data coria lina see 4 14 Stopping the Analog Input Object 2 000005 4 14 Analog Input Examples 00002 ee aee 4 15 Acquiring Data with a Sound Card 0 00 eens 4 15 Acquiring Data with a National
365. roperty value for the first line added ID 0 you can reference the line by its index using the Li ne property linel dio Line 1 set linel Direction Out Functions addline delete Properties HwLine Index 10 43 LineName Purpose Description Characteristics Values Example See Also 10 44 Specify a descriptive line name LineName specifies a descriptive name for a hardware line If a line name is defined then you can reference that line by its name If a line name is not defined then the line must be referenced by its index Line names are not required to be unique Y ou can also define descriptive line names when lines are added to a digital O object with the add i ne function Usage DIO Line Access Read write Data type String Read only Yes when running The default value is an empty string To reference a line by name it must contain only letters numbers and underscores and must begin with a letter Create the digital O object di o and add four hardware lines to it dio digitalio nidaq 1 addline dio 0 3 out To assign a descriptive name to the first line contained by di o linel dio Line 1 set linel LineName oe You can now reference this line by name instead of index set dio Joe Direction In Functions addline LogFileName Purpose Specify the name of the disk file to which information is logged Description Y ou can log acquired data de
366. rted hardware subsystems of a given type analog input analog output etc For example theSamp eRat e property is supported for all analog input subsystems regardless of the vendor In Properties Grouped by Category on page 10 3 the properties are summarized according to subsystem type and usage In Properties Listed Alphabetically on page 10 14 the properties are described in detail Getting Command Line Property Help To get command line property help you should use the daghe p function For example to get help for the Samp eRat e property daghel p SampleRate Note You can usedaghel p without creating a device object You can also get property characteristics such as the default property value using thepr opi nf o function For example suppose you create the analog input object ai for a sound card and you want to find the default value for the Samp eRate property al analoginput winsound out propinfo ai Sampl eRate out Default Value ans 8000 Properties Grouped by Category Properties Grouped by Category This section contains brief descriptions of all toolbox base properties The properties are categorized according to these subsystems e Analog input properties e Analog output properties e Digital I O properties Depending on the hardware device you are using additional property names or property values may be present The additional property names are described in Chapter
367. running The default value is an empty vector Create the analog input object ai and add two channels to it al analoginput nidaq 1 addchannel ai 0 1 Suppose you want to access filter coefficients during the acquisition You can create a structure to store these coefficients which can then be stored in UserData coeff a 1 0 coeff b 1 25 set ai UserData coeff 10 99 UserData 10 100 Device Specific Property Reference Overview 2 ee a 11 2 Getting Command LinePropertyHelp 11 2 Properties Listed by Vendor 11 3 National Instruments Properties 4 2 11 3 ComputerBoards Properties 11 4 Agilent Technologies Properties 11 4 Sound Card Properties 11 5 Properties Listed Alphabetically 11 6 11 Device Specific Property Reference 11 2 Overview The following sections provide descriptions of all toolbox device specific properties Device specific properties apply only to hardware devices of a specific type or from a specific vendor For example the Bi tsPer Sampl e property is supported only for sound cards whiletheNumMuxBoar ds property is supported only for National Instruments devices In Properties Listed by Vendor on page 11 3 the properties are summarized according to vendor In Properties Listed Alphabetically on page 11 6 the properties are described in d
368. ry Presents the complete analog input functionality Shows you how to perform data acquisition tasks using your analog output subsystem Shows you how to perform data acquisition tasks using your digital O subsystem Shows you how to save and load device objects data and event information using several disk file formats Presents a complete description of all toolbox functions Presents a complete description of all toolbox base properties Presents a complete description of all toolbox device specific properties Presents tips to help you troubleshoot your hardware Describes how to allocate and return memory resources Presents a glossary of data acquisition terms xxi Preface Installation Information xxii To acquire live measured data into the MATLAB environment or to output data from the MATLAB environment you must install these three components e The Data Acquisition Toolbox e Data acquisition hardware e Software such as drivers and support libraries as required by your data acquisition hardware Toolbox Installation To determine if the Data Acquisition Toolbox is installed on your system type ver at the MATLAB prompt MATLAB displays information about the versions of MATLAB you are running including a list of installed add on products and their version numbers Check the list to see if the Data Acquisition Toolbox appears For information about installing the toolbox see the
369. ry Resources Glossary C G lossary Accuracy Acquiring data Action function Action property Actuator Adaptor A D converter Analog input subsystem Analog output subsystem Bandwidth Base property Channel A determination of how close a measurement comes to the true value The process of inputting an analog signal from a sensor into an analog input subsystem and then converting the signal into bits that the computer can read An M file function that you construct to suit your specific data acquisition needs If you supply the action function as the value for an action property then the function is executed when the event associated with the action property occurs A property associated with a specific event type When an event occurs the engine examines the associated action property If an action function is given as the value for the action property then that function is executed All event types have an action property A device that converts data output from your computer into a physical variable The interface between the data acquisition engine and the hardware driver The adaptor s main purpose is to update the engine with properties that are unique to the hardware device An analog input subsystem Hardware that converts real world analog input signals into bits that a computer can read This is also referred to as an Al subsystem an A D converter or an ADC Hardware that con
370. s Channel Skew Channel SkewMode ClockSource I nput Type Sampl eRat e Specify the time between consecutive scanned hardware channels Specify how the channel skew is determined Specify the clock used to govern the hardware conversion rate Specify the analog input hardware channel configuration Specify the per channel rate at which analog data is converted to digital data 10 5 10 Base Property Reference Analog Input Action Properties DataMissedAction I np Act ut Over Range ion RuntimeError Act Sam Act Sam Act Sta Sto Tim Tim Tri ion plesAcquired ion plesAcquired i onCount rtAction pAction erAction erPeriod ggerAction Specify the M file action function to execute when data is missed Specify the M file action function to execute when acquired data exceeds the valid hardware range Specify the M file action function to execute when a run time error occurs Specify the M file action function to execute every time a predefined number of samples is acquired for each channel group member Specify the number of samples to acquire for each channel group member before a samples acquired event is generated Specify the M file action function to execute just before the device object starts running Specify the M file action function to execute just after the device object stops running Specify the M file action function to exe
371. s and create the variables blocksize andFs which are used for subsequent analysis The actual sampling rate is retrieved sinceit may beset by the engine to a value that differs from the specified value duration 1 l second acquisition set Al Sampl eRate 10000 Actual Rate get Al SampleRate set Al SamplesPerTrigger duration Actual Rate set Al TriggerType Manual blocksize get Al SamplesPerTrigger Fs Actual Rate 4 Acquire data Start Al issue a manual trigger and extract all data from the engine Beforestart is issued you should begin inputting data from the function generator into the data acquisition board start Al trigger Al data getdata Al 5 Clean up When you no longer need A you should remove it from memory and fromthe MATLAB workspace delete Al clear Al Analyzing the Data For this experiment analysis consists of finding the frequency of the input signal and plotting the results You can find the signal frequency with daqdocfft f mag daqdocfft data Fs bl ocksize This function which is shown in Analyzing the Data on page 4 17 calculates the FFT of data and requires the values of Sampl eRate and SamplesPerTrigger aS well asdata as inputs daqdocfft outputs the frequency and magnitude of dat a which you can then plot Analog Input Examples The results are given below plot f mag grid on yl abel Magnitude dB xlabel Frequency
372. s 0 7 to it al analoginput nidaq 1 addchannel ai 0 7 A two second acquisition is configured and the device object is executed set ai SampleRate 2000 duration 2 Actual Rate get ai SampleRate set ai SamplesPerTrigger Actual Rate durati on start ai Four thousand samples will be acquired for each channel group member To extract 1000 samples from the data acquisition engine for each channel data getdata ai 1000 9 53 flushdata See Also 9 54 You can usef ushdat a to remove the remaining 3000 samples from the data acquisition engine flushdata ai al Sampl esAvailable ans 0 Functions getdata Properties SamplesAvailable Sampl esPerTrigger TriggerRepeat get Purpose Syntax Arguments Description Return device object properties out get obj out get obj Channel index out get obj Line index out get obj PropertyName out get obj Channel index PropertyName out get obj Line index PropertyName get obj A device object or array of device objects obj Channel index Oneor more channels contained by obj obj Line index One or more lines contained by obj PropertyName A property name or a cell array of property names out get obj returns the structureout where each field nameis the name of a property of obj and each field contains the value of that property out get obj Channel index returns the structur
373. s calculated by the engine such that 1 second of data is collected and is based on the default value of Sampl eRate In general to calculate the acquisition time for each trigger you apply the formula acquisition time seconds samples per trigger sampling rate in Hz For example to acquire 5 seconds of data per trigger for each channel contained by ai set ai SamplesPerTrigger 500000 To continually acquire data you set SamplesPerTrigger toinf set ai SamplesPerTrigger inf A continuous acquisition will stop only if you issue thes top function or an error occurs Acquiring Data Acquiring Data After you configure the analog input object you can acquire data Acquiring data involves these three steps 1 Starting the analog input object 2 Logging data 3 Stopping the analog input object Starting the Analog Input Object You start an analog input object with thest art function For example to start the analog input object ai al analoginput winsound addchannel ai 1 2 start ai After start isissued theRunni ng property is automatically set to0n and both the device object and hardware device execute according to the configured and default property values While you are acquiring data with an analog input object you can preview the data with thepeekdata function peekdata takes a snapshot of the most recent data but does not remove data fromthe engine For example to preview the most recent
374. s created the properties listed below are automatically assigned values These general purpose properties provide descriptive information about the object based on its class type and adaptor Table 6 1 Descriptive Analog Output Properties Property Name Description Na me Specify a descriptive name for the device object Type Indicate the device object type You can display the values of these properties for ao with theget function get ao Name Type ans ni dagl A0d Analog Output Adding Channels to an Analog Output Object After creating the analog output object you must add hardware channels toit As shown by the figure in Adding Channels or Lines on page 3 8 you can think of a device object as a container for channels The collection of channels contained by the device object is referred to as a channel group As described in Mapping Hardware Channel I Ds to MATLAB Indices on page 3 9 a channel group consists of a mapping between hardware channel IDs and MATLAB indices see below When adding channels to an analog output object you must follow these rules e The channels must reside on the same hardware device Y ou cannot add channels from different devices or from different subsystems on the same device e The channels must be sampled at the same rate You add channels to an analog output object with theaddchannel function addchannel requires the device object and at least one h
375. s digital data to analog data is controlled with theSampl eRat e property Samp eRat e must be specified as samples per second For example to set the sampling rate for each channel of your National Instruments board to 100 000 samples per second 100 kHz ao analogoutput nidaq 1 addchannel ao 0 1 set ao SampleRate 100000 G etting Started with Analog O utput Data acquisition boards typically have predefined sampling rates that you can set If you specify a sampling rate that does not match one of these predefined values there are two possibilities e Iftherateis within the range of valid values then the engine automatically selects a valid sampling rate The rules governing this selection process are described in theSamp leRat e reference pages in Chapter 10 Base Property Reference e f the rate is outside the range of valid values then an error is returned Note For some sound cards you can set the sampling rate to any value between the minimum and maximum values defined by the hardware You can enable this feature with the Standar dSampl eRates property Refer to Chapter 11 Device Specific Property Reference for more information Most analog output subsystems allow simultaneous sampling of channels Therefore the maximum sampling rate for each channel is given by the maximum board rate After setting a value for Samp eRat e you should find out the actual rate set by the engine Actua
376. sample Properties MaxSampl esQueued Out putRange Repeat Output Sampl esAvail able Sampl esOut put Timeout UnitsRange 9 81 putsample Purpose Syntax Arguments Description Remarks Example See Also 9 82 Immediately output one sample putsampl e obj data obj An analog output object data The data to be queued in the engine putsample obj data immediately outputs the row vector dat a which consists of one sample for each channel contained by obj Using put sample is a good way to test your analog output configuration Additionally e putsample does not store samples in the data acquisition engine e putsample can be executed at any time after channels have been added to obj e putsample is not supported for sound cards Create the analog output object ao for a National Instruments board and add two hardware channels to it ao analogoutput nidaq 1 ch addchannel ao 0 1 Tocall put sample for ao putsample ao 1 1 Functions putdata putvalue Purpose Syntax Arguments Description Remarks Example Write values to lines putvalue obj data putvalue obj Line index data obj A digital 1 O object obj Line index One or more lines contained by obj data A decimal value or binary vector putvalue obj data writesdata tothe hardware lines contained by the digital I O object obj putvalue obj Line index data writesdat a tothehardwarelines spe
377. shown below User Application software Driver software d Hardware You Data Acquisition Toolbox and MATLAB NI DAQ National Instruments AT MI0O 16E 1 board The diagram illustrates that you supply information to the hardware and you receive information from the hardware The Data Acquisition System Driver Software For data acquisition device there is associated driver software that you must use Driver software allows you to access and control the capabilities of your hardware Among other things basic driver software allows you to e Bring data on to and get data off of the board e Control the rate at which data is acquired e Integrate the data acquisition hardware with computer resources such as processor interrupts DMA and memory e Integrate the data acquisition hardware with signal conditioning hardware e Access multiple subsystems on a given data acquisition board e Access multiple data acquisition boards Application Software Application software provides a convenient front end to the driver software Basic application software allows you to e Report relevant information such as the number of samples acquired e Generate events e Manage the data stored in computer memory e Condition a signal e Plot acquired data With some application software you can also perform analysis
378. space out daqfind out dagqfind PropertyName PropertyValue out dagfind S out daqfind obj PropertyName PropertyValue PropertyName A device object channel or line property name PropertyValue A device object channel or line property value obj A device object array of device objects channels or lines S A structure with field names that are property names and field values that are property values out An array or cell array of device objects channels or lines out daqfind returns all device objects that exist in the data acquisition engine The output out is an array out dagfind PropertyName PropertyValue returns all device objects channels or lines that exist in the data acquisition engine and have the specified property names and property values The property name property value pairs can be specified as a cell array out dagfind S returns all device objects channels or lines that exist in the data acquisition and have the property names and property values specified by S S is a structure with field names that are property names and field values that are property values out dagfind obj PropertyName PropertyValue returns all device object channels or lines listed by obj that have the specified property names and property values dagfind Remarks Example See Also More About Finding Device Objects Channels or Lines daqfi nd is particularly useful in thes
379. ssociated with each input signal and each input signal is connected to the same ground Single ended measurements are more susceptible to noise than differential measurements due to differences in the signal paths 1 25 1 Introduction to Data Acquisition 1 26 As shown below the input signal is connected to the positive amplifier socket labeled and the ground is connected to the negative amplifier socket labeled Amplifier Input signal Ground National Instruments suggests that you can use single ended inputs under any of these conditions e The input signal is high level greater than 1 volt e The leads connecting the signal are less than 10 feet e The input signal can share a common reference point with other signals You should use differential input connectors for any input signal that does not meet the preceding conditions Y ou can configure many National Instruments boards for two different types of single ended connections e Referenced single ended RSE connection The RSE configuration is used for floating signal sources In this case the hardware device itself provides the reference ground for the input signal e Nonreferenced single ended NRSE connection The NRSE input configuration is used for grounded signal sources In this case the input signal provides its own reference ground and the hardware device should not supply one Refer to your National Instruments hardware documentation for m
380. st port is line configurable while the remaining ports are port configurable 7 Digital input O utput 7 8 Referencing Individual Hardware Lines As described in the preceding section you can access lines with the Li ne property or with a line object To reference individual lines you must specify either MATLAB indices or descriptive line names MATLAB Indices Every hardware line contained by a digital I O object has an associated MATLAB index that is used to reference the line When adding lines with the addline function index assignments are made automatically The line indices start at 1 and increase monotonically up to the number of line group members The first line indexed in the line group represents the least significant bit LSB and the highest indexed line represents the most significant bit MSB Unlike adding channels with theaddchannel function you cannot manually assign line indices with addline For example the digital I O object di o created in the preceding section had the MATLAB indices 1 through 8 automatically assigned to the hardware lines O through 7 respectively To manually swap the hardware line order sothat line ID 1is the LSB you supply the appropriate index to hwl i nes and use the HwLi ne property hwlines 1 Hwline 1 hwlines 2 HwLine 0 Alternatively you can use the Li ne property 1 0 dio Line 1 HwLine dio Line 2 HwLine Descriptive Line Names Choosing a unique descrip
381. strates how to configure a hardware digital trigger ao analogoutput nidaq 1 addchannel ao 0 1 set ao TriggerType HwDigital With this trigger configuration ao will not start outputting data until the TTL signal is detected by the hardware on the appropriate pin 6 25 6 Analog O utput 6 26 The diagram below illustrates how you can connect a digital trigger signal to an MIO 16E Series board PFI6 WFTRIG corresponds to pin 5 TTL signal PFIO WFTRIG D A k MIO 16E Series board Agilent Technologies When using Agilent Technologies hardware there areadditional analog output trigger types that you must be aware of digital triggering on a positive edge and digital triggering on a negative edge IfTriggerType isHwDigitalPos thetrigger source is the positive edge of a digital signal IfTriggerType iSHwDi gi tal Neg the trigger source is the negative edge of a digital signal In both cases the digital signal is an external TTL signal that is input directly into the hardware device The example below illustrates how to configure such a trigger ao analogoutput hpel432 8 addchannel ao 1 set ao TriggerType HwDi gital Pos With this trigger configuration ao will not start outputting data until the TTL signal is detected by the hardware Configuring Events and Actions Configuring Events and Actions You can enhanc
382. supported devices visit the Data Acquisition Toolbox section of the MathWorks Web site at http www mathworks com products daq e Software such as drivers and support libraries as required by your data acquisition device Associated Products The MathWorks provides several associated products that are especially relevant to the kinds of tasks you can perform with the Data Acquisition Toolbox For more information about any of these products see either e The online documentation for that product if it is installed or if you are reading the documentation from the CD e TheMathWorks Website athttp www mat hworks com seethe products section Note The toolboxes listed below all include functions that extend MATLAB s capabilities xvii Products Associated with the Data Acquisition Toolbox Product Description Control System Tool box Database Toolbox Instrument Control Tool box MATLAB Report Generator Neural Network Toolbox Signal Processing Toolbox Statistics Toolbox System dentification Toolbox Wavelet Toolbox Tool for modeling analyzing and designing control systems using classical and modern techniques Tool for connecting to and interacting with most ODBC DBC databases from within MATLAB Tool for communicating with instruments that support the GPIB IEEE 488 HPIB interface the VISA standard or the serial port interface Tool for documenting informatio
383. t The second way requires two calls toadd i ne and specifies one line ID and multiple port IDs for each call addline dio 0 0 2 in addline dio 1 0 2 out Thethird way requires two calls toa ddI i ne and specifies multiplelinel Ds and one port ID for each call addline dio 0 1 0 addline dio 0 1 2 y out in in out as 7 Digital input O utput Writing and Reading Digital I O Line Values After you add lines to a digital I O object you can e Write values to lines e Read values from lines Note Unlike analog input and analog output objects you do not control the behavior of digital O objects by configuring properties This is because buffered digital I O is not supported and data is not stored in the engine Instead you either write values directly to or read value directly from one or more hardware lines Writing Digital Values Y ou write values to one or more digital 1 O lines with the put val ue function putval ue requires the digital I O object and the values to be written as input arguments You can specify the values to be written as a decimal value or as a binary vector binvec A binary vector is a logical array that is constructed with the least significant bit LSB in the first column and the most significant bit MSB in the last column For example the decimal value 23 is written in binvec notation as 1 1 1 0 1 2 2 22 24 You may find that binvecs are eas
384. t 227 7202 1 DFARS Part 227 7202 3 DFARS Part 252 227 7013 and DFARS Part 252 227 7014 Theterms and conditions of The MathWorks Inc Software License Agreement shall pertain to the government s use and disclosure of the Program and Documentation and shall supersede any conflicting contractual terms or conditions If this license fails to meet the government s minimum needs or is inconsistent in any respect with federal procurement law the government agrees to return the Program and Documentation unused to MathWorks MATLAB Simulink Stateflow Handle Graphics and Real Time Workshop are registered trademarks and Target Language Compiler is a trademark of The MathWorks Inc Other product or brand names are trademarks or registered trademarks of their respective holders Printing History May 1999 First printing New for Version 1 November 2000 Second printing Revised for Version 2 Release 12 Preface What Is the Data Acquisition Toolbox xvi Exploring the Toolbox 0 060 ee eee eee xvi Related Products 00 cece eee eee eee xvii System Requirements 000 0c cece ee eee xvii Associated Products 0 0 e eee eee eee xvii Using This Guide 00 c cece eee xix Expected Background 00sec eee eee xix Using the Documentation Examples 200 005 XX How This Guide is Organized sasssa aeaee XX Installation Information uaaa xxii To
385. t 6 31 usingputdata 6 19 voice activation Al pretriggers 5 28 repeating triggers 5 31 software trigger 5 23 execution Al object 4 13 AO object 6 9 DIO object 7 15 external clock 1 23 clock sources 10 24 extracting data 5 13 F fft 4 17 FIFO 1 27 TransferMode 11 25 filtering 1 34 finding device objects 9 28 floating signal 1 24 flow of data acquired 2 4 output 2 6 flushdata 9 53 full duplex A 18 BitsPerSample 11 7 functions addchannel 9 9 addline 9 14 addmuxchannel 9 17 analoginput 9 18 analogoutput 9 21 binvec2dec 9 24 clear 9 25 dagaction 9 27 daqfind 9 28 daghel p 9 30 daqhwinfo 9 32 daqmem 9 34 daqpropedit 9 37 daqread 9 39 daqregister 9 43 daqreset 9 44 daqschool 9 45 dec2binvec 9 46 delete 9 48 digitalio 9 50 disp 9 52 flushdata 9 53 get 9 55 getdata 9 57 getsample 9 61 getvalue 9 62 ischannel 9 63 isdioline 9 64 isvalid 9 65 length 9 67 load 9 69 makenames 9 71 muxchanidx 9 72 obj 2mfile 9 74 peekdata 9 76 propinfo 9 78 putdata 9 80 putsample 9 82 putvalue 9 83 save 9 84 set 9 85 setverify 9 88 showdagevents 9 90 size 9 92 start 9 94 Index stop 9 95 trigger 9 97 waittilstop 9 98 G gain 1 22 engineering units Al 5 56 gain list 4 5 get 3 15 getdata 5 13 event information 9 59 native data 10 53 time information 5 18 getsample 9 61 getvalue 7 12 graphical property editor 3 20 grounded signal 1 24 H hardware initializing 9 44 resources 2 17 sca
386. t ai TriggerCondition NegativeEdge Hardware Analog Triggering If Tri gger Type isHwAnal og the trigger is given by an analog signal For example to trigger your acquisition when the trigger signal is between 4 volts and 4 volts ai analoginput hpel432 8 addchannel ai 1 16 set ai TriggerType HwAnal og set ai TriggerCondition Entering set ai TriggerConditionValue 4 0 4 0 set ai TriggerChannel ai Channel 1 4 5 45 5 po ing More with Analog Input 5 46 Configuring Events and Actions You can enhance the power and flexibility of your analog input application by utilizing events An event occurs at a particular time after a condition is met and may result in one or more actions While the analog input object is running you can use events to display a message display data analyze data or perform just about any other action Actions are controlled through action properties and action functions All event types have an associated action property Action functions are M file functions that you construct to suit your specific data acquisition needs You execute an action when a particular event occurs by specifying the name of the M file action function as the value for the associated action property Note that daqacti on is the default value for some action properties Event Types The analog input event types and associated action properties are described below Table 5 11 Anal
387. t data block is filled Y ou can choose whether a log file is overwritten or if multiple log files are created with theLogToDiskMode property IfLogToDiskMode isOQverwrite the log fileis overwritten IfLogToDiskMode isl ndex newlogfiles are created each with an indexed name based on the value of LogFi leName Specifying a Filename Y ou specify the name of the log file with the LogFi eName property You can specify any value for LogFil eName including a directory path provided the filename is supported by your operating system Additionally if LogToDiskMode iS ndex then the log filename also follows these rules e ndexed log filenames are identified by a number This number precedes the filename extension and is incremented by one for successive log files e f no number is specified as part of the initial log filename then the first log file does not have a number associated with it For example if LogFil eName ismyfile daq then myfile daq isthe name of the first log file myf il e01 daq isthe name of the second log file and so on e LogFileName is updated after the log file is written after the stop event occurs e f the specified log filename already exists then the existing file is overwritten 8 7 8 Saving and Loading the Session 8 8 Retrieving Logged Information You retrieve logged information with thedaqread function You can retrieve any part of the information stored in a log file with one call todagr
388. t is running it behaves according to the previously configured or default property values After data is acquired you must extract it from the engine with theget dat a function Before you can output data you must queue it in the engine with the put data function 5 Clean up When you no longer need the device object you should remove it from memory using thede ete function and remove it from the MATLAB workspace using thec ear command The data acquisition session is used in many of the documentation examples included in this guide Note that the fourth step is treated differently for digital 1 O objects since they do not store data in the engine Therefore only analog input and analog output objects are discussed in this section 3 2 O verview Example The Data Acquisition Session This example illustrates the basic steps you take during a data acquisition session using an analog input object Y ou can run this example by typing daqdoc3_1 at the MATLAB command line 1 Create a device object Createthe analog input object Al for a sound card The installed adaptors and hardware I Ds are found with daqhwi nfo Al analoginput winsound Al analoginput nidaq 1 Al analoginput cbi 1 2 Add channels Add two channels toA addchannel Al 1 2 addchannel A1 0 1 For NI and CBI 3 Configure property values Configure the sampling rate to 11 025 kHz and define a 2 second acquisition set Al
389. t pass before the action function specified for Ti mer Acti on is called Timeis measured relative to when the hardware device starts running Some timer events may not be processed if your system is significantly slowed or iftheTi mer Peri od valueis too small For example a common application for timer events is to display data However since displaying data is a CPU intensive task some of these events may be dropped Usage Al AO DIO Common Access Read write Data type Double Read only No when running The default value is 0 1 second Properties Ti merAction TriggerAction Purpose Description Characteristics Values See Also Specify the M file action function to execute when a trigger occurs A trigger event is generated immediately after a trigger occurs This event executes the action function specified for Tri gger Acti on Under most circumstances the action function is not guaranteed to complete execution until sometime after Logging is set to 0n for analog input Al objects or Sending is set to0n for analog output AO objects Trigger event information is storedintheType andData fields of theEvent Log property TheType field valueisTrigger TheData field values are given below Data Field Value Description AbsTi me The absolute time as ac ock vector the event occurred Rel Sample The acquired Al or output AO sample number when the event occurred Channel The index number for
390. t signal and all input signals are connected to the same ground Single ended measurements are more susceptible to noise than differential measurements due to differences in the signal paths Data acquisition hardware that simultaneously samples all input signals and then holds the values until the A D converter digitizes all the signals A data acquisition hardware component that performs a specifictask The Data Acquisition Toolbox supports analog input analog output and digital I O subsystems An analog input trigger event initiates data logging to memory or a disk file An analog output trigger event initiates the output of data from the engine to the hardware The following abbreviations are used in this index Agilent Agilent Technologies Al analog input AO analog output CBI ComputerB oards DIO digital I O HP Hewlett Packard NI National Instruments A A D converter 1 7 input range 5 56 sampling rate 4 9 absolute time 5 19 accuracy 1 30 acquiring data 3 22 continuous samples per trigger 5 23 simultaneous input and output 6 37 trigger repeats 5 30 single point 9 61 action function 5 52 action properties Al object 5 46 AO object 6 27 saving property values to a MAT file 8 3 actuator 1 4 adaptor kit 2 7 adaptors registering A 19 supported hardware 2 7 third party A 19 addchannel Al object 4 4 AO object 6 4 addline 7 4 addmuxchannel 9 17 Agilent Technologies hardware channel configuration
391. t to disk etc In addition to these two functions there are several properties associated with managing acquired data These properties are listed below Table 5 5 Analog Input Data Management Properties Property Name Description Sampl esAcquired ndicate the number of samples acquired per channel SamplesAvailable ndicate the number of samples available per channel in the data acquisition engine SamplesPerTrigger Specify the number of samples to acquire for each channel group member for each trigger that occurs Previewing Data Before you extract and analyze acquired data you may want to examine preview the data as it is being acquired Previewing the data allows you to determine if the hardware is performing as expected and if your acquisition process is configured correctly Once you are convinced that your system is in order you may still want to monitor the data even as it is being analyzed or saved to disk Previewing data is managed with the peekdat a function For example to preview the most recent 1000 samples acquired for the analog input object ai data peekdata ai 1000 5 9 5 Doing More with Analog Input After start is issued you can call peekdata peekdata is a nonblocking function since it immediately returns control to MATLAB Therefore samples may be missed or repeated When apeekdata call is processed the most recent samples requested are immediately returned but the data
392. ta Acquisition 1 34 Much of this noise is common to both signal wires To remove most of this common mode voltage you should e Configure the input channels in differential mode Refer to Channel Configuration on page 1 24 for more information about channel configuration e Use signal wires that are twisted together rather than separate e Keep the signal wires as short as possible e Keep the signal wires as far away as possible from environmental electrical activity Filtering Filtering also reduces signal noise For many data acquisition applications a low pass filter is beneficial As the name suggests a low pass filter passes the lower frequency components but attenuates the higher frequency components The cut off frequency of the filter must be compatible with the frequencies present in the signal of interest and the sampling rate used for the A D conversion A low pass filter that s used to prevent higher frequencies from introducing distortion into the digitized signal is known as an antialiasing filter if the cut off occurs at the Nyquist frequency That is the filter removes frequencies greater than one half the sampling frequency These filters generally have a sharper cut off than the normal low pass filter used to condition a signal Antialiasing filters are specified according to the sampling rate of the system and there must be one filter per input signal Matching the Sensor Range and A D Converter Ra
393. ta by selecting the Record button on the Sound Recorder and then speak into the microphone While recording the green linein the Sound Recorder should indicate that data is being captured If this is the case then the analog input subsystem on your sound card is functioning properly After recording the audio data save it to disk The data is automatically saved as a WAV file Play the saved WAV file While playing the green line in the Sound Recorder should indicate that data is being captured If this is the case then the analog output subsystem on your sound card is functioning properly If you are not able to record or play data make sure that the sound card and input devices are enabled for recording and playback as described in the beginning of this section Testing with a CD Player To test your sound card with a CD player follow these steps 1 Check that your CD is physically connected to your sound card Open your computer and locate the back of the CD player If there is a wire connecting the Audio Out CD port with the sound card you can record audio data from your CD If thereis no wire connecting your CD and sound card you must either make this connection or use the microphone to record data Troubleshooting Sound Cards 2 Put an audio CD into your CD player The Windows CD Player application should be automatically invoked and begin playing the CD If this doesn t occur then you must access the app
394. ta is acquired the number of blocks dynamically increases up to a predetermined limit However the engine cannot guarantee that the appropriate block size number of blocks or total memory is allocated under these conditions e You select certain property values For example if the samples to acquire per trigger is significantly less than the FIFO buffer of your hardware e You acquire data at the limits of your hardware your computer or the toolbox In particular if you are acquiring data at very high sampling rates then the allocated memory must be carefully evaluated to guarantee that samples are not lost You are free to override the memory allocation rules used by the engine and manually changethe block size and number of blocks provided the device object isnot running However you should dosoonly after careful consideration since system performance may be adversely affected which may result in lost data You can manage memory resources using the Buf f eri ngConfig property and thedaqmem function With Buf f eri ngConfi g you can configure and return the block size and number of blocks used by a device object With da q me m you can return the current state of the memory resources used by a device object and configure the maximum memory that one or more device objects can use How Much Memory Do You N eed How Much Memory Do You Need The memory in bytes required for data storage depends on these factors e The num
395. tal 1 O object Before you can create a device object the associated hardware driver adaptor must be registered Adaptor registration occurs automatically However if for some reason an adaptor is not automatically registered then you must do so manually with thedagregister function Refer to Registering the Hardware Driver Adaptor on page A 19 for more information You can find out how to create device objects for a particular vendor and subsystem with the Obj ect Construct orName field of the daghwi nf o function For example to find out how to create an analog input object for an installed National Instruments board you supply the appropriate adaptor name to daghwi nfo out daghwinfo nidaq out Obj ectConstructorName ans analoginput nidaq 1 anal ogoutput nidaq 1 digitalio nidag 1 Creating a Device O bject The constructor syntax tells you that you must supply the adaptor name and the hardware ID totheanal ogi nput function ai analoginput nidaq 1 The association between device objects and hardware subsystems is shown below Al AO DIO object object object re ae Al AO DIO subsystem subsystem subsystem Creating an Array of Device Objects In MATLAB you can create an array from existing variables by concatenating those variables together The same is true for device objects For example suppose you create the analog input object ai and the analog output object ao
396. tart AO trigger A0 while strcmp AO Running On end 5 Clean up When you no longer need A0 you should remove it from memory and fromthe MATLAB workspace delete A0 clear AO 6 13 6 Analog O utput 6 14 Evaluating the Analog Output Object Status Y ou can evaluate the status of an analog output object by e Returning the values of certain properties e Invoking the display summary Status Properties The properties associated with the status of your analog output object allow you to evaluate e If the device object is running e If data is being output from the engine e How much data is queued in the engine e How much data has been output from the engine These properties are given below Table 6 5 Analog Output Status Properties Property Name Description Running Indicate if the device object is running SamplesAvailable Indicatethenumber of samples available per channel in the engine Samples Out put Indicate the number of samples output per channel from the engine Sending Indicate if data is being sent output tothe hardware device When data is queued intheengine Samp esAvail abl e is updated toreflect the total number of samples per channel that was queued When st art is issued Running is automatically set to 0n When the trigger executes Sending is automatically set to 0n and Sampl es Out put keeps a running count of the total number of samples per channel output from t
397. tation amplifier to settle to a specified accuracy To maintain full accuracy the amplifier output must settle to a level given by the magnitude of 0 5 LSB before the next conversion and is on the order of several tenths of a millisecond for most boards Settling timeisa function of sampling rate and gain value High rate high gain configurations require longer settling times while low rate low gain configurations require shorter settling times Precision Thenumber of bits used to represent an analog signal determines the precision resolution of the device The more bits provided by your board the more precise your measurement will be A high precision high resolution device divides the input range into more divisions thereby allowing a smaller detectable voltage value A low precision low resolution device divides the input range into fewer divisions thereby increasing the detectable voltage value The overall precision of your data acquisition system is usually determined by the A D converter and is specified by the number of bits used to represent the analog signal Most boards use 12 or 16 bits The precision of your measurement is given by Precision one part in 2 umber of bits The precision in volts is given by Precision voltage range 2 Mber of bits 1 31 1 Introduction to Data Acquisition 1 32 For example if you are using a 12 bit A D converter configured for a 10 volt range then Precision 10 volts
398. te reference material as needed If you want detailed information about a specific function refer to Chapter 9 Function Reference If you want detailed information about a specific property refer to Chapter 10 Base Property Reference or Chapter 11 Device Specific Property Reference If You Are an Experienced User Start with Data Acquisition Toolbox 2 0 in the Release Notes for a description of new and modified tool box features Y ou should then read the appropriate reference material as needed If you want detailed information about a specific function refer to Chapter 9 Function Reference If you want detailed information about a specific property refer to Chapter 10 Base Property Reference or Chapter 11 Device Specific Property Reference xix Preface XX Using the Documentation Examples When you encounter examples or code snippets in this book you may want to try them for yourself An easy way to dothis is to cut the relevant text from the PDF or HTML versions of this guide and paste it into the MATLAB workspace You access the PDF and HTML content with the Help browser Some examples are constructed as mini applications that illustrate one or two important toolbox features and serve as templates so you can see how to build applications that suit your specific needs These examples are included as toolbox M files and are treated as demos You can list all Data Acquisition To
399. th a National Instruments Board Suppose you must verify that the nominal frequency of a sine wave generated by a function generator is 1 00 kHz To perform this task you will input the function generator signal into a National Instruments board Y ou will then perform a fast Fourier transform FFT on the acquired data to find the nominal frequency of the generated sine wave The setup for this task is shown below Data Source National Instruments Board Data Sink 01 00 TIT 000 Figure T MANN MATLAB workspace A D A Configuring the Data Acquisition Session For this example you will acquire 1 second of data on one input channel The board is set to a sampling rate of 10 kHz which is well above the frequency of interest After you connect the input signal to the board you will trigger the acquisition one time using a manual trigger Y ou can run this example by typingdagdoc4_2 at the MATLAB command line 1 Create a device object Create the analog input object Al for a National Instruments board The installed adaptors and hardware IDs are found with daqhwinfo Al analoginput nidaq 1 2 Add channels Add one channel toa chan addchannel Al 0 4 19 4 G etting Started with Analog Input 4 20 3 Configure property values Assign values to the basic setup propertie
400. the device object at least one hardware line ID and the direction input or output of each added line as input arguments Y ou can optionally specify port Ds descriptive line names and an output argument For example to add eight output lines from port O tothe device object di o created in the preceding section hwlines addline dio 0 7 out The output argument hwl i nes is aline object that reflects the line array contained by di o You can display the class of hw i nes with thewhos command whos hwlines Name Size Bytes Class hwlines 8x1 536 dioline object Grand total is 13 elements using 536 bytes You can usehwl i nes to easily access lines For example you can easily configure or return property values for one or more lines As described in XXX you can also access lines with the Li ne property Adding Lines to a Digital l O O bject Once you add lines to a digital I O object the properties listed below are automatically assigned values These properties provide descriptive information about the lines based on their class type and ID Table 7 2 Descriptive Digital I O Line Properties Property Name Description HwLine Specify the hardware line 1D Index Indicate the MATLAB index of a hardware line Parent Indicate the parent device object of a line Type Indicate a line Y ou can display the values of these properties for chans with theget function get hwlines HwLine Index Parent
401. the most important properties and functions required for an analog output data acquisition session In addition several device specific examples are provided as well as ways to evaluate the status of the analog output object After reading this section you will be able to perform basic analog output tasks suited to your own data acquisition applications Creating an Analog Output Object Y ou create an analog output object with the anal ogout put function analogoutput accepts the adaptor name and the hardware device ID as input arguments For a list of supported adaptors refer to The Hardware Driver Adaptor on page 2 7 The device ID refers to the number associated with your board when it is installed Some vendors refer to the device D as the device number or the board number The device ID is optional for sound cards with an ID of 0 Usethedaghwi nf o function to determine the available adaptors and device Ds Each analog output object is associated with one board and one analog output subsystem F or example to create an analog output object associated with a National Instruments board with device D 1 ao analogoutput nidaq 1 The analog output object ao now exists in the MATLAB workspace You can display the class of ao with thewhos command whos ao Name Size Bytes Class ao 1x1 1334 analogoutput object Grand total is 53 elements using 1334 bytes 6 3 6 Analog O utput 6 4 Once the analog output object i
402. tics are related to configuring e Theinput channel type e The sampling rate e The channel skew scanning hardware only Properties associated with configuring and sampling input channels are given below Table 5 1 Analog Input Properties Related to Sampling Channels Property Name Description Channel Skew Specify the time between consecutive scanned hardware channels Channel SkewMode Specify how the channel skew is determined InputType Specify the analog input hardware channel configuration Sampl eRate Specify the per channel rate at which analog data is converted to digital data 5 3 5 Doing More with Analog Input 5 4 Input Channel Configuration Y ou can configure your hardware input channels with the nput Type property The device specific values for this property are given below Table 5 2 InputType Property Values Vendor InputType Value National Differential Singl eEnded Instruments NonReferencedSi ngl eEnded ComputerB oards Differential Singl eEnded Agilent Technologies Differential Sound Cards AC Coupled Thel nput Type value determines the number of hardware channels you can add to a device object You can return the channel IDs with thedaghwi nf o function For example Suppose you create the analog input object ai for a National Instruments board To display the differential channel IDs al analoginput nidaqg 1 hwinfo daghwi nfo ai hwinfo Differential
403. ties dialog box for a Windows NT 4 0 platform is shown below and is configured for both playback and recording Multimedia Properties i x Audio Video MIDI CDMusic Devices m Playback x l Volume Low y i Preferred device AudioPCI Playback hs IM Show volume control on the taskbar Recording Volume Low High COS N Preferred device AudioPCI Record Preferred quality co Quality Customize I Use preferred devices only A 12 Troubleshooting Sound Cards You can record data and then play it back using the Windows Sound Recorder panel To access this application Start gt P rograms gt Accessories gt Multimedia gt Sound Recorder The figure below shows how to record and play data 4 Sound Sound 1 X File Edit Effects Help Position Length 0 00 sec 0 00 sec lt del gt gt a E E Play button Record button Y ou must also make sure that your microphone or CD player is enabled for recording and playback using the Windows Volume Control panel To access this application Start gt P rograms gt Accessories gt Multimedia gt Volume Control The Volume Control panel is shown below The CD microphone and line devices are enabled for playback when the Mute check box is unchecked for the CD Balance Microphone Balance and Line Balance volume controls respectively You can play WAV files by leaving the Mute check box unchecked for the Wa
404. timeErrorAction Additionally a toolbox error message is automatically displayed to the MATLAB workspace If an error occurs that is not explicitly handled by the toolbox then the hardware specific error message is displayed The default value for RunTi meErrorAction iSdagaction which displays the event type the time the event occurred the device object name and the error message Run time errors include hardware errors and timeouts Run time errors do not include configuration errors such as setting an invalid property value Samples O utput Event A samples output event is generated immediately after the number of samples specified by theSamp es Out put Acti onCount property is output for each channel group member This event executes the action function specified for Sampl es Out put Action Start Event A start event is generated immediately after thest art function is issued This event executes the action function specified for St artAction When the action function has finished executing Running is automatically set to0n and the device object and hardware device begin executing Stop Event A stop event is generated immediately after the device object and hardware device stop running This occurs when e Thest op function is issued e The requested number of samples is output e A run time error occurs A stop event executes the action function specified for St opActi on Under most circumstances the action function is not gu
405. ting digital values 7 10 1 13 Index
406. tive name can be a useful way to identify and reference lines particularly for large line groups You can associate descriptive names with hardware lines using the add i ne function For example suppose you want to add 8 lines todi 0 and you want to associate the nametTri gLine with the first line added addline dio 0 out TrigLine addline dio 1 7 out Adding Lines to a Digital l O O bject Alternatively you can use the Li neName property addline dio 0 7 out dio Line 1 LineName Trigline You can now use the line name to reference the line dio TrigLine Direction in Example Adding Lines for National Instruments Hardware This example illustrates various ways you can add lines toa digital I O object associated with a National Instruments AT MIO 16DE 10 board This board is a multiport device whose characteristics are described in Line and Port Characteristics on page 7 5 To add eight input lines todi o from port O addline dio 0 7 in To add four input lines and four output lines todi o from port O addline dio 0 7 in in in in out out out out Suppose you want to add the first line from port O and port 2 configured for input and the second linefrom the same ports configured for output There are three ways to do this The first way requires only one call toadd i ne since it uses the hardware line Ds and not the port I Ds addline dio 0 1 8 9 in out in ou
407. to usage In Functions Listed Alphabetically on page 9 8 the functions are described in detail Getting Command Line Function Help To get command line function help you should use thedaghel p function For example to get help for theaddchannel function type daghel p addchannel Alternatively you can use the he p command help addchannel However the Data Acquisition Toolbox provides overloaded versions of several MATLAB functions That is it provides toolbox specific implementations of these functions using the same function name To get command line help for an overloaded toolbox function using thehe p command you must supply one of two possible class directories to hel p help daqdevice function name help daqchild function_name Note that the same help information is returned regardless of the class directory specified For example the Data Acquisition Toolbox provides an overloaded version of thedel ete function To obtain help for the MATLAB version of this function type help delete O verview Y ou can determine if a function is overloaded by examining the last section of the help For del et e the help contains the following overloaded versions not all are shown Overloaded methods help char delete m help scribehandle delete m help scribehgobj delete m help daqdevice delete m help daqchild delete m So to obtain help on the toolbox version of this function type help daqdevice delete
408. tored in EventLog Note Unless a run time error occurs Event Log records a start event trigger event and stop event for each data acquisition session The Data field values are described below The AbsTime Field AbsTi me is used by the run time error start stop and trigger events to indicate the absolute time the event occurred The absolute time is returned using MATLAB sclock format day month year hour minute second The Channel Field Channel is used by the input overrange event and the trigger event For the input overrange event Channel indicates the index number of the input channel that experienced an overrange signal F or the trigger event Channel indicates the index number for each input channel serving as a trigger source The OverRange Field Over Range is used by the input overrange event and can be On or Of f 1f Over Range isOn then theinput channel experienced an overrange signal If Over Range isOff then the input channel no longer experienced an overrange signal The RelSample Field Re Sampl e is used by all events stored in Event Log to indicate the sample number that was acquired when the event occurred Rel Sampl e is O for the start event and for the first trigger event regardless of the trigger type Rel Sampl e isNaN for any event that occurs before the first trigger executes The String Field String iS used by the run time error event to store the descriptive message that is generated when
409. tputRange Purpose Description Characteristics Values Example 10 56 Specify the range of the analog output hardware subsystem Out put Range is a two element vector that specifies the range of voltages that can be output by the analog output AO subsystem You should configure Out put Range sothat the maximum dynamic range of your hardwareis utilized For many devices the output range is expressed in terms of the gain and polarity AO subsystems have a finite number of Out put Range values that you can set If an output range is specified but does not match a valid range then the next highest supported range is automatically selected by the engine If Out put Range exceeds the range of valid values then an error is returned Use the daqhwi nf o function to return the output ranges supported by your board Since the engine can set the output range toa value that differs from the val ue you specify you should return the actual output range for each channel using the get function or the device object display summary Alternatively you can use theset verify function which sets the Out put Range value and then returns the actual value that is set Usage AO Channel Access Read write Data type Two element vector of doubles Read only Yes when running The default value is determined by the hardware driver Create the analog output object ao for a National Instruments board and add two hardware channels to it ao
410. tructure array 9 59 getdata See Also 9 60 The three events returned are the start event the trigger event and the stop event To return specific event information about the stop event you must access the Type and Data fields EventType events 3 Type EventData events 3 Data Functions flushdata getsample peekdata Properties DataMissedAction EventLog SamplesAvailable SamplesPerTrigger Ti meout getsample Purpose Syntax Arguments Description Remarks Example See Also Immediately acquire one sample sample getsampl e obj obj An analog input object sample A row vector containing one sample for each channel contained by obj sample getsample obj immediately returns a row vector containing one sample for each channel contained by obj Usinggetsampl e is a good way to test your analog input configuration Additionally e getsample does not store samples in or extract samples from the data acquisition engine e You can executegetsampl e at any time after channels have been added to obj e Except for sound cards you can useget sampl e onan analog input object that is not running Runni ng is Of f For sound cards the device object must be running Create the analog input object ai and add eight channels to it al analoginput nidaq 1 ch addchannel ai 0 7 The following command returns one sample for each channel sample getsample ai Fun
411. ts are recorded in the order in which they occur The first Event Log entry reflects the first event recorded the second Event Log entry reflects the second event recorded and so on The event types recorded in Event Log for analog output objects as well as the values for theType and Data fields are given below Table 6 10 Analog Output Event Information Stored in EventLog Event Type Type Field Value Data Field Value Run time error Error Abs Ti me Rel Sample String Start Start AbsTi me Rel Sample Stop Stop AbsTi me Rel Sample Trigger Trigger AbsTi me Rel Sample 6 29 6 Analog O utput 6 30 Samples output events and timer events are not stored in EventLog Note Unless a run time error occurs Event Log records a start event a trigger event and stop event for each data acquisition session TheData field values are described below The AbsTime Field AbsTi me is used by all analog output events stored in EventLog toindicate the absolute time the event occurred The absolute time is returned using MATLAB sc lock format day month year hour minute second The RelSample Field Re Sampl e is used by all events stored in Event Log to indicate the sample number that was output when the event occurred Rel Sampl e is O for the start event and for the first trigger event regardless of the trigger type Rel Sampl e isNaN for any event that occurs before the trigger executes The String Field String is used
412. ty get ai BufferingConfig ans 1024 30 Y ou return the memory resources with the da q me m function daqmem ai ans UsedBytes 122880 MaxBytes 18011136 TheUsedBytes field tells you how much memory is currently used by ai while theMaxBytes field tells you the maximum memory that ai can use to store acquired data Note that the value returned for MaxByt es depends on the total available computer memory and may be different for your platform Y ou can verify theUsedBytes value with the formula given in the previous section However you must first find the size in bytes of each sample using thedaqhwi nfo function hwinfo daqhwinfo ai hwi nfo NativeDataType ans int16 The value of the Nati veDat aType field tells you that each sample requires two bytes Therefore the initial allocated memory is 122 880 bytes However if you want to keep all the acquired data in memory then 176 400 bytes arerequired Example Managing Memory Resources The Data Acquisition Toolbox will accommodate this memory requirement by dynamically increasing the number of data blocks after you start ai start ai After all the data is acquired you can examine the final number of data blocks used by ai ai BufferingConfig ans 1024 44 The final total memory used is daqmem ai ans UsedBytes 180224 MaxBytes 18011136 Note that this was more than enough memory to store all the acquired data B Managing Your Memo
413. ty string See Also Properties EventLog Sampl esAcquiredActionCount TimerAction 10 67 SamplesAcquiredActionCount Purpose Description Characteristics Values See Also 10 68 Specify the number of samples to acquire for each channel group member before a samples acquired event is generated A samples acquired event is generated immediately after the number of samples specified by Sampl esAcquiredActi onCount is acquired for each channel group member This event executes the action function specified by the Sampl esAcquiredActi on property Usage Al Common Access Read write Data type Double Read only Yes when running The default value is 1024 Properties SamplesAcquiredAction SamplesAvailable Purpose Description Characteristics Values See Also ndicate the number of samples available per channel in the engine For analog input Al objects Samp es Avai able indicates the number of samples that can be extracted from the engine for each channel group member with theget data function For analog output AO objects Sampl es Avail able indicates the number of samples that have been queued with the put data function and can be sent output to each channel group member After data has been extracted Al or output AO theSamp es Avail able value is reduced by the appropriate number of samples For Al objects Sampl esAvail able is reset to zero after ast art function is issued For
414. ty values are given by a predefined list the default value is usually indicated by curly braces Default values for some properties are calculated by the data acquisition engine while others are determined by the hardware driver If there are device specific values they are listed separately e An example using the property e Related properties and functions BufferingConfig Purpose Description Characteristics Specify the per channel allocated memory Buf feringConfig is atwo element vector that specifies the per channel allocated memory The first element of the vector specifies the block size while the second element of the vector specifies the number of blocks The total allocated memory in bytes is given by block size number of blocks number of channels native data type Y ou can determine the native data type with daqhwi nfo Y ou can allocate memory automatically or manually IfBufferingMode isAuto theBufferingConfi y values are automatically set by the engine If BufferingMode iSManual then you must manually set theBufferingConfig values If you change the Buf f eri ngConfig values BufferingMode is automatically set to Manual When memory is automatically allocated by the engine the block size value depends on the sampling rate and is typically a binary number The number of blocks is initially set toa value of 30 but can dynamically increase to accommodate the memory requirements In most cases t
415. ual Trigger HwOn property toTrigger forai set ai ao TriggerType Manual set ai Manual TriggerHwOn Trigger Configureai for continuous acquisition call the action function qmoredata whenever 1000 samples are output and call dagaction whenai andao stop running set ai SamplesPerTrigger inf set ao SamplesOutputAction qmoredata ai set ao SamplesOutputActionCount 1000 set ai ao StopAction daqaction As shown below the action function gmor edat a extracts data from the engine and then queues it for output function qmoredata obj event ai data getdata ai 1000 putdata obj data 6 37 6 Analog O utput 6 38 Queue data in the engine start the device objects and execute the manual triggers data zeros 4000 1 putdata ao data start ai ao trigger ai ao Note Device objects cannot execute simultaneously unless you use an external hardware trigger Y ou can determine the starting time for each device object with the InitialTriggerTi me property The difference in seconds between the starting times for ai andao is aitime ai InitialTriggerTime aotime ao InitialTriggerTi me delta abs aotime aitime sprintf d delta 6 ans 2 288818e 005 Note that this number depends on the specific platform you are using To stop both device objects stop ai ao The output from dagaction is shown below Stop event occurred at 13 00 25 for the object wins
416. uit your specific application needs If you want detailed information about outputting data refer to Chapter 6 Analog Output 1 Create a device object Createthe analog output object ao for a sound card ao analogoutput winsound 2 Add channels Add two hardware channels to ao addchannel ao 1 2 3 Configure property values Configure the sampling rate to 44 1 kHz for each channel set ao SampleRate 44100 2 9 2 G etting Started with the Data Acquisition Toolbox 2 10 4 Output data Create 1 second of output data and queue the data in the engine for eventual output to the analog output subsystem You must queue one column of data for each hardware channel added data sin linspace 0 2 pi 44100 putdata ao data data Start the output When all the data is output ao automatically stops executing start ao Block the MATLAB command line until ao stops running while strcmp ao Running On end 5 Clean up When you no longer need ao you should remove it from memory and from the MATLAB workspace del ete ao clear ao Reading and Writing Digital Values If you have a supported National Instruments board with at least eight digital I O lines you can run the following example which outputs digital values and then reads back those values You should modify this example to suit your specific application needs If you want detailed information about reading and writing digital v
417. unction syntax All valid input argument and output argument combinations are shown In some cases an ellipsis is used for the input arguments This means that all preceding input argument combinations are valid for the specified output argument s e A description of each argument e A description of the function e Additional remarks about usage e An example of usage e Related functions or properties 9 8 addchannel Purpose Syntax Arguments Description Add hardware channels to an analog input or analog output object chans addchannel obj hwch chans addchannel obj hwch index chans addchannel obj hwch names chans addchannel obj hwch index names obj An analog input or analog output object hwch Specifies the numeric IDs of the hardware channels added to the device object Any MATLAB vector syntax can be used index The MATLAB indices to associate with the hardware channels Any MATLAB vector syntax can be used provided the vector elements are monotonically increasing names A descriptive channel name or cell array of descriptive channel names chans A column vector of channels with the same length as hwch chans addchannel obj hwch adds the hardware channels specified by hwch tothe device object obj The MATLAB indices associated with the added channels are assigned automatically chans is a column vector of channels chans addchannel obj hwch index adds th
418. until astop function is issued or an error occurs You can quickly evaluate how many triggers have executed by examining the Tri ggersExecuted property or by invoking the display summary for the device object The display summary is invoked by typing the device object name at the MATLAB command line Usage Al Common Access Read write Data type Double Read only Yes when running The default value is zero Functions disp stop Properties TriggersExecuted TriggerType TriggersEx ecuted Purpose Description Characteristics Values Example See Also ndicate the number of triggers that execute You can find out how many triggers executed by returning the value of Tri ggersExecuted The trigger number for each trigger executed is also recorded by theData Trigger field of theEvent Log property Usage Al AO Common Access Read only Data type Double Read only N A when running The default value is zero Create the analog input object ai and add one channel toit al analoginput winsound ch addchannel ai 1 Configure ai to acquire 40 000 samples with five triggers using the default sampling rate of 8000 Hz set ai TriggerRepeat 4 start ai TriggersExecuted returns the number of triggers executed ai TriggersExecuted ans 5 Properties EventLog 10 93 TriggerType Purpose Description Characteristics Values 10 94 Specify the type of trigger to execute Tr
419. ur units range or sensor range values are asymmetric then you must also include the appropriate offset in the formula The A D value is constrained by the nput Range property which reflects the gain and polarity of your hardware channels and is usually returned as a voltage value You should choose an input range that utilizes the maximum dynamic range of your A D subsystem The best input range is the one that most closely encompasses the expected sensor range If the sensor signal is larger than the input range then the hardware will usually clip saturate the signal The units range is given by theUni ts Range property while the sensor rangeis given by theSensor Range property Uni ts Range is specified as a voltage value whileSensor Range is specified as an engineering unit such as Newtons or g s 1 g 9 80 m s s These property values control the scaling of data when it is extracted from the engine with the get dat a function You can find the appropriate units range and sensor range from your sensor s specification sheet For example supposeSensorRange iS 1 1 andUnitsRange is 10 10 If an A D valueis 2 5 then the scaled value is 2 5 20 2 or 25 in the appropriate units Example Performing a Linear Conversion This example illustrates how to configure the engineering units properties for an analog input object connected to a National Instruments PCI 6024E board An accelerometer is connected to a device which is und
420. ure containing property name property value pairs and Hw nf o is a structure containing hardware information The entire event log is returned to daqi nfo Obj nfo EventLlog 9 40 daqread Remarks Example daginfo daqread file info returns the structuredaqi nf o which contains two fields Obj nfo and Hwl nf o 0bj I nf o is a structure containing property name property value pairs and Hwi nf o is a structure containing hardware information The entire event log is returned to daqi nfo Obj nfo EventLog More About daq Files e Theformat used by da qr ead to return data relative time absolute time and event information is identical to the format used by the get dat a function If data from multiple triggers is read then the size of the resulting data array is increased by the number of triggers issued since each trigger is separated by a NaN Obj nfo EventLog always contains the entire event log regardless of the value specified by Sampl es Ti me or Triggers e Data Acquisition Toolbox da q files are created by specifying a value for the LogFil eName property or accepting the default value and configuring the Loggi ngMode property toDisk or Di sk8Memor y Suppose you configure the analog input object ai for a National Instruments board as shown below The object acquires one second of data for four channels and saves the data to the output file data daq ai analoginput nidaq 1 chans a
421. urned using MATLAB scl ock format year month day hour minute seconds For example the absolute time of the first trigger event for the preceding example is abstime ai InitialTriggerTime abstime 1 0e 003 1 9990 0 0040 0 0170 0 0100 0 0220 0 0041 Toconvert thec ock vector toa more convenient form you can usethes printf function t fix abstime sprintf d d d t 4 t 5 t 6 ans 10 22 4 You can also use thes howdaqevents function to return the absolute time of each trigger event For more information about trigger events refer to Recording and Retrieving Event Information on page 5 49 Device Specific Hardware Triggers Many data acquisition devices possess the ability to accept a hardware trigger Hardware triggers are processed directly by the hardware and can be either a digital signal or an analog signal Hardwaretriggers are often used when speed is required since a hardware device can process an input signal much faster than software The device specific hardware triggers are presented to you as additional property values Hardware triggers for National Instruments ComputerBoards and Agilent Technologies devices are discussed below and in Chapter 10 Base Property Reference Note that the available hardware trigger support depends on the board you are using Refer to your hardware documentation for detailed information about its triggering capabilities 5 37 5 Doing More with An
422. ut triggers are given below Table 6 7 Analog Output Trigger Properties Property Name Description Initial TriggerTime Indicate the absolute time of the first trigger TriggerAction Specify the M file action function to execute when a trigger occurs TriggersExecuted Indicate the number of triggers that execute TriggerType Specify the type of trigger to execute Except for Tri gger Acti on thesetrigger related properties are discussed in the following sections Tri ggerActi on is discussed in Configuring Events and Actions on page 6 27 6 21 6 Analog O utput 6 22 Defining a Trigger Trigger Types Defining a trigger for an analog output object involves specifying the trigger type with theTri ggerType property You can think of the trigger type as the source of the trigger The analog output Tri gger Type values are given below Table 6 8 Analog Output TriggerType Property Values TriggerType Value Description mmedi ate The trigger occurs just after you issue thest art function Manual The trigger occurs just after you manually issue the trigger function Trigger types can be grouped into two main categories e Device independent triggers e Device specific hardware triggers The trigger types shown above are device independent triggers since they are available for all supported hardware F or these trigger types the action that initiates the trigger event involves issuing a tool
423. utomatically and can usually be manually changed using a vendor supplied device configuration utility National Instruments refers to this number as the device number digitalio There are two ways you can determine the D for a particular device e Typedaqhwinfo adaptor e Execute the vendor supplied device configuration utility Example To create a digital I O object for a National Instruments device defined as device number 1 DIO digitalio nidaq 1 See Also Functions addline daqhwi nfo Properties Name 9 51 disp Purpose Syntax Arguments Description Remarks Example 9 52 Display summary information for device objects channels or lines disp obj disp obj Channel index disp obj Line index obj A device object obj Channel index Oneor more channels contained by obj obj Line index One or more lines contained by obj disp obj displays summary information for the specified device object obj and any channels or lines contained by obj Typingobj at the command line produces the same summary information disp obj Channel index displays summary information for the specified channels contained by obj Typingobj Channel index at the command line produces the same summary information disp obj Line index displays summary information for the specified lines contained by obj Typingobj Li ne index at the command line produces the same summary information You
424. valid values then an error is returned Usethedaghwi nf o function to return the input ranges supported by your board Since the engine can set the input range to a value that differs from the value you specify you should return the actual input range for each channel using theget function or the device object display summary Alternatively you can usetheset verify function which sets the nput Range value and then returns the actual value that is set Note If your hardware supports a channel gain list then you can configure nput Range for individual channels Otherwise nput Range must have the same value for all channels contained by the analog input object You should use nput Range in conjunction with the Sensor Range property These two properties should be configured such that the maximum precision is obtained and the full dynamic range of the sensor signal is covered 10 39 InputRange Characteristics Values Example See Also 10 40 Usage Al Channel Access Read write Data type Two element vector of doubles Read only Yes when running The default value is supplied by the hardware driver Create the analog input object ai for a National Instruments board and add two hardware channels to it al analoginput nidaq 1 addchannel ai 0 1 You can return theinput ranges supported by the board with the nput Ranges field ofthedaqhwi nfo function out daghwi nf o ai out I nput Ranges
425. ve Balance volume control E Volume Control BEI Options Help Volume Control CD Wave Microphone Line Balance Balance Balance Balance Balance Ho o 0 eka ofa 9 59 Volume Volume Volume Volume Volume T Mute all T Mute T Mute FT Mute Mute Advanced Advanced AudioPCI Mixer A 13 A Troubleshooting Your Hardware If the CD microphone or Wave Output controls do not appear in the Volume Control panel you must modify the playback properties by selecting Properties from the Options menu The Properties dialog box is shown below for playback devices Select the appropriate device check box to enable playback Properties i Lx Mixer device peman Adjust volume for Playback C Recording Gther z Show the following volume controls Y Volume Control ACD Wave Synthesizer wi Cancel To check if the CD and microphone are enabled for recording select the Recording radio button in the Properties dialog box and then select the appropriate device check box to enable recording The Properties dialog box is shown below for recording devices Properties ixi Mixer device AudioPCI Mixer Adjust volume for C Playback Recording Other z Show the following volume controls CD Microphone Line Auxiliary RK RRK X Po Cancel Troubleshooting Sound
426. ved the array x ail ail ai2 only ai 1 andai2 arecreated in the engine and x 1 will equal x 2 Values for read only properties are restored to their default values upon loading For example theE vent Log property is restored to an empty vector Usethepropinfo function to determine if a property is read only Values for theBuf f eri ngConf i g property when theBufferingMode property isset toAuto andtheMaxSamp esQueued property may not be restored tothe same value since both these property values are based on available memory Note oad is not used to read in acquired data that has been saved to a log file You should use the daqr ead function for this purpose If you usethehel p command to display the M file help for oad then you must supply the pathname shown below help daq private load This exampleillustrates the behavior of oad when the loaded device object has properties that differ from the workspace object ai analoginput winsound addchannel ai 1 2 save al ai SampleRate 10000 load ai Warning Loaded object has updated property values Functions dagread propinfo save makenames Purpose Syntax Arguments Description Remarks Example See Also Generate a list of descriptive channel or line names names makenames prefix index prefix A string that constitutes the first part of the name index Numbers appended to the end of prefix any MATLAB vector syntax can be
427. vent Al object 5 48 AO object 6 28 StopAction Al object 5 48 AO object 6 28 synchronizing triggers 10 49 T third party adaptors A 19 time absolute 5 19 initial trigger 5 19 relative 5 18 Timeout 5 31 timer event Al object 5 48 Index AO object 6 28 DIO object 7 15 Ti mer Action Al object 5 48 AO object 6 28 DIO object 7 15 Ti mer Peri od Al object 5 48 AO object 6 28 DIO object 7 15 toolbox components data acquisition engine 2 4 hardware driver adaptor 2 7 M files 2 3 transducer 1 4 trigger Al object 5 23 AO object 6 22 trigger event Al object 5 48 AO object 6 29 TriggerAction Al object 5 48 AO object 6 29 TriggerCondition 5 21 TriggerConditionValue 5 21 TriggerDelay 5 26 TriggerDelayUnits 5 26 triggered acquisition 5 20 triggered output 6 21 TriggerRepeat 5 30 triggers delays 5 26 postriggers 5 28 pretriggers 5 27 repeating 5 30 samples acquired for each trigger 4 12 synchronizing for Al and AO 10 49 times Al object 5 37 AO object 6 24 initial trigger 5 19 trigger conditions Al 5 21 trigger types Al object 5 21 AO object 6 22 TriggersExecuted Al object 5 36 AO object 6 24 TriggerType Al object 5 21 AO object 6 22 Type Al object 4 3 4 5 AO object 6 4 6 5 DIO object 7 3 7 5 U undersampling 1 35 Universal Library driver A 6 UserData saving values to a MAT file 8 3 V verifying property values 4 10 voice activation example 5 23 W waittilstop 9 98 wri
428. ver a predefined period of time passes Specify the period of time between timer events Specify the M file action function to execute when a trigger occurs Properties Grouped by Category Analog Output General Purpose Properties BufferingConfig BufferingMode Channel EventLog Name Out Of Dat a Mode Tag Type UserData Specify the per channel allocated memory Specify how memory is al located Contain hardware channels added to the device object Store information for specific events Specify a descriptive name for the device object Specify how the value held by the analog output subsystem s determined Specify a device object label Indicate the device object type Store data that you want to associate with a device object Channel Properties The analog output channel properties are given below Analog Output Channel Properties Channel Na me Default Channel Value HwChannel Index NativeOffset Specify a descriptive channel name Specify the value held by the analog output subsystem Specify the hardware channel ID Indicate the MATLAB index of a hardware channel Indicate the offset to use when converting data from native format to doubles 10 11 10 Base Property Reference 10 12 Analog Output Channel Properties Continued NativeScaling Indicate the scaling to use when converting data from native format to doubles Out put Range Spe
429. verts digital data to a real world analog signal This is also referred to as an AO subsystem a D A converter or a DAC The range of frequencies present in the signal being measured Y ou can also think of bandwidth as being related to the rate of change of the signal A slowly varying signal has a low bandwidth while a rapidly varying signal has a high bandwidth A property that applies to all supported hardware subsystems of a given type analog input analog output etc For example the Sampl eRat e property is supported for all analog input subsystems regardless of the vendor A component of an analog input subsystem or an analog output subsystem that you read data from or write data to Channel group Channel property Channel skew Common property Configuration Counter timer subsystem D A converter Data acquisition session Data block Device object Device specific property Differential input The collection of channels contained by an analog input object or an analog output object For scanning hardware the channel group defines the scan order A property that applies to individual channels The time gap between consecutively sampled channels Channel skew exists only for scanning hardware A property that applies to every channel or line contained by a device object The process of supplying the device object with the resources and information necessary to carry out the desired tasks Conf
430. vice object property values and event information and hardware information toa disk file by setting theLoggi ngMode property to Disk orDisk amp Memory Y ou may specify any value for LogFi le Name as long as it conforms to the MATLAB naming conventions the name cannot start with a number and cannot contain spaces If no extension is specified as part of LogFi eNa me then daq is used The default value for LogFileName islogfile daq Y ou can choose whether an output file is overwritten or if multiple log files are created with theLogToDiskMode property SettingLogToDiskMode to Overwrite causes the output file to be overwritten Setting LogToDiskMode to ndex causes new data files to be created each with an indexed name based on the value of LogFi eName Characteristics Usage Al Common Access Read write Data type String Read only Yes when running Values The default valueis ogfile daq See Also Properties Logging LoggingMode LogToDiskMode 10 45 Logging Purpose Description Characteristics Values See Also 10 46 ndicate if data is being logged to memory or to a disk file Along with theRunni ng property Loggi ng reflects the state of an analog input object Logging can beOn or Off Logging is automatically set to0n when a trigger occurs When Logging is On acquired data is being stored in memory or to a disk file Logging is automatically set to 0f f when the requested samples are acquired an
431. when TriggerType iSHwDi gital None No trigger condition is required The following trigger conditions are available when Tri ggerType is HwAnal ogChannel or HwAnal ogPin AboveHi ghLevel Bel owLowLevel InsideRegion LowHysteresis Hi ghHysteresis ComputerBoards Thetrigger occurs when the analog signal is above the specified value Thetrigger occurs when the analog signal is below the specified value Thetrigger occurs when the analog signal is inside the specified region The trigger occurs when the analog signal is less than the specified low value with hysteresis given by the specified high value The trigger occurs when the analog signal is greater than the specified high value with hysteresis given by the specified low value The following trigger conditions are available whenTriggerType iSHwDi gital GateHi gh GateLow TrigHi gh Tri glow TrigPosEdge Tri gNegEdge The trigger occurs as long as the digital signal is high The trigger occurs as long as the digital signal is low The trigger occurs when the digital signal is high The trigger occurs when the digital signal is low The trigger occurs when the positive rising edge of the digital signal is detected The trigger occurs when the negative falling edge of the digital signal is detected TriggerCondition The following trigger conditions are available when Trigger Type iSHwAnal og Tri gAbove Tri gBel ow
432. will be described in your hardware documentation and depends on the specific board you are using and your platform configuration 11 25 TransferMode Characteristics Values 11 26 Vendor National Instruments ComputerB oards Usage Al AO Common Access Read write Data type String Read only Yes when running National Instruments Interrupts Transfer data using interrupts Si ngl e DMA Transfer data using a single DMA channel Dual DMA Transfer data using two DMA channels This default property value is supplied by the driver For most devices that support data transfer via interrupts and DMA Si ngl eDMA is the default value ComputerBoards Default The transfer mode is automatically selected by the driver based on the board type and the sampling rate Interrupt Per Transfer single data points using interrupts Point DMA Transfer data using a single DMA channel Al only InterruptPer Transfer a block of data using interrupts Al only Block Troubleshooting Y our Hardware Overview Troubleshooting National Instruments Hardware What Driver Are You Using Is Your Hardware F unctioning Properly Troubleshooting ComputerBoards Hardware What Driver Are You Using Is Your Hardware F unctioning Properly 5 Troubleshooting Agilent p Hardware What Driver Are You Using Is Your Hardware F unctioning Properly Troubleshooting Sound Cards Microphone and Sound Card Types
433. wly varying signals you need only consider the minimum time for a significant change in the signal The frequency is related to the bandwidth of your measurement Bandwidth is discussed in the next section e Duration How long do you want to sample the signal for If you are storing data to memory or toa disk file then the duration determines the storage resources required The format of the stored data also affects the amount of storage space required For example data stored in ASCII format takes more space than data stored in binary format Sensor Bandwidth In areal world data acquisition experiment the physical phenomena you are measuring has expected limits For example the temperature of your automobile s cooling system varies continuously between its low limit and high limit The temperature limits as well as how rapidly the temperature varies between the limits depends on several factors including your driving habits the weather and the condition of the cooling system The expected limits may be readily approximated but there are an infinite number of possible temperatures that you can measure at a given time As explained in Quantization on page 1 20 these unlimited possibilities are mapped toa finite set of values by your data acquisition hardware The bandwidth is given by the range of frequencies present in the signal being measured You can also think of bandwidth as being related to the rate of change of the s
434. xer board muxi dx The index number of the multiplexed channel absmuxidx The absolute index number of the multiplexed channel scanidx The scanning index number of the multiplexed channel scanidx muxchanidx obj muxboard muxidx returns the scanning index number of the multiplexed channel specified by muxi dx The multiplexer mux board is specified by muxboard For each mux board muxi dx can range from 0 31 for differential inputs and 0 63 for single ended inputs mux board and muxi dx are vectors of equal length scanidx muxchanidx obj absmuxidx returns the scanning index number of the multiplexed channel specified by abs muxidx absmuxi dx is the absolute index of the channel independent of the mux board For single ended inputs the first mux board has absolute index values that range between 0 and 63 the second mux board has absolute index values that range between 64 and 127 the third mux board has absolute index values that range between 128 and 191 the fourth mux board has absolute index values that range between 192 and 255 For example the absolute index value of the second single ended channel on the fourth mux board muxboard is 4and muxi dx is 1 is 193 scani dx identifies the column number of the data returned by get data and peekdata Refer tothe AMU X 64T User Manual for more information about adding mux channels based on hardware channel IDs and the number of mux boards used mux chanidx Example
435. ximum number of decimate by two passes allowed is 16 and the maximum decimation factor is 5 216 The effective sample rate is defined as the rate at which data is received from an input or used by a source and is normally equal to 2 56 times the span If the data is oversampled then the effective sample rate is 5 12 times the span If the digital filters in a module have a cutoff that is sharper than 1 2 56 then some of the frequencies above the maximum span may contain valid alias protected data This is the case with the E1432 and E 1433 modules which havea top span filter cutoff of clock frequency 2 226 which is 23 kHz when the clock frequency is 51 2 kHz 88 3 KHz when the clock frequency is 11 21 Span Characteristics Values See Also 11 22 196 608 kHz However Span ignores the extra bandwidth sothat the maximum span is always 1 2 56 times the effective sample rate Span applies toan entire E 1432 module rather than to one of its channels After a hardware reset each module is automatically set tothe maximum legal span Vendor Agilent Technologies Usage Al AO Common Access Read write Data Type Double Read only Yes while Running Normally the maximum valid span is given by the clock frequency divided by 2 56 Valid spans are given by the maximum span divided by powers of two and the maximum span divided by five and by powers of two The value set for Span automatically updates theSamp eRate value
436. y daqmem out daqmem ai out UsedBytes ans 61440 The allocated memory is more than sufficient to store 8000 two byte samples for two channels If more memory was required then the number of blocks would dynamically grow since Buf feringMode is set toAuto Functions daqhwinfo daqmem Properties BufferingMode SampleRate SamplesPerTrigger BufferingMode Purpose Description Characteristics Values See Also Specify how memory is allocated wo wo rr wo ufferingMode can beset toAuto or Manual IfBufferingMode is set toAuto he data acquisition engine automatically allocates the required memory If uf feringMode isset toManual you must manually allocate memory with the uf feringConfig property IfBufferingMode issettoAuto andtheSampl eRat e valueis changed then the Buf feringConfig values may be recalculated by the engine Specifically you can increase decrease the block size ifSampl eRat e is increased decreased If Buf feringMode is set toAuto and you changethe Buff eri ngConfig values then Buf feri ngMode is automatically set toManual IfBufferingMode is set to Manual then you cannot set the number of blocks to a value less than three For most data acquisition applications you should set Buf f eri ngMode toAuto and have memory allocated by the engine since this minimizes the chance of an out of memory condition Usage Access Data type Read only when running Auto Manual Fun
437. y returning the value of the Tri ggersExecuted property If TriggersExecuted is0 then thetrigger event did not occur If Tri ggersExecuted is1 then the trigger event occurred Event information is also recorded by the Event Log property A convenient way to access event log information is with theshowdaqevents function For example suppose you create the analog output object ao for a sound card and add one channel toit ao is configured to output 8 000 samples using the default sampling rate of 8000 Hz ao analogoutput winsound addchannel ao 1 data sin linspace 0 1 8000 putdata ao data start ao 6 23 6 Analog O utput 6 24 TriggersExecuted returns the number of triggers executed ao TriggersExecuted ans 1 You can useshowdaqevents toreturn information for all events that occurred whileao was executing showdagevents ao 1 Start 10 43 25 0 2 Trigger 10 43 25 0 3 Stop 10 43 26 8000 For more information about recording and retrieving event information refer to Recording and Retrieving Event Information on page 6 29 When Did the Trigger Occur Y ou can return the absolute time of the trigger with the ni tial Trigger Ti me property Absolute time is returned as ac ock vector in the form year month day hour minute seconds For example the absolutetime of the trigger event for the preceding exampleis abstime ao InitialTriggerTime abstime 1 0e 003 1 9990 0 0
438. yValue reads the specified data from f i e The amount of data returned and the format of the data is specified with the properties shown below Property Name Description Samples Specify the sample range Ti me Specify the relative time range Triggers Specify the trigger range Channels Specify the channel range Channel names can be specified as a cell array Dat aFor mat Specify the data format as doubles ornative Ti meFor mat Specify the time format asvector or matrix TheSampl es Ti me andTriggers properties are mutually exclusive data time dagread returns sample time pairs ti me is a vector with the same length as data and contains the relative time for each sample Relative time is measured with respect to the first trigger that occurs data time abstime daqread returns sample time pairs and the absolute time of the first trigger abst ime is returned as acl ock vector data time abstime events dagread returns sample time pairs the absolute time of the first trigger and a log of events events contains the appropriate events based on theSampl es Ti me or Triggers value specified The entire event log is returned only if Samples Ti me orTriggers is not specified data time abstime events daginfo daqread returns sample ti me pairs the absolute time the event log andthestructuredaginfo which contains two fields Obj nfo and Hwl nfo Obj nfo is a struct
439. ying a Filename 8 7 Retrieving Logged Information o a a a a a a a 8 8 Example Logging and Retrieving Information 8 10 8 Saving and Loading the Session 8 2 Overview During a data acquisition session you may want to save your work to one or more disk files in order to document or debug your application post process data and so on The components of a data acquisition session that you can save to disk are divided into two separate parts e Device objects and their associated property values e Information associated with acquiring data with an analog input object including Acquired data Event information Device object and channel information Hardware information You can save specific components of your session to an M file using the obj 2mfil e function toa MAT file using thes ave command or toa binary daq file using the LoggingMode property Saving and Loading Device O bjects Saving and Loading Device Objects You can save a device object to disk using two possible formats e Asan M file using theobj 2mf i e function e As a MAT file using thes ave command For analog input objects you can also save acquired data hardware information and so on toa log file Refer to Logging Information to Disk on page 8 6 for more information Saving Device Objects to an M File Y ou can save a device object to an M file using theo bj 2mf i e function obj 2mfile provides
440. yntax Arguments Description Remarks 9 30 Display help for device objects constructors adaptors functions and properties daghel p out daghel p name out daghel p obj out daghel p obj name name A device object constructor adaptor function or property name obj A device object out Contains the specified help text daqhel p displays a complete listing of Data Acquisition Toolbox constructors and functions along with a brief description of each ut daqhelp name returns help for the device object constructor daptor function or property specified by na me The help text is returned to out o e o ut daqhelp obj returns a complete listing of functions and properties for he device object obj toout Help for obj s constructor is also displayed t out daghelp obj name returns help for name for the specified device object obj toout name can bea constructor adaptor property or function name More About Displaying Help e When displaying property help the names in the See Also section that contain all upper case letters are function names The names that contain a mixture of upper and lower case letters are property names e When displaying function help the See Also section contains only function names daghelp Example See Also Rules for Specifying Names For thedaghel p name syntax e Ifname is the name of a device object constructor a compl
Download Pdf Manuals
Related Search
Related Contents
Manual de Instalação e uso do Produto UPS WD Elements Play Multimedia Drive User Manual Philips Stereo audio cable SWA2724W Running a small call-center with QueueMetrics and Trixbox SU_PS3_MAN INT_up - Support Copyright © All rights reserved.
Failed to retrieve file