# NIDAQ custom analog output waveform

**URL:** https://mworks.discourse.group/t/nidaq-custom-analog-output-waveform/466
**Category:** Support
**Created:** [February 1, 2016, 5:54pm UTC](https://mworks.discourse.group/t/nidaq-custom-analog-output-waveform/466 "2016-02-01T17:54:34Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)
#### Post date: [February 1, 2016, 5:54pm UTC](https://mworks.discourse.group/t/nidaq-custom-analog-output-waveform/466/1 "2016-02-01T17:54:34Z")

</div>

Hi Evan,

Per your request, I’ve come up with an initial plan for adding support for custom analog output voltage waveforms to MWorks’ NIDAQ interface. Here are the changes involved:

1. Extend the existing Analog Output Voltage Waveform Channel to support a new waveform type (“custom”). Add a parameter called “samples”, whose value should be a list (or the name of a variable containing a list) of voltage samples in the waveform, one per `analog_output_data_interval` time step.

2. Add two parameters to NIDAQ Device:

The list of samples associated with a custom waveform can be changed at any time, but the changes won’t take effect until analog output is stopped and restarted. The reason for this is that changing the output samples for one channel requires re-sending the samples for _all_ channels (again, due to the single-task limitation of NI’s API). Rather than implicitly restarting all waveform output channels when one gets new samples, MWorks will require you to explicitly stop output in order for any changes to take effect, so that it’s clear in your experiment that _all_ waveform output channels are restarting.

I think that covers everything. Does it sound like this will meet your needs?

Thanks,  
Chris

---

<div class="post-metadata">

### Author: ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)
#### Post date: [February 2, 2016, 10:23pm UTC](https://mworks.discourse.group/t/nidaq-custom-analog-output-waveform/466/2 "2016-02-02T22:23:58Z")

</div>

Hi Chris,

I think that covers everything we discussed. There is a particular  
important scenario that this may also cover, but I’m not sure. The desired  
behavior would be a pulse with a duration on the order of hundreds of  
milliseconds, followed by a decay waveform to zero which lasts on the order  
of tens of milliseconds. The durations would be pre-set, but in the event  
of a subject response (say a saccade), the pulse would terminate with the  
decay waveform as soon as possible. However, if the output is finished (or  
if the decay has already started), the decay waveform should _not_ be  
re-delivered.

Can a new waveform be loaded into NIDAQ while the output is running? Even  
if that’s possible, there would need to be a way to avoid restarting the  
decay waveform if that’s when the response came, which would happen often  
enough to be a worry. One way I can think of avoiding the issue is with a  
separate MWorks timer that expires when the main pulse finishes and after  
which the update would be withheld. Any other ideas would be greatly  
appreciated!

Another question - when you say that the parameters are specific to the  
device rather than the channel, I assume different channels can still have  
different waveforms. Is that correct?

Thanks!

---

<div class="post-metadata">

### Author: ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)
#### Post date: [February 3, 2016, 8:16pm UTC](https://mworks.discourse.group/t/nidaq-custom-analog-output-waveform/466/3 "2016-02-03T20:16:48Z")

</div>

Hi Evan,

> when you say that the parameters are specific to the device rather than the channel, I assume different channels can still have different waveforms. Is that correct?

Yes, that’s correct. The waveform for each channel is arbitrary, but all channels start/stop/repeat as a group. Also, because all channels share the same onboard sample buffer, each waveform must contain the same number of samples.

> Can a new waveform be loaded into NIDAQ while the output is running?

Yes, that is supported by NI’s API, even when repetition is enabled. I believe the device begins outputting the new samples as soon as they’re received.

Given this, another way we could implement custom output waveforms is to make any changes to the “samples” parameter apply immediately, without requiring analog output to be stopped and restarted. Then, you could achieve the scenario you described by first outputting just the pulse and then replacing it with the decay at the appropriate time. To avoid having the pulse signal stop before the decay is loaded, you could pad the end of the pulse with some extra samples.

While it should work, one issue with this design is that it really only makes sense with a single analog output channel. As I said before, changing the output of one channel requires re-sending the samples for _all_ channels, meaning all channels would restart every time one was updated. In general, I think this would be unexpected and unhelpful behavior, so I’d probably make MWorks enforce the requirement that a custom waveform channel be the _only_ analog output channel.

Chris

---

<div class="post-metadata">

### Author: ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)
#### Post date: [February 10, 2016, 2:36pm UTC](https://mworks.discourse.group/t/nidaq-custom-analog-output-waveform/466/4 "2016-02-10T14:36:13Z")

</div>

Hi Evan,

Do you have any more thoughts on my proposed design? Should I go ahead and implement it?

Thanks,  
Chris

---

<div class="post-metadata">

### Author: ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)
#### Post date: [February 10, 2016, 3:44pm UTC](https://mworks.discourse.group/t/nidaq-custom-analog-output-waveform/466/5 "2016-02-10T15:44:43Z")

</div>

Hi Chris,

I just emailed the lab looking for feedback a few days ago, I would give it  
a couple more days before starting on the implementation. Do you think it  
would be useful to get feedback from others as well?

Evan

---

<div class="post-metadata">

### Author: ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)
#### Post date: [February 24, 2016, 4:07pm UTC](https://mworks.discourse.group/t/nidaq-custom-analog-output-waveform/466/6 "2016-02-24T16:07:56Z")

</div>

Hi Chris,

You can go ahead and implement this; I haven’t received any feedback. It’s  
not currently urgent.

Thanks,  
Evan

---

<div class="post-metadata">

### Author: ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)
#### Post date: [July 19, 2022, 10:10pm UTC](https://mworks.discourse.group/t/nidaq-custom-analog-output-waveform/466/7 "2022-07-19T22:10:04Z")

</div>


