YTM32B1ME0 读取ADC FIFO数据的通道号与配置通道不一致
-
问题现象描述:
1.我配置ADC的一组为: 通道 0,1,12,13;当我读取ADC->FIFO时,有缺少的还有重复的channel-ID;
2.使用库函数读取ADC->FIFO时,存放寄存器变量的uint32 regValue的值 与寄存器视图 的值 不一致;下面是我ADC的工具配置信息:
/* adc_config0 */ const adc_converter_config_t adc_config0={ .clockDivider=0, .startTime=12, .sampleTime=2, .overrunMode=false, .autoOffEnable=false, .waitEnable=false, .trigger=ADC_TRIGGER_SOFTWARE, .align=ADC_ALIGN_RIGHT, .resolution=ADC_RESOLUTION_12BIT, .dmaWaterMark=0, .dmaEnable=false, .sequenceConfig={ .sequenceMode=ADC_CONV_LOOP, .sequenceIntEnable=false, .convIntEnable=false, .readyIntEnable=false, .ovrunIntEnable=false, .sampIntEnable=false, .channels={ ADC_INPUTCHAN_EXT0, ADC_INPUTCHAN_EXT1, ADC_INPUTCHAN_EXT12, ADC_INPUTCHAN_EXT13, }, .totalChannels=4, }, .compareConfig={ .compareEnable=false, .compareAllChannelEnable=false, .compHigh=4095, .compLow=0, .compIntEnable=false, }, };
#define ADC_INST 0U adc_converter_config_t get_adc_config0; uint8_t set_adc_sequence_cnt = 2; uint8_t get_adc_sequence_cnt = 2; void ADC_Init(void) { ADC_DRV_ConfigConverter(ADC_INST,&adc_config0); ADC_DRV_Start(ADC_INST); //get adc sequence length set_adc_sequence_cnt = adc_config0.sequenceConfig.totalChannels; ADC_DRV_GetConverterConfig(ADC_INST, &get_adc_config0); get_adc_sequence_cnt = get_adc_config0.sequenceConfig.totalChannels; }
void ADC_Get_Value_10ms(void) { uint32 reg_value = 0; for (uint8_t i = 0; i < set_adc_sequence_cnt; i++) { reg_value = ADC_DRV_ReadSeqtagAndData(ADC_INST); // uint8_t channel_id = reg_value>>16; uint8_t channel_id = (reg_value>>16)&0x1f; uint16_t chan_raw_data = (reg_value&0x0000ffff); if(channel_id == 0)//ADC0_SE0 { uint16 ADC_mV_IntPackVolt = 0; ADC_mV_IntPackVolt = (reg_value&0x0000ffff)*3300/4096; //test code to view the convert result of ADC ADC_mV_IntPackVolt = 1100; } } ADC_DRV_Start(ADC_INST); }
-
Diga 请问下问题1出现的原因是什么:
1.我配置ADC的一组为: 通道 0,1,12,13;当我读取ADC->FIFO时,读出的通道是0, 12, 9, 9; -
FarlyHuang 大抵是因为你下面打开了 Memory 窗口,0x4004004C 正好是 ADC->FIFO 寄存器的地址,跟读左侧的寄存器窗口效果是一样的
-
Diga 我现在把memory读取ADC-> FIFO的视图关闭了,现在读取通道号仍然与配置不一样
下次是我调试的配置:
/* adc_config0 */ const adc_converter_config_t adc_config0={ .clockDivider=0, .startTime=12, .sampleTime=2, .overrunMode=false, .autoOffEnable=false, .waitEnable=false, .trigger=ADC_TRIGGER_SOFTWARE, .align=ADC_ALIGN_RIGHT, .resolution=ADC_RESOLUTION_12BIT, .dmaWaterMark=0, .dmaEnable=false, .sequenceConfig={ .sequenceMode=ADC_CONV_LOOP, .sequenceIntEnable=false, .convIntEnable=false, .readyIntEnable=false, .ovrunIntEnable=false, .sampIntEnable=false, .channels={ ADC_INPUTCHAN_EXT0, ADC_INPUTCHAN_EXT1, ADC_INPUTCHAN_EXT12, ADC_INPUTCHAN_EXT13, }, .totalChannels=4, }, .compareConfig={ .compareEnable=false, .compareAllChannelEnable=false, .compHigh=4095, .compLow=0, .compIntEnable=false, }, };
#include "adc.h" #define ADC_INST 0U adc_converter_config_t get_adc_config0; uint8_t set_adc_sequence_cnt = 2; uint8_t get_adc_sequence_cnt = 2; void ADC_Init(void) { ADC_DRV_ConfigConverter(ADC_INST,&adc_config0); ADC_DRV_Start(ADC_INST); //get adc sequence length set_adc_sequence_cnt = adc_config0.sequenceConfig.totalChannels; ADC_DRV_GetConverterConfig(ADC_INST, &get_adc_config0); get_adc_sequence_cnt = get_adc_config0.sequenceConfig.totalChannels; } uint32_t adc_FIFO_values[] = {0,0,0,0}; uint16_t adc_channels_values[] = {0,0,0,0}; void ADC_Get_Value_10ms(void) { uint32 reg_value = 0; for (uint8_t i = 0; i < set_adc_sequence_cnt; i++) { reg_value = ADC_DRV_ReadSeqtagAndData(ADC_INST); uint8_t channel_id = reg_value>>16; // uint8_t channel_id = (reg_value>>16)&0x1f; uint16_t chan_raw_data = (reg_value&0x0000ffff); adc_FIFO_values[i] = reg_value; adc_channels_values[i] = channel_id; if(channel_id == 0)//ADC0_SE0 { uint16 ADC_mV_IntPackVolt = 0; ADC_mV_IntPackVolt = (reg_value&0x0000ffff)*3300/4096; //test code to view the convert result of ADC ADC_mV_IntPackVolt = 1100; } } ADC_DRV_Start(ADC_INST); }
-
FarlyHuang 看起来还是有个什么东西在读取 ADC->FIFO ,你读到的第三个值 0x9094C,应该就是 FIFO 空了之后的值。也就是你软件读了两个值之后,ADC->FIFO 已经空了。
可以再 check 一下你的调试环境,如果可以的话,尽量换别的 IDE 再试试(KEIL,IAR,OZone) -
Diga 好的, 我用OZone尝试一下
-
Diga 感谢指导, 使用OZone 尝试后,读取的通道ID与配置项一致了;
顺便请教一下,如果使用vs code debug情况下,怎么排查问题是哪里引起的乱序呢? 因为使用vs code是比较方便的
-
FarlyHuang 关于vscode debug,你可以在这个地方问题:https://github.com/Marus/cortex-debug
-
Frankie 好的,感谢
-
帮助没办法联网的电脑使用YCT
帮助改进和优化YT CONFIG TOOL,有机会抽取YTM32B1ME0 EVB哦...