Analog output digital start trigger c api

Hi, I am attempting to start analog output based off a digital trigger (either PFIO, or a PXI line)  I can do this easy in LabVIEW.  However with the C API (through Python wrappers), the problem isthat when I call DAQmxBaseWriteAnalogF64, the write will always timeout as the acquisition has not been triggered.   However, I cannot call this after the trigger occurs, as obviously that will be too late.
I cannot find any C API examples where analog output is triggered off a digital trigger.  I can find them for analog input, but that is fundamentally different as you can performan read anytime after the trigger occurs.
Python code as follows (the functions are equivalent ot C API, though you do not need ot pass the task handle as it maintained as part of the Task object)
# create analog output task
analog_output = Task()
analog_output.CreateAOVoltageChan("Dev1/ao0","",-10.0,10.0, DAQmx_Val_Volts, None)
analog_output.CfgSampClkTiming("",outputRate, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, numSamples)
analog_output.CfgDigEdgeStartTrig("/Dev1/PFI0", DAQmx_Val_Rising)
analog_output.StartTask()
analog_output.WriteAnalogF64(numSampsPerChan=numSamples, autoStart=False,timeout=1.0, dataLayout=DAQmx_Val_GroupByChannel, writeArray=data, reserved=None, sampsPerChanWritten=byref(samplesWritten))
print("Analog output: Wrote %d samples" % samplesWritten.value)
# create digital trigger
dig_out = Task()
dig_out.CreateDOChan("Dev1/port0", "", DAQmx_Val_ChanForAllLines)
# create digital trigger function
highSamples = 1000
numpts = 3 * highSamples
doData = np.zeros((numpts,), dtype=np.uint32)
doData[highSamples:2*highSamples] = 2**32 - 1
# send digital trigger
doSamplesWritten = c_int32()
dig_out.WriteDigitalU32(numSampsPerChan=numpts, autoStart=True, timeout=1.0, dataLayout=DAQmx_Val_GroupByChannel, writeArray=doData, reserved=None, sampsPerChanWritten=byref(doSamplesWritten))
print("Digital output: Wrote %d samples" % doSamplesWritten.value)
 

Hi PatrickR,
You can review some of the text based NI DAQmx (ANSI C) code examples on generating an analog output using a digital start trigger. If you included/checked text-based support dusing your NI DAQmx driver installation, you can navigate to Windows Start>All Programs>National Instruments>NI DAQ>Teaxt-Based Code Support>ANSI C Examples>Analog Out>Generate Voltage>Mult Volt Updates-Int Clk-Dig Start. If you have any questions/concerns regarding the NI hardware.

Similar Messages

  • Digital start trigger and high speed camera

    Is there any particular option or way available in LabVIEW to initiate the data acquisition and high speed camera using a digital start trigger? If yes, shall I create a task for high speed camera and then synchronize it with the other tasks?
    Kind Regards, 

    Hi Helen19411,
    The way to trigger data acquisition in LabVIEW is to use the 'DAQmx Start Trigger VI'. To set this up I recommend taking a look at this example: 
    http://www.ni.com/example/25282/en/
    Without any information about the high speed camera you are using, I can't give much advice. If the device is viewable in MAX then you may be able to create a task, and so long as you synchronise both channels in your code, the digital trigger should activate both events.
    Kind Regards,
    TomS
    Applications Engineer
    National Instruments

  • Producer consumer with analog and digital inputs and outputs

    Hi everyone,
    I am working on a control system program for some practical test work. Currently I am working on the data acuisition component of the Labview program. My architecture is produced-consumer loops with a que. My system will have analog inputs, analog outputs, digital inputs and digital outputs. It's not a time critical sytem, but I would like all of the data acquisition to be synchronised. I have attached my program as it is at the moment. I am having trouble getting all of the data into the que since I have two data types. Also, I'm not sure if i've synchronised the four read/write sequences correctly. I would greatly appreciate if somebody could take a look at my program and give me some advice. Thanks in advance.
    Solved!
    Go to Solution.
    Attachments:
    control_v2_DAQ loop.vi ‏46 KB

    Robert, the specific error that I get is:
    Error -200462 occurred at DAQmx Start Task.vi:6
    Possible reason(s):
    Generation cannot be started because the output buffer is empty. 
    Write data before starting a buffered generation. The following actions can empty the buffer: changing the size of the buffer, unreserving a task, setting the Regeneration Mode property, changing the Sample Mode, or configuring retriggering.
    Task Name: Heater testing lab digital outputs
    This error occurs at the 'DAQmx write.vi' function. I just want to sent one sample per second, for each channel. I would like the producer and consumer loops to each run once every second.
    I have attached part of my code with just the data acquisition and writing. Any help would be greatly appreciated.
    Attachments:
    control_v2_ML_simple.vi ‏83 KB

  • Using a Counter as a start trigger to one or more tasks

    I am using the NI USB-6251. I want to configure a counter (e.g. Dev1/ctr0) at a user-specified frequency and the rising edge on this counter should act as a start trigger for an analog input task and a digital output task. 
    I've tried to do this by creating a task for the counter:
    integStartTriggerTask.COChannels.CreatePulseChanne​lFrequency(
    "Dev1/ctr0",
    "Integration Start Trigger",
    COPulseFrequencyUnits.Hertz,
    COPulseIdleState.Low,
    0,
    integFreqHz,
    0.5);
    and then connecting this to the StartTrigger for the analog input task:
    analogReadTask.Triggers.StartTrigger.ConfigureDigi​talEdgeTrigger("Dev1/ctr0", DigitalEdgeStartTriggerEdge.Rising);
    However running this gives the error: 
    Source terminal to be routed could not be found on the device.
    Make sure the terminal name is valid for the specified device. Refer to Measurement & Automation Explorer for valid terminal names.
    Property: NationalInstruments.DAQmx.DigitalEdgeStartTrigger.​Source
    Property: NationalInstruments.DAQmx.DigitalEdgeStartTrigger.​Edge
    Source Device: Dev1
    Source Terminal: Dev1/ctr0
    Task Name: analogReadTask
    I have also tried "Dev1/ctr0/StartTrigger" instead of "Dev1/ctr0". What am I doing incorrectly? Thanks.

    Hi zkhan.cimtec,
    To use a digital trigger for your start task you need to use a PFI line to read a signal that is coming in. You are setting up a task that outputs a start trigger on your counter line, but you can't read off that same line to start the task since that line is already configured for output. An example of how to setup a start trigger coming into a PFI line can be found in the examples here:
    <National Instruments Public>\NI-DAQ\Examples\DAQmx ANSI C\Analog In\Measure Voltage\Cont Acq-Ext Clk-Dig Start
    Hope this helps,
    Kevin

  • Synchronizing analog and digital i/o

    We're using LabView 6.0 and a PCI-MIO-16E-4 to run our electrophysiology experiments, and have a moderately tricky set of requirements.
    What we have so far: four analog inputs and two analog outputs to monitor and control two recording electrodes. We need tight synchronization (within << 1 msec) between input and output so that we can properly correlate the timing of responses with the timing of stimuli during each presentation (which are no more than a few seconds long). We do this by using the Clock Config AIs to have our output side set the scan clock (via the AO update signal through PFI 5) and the input side use that scan clock. This all works and we're happy with it.
    What we need: we'd like to independently control at least 6 (preferably more) stimulator devices. The stimulators look for TTL triggers, so in principle we could use the DIO ports to send those trigger events. The trouble is timing: we want the digital output to be tightly synchronized (again << 1 msec) with the analog i/o and to be able to specify the timing of those events to within 100 usec or so. I've put together a very dumb VI that takes as input an array of (bit pattern,time) pairs, then uses a While loop and Wait to manage that event list and Write to Digital Port to generate the trigger events. Since Wait is only 1 msec precision, and since we don't have a good way to synchronize with the analog i/o, we've got jitter in the trigger events of about 1 msec, which is too big.
    One solution to the Wait resolution problem might be pattern i/o, but our board apparently doesn't do that. I have vague ideas about synchronizing the start of the digital and analog by setting the analog output to start on a trigger and having the digital side write that trigger value to start everyone, but in practice I haven't got that working yet. (A possibly related problem: though our scan clock is supposedly running through PFI5, if I hook an oscilliscope to that terminal on our BNC-2090, I don't see anything. I'm probably doing something stupid. Can anyone spot it?)
    I'm new to LabView (though an experienced C/C++ programmer) and thus would greatly appreciate any advice or examples people could provide.
    Thanks much,
    Kevin

    You are going to need some additional hardware to fully implement your problem. An interim approach would be to digitize the digital lines along with the analog data so that you at least have a corrolation of your existing data. The more complete solution is to use either a pattern generation board from NI or the DIO-64 board from our company. www.viewpointusa.com. With this board, you can "schedule" a digital pattern at a specific clock tick. resolutions to better than a microsecond are possible. The clock tick could come from the same clock that your are using. The reason your scope may not have seen the clock signal on your current setup is that the pulse is VERY short. your scope settings may not have been set to pick it up.
    Stu McFarlane
    Viewpoint Systems, Inc.

  • Using the same wire for positive edge start trigger and negative edge stop trigger for 6533

    I would produce a start trigger for an external data source to start them.
    Emediatly after this starttrigger this source produces a trigger Signal.
    I would like to use this trigger Signal as an extern trigger which should provide some functions:
    1. on the positive edge of the Signal some pattern should read in with an external clock.
    2. on the negative edge of the trigger signal this process should stop.
    I would do this with CVI

    Hey Schicki,
    I have included two links below that should help you with your application. The first one is setup to perform digital pattern I/O with an external clock in CVI. The second shows how to incorporate start/stop triggers in digital pattern I/O operations. You should be able to combine parts of these two programs to complete your application.
    NI 6534 Double-Buffered Pattern Generation, External Clock -- CVI
    http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=B45EACE3E7FD56A4E034080020E74861&p_node=DZ52321&p_source=External
    Output Digital Data from a Buffer to a Group of Two Digital Ports Upon a Digital Start Trigger
    http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=B45EACE3EA4556A4E034080020E74861&p_node=DZ52321&p_s
    ource=External
    I hope this helps.
    Regards,
    Todd D.
    NI Applications Engineer

  • Hardware buffered analog output single shot

    Using DAQmx and M-Series hardware i'm trying to fire a single shot analog output buffered waveform.   I need the output hardware timed.  I'm able to output a hardware buffered waveform but can't figure on how to configure it for or stop it after prescribed number of cycle runs.
    Thanks in advance.
    Solved!
    Go to Solution.

    Hi,
    You have a couple of options. You can set your timing to N
    samples and you acquisition will stop when N samples have passed. Or you can
    use a counter to control the clock of the analog output and then the counter
    can be paused whenever you can.  Before
    we go and dig into the specific details of the scheme let me suggest a couple
    excellent reading materials and let me know if they help. M Series Synchronization
    with LabVIEW and NI-DAQmx, Continuous Analog Output
    with Pause Trigger and Programmatic Grounding of Output in DAQmx, NI-DAQmx: Retriggerable
    Analog Output -- LabVIEW and M Series: Analog Trigger
    Source.
    Also don’t forget to take a look at simpler examples like: Cont
    Gen Voltage Wfm-Int Clk-Pause Trigger.vi
    I hope it helps
    Jaime Hoffiz
    National Instruments
    Product Expert
    Digital Multimeters and LCR Meters

  • What is the best way to Sync Digital Output(TTL) with Analog Output?

    I am trying to generate Analog waveform that synchronize the rising edge of a digital signal(TTL). The ttl will be used as trigger for camera. The board I have is USB-6343X. In my draft,  I used a clock as ttl so I can tune frequency easily. Could any one tell me what's the best way to accomplish such task? My draft seems working, but I hope there's more neat way. Thanks in advance for any help!
    Kind regards,
    Eric

    Hi Econg,
    You should be able to trigger your TTL output with the analog output by using the ao/StartTrigger as your trigger source on the counter task. You wouldn't have to have the extra Get Full Terminal Name.vi in your analog output task.
    Here is an example using your modified code. You will have to change the cDAQ1/ao/StartTigger to *your device*/ao/StartTrigger, but it should then trigger the counter output at the exact time when the analog output starts.

  • Read analog trigger signal gated by digital pause trigger

    Hi!
    I want to use and analog trigger together with digital pause trigger. At the same time i want to see on the scope the analog trigger signal which was gated by gate signal. Is it possible? Can i somehow wire the gated trigger to one of the outputs of the board?
    Thanks in advance.
     

     Hi Sergei_phys,
    Thank you for the forum post!
    I have a few questions about your post:
    What hardware are you using? Is it NI or 3rd party? You mention using a scope, is that a NI piece of hardware/module?
    In theory you can have a analog trigger to start the acquisition and a digital trigger to pause , but it depends of the hardware.
    Thanks,
    DanC12
     

  • PID Control - analog input, digital outputs

    Hello everyone,
    I am trying to use the PID toolkit to convert my existing feedback control system to one using PID or just PI whatever works best. Problem is that the tutorials out there discuss in detail about obtaining Analog inputs and using the PID output to control an analog output. Are there any tutorials that show how I can control my process variable which is an analog input by using the PID output to generate digital outputs?
    Basically, what I am doing is controlling the incline of my device with two digital outputs that control two solenoid valves. The angle is calculated from a calibration curve that plots distance sensor voltage with Angle. Any help would be immensely apprecitated. I want to try this out on my own before I post some vi's. Thanks!
    V
    I may not be perfect, but I'm all I got!

    That is exactly what I am doing currently. I have error bands specified around the target to make sure that it doesn't oscillate. But, under load conditions such as pulsed load conditions, the device goes out of bounds and the values trigger to correct for it. But, what I need is seemless or atleast seemless correction. Currently what I see is sudden adjustments to the incline. Please find attached what I am currently using. I am trying to get a more finer solution if at all possible.
    Note: Within 5% of the target = NO action
              Between 5% and 15% = Pulsed ACtion ( DO On for Pulse width time)
              Greater than 15% = continuous action until it reaches Pulse band
    I may not be perfect, but I'm all I got!
    Attachments:
    TDML_subElevationControl.vi ‏41 KB
    TDML_subPulsedValveFuntion.vi ‏16 KB

  • Analog start trigger for x series card gives an error?

    Hi everyone,
    I am having some trouble setting up an analog start trigger for DAQ using an x series PCIe card (6351)... Attached is my configuration... After reading the manual (http://digital.ni.com/manuals.nsf/websearch/08B4B2E1B5373B94862579BA006E6BAB), my understanding is that AFPI0 is a compatable analog trigger for the device; however, the vi will not run and I get an error... Although if I change the soruce to "Force" (which is ai0) it works..
    Also, the device document says (pg 11-8):
    "To improve trigger accuracy, do the following:
    • Use an AI channel (with a small input range) instead of APFI <0,1> as your trigger source. The DAQ device does not amplify the APFI <0, 1> signals. When using an AI channel, the NI-PGIA amplifies the AI channel signal before driving the analog trigger circuitry. If you configure the AI channel to have a small input range,"
    To me, this implies that I probably should use "Force" as the trigger soruce anyway (note that the instrunment is used to acquire data load cell data generated from human muscle contractions; so slew rates are relatively low compared to signals acquired from industrial tests).
    Could someone please comment on these issues for me?
    Regards,
    Jack
    LV2010
    Attachments:
    Untitled 1.vi ‏22 KB

    Ok... I think I have answered by own question... APFI0 needs a low impedence signal to drive the terminal... I mistakenly thought this was an internal terminal or trigger...
    So I should stick with using the first analog signal acquired in my DAQ device (e.g. ai0) as the trigger source?
    Regards,
    Jack
    LV2010

  • PXI question: four analog ouput cards to start-trigger simultaneously

    Hi all,
    Here's the situation:
    We have built a system that ouputs 24 analog signals using a PXIE-1073 chassis.  It has 5 slots:
    Slot 1:          Internal
    Slot 2:          Empty
    Slot 3:          Empty
    Slot 4 (Hybrid): PXI-6733
    Slot 5 (Hybrid): PXI-6733
    Slot 6 (Hybrid): PXI-6733
    As you can see, it has three analog output cards, which occupy all three of the hybrid slots.  And we have two empty slots. 
    Our LabVIEW code is designed to output analog signals on all three cards (at the same rate) using three DAQmx tasks which start-trigger simultaneously.  To do the triggering, we setup two of the tasks to start-trigger off of the first task (master-slaves style).  In this manner, we can get all outputs to start at the same time.  Its actually quite simple.
    My question:  I want to add another output card.  But I am fairly I can only use hybrid slots for my application.  I remember working with NI and they told me I had to use the hybrid slots to be able to get the triggers routed automatically along the backplane.  Our code actually failed (error) when we used the non-hybrid slots (I forgot the error code).
    Is there any way to add another PXI-6733 and have it trigger with the other cards?

    I can't speak to the chassis, but I'd warn you that if you want your tasks sync'ed, you'd better share a sample clock too and not just a start trigger.  The onboard clocks will have a tolerance (often ~50 ppm, dunno for your 6733's)  and their sampling instants will drift apart from one another over time.  In fact, I rarely both with triggers at all for syncing tasks & boards.  I'll usually *only* share a sample clock, and then make sure I start all the slave tasks before the master whose sample clock is being shared.
    Good luck on your real question though...
    -Kevin P

  • Analog comparison/start trigger

    Is it possible to use the analog comparison (typ under start trigger) with a continous task that I want to start immediately?  I want to take samples from the get go, but then generate the analogcomparisonevent pulse when the values leave an analog window.  The way it seems so far is that it will only work if I use that as the start trigger, but then I don't recieve samples until that trigger is reached.
    Any help is appreciated.

    Hi again Michael,
    Here's what I'd do in your case:
    1.  Set up the analog input task to be continuous.
    2.  Set up the quadrature position encoder to be hardware timed as well, but use the AI Sample Clock for the clock source.  This way, you will still have one counter left and your AI and CI tasks will be synchronized.
    3.  Set up a "dummy" Counter Output task to generate a single pulse that will be retriggerable.  You should be able to use the analog trigger from the AI channel or you can route the signal externally to the APFI line and use that to do the triggering.  You can use either the analog comparison event or the pulse generated on the Ctr1InternalOutput terminal as you are generating a retriggerable pulse anyway.  Either one should work.
    Let me know if you have questions about this.
    Regards,
    John Bongaarts
    AE Specialist - Test Products

  • Data acquisition from analog start trigger to analog stop trigger

    Hi,
    I'm trying to start and to stop a data aquisition by using an analog input trigger. I'm using NI-USB-6251. At input channel ai0 is a sin-signal connected. At input channel apfi0 is an analog trigger signal connected. I can start the trigger signal by pushing a button on my frequency generator. Here's a part of my code:
    Hi,
    ich versuche eine Messung mit einem analogen Eingangssignal zu starten und zu beenden. Ich benutze die Messkarte NI-USB-6251. An Eingang ai0 ist ein Sinus-Signal angeschlossen. An Eingang apfi0 ist der Triggereingang angeschlossen. Das Triggersignal löse ich immer per Tastendruck auf dem Funktionsgenerator aus. Hier ist ein Teil des Quellcodes:
    TaskHandle taskHandle = 0;
    int32 read;
    float64 *data;
    float64 sampleRate = 1000; //Samples per Channel per Second
    uInt64 sampsPerChan = 4000; //Samples per Channel to read
    int sumOfChan = 1;
    double triggerLevel = 2.0;
    double min = -0.2;
    double max = 0.2;
    double timeOutReadAnalog = 10.0;
    void calculate()
    DAQmxCreateTask("", &taskHandle);
    DAQmxCreateAIVoltageChan(taskHandle, "/dev1/ai0", "", DAQmx_Val_Cfg_Default, min, max, DAQmx_Val_Volts, NULL);
    DAQmxCfgSampClkTiming(taskHandle, "", sampleRate, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, sampsPerChan);
    DAQmxCfgAnlgEdgeStartTrig (taskHandle, "/dev1/apfi0", DAQmx_Val_RisingSlope, triggerLevel);
    DAQmxCfgAnlgEdgeRefTrig (taskHandle, "/dev1/apfi0", DAQmx_Val_RisingSlope, triggerLevel, 3000);
    DAQmxStartTask(taskHandle);
    if( (data=malloc(sampsPerChan*sumOfChan*sizeof(float64)))==NULL )
    MessagePopup("Error","Not enough memory");
    //set start and stop trigger
    //set breakpoint here
    DAQmxReadAnalogF64 (taskHandle, -1, timeOutReadAnalog, DAQmx_Val_GroupByChannel, data, (sampsPerChan * sumOfChan), &read, NULL);
    I've choosen the sample rate (1000/s) and the samples per channel (4000), that the aquisition needs 4 seconds to be complete. I can start the aquisition by Start-Trigger, but I think I have a problem with the function DAQmxCfgAnlgEdgeRefTrig. Actually the array will always be filled with 4000 values. I thought I can start the aquisition by triggering once and e.g. after two seconds triggering again for stopping aquisition with result of 2000 values in the array. I hope you can help me with this problem.
    Ich habe die Sample Rate (1000/s) und die Samples pro Kanal (4000) so gewählt, dass die Aufzeichnung 4 Sekunden dauert. Ich schaffe es auch die Aufzeichnung über den Trigger zu starten, jedoch funktioniert das Stoppen mit der Funktion DAQmxCfgAnlgEdgeRefTrig nicht. Aktuell ist es so, dass das Array immer mit 4000 Werten gefüllt wird.
    Ich hatte mir erhofft, dass ich durch einmalige Triggerung die Messung starten kann und beispielsweise nach zwei Sekunden erneut triggere und die Messung damit stoppe und dann nur 2000 Werte eingelesen habe.
    Ich hoffe, ihr könnt mir dabei helfen.

    Hi Martin,
    I looked over your code and noticed that you called the function without checking the returnvalue.
    Try to change the line to the following:
    First: define a new int32 value and call it for example: errorcode
    Second: The function returns a status code, wich if it fails, includes an error code so save this code in the new generated value
    errorcode = DAQmxCfgAnlgEdgeRefTrig (taskHandle, "/dev1/apfi0", DAQmx_Val_RisingSlope, triggerLevel, 3000);
    and try to run the programm and read out this value.
    If you got this value, please post it here and I will try to help you if I can.
    Regards
    Philipp

  • How to store the output of a analog to digital converter into an 2D array

    Hi
    I am doing my M.Tech Thesis in Image reconstruction and I am using labview for simulation and I want to know how to store the output of a analog to digital converter into an 2D labview array.

    nitinkajay wrote:
    I want to know how to store the output of a analog to digital converter into an 2D labview array.
    How exactly are you performing 'Analog to Digital'???
    Grabbing image using camera OR performing data acquisition using DAQ card OR some other way????
    I am not allergic to Kudos, in fact I love Kudos.
     Make your LabVIEW experience more CONVENIENT.

Maybe you are looking for

  • Read classpath from a file on dos command line

    Hi, How to supply the classpath information from a file. I have a file with my classpath and I want to run java command as below java -cp classpath.txt com.mycompany.MyTest How to supply classpath information that is in classpath.txt file to java exe

  • Help with a new install of Adobe Acrobat

    I just had to install Adober Acrobat on a new laptop, and I need to point it to all the forms I was tracking on my old laptop.  How do I go about doing this?

  • Why the db file is so big?

    hello,now i use BDB as my database; pdb->open(NULL, m_dbName, NULL, DB_QUEUE, DB_CREATE, 0); now, there have two processes , one is FEP, the other is DP FEP write 10000 datas to DB_QUEUE one second; DP read 10000 datas from DB_QUEUE one second; after

  • How do I remove unwanted (eg: Skitch) updates from the App Store?

    Skitch 1.0 is great.  Evernote bought Skitch and produced a stripped down version of Skitch and called it 2.0.  The unanimous assessment of the update is that it is a major step backwards.  I usually click 'update all' apps for my iPhone/iPad because

  • Skip lines while loading

    How can i skip the last lline while loading from a file? I dont thnk SKIP would help me, Please can someone help me to achieve this in SQL LOADER. Cheers