搜索
bottom↓
回复: 2

有熟悉NI采集卡的坛友么?如何让外触发一次AD就采集一次?

[复制链接]

出130入129汤圆

发表于 2014-8-17 18:33:48 | 显示全部楼层 |阅读模式
如果是自己做板用单片机是很简单的事情,但是用上采集卡涉及到硬件软件之间来回协调,就有些费解了。

用法很直观:NI USB-6210采集卡(AD速度250kps/s),计数器接口外接编码器,信号下降沿计数。
                  编码器转速是变化的,信号频率最大为25kHz,在每个脉冲到来的时候触发一次AD采集,采集完等下一个脉冲。

看了NI的范例,然后用手头有的低端6008采集卡试了下,外触发只能用一次,也就是说让AD采集启动后,就不能再次触发了。
6210贵一点,好像可以重复触发,但暂时没收到,不过看代码觉得就25kHz这个触发频率有些难实现。

范例是    收到触发信号--->回调函数处理数据--->然后继续等待触发信号--->回调函数处理数据

  1. /*********************************************************************
  2. *
  3. * ANSI C Example program:
  4. *    ContAcq-IntClk-DigStart-Retrig.c
  5. *
  6. * Example Category:
  7. *    AI
  8. *
  9. * Description:
  10. *    This example demonstrates how to acquire finite amounts of data
  11. *    on each digital trigger.
  12. *
  13. * Instructions for Running:
  14. *    1. Select the physical channel to correspond to where your
  15. *       signal is input on the DAQ device.
  16. *    2. Enter the minimum and maximum voltage range.
  17. *    Note: For better accuracy try to match the input range to the
  18. *          expected voltage level of the measured signal.
  19. *    3. Select the number of points to acquire per channel.
  20. *    4. Specify the rate of the sample clock.
  21. *    5. Select a source for the digital edge start trigger.
  22. *    6. Select the edge, rising or falling, on which to trigger.
  23. *
  24. * Steps:
  25. *    1. Create a task.
  26. *    2. Create an analog input voltage channel.
  27. *    3. Setup the timing for the acquisition. In this example, the
  28. *       Sample Clock is generated internally by the board. Rate
  29. *       specifies the rate of the internal clock. The timing is set
  30. *       to take a finite number of samples. The number of samples is
  31. *       specified by the Samples per Channel control. For a
  32. *       retriggerable acquisition, the Samples per Channel defines
  33. *       the number of samples to acquire for each trigger.
  34. *    4. Set the parameters for a digital edge start trigger.
  35. *    5. Set the Trigger Attribute to set the operation for
  36. *       retriggerable.
  37. *    6. Call the Start function to start the acquistion.
  38. *    7. Read the data in the EveryNCallback function until the stop
  39. *       button is pressed or an error occurs.
  40. *    8. Call the Clear Task function to clear the task.
  41. *    9. Display an error if any.
  42. *
  43. * I/O Connections Overview:
  44. *    Make sure your signal input terminal matches the Physical
  45. *    Channel I/O control. Also, make sure your analog trigger
  46. *    terminal matches the Trigger Source Control. For further
  47. *    connection information, refer to your hardware reference manual.
  48. *
  49. *********************************************************************/

  50. #include <stdio.h>
  51. #include <NIDAQmx.h>

  52. #define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else

  53. int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData);
  54. int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData);

  55. int main(void)
  56. {
  57.         int32       error=0;
  58.         TaskHandle  taskHandle=0;
  59.         char        errBuff[2048]={'\0'};

  60.         /*********************************************/
  61.         // DAQmx Configure Code
  62.         /*********************************************/
  63.         DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
  64.         DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
  65.         DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",10000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,1000));
  66.         DAQmxErrChk (DAQmxCfgDigEdgeStartTrig(taskHandle,"/Dev1/PFI0",DAQmx_Val_Falling));
  67.         DAQmxErrChk (DAQmxSetStartTrigRetriggerable(taskHandle,1));

  68.         DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(taskHandle,DAQmx_Val_Acquired_Into_Buffer,1000,0,EveryNCallback,NULL));
  69.         DAQmxErrChk (DAQmxRegisterDoneEvent(taskHandle,0,DoneCallback,NULL));

  70.         /*********************************************/
  71.         // DAQmx Start Code
  72.         /*********************************************/
  73.         DAQmxErrChk (DAQmxStartTask(taskHandle));

  74.         printf("Acquiring samples continuously. Press Enter to interrupt\n");
  75.         getchar();

  76. Error:
  77.         if( DAQmxFailed(error) )
  78.                 DAQmxGetExtendedErrorInfo(errBuff,2048);
  79.         if( taskHandle!=0 ) {
  80.                 /*********************************************/
  81.                 // DAQmx Stop Code
  82.                 /*********************************************/
  83.                 DAQmxStopTask(taskHandle);
  84.                 DAQmxClearTask(taskHandle);
  85.         }
  86.         if( DAQmxFailed(error) )
  87.                 printf("DAQmx Error: %s\n",errBuff);
  88.         printf("End of program, press Enter key to quit\n");
  89.         getchar();
  90.         return 0;
  91. }

  92. int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData)
  93. {
  94.         int32       error=0;
  95.         char        errBuff[2048]={'\0'};
  96.         static int  totalRead=0;
  97.         int32       read=0;
  98.         float64     data[1000];

  99.         /*********************************************/
  100.         // DAQmx Read Code
  101.         /*********************************************/
  102.         DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,1000,10.0,DAQmx_Val_GroupByScanNumber,data,1000,&read,NULL));
  103.         if( read>0 ) {
  104.                 printf("Acquired %d samples. Total %d\r",read,totalRead+=read);
  105.                 fflush(stdout);
  106.         }

  107. Error:
  108.         if( DAQmxFailed(error) ) {
  109.                 DAQmxGetExtendedErrorInfo(errBuff,2048);
  110.                 /*********************************************/
  111.                 // DAQmx Stop Code
  112.                 /*********************************************/
  113.                 DAQmxStopTask(taskHandle);
  114.                 DAQmxClearTask(taskHandle);
  115.                 printf("DAQmx Error: %s\n",errBuff);
  116.         }
  117.         return 0;
  118. }

  119. int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData)
  120. {
  121.         int32   error=0;
  122.         char    errBuff[2048]={'\0'};

  123.         // Check to see if an error stopped the task.
  124.         DAQmxErrChk (status);

  125. Error:
  126.         if( DAQmxFailed(error) ) {
  127.                 DAQmxGetExtendedErrorInfo(errBuff,2048);
  128.                 DAQmxClearTask(taskHandle);
  129.                 printf("DAQmx Error: %s\n",errBuff);
  130.         }
  131.         return 0;
  132. }
复制代码

阿莫论坛20周年了!感谢大家的支持与爱护!!

你熬了10碗粥,别人一桶水倒进去,淘走90碗,剩下10碗给你,你看似没亏,其实你那10碗已经没有之前的裹腹了,人家的一桶水换90碗,继续卖。说白了,通货膨胀就是,你的钱是挣来的,他的钱是印来的,掺和在一起,你的钱就贬值了。

出0入0汤圆

发表于 2014-9-30 09:49:52 | 显示全部楼层
用labview,上手很快的。

出0入0汤圆

发表于 2014-9-30 10:44:32 | 显示全部楼层
CVI也很方便,没折腾过NI USB-6210采集卡,不懂,帮顶。
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-10-3 01:19

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表