在线时间5 小时
UID94779
注册时间2007-8-7
NXP金币0
该用户从未签到
注册会员

- 积分
- 92
- 最后登录
- 1970-1-1
|
目前正在使用MK60FX512VLQ12+MQX4.0构建我的系统,该芯片内部集成了4个ADC,每个ADC具有2个通道,目前我想使用ADC1、ADC2和ADC3,结合PDB形成一个6通道AD的连续采样,但是,当我将6个通道都启动后,只有ADC1的两个通道能正常工作,ADC2和ADC3的几个通道只能在系统刚刚启动时工作一会,然后从中读取的数据就为没有数据了,READ函数返回是0.
但是如果我只启用3个ADC中的任意一个,那么该ADC的两个通道都可以正常工作。
好查看了相关驱动,没能发现问题,难道MQX中只能支持一个ADC,两个通道同时工作?
- #define ADC_CH1 "adc3:" /* must be #1 as the inputs are wired to ADC 1 */
- #define MY_TRIGGER ADC_PDB_TRIGGER
- #if !BSPCFG_ENABLE_ADC3
- #error This application requires BSPCFG_ENABLE_ADC1 defined non-zero in user_config.h. Please recompile BSP with this option.
- #endif /* BSPCFG_ENABLE_ADCx */
- #define ADC_CH2 "adc2:" /* must be #1 as the inputs are wired to ADC 1 */
- #if !BSPCFG_ENABLE_ADC2
- #error This application requires BSPCFG_ENABLE_ADC1 defined non-zero in user_config.h. Please recompile BSP with this option.
- #endif /* BSPCFG_ENABLE_ADCx */
- #define ADC_CH3 "adc1:" /* must be #1 as the inputs are wired to ADC 1 */
- #if !BSPCFG_ENABLE_ADC1
- #error This application requires BSPCFG_ENABLE_ADC1 defined non-zero in user_config.h. Please recompile BSP with this option.
- #endif /* BSPCFG_ENABLE_ADCx */
- /* Task IDs */
- #define MAIN_TASK 5
- /* Function prototypes */
- extern void main_task(uint_32);
- const TASK_TEMPLATE_STRUCT MQX_template_list[] =
- {
- /* Task Index, Function, Stack, Priority, Name, Attributes, Param, Time Slice */
- {MAIN_TASK, main_task, 1000, 8, "Main", MQX_AUTO_START_TASK, 0, 0 },
- {0}
- };
- /* ADC device init struct */
- const ADC_INIT_STRUCT adc_init = {
- ADC_RESOLUTION_DEFAULT, /* resolution */
- };
- #if MQX_USE_LWEVENTS
- static LWEVENT_STRUCT evn;
- #endif
- /* BSP_ADC_UCH1 init struct */
- const ADC_INIT_CHANNEL_STRUCT adc_uch1_channel_param =
- {
- ADC3_SOURCE_AD17, /* physical ADC channel */
- ADC_CHANNEL_MEASURE_LOOP | ADC_CHANNEL_START_TRIGGERED, /* runs continuously after IOCTL trigger */
- 1, /* number of samples in one run sequence */
- 0, /* time offset from trigger point in us */
- 6000, /* period in us (= 625us ) */
- 0x10000, /* scale range of result (not used now) */
- ADC_BUFFER_SIZE, /* circular buffer size (sample count) */
- MY_TRIGGER, /* logical trigger ID that starts this ADC channel */
- #if MQX_USE_LWEVENTS
- // &evn,
- // 0x01 /* mask of event to be set */
- NULL
- #endif
- };
- /* BSP_ADC_UCH2 init struct */
- const ADC_INIT_CHANNEL_STRUCT adc_uch2_channel_param =
- {
- ADC2_SOURCE_AD17, /* physical ADC channel */
- ADC_CHANNEL_MEASURE_LOOP | ADC_CHANNEL_START_TRIGGERED, /* runs continuously after IOCTL trigger */
- 1, /* number of samples in one run sequence */
- 0, /* time offset from trigger point in us */
- 6000, /* period in us (= 625us ) */
- 0x10000, /* scale range of result (not used now) */
- ADC_BUFFER_SIZE, /* circular buffer size (sample count) */
- MY_TRIGGER, /* logical trigger ID that starts this ADC channel */
- #if MQX_USE_LWEVENTS
- // &evn,
- // 0x01 /* mask of event to be set */
- NULL
- #endif
- };
- /* BSP_ADC_UCH3 init struct */
- const ADC_INIT_CHANNEL_STRUCT adc_uch3_channel_param =
- {
- ADC1_SOURCE_AD7A, /* physical ADC channel */
- ADC_CHANNEL_MEASURE_LOOP | ADC_CHANNEL_START_TRIGGERED, /* runs continuously after IOCTL trigger */
- 1, /* number of samples in one run sequence */
- 0, /* time offset from trigger point in us */
- 6000, /* period in us (= 625us ) */
- 0x10000, /* scale range of result (not used now) */
- ADC_BUFFER_SIZE, /* circular buffer size (sample count) */
- MY_TRIGGER, /* logical trigger ID that starts this ADC channel */
- #if MQX_USE_LWEVENTS
- // &evn,
- // 0x01 /* mask of event to be set */
- NULL
- #endif
- };
- /* BSP_ADC_ICH1 init struct */
- const ADC_INIT_CHANNEL_STRUCT adc_ich1_channel_param =
- {
- ADC3_SOURCE_AD16, /* physical ADC channel */
- ADC_CHANNEL_MEASURE_LOOP | ADC_CHANNEL_START_TRIGGERED, /* runs continuously after IOCTL trigger */
- 1, /* number of samples in one run sequence */
- 3000, /* time offset from trigger point in us */
- 6000, /* period in us (= 625us ) */
- 0x10000, /* scale range of result (not used now) */
- ADC_BUFFER_SIZE, /* circular buffer size (sample count) */
- MY_TRIGGER, /* logical trigger ID that starts this ADC channel */
- #if MQX_USE_LWEVENTS
- // &evn,
- // 0x01 /* mask of event to be set */
- NULL
- #endif
- };
- /* BSP_ADC_ICH2 init struct */
- const ADC_INIT_CHANNEL_STRUCT adc_ich2_channel_param =
- {
- ADC2_SOURCE_AD16, /* physical ADC channel */
- ADC_CHANNEL_MEASURE_LOOP | ADC_CHANNEL_START_TRIGGERED, /* runs continuously after IOCTL trigger */
- 1, /* number of samples in one run sequence */
- 3000, /* time offset from trigger point in us */
- 6000, /* period in us (= 625us ) */
- 0x10000, /* scale range of result (not used now) */
- ADC_BUFFER_SIZE, /* circular buffer size (sample count) */
- MY_TRIGGER, /* logical trigger ID that starts this ADC channel */
- #if MQX_USE_LWEVENTS
- // &evn,
- // 0x01 /* mask of event to be set */
- NULL
- #endif
- };
- /* BSP_ADC_ICH3 init struct */
- const ADC_INIT_CHANNEL_STRUCT adc_ich3_channel_param =
- {
- ADC1_SOURCE_AD6A, /* physical ADC channel */
- ADC_CHANNEL_MEASURE_LOOP | ADC_CHANNEL_START_TRIGGERED, /* runs continuously after IOCTL trigger */
- 1, /* number of samples in one run sequence */
- 3000, /* time offset from trigger point in us */
- 6000, /* period in us (= 625us ) */
- 0x10000, /* scale range of result (not used now) */
- ADC_BUFFER_SIZE, /* circular buffer size (sample count) */
- MY_TRIGGER, /* logical trigger ID that starts this ADC channel */
- #if MQX_USE_LWEVENTS
- // &evn,
- // 0x01 /* mask of event to be set */
- NULL
- #endif
- };
- /*TASK*-----------------------------------------------------
- **
- ** Task Name : main_task
- ** Comments :
- **
- *END*-----------------------------------------------------*/
- void main_task
- (
- uint_32 initial_data
- )
- {
- ADC_RESULT_STRUCT result_data;
- _mqx_int i,n;
- MQX_FILE_PTR f_adc1,f_adc2,f_adc3;
- MQX_FILE_PTR f_adc1_ch1,f_adc2_ch1,f_adc3_ch1;
- MQX_FILE_PTR f_adc1_ch2,f_adc2_ch2,f_adc3_ch2;
- uint_8 long_sample = 20;
- uint_8 hw_avage = 32;
-
- printf("\n\n-------------- Begin ADC example --------------\n\n");
- #if MQX_USE_LWEVENTS
- if (_lwevent_create(&evn, 0) != MQX_OK) {
- printf("\nMake event failed!\n");
- _task_block();
- }
- #endif
-
- //ADC 1 init
- #ifdef ADC_CH1
- printf("Opening ADC_CH1 device ...");
- f_adc1 = fopen(ADC_CH1, (const char*)&adc_init);
- if(f_adc1 != NULL)
- {
- printf("done\n");
- }
- else
- {
- printf("failed\n");
- _task_block();
- }
- printf("Opening ADC_CH1 channel #1 ...");
- f_adc1_ch1 = fopen(ADC_CH1 "first", (const char*)&adc_uch1_channel_param);
- if(f_adc1_ch1 != NULL)
- {
- printf("done, prepared to start by trigger\n");
- }
- else
- {
- printf("failed\n");
- _task_block();
- }
- printf("Opening channel #2 ...");
- f_adc1_ch2 = fopen(ADC_CH1 "second", (const char*)&adc_ich1_channel_param); /* ADC_CH1:2 is running now */
- if(f_adc1_ch2 != NULL)
- {
- printf("done, one sequence started automatically\n");
- }
- else
- {
- printf("failed\n");
- _task_block();
- }
- _time_delay(1000);
-
- printf("Triggering ADC_CH1 channel ...");
- ioctl(f_adc1, ADC_IOCTL_FIRE_TRIGGER, (pointer) MY_TRIGGER); //now start the ADC convert
- printf("triggered!\n");
- #endif
- #ifdef ADC_CH2
- printf("Opening ADC_CH2 device ...");
- f_adc2 = fopen(ADC_CH2, (const char*)&adc_init);
- if(f_adc2 != NULL)
- {
- printf("done\n");
- }
- else
- {
- printf("failed\n");
- _task_block();
- }
- printf("Opening ADC_CH2 channel #1 ...");
- f_adc2_ch1 = fopen(ADC_CH2 "first", (const char*)&adc_uch2_channel_param);
- if(f_adc2_ch1 != NULL)
- {
- printf("done, prepared to start by trigger\n");
- }
- else
- {
- printf("failed\n");
- _task_block();
- }
- printf("Opening ADC_CH2 channel #2 ...");
- f_adc2_ch2 = fopen(ADC_CH2 "second", (const char*)&adc_ich2_channel_param); /* ADC_CH1:2 is running now */
- if(f_adc2_ch2 != NULL)
- {
- printf("done, one sequence started automatically\n");
- }
- else
- {
- printf("failed\n");
- _task_block();
- }
- _time_delay(1000);
-
- printf("Triggering ADC_CH2 channel ...");
- ioctl(f_adc2, ADC_IOCTL_FIRE_TRIGGER, (pointer) MY_TRIGGER); //now start the ADC convert
- printf("triggered!\n");
- #endif
复制代码
|
|