公告

大中华汽车电子生态圈社区并入开发者社区- 更多资讯点击此

Tip / 登入 to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
zzyzz
Level 3
Level 3
10 questions asked Welcome! 5 comments on blog
参考demo修改该工程,但是只看到需要修改adcGroup组。该板的MCU-IC2DC芯片输出的三个引脚:AN0(group0)、AN8(group1)、AN16(group2)是否也要进行配置?请问该如何配置?
0 点赞
2 回复数
zzyzz
Level 3
Level 3
10 questions asked Welcome! 5 comments on blog
#include "Vadc/Adc/IfxVadc_Adc.h" #include "_Reg/IfxVadc_reg.h" #include "Cpu/Std/Platform_Types.h" // 定义ADC模块变量 vadc IfxVadc_Adc vadc; // 定义组变量 ADCGroup IfxVadc_Adc_Group adcGroup; // 定义通道变量 adcChannel[3] IfxVadc_Adc_Channel adcChannel[3]; // 定义结果变量 ADC_result[3] unsigned int ADC_result[3]; // 定义转换结果 conversionResult Ifx_VADC_RES conversionResult; void ADC_init(void) { int chnIx; //配置规则:先建立局部配置变量(xxxConfig),然后初始化该变量(通过函数XXXinitXXXConfig),然后修改配置变量(xxxConfig),修改完后确认配置xxx_initxxx。 // 1.创建adc配置 IfxVadc_Adc_Config adcConfig; // 1.初始化并修改adc配置 IfxVadc_Adc_initModuleConfig(&adcConfig, &MODULE_VADC); // 1.确认adc配置 // IfxVadc_Adc vadc; // declared globally IfxVadc_Adc_initModule(&vadc, &adcConfig); // 2.创建adc组配置 IfxVadc_Adc_GroupConfig adcGroupConfig; // 2.1初始化并修改adc组2的配置 IfxVadc_Adc_initGroupConfig(&adcGroupConfig, &vadc); // 更改组(默认为GroupId_0,更改为GroupId_2) adcGroupConfig.groupId = IfxVadc_GroupId_2; // 重要提示:通常我们使用同一组作为主要组 adcGroupConfig.master = adcGroupConfig.groupId; // 启用所有仲裁请求源 adcGroupConfig.arbiter.requestSlotQueueEnabled = TRUE; // 启用队列模式 adcGroupConfig.arbiter.requestSlotScanEnabled = TRUE; // 启用扫描模式 adcGroupConfig.arbiter.requestSlotBackgroundScanEnabled = TRUE; // 启用背景扫描 // 在“总是”模式下启用所有门(无边缘检测) adcGroupConfig.queueRequest.triggerConfig.gatingMode = IfxVadc_GatingMode_always; adcGroupConfig.scanRequest.triggerConfig.gatingMode = IfxVadc_GatingMode_always; adcGroupConfig.backgroundScanRequest.triggerConfig.gatingMode = IfxVadc_GatingMode_always; // 2.1确认adc组2的配置 IfxVadc_Adc_initGroup(&adcGroup, &adcGroupConfig); // 2.2初始化并修改adc组0的配置 adcGroupConfig.groupId = IfxVadc_GroupId_0; adcGroupConfig.master = adcGroupConfig.groupId; adcGroupConfig.backgroundScanRequest.autoBackgroundScanEnabled = TRUE; adcGroupConfig.backgroundScanRequest.triggerConfig.gatingMode = IfxVadc_GatingMode_always; adcGroupConfig.arbiter.requestSlotBackgroundScanEnabled = TRUE; // 2.2确认adc组0的配置 IfxVadc_Adc_initGroup(&adcGroup, &adcGroupConfig); // 2.3初始化并修改adc组1的配置 adcGroupConfig.groupId = IfxVadc_GroupId_1; adcGroupConfig.master = adcGroupConfig.groupId; adcGroupConfig.backgroundScanRequest.autoBackgroundScanEnabled = TRUE; adcGroupConfig.backgroundScanRequest.triggerConfig.gatingMode = IfxVadc_GatingMode_always; adcGroupConfig.arbiter.requestSlotBackgroundScanEnabled = TRUE; // 2.3确认adc组1的配置 IfxVadc_Adc_initGroup(&adcGroup, &adcGroupConfig); // 3.创建3个通道的配置 IfxVadc_Adc_ChannelConfig adcChannelConfig[3]; for(chnIx=0; chnIx<3; ++chnIx) { // 3.初始化并修改通道配置 IfxVadc_Adc_initChannelConfig(&adcChannelConfig[chnIx], &adcGroup); adcChannelConfig[chnIx].channelId = (IfxVadc_ChannelId)(chnIx); adcChannelConfig[chnIx].resultRegister = (IfxVadc_ChannelResult)(chnIx); // use dedicated result register // 3.确认通道的配置 IfxVadc_Adc_initChannel(&adcChannel[chnIx], &adcChannelConfig[chnIx]); // 增加自动扫描 unsigned channels = (1 << adcChannelConfig[chnIx].channelId); unsigned mask = channels; boolean continuous = TRUE; IfxVadc_Adc_setScan(&adcGroup, channels, mask, continuous); } }
0 点赞
zzyzz
Level 3
Level 3
10 questions asked Welcome! 5 comments on blog
// 执行扫描函数 void ADC_Scan_Demo(void) { unsigned char chnIx; // 开始自动扫描 IfxVadc_Adc_startScan(&adcGroup); // 检查结果 for(chnIx=0; chnIx<3; ++chnIx) { //unsigned group = adcChannel[chnIx].group->groupId; //unsigned channel = adcChannel[chnIx].channel; // 等待有效结果 //Ifx_VADC_RES conversionResult; do{ conversionResult = IfxVadc_Adc_getResult(&adcChannel[chnIx]); } while( !conversionResult.B.VF ); // 输出转换结果 ADC_result[chnIx] = conversionResult.B.RESULT; // print result, check with expected value { // unsigned expected = ((adcMaxPlus1Value * (VADC_COMMANDS_CHN_PER_VOLTAGE_GROUP*group + channel) * vStep) / (vRef-vGnd)); // result |= clib_trace(conversionResult.B.CHNR, channel); // result |= clib_trace_tolerant(conversionResult.B.RESULT, expected, 5); } } }
0 点赞