how to write a 5v in the out put of digital port of DAC by igor?
diana
for switching on a equipment using igor pro, i need to connect it on 5 v voltage. i wanna use a 5volt digital in digital output of A NI DAQ which is connected to equipment.
i am using ''DAQmx_DIO_Write'' command in the igor but i couldn't do it correctly. how can i do it?
thanks
DAQmx_DIO_Config
?HJ
September 17, 2015 at 06:14 am - Permalink
i am writing these codes for having 5 volt at output:
•DAQmx_DIO_Config/DEV="dev1"/DIR=1/LGRP=0/RPTC=1"/dev1/port0"
•fDAQmx_DIO_Write("dev1", V_DAQmx_DIO_TaskNumber, 5)
but i want to remove 5 v or change it to 0 , and provide 5v whenevr i want. i used ;•fDAQmx_DIO_Finished("dev1",V_DAQmx_DIO_TaskNumber) but i still have 5 volt. how i can change the out put whenever i would like?
thanks
September 17, 2015 at 08:36 am - Permalink
I wonder if you really want the analog output:
fDAQmx_WriteChan("Dev1", 0, 5, -10, 10)
The "-10, 10" part must be adjusted to your particular device and needs, but that range usually works.
If you really want to turn a digital line on or off, then you may want something more like this:
fDAQmx_DIO_Write("dev1", V_DAQmx_DIO_TaskNumber, 1) // 1 to turn the line on
fDAQmx_DIO_Write("dev1", V_DAQmx_DIO_TaskNumber, 0) // 0 to turn the line off
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
September 17, 2015 at 09:58 am - Permalink
Two possibilities come to mind: (1) put a space before the quoted linespec string, and (2) look into specifying a /CLK flag.
You haven't described your NIDAQ device, and the command help file says:
Such devices use what National Instruments calls "correlated DIO", which is just their term for using a source
of pulses from somewhere else as the clock. On devices that support "correlated DIO", you are required to
use the /CLK flag to specify a clock source. That clock source could be a counter pulse train output, in which
case the clock source could be something like /CLK={"/Devname/Ctr0InternalOutput"} to use the output of
counter zero. Another possibility is to sync the DIO operation to the analog input scan or waveform output
operation using either /CLK={"/Devname/ai/sampleclock"} or /CLK={"/Devname/ao/sampleclock"}.
Yet another possibility is to use a pulse train from some external source, fed in through one of the PFI pins.
September 17, 2015 at 10:01 am - Permalink
Hi John
Thank so much, yes you are right but what i mean was the second code based on digital 0,1 . thank you for your comment.
in addition if i want to turn digital lines on or off for different lines how can i do it?. for example line 1 on, line 2 off, line 3 on an line 4 on.
sorry for asking again and thank you for your kind comments
September 17, 2015 at 01:10 pm - Permalink
There are two ways to do it. The choice depends on whether you want to control each line as an independent entity, or if you consider the lines to be all part of some larger thing. One case in which you might use the second choice is if the lines represent a number, or a setting for an instrument. The first choice might be used if each line controls a switch or valve and they need to be controlled separately.
Choice 1 (control each line independently, this is what my earlier example does):
To control port 0, line 0:
fDAQmx_DIO_Write("dev1", V_DAQmx_DIO_TaskNumber, 1) // 1 to turn the line on
fDAQmx_DIO_Write("dev1", V_DAQmx_DIO_TaskNumber, 0) // 0 to turn the line off
To control a different line, create a task for that line. For instance, for line 3:
DAQmx_DIO_Config/DEV="dev1"/DIR=1/LGRP=1 "/dev1/port0/line3"
You need to use the particular task number created for each line, so you need to store the task number. You might do it like this:
DAQmx_DIO_Config/DEV="dev1"/DIR=1/LGRP=1 "/dev1/port0/line0"
line0task = V_DAQmx_DIO_TaskNumber;
Variable/G line3task
DAQmx_DIO_Config/DEV="dev1"/DIR=1/LGRP=1 "/dev1/port0/line3"
line3task = V_DAQmx_DIO_TaskNumber;
And now, in a function that needs to set those lines to some state:
Variable on_or_off
NVAR line0task // connect to the global variable with the line 0 task number
Variable linesetting = on_or_off == 0 ? 0 : 1 // just a complicated way to get zero or one
fDAQmx_DIO_Write("dev1", line0task, linesetting) // 1 to turn the line on
end
Choice 2 (control several lines together)
For this use /LGRP=0 instead of LGRP=1
The DAQmx_DIO_Config command uses a LineSpec that specifies more than one line. To use all the lines in port 0 (usually 8 lines)
DAQmx_DIO_Config/DEV="dev1"/DIR=1/LGRP=1 "/dev1/port0"
Now the lines are represented by a bit in the setting. So line 0 is bit 0, line 1 is bit 1, etc. To set line 0, line 3 and line 4 you would use 2^0 + 2^3 + 2^4 = 1 + 8 + 16 = 25. So to control the entire port 0:
DAQmx_DIO_Config/DEV="dev1"/DIR=1/LGRP=0 "/dev1/port0"
port0task = V_DAQmx_DIO_TaskNumber
fDAQmx_DIO_Write("dev1", port0task, 25) // turns on lines 0, 3 and 4 while turning off lines 1, 2, 5, 6, and 7
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
September 17, 2015 at 02:47 pm - Permalink
Thanks very much . i was writing to do something like your first suggestion. but even the second one is really nice to understand what is happening. i would like to say a big thank you to you for your kind and complete explanation to me.
i am studying the some commands to use a NIDAQ to writing and reading some data from an external device. as you mentioned before, i can set some values to specified analog output channel by using :
fDAQmx_WriteChan
but i am a bit confused that how i can write a value and send it to my Dc supply by NIDAQ, ( regarding the creation of interface between NIDAQ and a DC supply), for example : i need to have 50v on dc supply output (which can work between 0 -100v), and i configured my minimum and maximum values for each output analog channel of NIDAQ between -10 and+10. so , what value in the analog output should be written to have 50v in dc supply. i should send 5v(out of 10) to analog output port to get 50v dc (out of 100v) from dc supply which is connected to NIDAQ?!
i would like to know the concept of this
again thank you for your help
September 18, 2015 at 02:56 am - Permalink
HJ
September 18, 2015 at 04:19 am - Permalink
HI
Thank you for your help. yes i found it and started writing codes to send some analog data and now i can see the output voltage. but for reading data i tried to use :
fDAQmx_ReadChan("dev1", 0, -10, 10, 1)
but i couldn't have any result. actually when i used wavescancontrol tools from igor from NIDAQ tools mx and select channel o for displaying, i can see all changes which i am doing but in the analog data (between 0,10).
in fact, i don't know when i am writing fDAQmx_ReadChan("dev1", 0, -10, 10, 1) in the command line nothing is happened so that i expect to have voltage value. what is the problem?
thank you
September 18, 2015 at 10:51 am - Permalink
If you really want an analogue read back (for real applications you don't -- for testing and learning it might be useful) you will have to wire AO0 to AI0.
The behavior "noting happens" is correct in this case. The function returns the read value. Unless you use the "print" command, the returned value is discarded for user functions (built-in functions generate an error).
print fDAQmx_ReadChan("dev1", 0, -10, 10, 1)
will probably print some value close to zero in the history. If you wire AI0 to AO0 (I assume Gnd is connected internally) you should be able to read back the set voltage.
PM me, if you want a small sloppy "set-level and read back a response" example (I will document it a little in this case -- sloppy: I will not put it here :-) )
HJ
September 21, 2015 at 01:01 pm - Permalink
Hello
Thank you so much for your comments. yes, i checked the output , i connected them correctly, thank you for your reminding. i can say that now i can read data from my equipment but the returned value is scaled based on min and max voltage (-10, 10), approximately the same value which i wrote and sent to it based on the channel voltage range. that's okay, now i would like to have real value in the igor. so i should write code for that and try to multiply this returned value by a factor based on scaled voltage of supply and DAQ, i am right?
September 19, 2015 at 08:51 am - Permalink
Hi John
sorry for asking frequent question, when i am trying to execute your codes and suggestions as a function, i cannot see any response. while i tried to use these codes in the command line and it works fine. but i just useed them as a function in the window procedure and then compiled them and tried to execute the function but without any result !
so i used print setLine0(0) in the command line and the response was : NAN!
what is wrong?
September 19, 2015 at 01:02 pm - Permalink
If you have professional electricians around, they are probably happy to help you with a safe version to measure the actual output voltage ("1:100 - voltage divider in a box", "insulating amplifier", etc).
Writing code could either include a constant factor, a calibration curve, or the voltage divider. If you can live with low accuracy go for the fist option. For medium accuracy use a calibrated multimeter and measure the power supply output voltage as a function of your "selection voltage" (it should be proportional; in this case you verified that the constant factor is sufficient). From this you can "make" the output proportional). Ask professionals for option 3.
I didn't go through JW's code in detail. However, the returned NaN is normal. It is the default value in case a function is returning no value (have a look at the
return
command in the help file). Only functions using "return" will return a "meaningful" value (quotes since NaN might also have a special meaning).HJ
September 19, 2015 at 04:22 pm - Permalink
HJDrescher is correct- the NaN return is because my function doesn't return anything. My apologies- I have violated my own rules and advice to many customers- always include error checking in NIDAQ Tools code!
I should also confess that my code is not checked- it is difficult for me because my only DAQ devices are on a very old XP machine that I rarely turn on. Here is an attempt at a better function:
Variable on_or_off
NVAR line0task // connect to the global variable with the line 0 task number
Variable linesetting = on_or_off == 0 ? 0 : 1 // just a complicated way to get zero or one
Variable result = fDAQmx_DIO_Write("dev1", line0task, linesetting) // 1 to turn the line on
If (result)
print "Error from fDAQmx_DIO_Write:"
print fDAQmx_ErrorString()
endif
end
My guess at why setLine0() doesn't do anything is that I failed to point out that you must run DAQmx_DIO_Config before setLine0(). I left it out of setLine0() because you must only run the DAQmx_Config operation once, record the task number you get from it, and then call fDAQmx_DIO_Write using that task number every time you need to change the digital outputs. That is the reason for the line
NVAR line0task
: it connects to a global variable called "line0task". That global variable is created by the command lines above the function definition.I threw a lot of commands and code at you with insufficient explanation. You have chosen a difficult way to learn Igor programming- including data acquisition in the problem makes everything MUCH harder!
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
September 21, 2015 at 10:03 am - Permalink
Thank you again for your continual guidance. I did something based on your help and at least now i can say that it is working . Thanks
just i would like to know that is it possible to scan data from 2 input at the same time? i wrote a code based on
DAQmx_Scan/DEV="dev1"/BKG Waves="Wave1, 1,-10,10"
but if i want to scan channel 2 like channel 1 (above code) at the same time, how can i do it? is it possible to scan 2 channels simultaneously and display the waves?
thank you in advance
October 8, 2015 at 08:17 am - Permalink
That is covered in the NIDAQ Tools MX Help help file:
DisplayHelpTopic "Analog Input"
Copy that command, paste it into Igor's command line and press Enter. The example commands there do exactly that- scanning two channels simultaneously into two waves.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
October 8, 2015 at 03:14 pm - Permalink
October 13, 2015 at 02:44 am - Permalink
Hi John
thanks for your all help to me. i am trying to send some data to NIDAQ in analog ports. i mean i want to send a sinewave to NIDAQ (and then to power supply) and finally scan the sinewave . i wrote some codes but i think something is wrong :-(
here is the codes:
Function sinnwave()
Make/B/O/N=10000 sinn
Variable x=0
For(I=0;I<10000;I=I+0.0001)
sinn[I]=5*sin(2*Pi*1*I)
fDAQmx_WriteChan("NIdevice", 0, (sinn[I]), -10, 10)
endfor
end
.................................................
scanning data
Function scan()
Make/O/N=10000 Wave1
SetScale/P x,0,0.0001, "s", Wave1
DAQmx_Scan/DEV="NIdevice" /BKG Waves="Wave1, 3/NRSE,-10,10"
Display Wave1
end
so, how can i do this purpose fro sending a sinwave data to NIDAQ for sending to external power supply and scan it again.
Thank you in advance
Diana
November 8, 2015 at 11:25 pm - Permalink
This is the most obvious part to fix first. You should be using "DAQmx_WaveformGen" to set up and start the waveform generation operation. See the Command Help file for details.
November 9, 2015 at 10:15 am - Permalink