Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to seperately control two lines of a digital IO to both output continuosly?

My end result is that I want to output to a digital line a waveform continuously but that needs to change at certain not so uniform intervals.  Basically all I'm changing is Pulse Width.  I can currently do this by stopping the task, writing the new waveform to the task, then restarting task.  This is cool, except I want the change to be IMMEDIATE (on one clock tick, output last sample from 1st waveform, on next clock tick output first sample from 2nd waveform).  The DAQ I'm using is USB-6251 and I need to use the buffered port for this, as my counters are tied up.  Maybe there's an easy solution for this????

My intitial thought was, maybe this isn't possible to do with one waveform on one line.  My approach was then to use two Digital output lines and have my current waveform outputing on say P.0. and have my next waveform set up on P.1. and as soon as I need to switch waveforms I just stop writing to P.0. and begin writing to P.1 and OR these in hardware.  I figured this could happen in one clock tick.  So this program crashes.  Should I be able to do this?  I'm guessing the buffer is on a PORT level even when you're accessing individual lines and this is where my problem lies.  Is this the case?

Any help would be awesome and much appreciated.


0 Kudos
Message 1 of 4
(2,671 Views)

Hi mavric,

There doesn't seem to be an easy solution for what you would like to implement.  If I understand you correctly, you would like to dynamically update the pulse width of your output waveform from one tick of the clock to the next.  The first problem is that you are using the digital lines to do the waveform generation.  This will update with a new output point at every tick of the clock but the pulse width, frequency and other properties would need to be configured before the task has started.  I believe you have figured this out already since you said you are currently implementing it by stopping and starting the task. 

This online knowledgebase has a similar concept to what you would like to do.  However, this uses a Counter Output to have a continuous pulse train output.  In this example, property nodes are used to update the duty cycle of the pulse train within a loop after the task has started.  If you open up the attached example, you will see that the property nodes are only updated as fast as the loop can run (software timed) and therefore the duty cycle of the pulse train can only be updated due to software and not by ticks of a hardware timed clock. 

Finally, in the M series user manual on page 101, it indicates that you can generate digital waveforms only on port 0 DIO lines.  This is probably why your program is crashing when you try to write out a waveform to Port 1 directly after the other waveform generation.

Your best option is to either try to use a counter for your pulse train and implement the example in the linked KB, or to continue to stop and start the task with the digital output as you have previously done.  Hopefully this information will be helpful!

Regards,
Vanessa L.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 4
(2,638 Views)
Vanessa,

Alright, over the weekend I got a chance to investigate some more and get a better feel for what I need to do.  Basically to get what I desire, I need to pretty much always be filling the buffer with the property 'RegenMode' of my task set to "Do Not Allow Regeneration."  And I will be able to use one line rather than the two line method I described above.

However there is one catch.  I know you mentioned that port 0 "only" allows waveform generation (that was a written mistake on my part, what I meant above was P0.0 and P0.1, not P.0 and P.1) but what I want to know is whether or not you can write to a buffer on a line basis?  So basically I have 8 lines of Port 0 that I can write continuous data to.  I know I can write an array of 8-bit unsigned ints to P0's buffer controlling all 8 lines of that port, but what I want to know is if I have a buffer to each line that I can write to independently of one another.  So I have an array of data that I want to write to line 0 of P0 (P0.0) and an array of data that I want to write to line 1 of P0 (P0.1), but since they change values at different times, I want to write them individually.  Is this possible?  Or can you only write arrays to a buffer in 8-bit unsigned integer form?

Thanks for the help and sorry for the confusion,
Mavric
0 Kudos
Message 3 of 4
(2,633 Views)

Hi Mavric,

In order to write data to a digital output port, you have to change the entire buffer (one per port) with every write.  Therefore, you cannot write to a buffer for specific lines. As you said, when you write out data, you will use 8-bit unsigned integer data which is written out with one array for all 8 lines.  However, you could rewrite the buffer for the entire port (including P0.1 and P0.2) , changing only 1 line in the array and keeping the other constant.  This way, you it would look like you were writing to each line individually. 

Regards,
Vanessa L.
Applications Engineer
National Instruments
0 Kudos
Message 4 of 4
(2,617 Views)