Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How to program to trigger off a channel then recording all other channels?

I am converting my program from Visual C++ 6.0 to .NET (yup we are kind of slow 🙂 so that we can use the new NIDAQ driver with M card.  Now I have some trouble converting the data acqusition routine.  I am trying to trigger off a channel then record data from all the channels.  I was told that I will have to have an extra circuit to wire the channel to TTL line.  Is this true?  I never had to do this in the older software.  I basically set the pretrigger and use SWAnalog and that is it.  The following is the code from the older software.  Right now in my .NET evenvironment, I basically monitor the voltage from the trigger channel then once the voltage exceed the level, I went into my buffer to grab the pretrigger and post trigger data.  It was fine except that the buffer is kindda huge and it slows down the data acq process by far since we still have older PC that is slow.    I attached the code of the new way (in .NET) that I am doing with this message as well.  Sorry for a long message and I hope someone can help me out!!  Thanks, Yajai.
 
 
//// Older way
void CWinTFSView::StartDaq()

 COleVariant vOptional((long) DISP_E_PARAMNOTFOUND, VT_ERROR);
  
 CString ScanChannels[9];
 
 int Device;
 long Scans;
 float SampleRate;
 float ScanRate;
 long PreTriggerScans;
 Device = 1;
 Scans = int (m_ActualPointPerRecord) *m_TotalChannel;
 SampleRate = (int) (1000000/(m_TimePerPoint));
 ScanRate = SampleRate;
 
 PreTriggerScans = m_TriggerDelay/m_TimePerPoint;
 m_CWAI.GetChannels().RemoveAll();
 // InsertChannel 
 ScanChannels[1].Insert(0, "0");
 ScanChannels[2].Insert(0, "1");
 ScanChannels[3].Insert(0, "2");
 ScanChannels[4].Insert(0, "3");
 ScanChannels[5].Insert(0, "4");
 ScanChannels[6].Insert(0, "5");
 ScanChannels[7].Insert(0, "6");
 ScanChannels[8].Insert(0, "7");
 CString Ch ="";
 bool First = TRUE;
 for(int i = 1; i< 9; i++)  
 {
  if(m_Ch[i] == TRUE) 
  {
   switch (m_NiGain[i]) {
   case 1:
    m_CWAI.GetChannels().Add(ScanChannels[i],CNiVariant(10),CNiVariant(-10), vOptional, vOptional);
    break;
   case 2:
    m_CWAI.GetChannels().Add(ScanChannels[i],CNiVariant(5),CNiVariant(-5), vOptional, vOptional);
    break;
   case 4:
    m_CWAI.GetChannels().Add(ScanChannels[i],CNiVariant(2.5),CNiVariant(-2.5), vOptional, vOptional);
    break;
   
   }
   
  }
    
 }
 m_CWAI.SetDevice(Device);
 
 char temp[10];
 int RealTriggerCh = m_TriggerChannel - 1;
 itoa(RealTriggerCh, temp, 10);
 
 m_CWAI.GetStopCondition().SetType(cwaiSWAnalog);
 
 m_CWAI.GetStopCondition().SetLevel(m_TriggerLevel);
 m_CWAI.GetStopCondition().SetSource(temp);
 m_CWAI.GetStopCondition().SetPreTriggerScans(PreTriggerScans);
 m_CWAI.GetStopCondition().SetMode(cwaiFalling);
 
  
 
 m_CWAI.SetNScans(Scans);
 m_CWAI.GetScanClock().SetFrequency(ScanRate);
 m_CWAI.GetStopCondition().SetHysteresis(float (0.05));
  
 m_AcquireMode = true;
 m_CWAI.Configure();
 //delay function
 int k;
 for(i = 1; i<= m_TIME_DELAY; i++)
  k = 1;
 m_CWAI.Start();
}
 ///////////////////////////
 
 
0 Kudos
Message 1 of 6
(3,374 Views)
Hello DrObb,
I'm not sure I know exactly what you are trying to do, but I'd like to offer some suggestions.  First, it looks like you are trying to use some sort of software analog triggering?  Depending on your M Series device, you might be able to use hardware analog triggering.  The 625x and 628x families have hardware analog triggering capabilities.  You can use an analog trigger on any one of the analog input channels or the APFI line.  Additionally, all M Series have digital triggering support.  So it should not be necessary to use external circuitry unless you have a 622x device and you need analog triggering.
 
As far as the .NET programming, I suggest looking at some existing shipping examples.  If you included .NET support when you installed NI-DAQmx, you should have a bunch of .NET examples in the following directory (regardless of whether or not you have measurement studio):  C:\Program Files\National Instruments\MeasurementStudioVS2003\DotNET\Examples\DAQmx\Analog In\Measure Voltage
It looks like you probably want to use an analog reference trigger (if you want pre and post trigger data).  So you might have to take pieces of a couple examples, like the analog start trigger example and the digital reference trigger example.  Good luck, re-post if you have additional questions!
 
-Alan A.
 
0 Kudos
Message 2 of 6
(3,359 Views)

Alan,

Thank you so much for replying to my question.  My problem was that if I used Digital Ref and I try to trigger off Dev/ai0 then I cannot acquire data from other channels (error message if I try to create more than 1 channel and trigger off the first channel).  So I ended up use Internal Clk SW trigger which is a continuous acquisition and the software manually check for trigger.  This way is very slow in older PCs (slow speed).  I hope that you (or someone) would be able to guide me out on how to make this more efficeient.

Thanks,

Yajai

0 Kudos
Message 3 of 6
(3,352 Views)
I'm assuming you meant that you tried using an analog reference trigger using DevX/aiY.  In which case, you are correct, if you set up an acquisition with more than one channel, then you can't directly use one of the analog input channels as the trigger channel.  However, you could physically wire the signal you want to trigger off of to an analog input channel and the APFI terminal.  Then you can set the trigger to be the APFI channel and still acquire all the channels of data.
 
I understand your concern with software triggering being slow and processor intensive.  That is why I'm really trying to help get you up and running with a hardware trigger 🙂
 
-Alan A.
0 Kudos
Message 4 of 6
(3,345 Views)

Again thank you so much for taking time with my questions.  My big problem is that there is no dedicated channel for the trigger.  Users can set any of the 16 channels for a trigger.  So it is not a easy wiring from the trigger channel to PFI line.  We will need a multiplexer of some sort and need digital I/O line to do it.  Unfortunately, we use all our digital IO line for other purposes so it is impossible for us to have a cuircuit for multiplexer.  Is there any other trick you can suggest to help me out in this regard?  Using SW trigger with continuous data acquisition is way too slow and we got a lot of complaints from our clients, unfortunately. 

I really appreciate your helps,

Yajai.

0 Kudos
Message 5 of 6
(3,331 Views)
Ok, I see your problem.  Unfortunately, I don't think there is a good way around this...without either an external mux or knowing the trigger channel prior to running the program (so it could be hardwired to the APFI pin).  So, looks like sw triggering might be the only way to attack this particular problem.  You can always try to optimize your processing code as much as possible by doing things like reading fewer samples and reading more often, slowing down the sample rate a much as possible, doing the processing in a separate thread, etc.
-Alan A.
0 Kudos
Message 6 of 6
(3,300 Views)