Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

NI-6008 selecting voltage range from Matlab .m file

Solved!
Go to solution

Hi, I need to select a voltage range such as -1V to +1V from .m file in MATLAB to acquire data from NI-6008 DAQ.

I appreciate if some one send me an example code.

The system is working fine and I can successfully control sampling rate but not the Voltage range.

 

 

Regards

0 Kudos
Message 1 of 8
(4,803 Views)

Please see this discussion forum post related to your input task:
http://forums.ni.com/t5/Multifunction-DAQ/ni-daq-6008-with-matlab/td-p/2515242

0 Kudos
Message 2 of 8
(4,770 Views)

 


@Karl-G wrote:

Please see this discussion forum post related to your input task:
http://forums.ni.com/t5/Multifunction-DAQ/ni-daq-6008-with-matlab/td-p/2515242



Thanks. I will check it.

 

Best regards.

0 Kudos
Message 3 of 8
(4,756 Views)

@Karl-G wrote:

Please see this discussion forum post related to your input task:
http://forums.ni.com/t5/Multifunction-DAQ/ni-daq-6008-with-matlab/td-p/2515242


Hi Karl, it seems that non of the provided answers in the discussion solve my problem. Therefore my question is still waiting for a valid answer.

 

Many thanks for your help

 

 

 

 

0 Kudos
Message 4 of 8
(4,755 Views)

s = daq.createSession('ni')
ch = s.addAnalogInputChannel('dev1', 0, 'voltage')
ch.Range = [-1 1]

 

Alternatively,

 

s = daq.createSession('ni')
s.addAnalogInputChannel('dev1', 0, 'voltage')

s.Channels(1).Range = [-1 1]

 

Wael Hemdan

MathWorks

0 Kudos
Message 5 of 8
(4,750 Views)

@whemdan wrote:

s = daq.createSession('ni')
ch = s.addAnalogInputChannel('dev1', 0, 'voltage')
ch.Range = [-1 1]

 

Alternatively,

 

s = daq.createSession('ni')
s.addAnalogInputChannel('dev1', 0, 'voltage')

s.Channels(1).Range = [-1 1]

 

Wael Hemdan

MathWorks


Thanks Wael.

I will try the second alternative as the first one did not work.

 

Best regards to you.

 

 

 

0 Kudos
Message 6 of 8
(4,746 Views)
Solution
Accepted by topic author Mus90

Hi

 

Both alternatives are equivalent, the 2nd alternative is how to get to a channel if you had not saved it to a variable when you created it.

 

When you say it did not work, did you get an error message?

 

I just tried it on my machine with an NI USB-6008 with 4 channels, and range set to [-1 1] on one of those channels:

 

>> s = daq.createSession('ni')

s =

Data acquisition session using National Instruments hardware:
   Will run for 1 second (1000 scans) at 1000 scans/second.
   No channels have been added.
  

>> s.addAnalogInputChannel('dev2', 0:3, 'voltage')

ans =

Data acquisition session using National Instruments hardware:
   Will run for 1 second (1000 scans) at 1000 scans/second.
   Number of channels: 4
      index Type Device Channel MeasurementType      Range       Name
      ----- ---- ------ ------- --------------- ---------------- ----
      1     ai   Dev2   ai0     Voltage (Diff)  -20 to +20 Volts
      2     ai   Dev2   ai1     Voltage (Diff)  -20 to +20 Volts
      3     ai   Dev2   ai2     Voltage (Diff)  -20 to +20 Volts
      4     ai   Dev2   ai3     Voltage (Diff)  -20 to +20 Volts

 

>> s.Channels(2).Range = [-1 1]

s =

Data acquisition session using National Instruments hardware:
   Will run for 1 second (1000 scans) at 1000 scans/second.
   Number of channels: 4
      index Type Device Channel MeasurementType       Range        Name
      ----- ---- ------ ------- --------------- ------------------ ----
      1     ai   Dev2   ai0     Voltage (Diff)  -20 to +20 Volts
      2     ai   Dev2   ai1     Voltage (Diff)  -1.0 to +1.0 Volts
      3     ai   Dev2   ai2     Voltage (Diff)  -20 to +20 Volts
      4     ai   Dev2   ai3     Voltage (Diff)  -20 to +20 Volts
   
Properties, Methods, Events

>> s.inputSingleScan

ans =

   -0.0034    0.0008    0.0012    0.0059

 

Wael Hemdan

MathWorks

0 Kudos
Message 7 of 8
(4,741 Views)

@whemdan wrote:

Hi

 

Both alternatives are equivalent, the 2nd alternative is how to get to a channel if you had not saved it to a variable when you created it.

 

When you say it did not work, did you get an error message?

 

I just tried it on my machine with an NI USB-6008 with 4 channels, and range set to [-1 1] on one of those channels:

 

>> s = daq.createSession('ni')

s =

Data acquisition session using National Instruments hardware:
   Will run for 1 second (1000 scans) at 1000 scans/second.
   No channels have been added.
  

>> s.addAnalogInputChannel('dev2', 0:3, 'voltage')

ans =

Data acquisition session using National Instruments hardware:
   Will run for 1 second (1000 scans) at 1000 scans/second.
   Number of channels: 4
      index Type Device Channel MeasurementType      Range       Name
      ----- ---- ------ ------- --------------- ---------------- ----
      1     ai   Dev2   ai0     Voltage (Diff)  -20 to +20 Volts
      2     ai   Dev2   ai1     Voltage (Diff)  -20 to +20 Volts
      3     ai   Dev2   ai2     Voltage (Diff)  -20 to +20 Volts
      4     ai   Dev2   ai3     Voltage (Diff)  -20 to +20 Volts

 

>> s.Channels(2).Range = [-1 1]

s =

Data acquisition session using National Instruments hardware:
   Will run for 1 second (1000 scans) at 1000 scans/second.
   Number of channels: 4
      index Type Device Channel MeasurementType       Range        Name
      ----- ---- ------ ------- --------------- ------------------ ----
      1     ai   Dev2   ai0     Voltage (Diff)  -20 to +20 Volts
      2     ai   Dev2   ai1     Voltage (Diff)  -1.0 to +1.0 Volts
      3     ai   Dev2   ai2     Voltage (Diff)  -20 to +20 Volts
      4     ai   Dev2   ai3     Voltage (Diff)  -20 to +20 Volts
   
Properties, Methods, Events

>> s.inputSingleScan

ans =

   -0.0034    0.0008    0.0012    0.0059

 

Wael Hemdan

MathWorks


Great.

Thanks a lot Wael.

It is now perfectly working.

 

Best regards

0 Kudos
Message 8 of 8
(4,728 Views)