# Multifunction DAQ

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## NI-6008 selecting voltage range from Matlab .m file

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

Message 1 of 8
(5,183 Views)

## Re: NI-6008 selecting voltage range from Matlab .m file

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

Message 2 of 8
(5,150 Views)

## Re: NI-6008 selecting voltage range from Matlab .m file

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

Message 3 of 8
(5,136 Views)

## Re: NI-6008 selecting voltage range from Matlab .m file

@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

Message 4 of 8
(5,135 Views)

## Re: NI-6008 selecting voltage range from Matlab .m file

s = daq.createSession('ni')
ch.Range = [-1 1]

Alternatively,

s = daq.createSession('ni')

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

Wael Hemdan

MathWorks

Message 5 of 8
(5,130 Views)

## Re: NI-6008 selecting voltage range from Matlab .m file

@whemdan wrote:

s = daq.createSession('ni')
ch.Range = [-1 1]

Alternatively,

s = daq.createSession('ni')

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.

Message 6 of 8
(5,126 Views)
Solution
Accepted by Mus90

## Re: NI-6008 selecting voltage range from Matlab .m file

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.

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

Message 7 of 8
(5,121 Views)

## Re: NI-6008 selecting voltage range from Matlab .m file

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

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

Message 8 of 8
(5,108 Views)