Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a simple Analog Comparator?

 

Hi everyone!

 

It's strange for me that I couldn't find almost any example on the related subject (except some ideas, but nothing in details), although I think it's quite usual. We have to acquire data continuosly on four ai channels (ai0,ai1,ai2,ai3). That is done using AITaskHandle task. In addition we would like to have a digital output (as the output of an analog comparator) related to one of these ai channels. (For example let's choose ai3, and 1.7V level;In this case we need to have a digital output which gives 5V when the voltage on ai3 is higher than 1.7V, 0V otherwise.)

 

It is probably sure that we'll have to create a new task for handling this but what kind of task? (I was trying to set some trigger conditions to both 'ai' tasks and 'do' task, but with no success. Anyway I heard that "Analog Comparison Event" must be exported, if so, than how can it be coded? The 'DAQmxExportSignal' function does not have a SignalID on this event.)

 

Thanks for the help!

TarPista

0 Kudos
Message 1 of 4
(3,914 Views)

Hi TarPista,

 

I don't know which developement system you use, but I can give you a general idea.

 

An easy way is to build software comparator. Analog input task for reading four channels, in paralell you creat software timed Digital output task.

The Number of samples to read per AI channel will take the Width of comparison window >> you compare all the elements to you Comparison level, so you get an array of booleans. You make logical AND over the array and write the result to the digital output in each iteration.

If your comparison window is equal to 1, then use logical OR function over the compared array.

You can trigger the AI channel. Being software timed, the DI task must wait in "commit" state until AI trigger occurs.

 

 

Good luck!

 

Regards,

Matyas

0 Kudos
Message 2 of 4
(3,853 Views)

Here is the example Matyas was talking about.

 

I hope this helps.

 

Regards

Barna D.

 

0 Kudos
Message 3 of 4
(3,849 Views)

Thx for both of you! I thought for hardware timed comparator.

The solution is that u only need to export the Analog Comparison Event, and for doing this the analog comparator must be enabled. Setting an analog trigger will do that.

The 'DAQmxExportSignal' does not work for me for some reason - I dont know why -, but the DAQmxConnectTerms does - who cares:

 

DAQmxClearTask(AITrigTaskHandle);
DAQmxCreateTask("AITriggerForZwick", out AITrigTaskHandle);
DAQmxCreateAIVoltageChan(AITrigTaskHandle, "Dev1/ai4", "", DAQmx_Val_RSE, -10.0, 10.0, DAQmx_Val_Volts, null);
DAQmxCfgSampClkTiming(AITrigTaskHandle, "", 10000.0, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 1000);
DAQmxCfgAnlgEdgeStartTrig(AITrigTaskHandle, "Dev1/ai4", DAQmx_Val_Rising, 2.5);
//DAQmxExportSignal(AITrigTaskHandle, DAQmx_Val_StartTrigger, "/Dev1/PFI3");
DAQmxConnectTerms("/Dev1/AnalogComparisonEvent", "/Dev1/PFI3", DAQmx_Val_DoNotInvertPolarity);
DAQmxStartTask(AITrigTaskHandle);

 

Anyway I use the normal DAQmx C api in .NET, C# :). The reason is that when I started using NI cards, there was no driver for .NET - as far as I remember - or if was, you would have to pay for using it. That's why I was looking for a workaround. Since then I am quite familiar with this driver and dont feel like getting to know a completely new one 🙂

 

Cheers

0 Kudos
Message 4 of 4
(3,813 Views)