查看: 2288|回复: 1

[求助] ADC2和ADC3的疑问!!

[复制链接]

该用户从未签到

11

主题

44

帖子

0

注册会员

Rank: 2

积分
92
最后登录
1970-1-1
发表于 2014-11-21 13:31:44 | 显示全部楼层 |阅读模式
目前正在使用MK60FX512VLQ12+MQX4.0构建我的系统,该芯片内部集成了4个ADC,每个ADC具有2个通道,目前我想使用ADC1、ADC2和ADC3,结合PDB形成一个6通道AD的连续采样,但是,当我将6个通道都启动后,只有ADC1的两个通道能正常工作,ADC2和ADC3的几个通道只能在系统刚刚启动时工作一会,然后从中读取的数据就为没有数据了,READ函数返回是0.
但是如果我只启用3个ADC中的任意一个,那么该ADC的两个通道都可以正常工作。
好查看了相关驱动,没能发现问题,难道MQX中只能支持一个ADC,两个通道同时工作?

  1.     #define ADC_CH1 "adc3:" /* must be #1 as the inputs are wired to ADC 1 */
  2.     #define MY_TRIGGER ADC_PDB_TRIGGER
  3.     #if !BSPCFG_ENABLE_ADC3
  4.         #error This application requires BSPCFG_ENABLE_ADC1 defined non-zero in user_config.h. Please recompile BSP with this option.
  5.     #endif /* BSPCFG_ENABLE_ADCx */

  6.     #define ADC_CH2 "adc2:" /* must be #1 as the inputs are wired to ADC 1 */
  7.     #if !BSPCFG_ENABLE_ADC2
  8.         #error This application requires BSPCFG_ENABLE_ADC1 defined non-zero in user_config.h. Please recompile BSP with this option.
  9.     #endif /* BSPCFG_ENABLE_ADCx */

  10.     #define ADC_CH3 "adc1:" /* must be #1 as the inputs are wired to ADC 1 */
  11.     #if !BSPCFG_ENABLE_ADC1
  12.         #error This application requires BSPCFG_ENABLE_ADC1 defined non-zero in user_config.h. Please recompile BSP with this option.
  13.     #endif /* BSPCFG_ENABLE_ADCx */

  14. /* Task IDs */
  15. #define MAIN_TASK 5

  16. /* Function prototypes */
  17. extern void main_task(uint_32);

  18. const TASK_TEMPLATE_STRUCT MQX_template_list[] =
  19. {
  20.     /* Task Index,  Function,  Stack,  Priority,    Name,       Attributes,             Param,  Time Slice */
  21.     {MAIN_TASK,     main_task, 1000,      8,        "Main",     MQX_AUTO_START_TASK,    0,      0           },
  22.     {0}
  23. };


  24. /* ADC device init struct */
  25. const ADC_INIT_STRUCT adc_init = {
  26.     ADC_RESOLUTION_DEFAULT,     /* resolution */
  27. };

  28. #if MQX_USE_LWEVENTS
  29. static LWEVENT_STRUCT evn;
  30. #endif

  31. /* BSP_ADC_UCH1 init struct */
  32. const ADC_INIT_CHANNEL_STRUCT adc_uch1_channel_param =
  33. {
  34.     ADC3_SOURCE_AD17, /* physical ADC channel */
  35.     ADC_CHANNEL_MEASURE_LOOP | ADC_CHANNEL_START_TRIGGERED, /* runs continuously after IOCTL trigger */
  36.     1,             /* number of samples in one run sequence */
  37.     0,              /* time offset from trigger point in us */
  38.     6000,         /* period in us (= 625us ) */
  39.     0x10000,        /* scale range of result (not used now) */
  40.     ADC_BUFFER_SIZE,             /* circular buffer size (sample count) */
  41.     MY_TRIGGER,     /* logical trigger ID that starts this ADC channel */
  42. #if MQX_USE_LWEVENTS
  43. //     &evn,
  44. //     0x01            /* mask of event to be set */
  45.                         NULL
  46. #endif
  47. };

  48. /* BSP_ADC_UCH2 init struct */
  49. const ADC_INIT_CHANNEL_STRUCT adc_uch2_channel_param =
  50. {
  51.     ADC2_SOURCE_AD17, /* physical ADC channel */
  52.     ADC_CHANNEL_MEASURE_LOOP | ADC_CHANNEL_START_TRIGGERED, /* runs continuously after IOCTL trigger */
  53.     1,             /* number of samples in one run sequence */
  54.     0,              /* time offset from trigger point in us */
  55.     6000,         /* period in us (= 625us ) */
  56.     0x10000,        /* scale range of result (not used now) */
  57.     ADC_BUFFER_SIZE,             /* circular buffer size (sample count) */
  58.     MY_TRIGGER,     /* logical trigger ID that starts this ADC channel */
  59. #if MQX_USE_LWEVENTS
  60. //     &evn,
  61. //     0x01            /* mask of event to be set */
  62.                         NULL
  63. #endif
  64. };

  65. /* BSP_ADC_UCH3 init struct */
  66. const ADC_INIT_CHANNEL_STRUCT adc_uch3_channel_param =
  67. {
  68.     ADC1_SOURCE_AD7A, /* physical ADC channel */
  69.     ADC_CHANNEL_MEASURE_LOOP | ADC_CHANNEL_START_TRIGGERED, /* runs continuously after IOCTL trigger */
  70.     1,             /* number of samples in one run sequence */
  71.     0,              /* time offset from trigger point in us */
  72.     6000,         /* period in us (= 625us ) */
  73.     0x10000,        /* scale range of result (not used now) */
  74.     ADC_BUFFER_SIZE,             /* circular buffer size (sample count) */
  75.     MY_TRIGGER,     /* logical trigger ID that starts this ADC channel */
  76. #if MQX_USE_LWEVENTS
  77. //     &evn,
  78. //     0x01            /* mask of event to be set */
  79.                         NULL
  80. #endif
  81. };

  82. /* BSP_ADC_ICH1 init struct */
  83. const ADC_INIT_CHANNEL_STRUCT adc_ich1_channel_param =
  84. {
  85.     ADC3_SOURCE_AD16, /* physical ADC channel */
  86.     ADC_CHANNEL_MEASURE_LOOP | ADC_CHANNEL_START_TRIGGERED, /* runs continuously after IOCTL trigger */
  87.     1,             /* number of samples in one run sequence */
  88.     3000,              /* time offset from trigger point in us */
  89.     6000,         /* period in us (= 625us ) */
  90.     0x10000,        /* scale range of result (not used now) */
  91.     ADC_BUFFER_SIZE,             /* circular buffer size (sample count) */
  92.     MY_TRIGGER,     /* logical trigger ID that starts this ADC channel */
  93. #if MQX_USE_LWEVENTS
  94. //     &evn,
  95. //     0x01            /* mask of event to be set */
  96.                         NULL
  97. #endif
  98. };

  99. /* BSP_ADC_ICH2 init struct */
  100. const ADC_INIT_CHANNEL_STRUCT adc_ich2_channel_param =
  101. {
  102.     ADC2_SOURCE_AD16, /* physical ADC channel */
  103.     ADC_CHANNEL_MEASURE_LOOP | ADC_CHANNEL_START_TRIGGERED, /* runs continuously after IOCTL trigger */
  104.     1,             /* number of samples in one run sequence */
  105.     3000,              /* time offset from trigger point in us */
  106.     6000,         /* period in us (= 625us ) */
  107.     0x10000,        /* scale range of result (not used now) */
  108.     ADC_BUFFER_SIZE,             /* circular buffer size (sample count) */
  109.     MY_TRIGGER,     /* logical trigger ID that starts this ADC channel */
  110. #if MQX_USE_LWEVENTS
  111. //     &evn,
  112. //     0x01            /* mask of event to be set */
  113.                         NULL
  114. #endif
  115. };

  116. /* BSP_ADC_ICH3 init struct */
  117. const ADC_INIT_CHANNEL_STRUCT adc_ich3_channel_param =
  118. {
  119.     ADC1_SOURCE_AD6A, /* physical ADC channel */
  120.     ADC_CHANNEL_MEASURE_LOOP | ADC_CHANNEL_START_TRIGGERED, /* runs continuously after IOCTL trigger */
  121.     1,             /* number of samples in one run sequence */
  122.     3000,              /* time offset from trigger point in us */
  123.     6000,         /* period in us (= 625us ) */
  124.     0x10000,        /* scale range of result (not used now) */
  125.     ADC_BUFFER_SIZE,             /* circular buffer size (sample count) */
  126.     MY_TRIGGER,     /* logical trigger ID that starts this ADC channel */
  127. #if MQX_USE_LWEVENTS
  128. //     &evn,
  129. //     0x01            /* mask of event to be set */
  130.                         NULL
  131. #endif
  132. };
  133. /*TASK*-----------------------------------------------------
  134. **
  135. ** Task Name    : main_task
  136. ** Comments     :
  137. **
  138. *END*-----------------------------------------------------*/
  139. void main_task
  140.    (
  141.       uint_32 initial_data
  142.    )
  143. {
  144.                 ADC_RESULT_STRUCT result_data;
  145.                 _mqx_int i,n;
  146.                 MQX_FILE_PTR f_adc1,f_adc2,f_adc3;
  147.                 MQX_FILE_PTR f_adc1_ch1,f_adc2_ch1,f_adc3_ch1;
  148.                 MQX_FILE_PTR f_adc1_ch2,f_adc2_ch2,f_adc3_ch2;
  149.                 uint_8 long_sample = 20;
  150.                 uint_8 hw_avage = 32;
  151.        
  152.     printf("\n\n-------------- Begin ADC example --------------\n\n");

  153. #if MQX_USE_LWEVENTS
  154.     if (_lwevent_create(&evn, 0) != MQX_OK) {
  155.         printf("\nMake event failed!\n");
  156.         _task_block();
  157.     }
  158. #endif
  159.                
  160. //ADC 1 init
  161. #ifdef ADC_CH1
  162.     printf("Opening ADC_CH1 device ...");
  163.     f_adc1 = fopen(ADC_CH1, (const char*)&adc_init);
  164.     if(f_adc1 != NULL)
  165.     {   
  166.         printf("done\n");
  167.     }
  168.     else
  169.     {   
  170.         printf("failed\n");
  171.         _task_block();
  172.     }
  173.     printf("Opening ADC_CH1 channel #1 ...");
  174.     f_adc1_ch1 = fopen(ADC_CH1 "first", (const char*)&adc_uch1_channel_param);
  175.     if(f_adc1_ch1 != NULL)
  176.     {   
  177.         printf("done, prepared to start by trigger\n");
  178.     }
  179.     else
  180.     {   
  181.         printf("failed\n");
  182.         _task_block();
  183.     }
  184.     printf("Opening channel #2 ...");
  185.     f_adc1_ch2 = fopen(ADC_CH1 "second", (const char*)&adc_ich1_channel_param); /* ADC_CH1:2 is running now */
  186.     if(f_adc1_ch2 != NULL)
  187.     {   
  188.         printf("done, one sequence started automatically\n");
  189.     }
  190.     else
  191.     {   
  192.         printf("failed\n");
  193.         _task_block();
  194.     }
  195.     _time_delay(1000);
  196.    
  197.     printf("Triggering ADC_CH1 channel ...");
  198.     ioctl(f_adc1, ADC_IOCTL_FIRE_TRIGGER, (pointer) MY_TRIGGER);                        //now start the ADC convert
  199.     printf("triggered!\n");
  200. #endif

  201. #ifdef ADC_CH2
  202.     printf("Opening ADC_CH2 device ...");
  203.     f_adc2 = fopen(ADC_CH2, (const char*)&adc_init);
  204.     if(f_adc2 != NULL)
  205.     {   
  206.         printf("done\n");
  207.     }
  208.     else
  209.     {   
  210.         printf("failed\n");
  211.         _task_block();
  212.     }
  213.     printf("Opening ADC_CH2 channel #1 ...");
  214.     f_adc2_ch1 = fopen(ADC_CH2 "first", (const char*)&adc_uch2_channel_param);
  215.     if(f_adc2_ch1 != NULL)
  216.     {   
  217.         printf("done, prepared to start by trigger\n");
  218.     }
  219.     else
  220.     {   
  221.         printf("failed\n");
  222.         _task_block();
  223.     }
  224.     printf("Opening ADC_CH2 channel #2 ...");
  225.     f_adc2_ch2 = fopen(ADC_CH2 "second", (const char*)&adc_ich2_channel_param); /* ADC_CH1:2 is running now */
  226.     if(f_adc2_ch2 != NULL)
  227.     {   
  228.         printf("done, one sequence started automatically\n");
  229.     }
  230.     else
  231.     {   
  232.         printf("failed\n");
  233.         _task_block();
  234.     }
  235.     _time_delay(1000);
  236.    
  237.     printf("Triggering ADC_CH2 channel ...");
  238.     ioctl(f_adc2, ADC_IOCTL_FIRE_TRIGGER, (pointer) MY_TRIGGER);                        //now start the ADC convert
  239.     printf("triggered!\n");
  240. #endif
复制代码

我知道答案 目前已有1人回答
回复

使用道具 举报

该用户从未签到

4

主题

38

帖子

0

注册会员

Rank: 2

积分
128
最后登录
2014-12-31
发表于 2014-12-8 15:41:57 | 显示全部楼层
我也碰到一个问题就是adc2 不知道如何触发启动dma
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /3 下一条

Archiver|手机版|小黑屋|恩智浦技术社区

GMT+8, 2025-7-20 16:51 , Processed in 0.084379 second(s), 20 queries , MemCache On.

Powered by Discuz! X3.4

Copyright © 2001-2024, Tencent Cloud.

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