LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Finite analog output - digital trigger

I am writing a program that will generate an analog DC output of varying duration triggered off of a digital signal. I have modified one of the DAQmx examples to do this. The output will be 5 V for a duration, then go to 0 V. If the duration is set to under 1000 ms, it generates the voltage correctly and stops after about 1 second. However, anything at 1000 ms or above does not generate the 0 V signal when the time has elapsed.

 

When the duration is under 1000 ms, I would expect the DAQmx Is Task Done VI to be true after the time limit is complete, but it never changes to true.

 

Any ideas about what I am doing wrong?

0 Kudos
Message 1 of 13
(4,217 Views)

If you do your calculations at duration=1000, you will see that the dimension size for 5v is 1000 and the dimension size for 0v is 0.  So the DAQ output will never go to 0 for any duration equal to 1000 or 2000 or 3000, or any multiple of 1000.  This is because you are subtracting 1000 - 1000 = 0.  So when you have a multiple of 1000, you should add 1 to the 0v dimension size.  Or you could check the dimension size and add 1 if it is 0.

 

In your waiting until done loop, you don't have any wire from the task done output.  This is what you should be using to stop the loop.  Add another OR gate and wire the task done output to the Stop button and Status out.

 

- tbob

Inventor of the WORM Global
Message 2 of 13
(4,205 Views)

Thanks, that did the trick.

0 Kudos
Message 3 of 13
(4,181 Views)

I am now having trouble setting this up for retriggering. I have followed an example here. The difference is that I do not want to output a continous waveform, only a short sequence. I have attached the VI I am using. The triggering signal is a 50 Hz square wave. When I run the program, I get an output on one edge, but the rest are ignored. If I change the Clock sample mode to continuous, it does retrigger, but only very slowly (once every couple seconds). I am also concered that the "Task done?" output is reading true constantly after the first trigger.

0 Kudos
Message 4 of 13
(4,152 Views)

Is your attachement a real VI?  My company's spam filter won't let me open it.  I can open your first attachment fine.  Something is different here.  Try to attach again, using a real VI.

- tbob

Inventor of the WORM Global
0 Kudos
Message 5 of 13
(4,141 Views)

I did have the file open at the time. Here it is again.

0 Kudos
Message 6 of 13
(4,138 Views)

This is very strange.  I cannot open this file.  It gets blocked by our spam filter.  However, I can open the file in your first post.  Are you doing anything different when posting the VI?

- tbob

Inventor of the WORM Global
0 Kudos
Message 7 of 13
(4,121 Views)

Not sure but here is an image anyway.

 

18971i6003EC9A6B78C405

0 Kudos
Message 8 of 13
(4,109 Views)

@dave6k wrote:

I am now having trouble setting this up for retriggering. I have followed an example here. The difference is that I do not want to output a continous waveform, only a short sequence. I have attached the VI I am using. The triggering signal is a 50 Hz square wave. When I run the program, I get an output on one edge, but the rest are ignored. If I change the Clock sample mode to continuous, it does retrigger, but only very slowly (once every couple seconds). I am also concered that the "Task done?" output is reading true constantly after the first trigger.


There are some parameters that you have not set properly.  In the Counter Create Channel funciton, you did not wire in a frequency.  The default is 1Hz.  so that is why your retrigger is slow.  The way the counter works is that you set up a frequency for the pulse output, then set the timing for either continuous or for finite samples.  If you set for finite samples, then you also have to wire in the number of samples.  Every time the counter receives a trigger, it will output the number of samples specified at the frequency specified.  Until it is done, it will ignore any more triggers.  After it is done, it will look for the next trigger and do its output again.

 

So what are you wanting the counter to do?  How many pulses out per trigger event and at what frequency?  Are you wanting to output one pulse per trigger?  Why not use the trigger itself as an output instead of the counter?  Are you wanting to output so many pulses at a faster rate for every trigger?  Your frequency setting and number of samples should be faster than the incoming trigger.  For example, if the input trigger is 50 Hz, which is 20mS per trigger, you can send out 20 pulses at a 1KHz rate.  1KHz period is 1mS.  So 20 pulses times 1mS is 20mS.  Your period ( 1/freq) times your number of samples cannot be greater than the incoming trigger period.  In fact it should be less so that you don't miss a trigger.  With the default values, the counter will output 1000 pulses at 1 pulse per second.  You need to change these settings.  I hope this is clear.

 

I noticed in your loop that you are waiting until the stop button is pressed or an error occurs.  Should you not use the Task Done output to stop the loop also?  The way you have your code, the analog output will happen just one time.  It will output a certain number of samples and then the loop will wait until stop is pressed.  Is this what you really want to do?  Why wait until stop is pressed with the analog out being idle.  Well I guess the counter should continue until stop is pressed.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 9 of 13
(4,104 Views)

What I am trying to do is to output a pulse of varying duration (1-2 ms) on every rising or falling edge (depends on the situation) of the trigger. If the trigger is 50 Hz, there should be 50 pulses in a second. On the DAQ hardware I have, I cannot make a digital input "retriggerable", so that's why I am using the counter. I understand your point about the frequency, I have changed it and made it the same as the clock rate for the AO. It seems to be working, although I don't quite understand why the samples per channel on the counter has to be greater than the duration of the analog output. If I don't do this, the output looks aliased. For example, I set the duration to 2 ms and the samples per channel to 2.1 ms with a 50 Hz trigger and it is OK, but not if both are 2 ms.

0 Kudos
Message 10 of 13
(4,099 Views)