Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Generating a TTL signal 6221

Hi,
I am trying to send a simple TTL signal using the PCI-6221. I was using MATLAB to do this through the parallel port. I would turn on and off the high signal for each of the seven outputs I have to use (Pins 2-8). However, I need to control the frequency of these signals (I am modulating a laser) with some accuracy. I have tried to do this using the help files and the forums and I think I need more help. I have wired the 7 outputs to the Digital Output Channels on the Block Connector (P0.0-P0.6), but I can't seem to figure out how to do this simply. Here's a sample of the MATLAB code I used to do this.

function laserautocontrol(powerlevel,n)

dio = digitalio('parallel',1);

addline(dio,0,'out','DataInput1');
addline(dio,1,'out','DataInput2');
addline(dio,2,'out','DataInput3');
addline(dio,3,'out','DataInput4');
addline(dio,4,'out','DataInput5');
addline(dio,5,'out','DataInput6');
addline(dio,6,'out','DataInput7');

powerproper = powerlevel/100*120;

initializedata = logical([0 0 0 0 0 0 0]);
startdata = dec2binvec(powerproper,7);
stopdata = logical([0 0 0 0 0 0 0]);

putvalue(dio,initializedata);

tic;
for i=1:n
   
    putvalue(dio,startdata);
    putvalue(dio,stopdata);
    pause(0.01);
   
end

putvalue(dio,stopdata);

toc;

delete(dio)
clear dio

Any help would be greatly appreciated. Thanks.
0 Kudos
Message 1 of 4
(4,799 Views)

Hello,

Let me preface this by saying that I am not at all familiar with programming NI devices in MATLAB.  However, from what I can tell, it looks like you are using software timing to control the output frequency.  Your PCI-6221 does support correlated digital I/O.  This means that you can supply a pulse train to time your digital I/O in hardware.  This is much more deteriministic than timing the output in software, and can also go at much faster rates.  I would suggest generating a pulse train with one of your device's counters and then using this to time a correlated digital output task. Let me know if you have any questions about this.

Unfortunately, while many people in these forums could help you program this in LabVIEW, you're not going to find many MATLAB experts around here.  I am sorry to say that I can't really help you with the MATLAB programming aspect.  If no one here is able to offer you more advice, I would suggest visiting the MATLAB forums to see if anyone there has any suggestions.

Good luck with your application!

Message 2 of 4
(4,778 Views)
Thanks Elizabeth.
I should have said that I'd like to use LabView to do this. I was using MATLAB, but my advisor suggested using LabView since we can, as you said, control the timing much more accurately. I am trying to figure out where to start. I can generate a analog waveform and convert it to a boolean array. Do I feed that into the DAQ assistant in some way? Thanks again.

Message Edited by caballero on 07-18-2007 12:39 PM

0 Kudos
Message 3 of 4
(4,776 Views)
I figured it out. Thanks. Here's how I did it.

Message Edited by caballero on 07-18-2007 06:26 PM

0 Kudos
Message 4 of 4
(4,760 Views)