[YT32B1LE05]采样ADC DMA的方式获取ADC数据,其ADC值出现了4095的情况
-
/* adc_config0 */
const adc_converter_config_t adc_config0={
.clockDivider=0,
.startTime=32,
.sampleTime=5,
.overrunMode=false,
.autoOffEnable=false,
.waitEnable=false,
.trigger=ADC_TRIGGER_SOFTWARE,
.align=ADC_ALIGN_RIGHT,
.resolution=ADC_RESOLUTION_12BIT,
.dmaWaterMark=2,
.dmaEnable=true,
.sequenceConfig={
.sequenceMode=ADC_CONV_LOOP,
.sequenceIntEnable=true,
.convIntEnable=false,
.readyIntEnable=false,
.ovrunIntEnable=false,
.sampIntEnable=false,
.channels={
ADC_INPUTCHAN_EXT2,
ADC_INPUTCHAN_EXT4,
ADC_INPUTCHAN_EXT5,
},
.totalChannels=3,
},
.compareConfig={
.compareEnable=false,
.compareAllChannelEnable=false,.compHigh=4095, .compLow=0, .compIntEnable=false, },
};
-
ADC_Init接口函数:
ADC_DRV_ConfigConverter(0,&adc_config0);
DMA_DRV_Init(&dmaState,&dmaController_InitConfig,dmaChnState,dmaChnConfigArray,NUM_OF_CONFIGURED_DMA_CHANNEL);/* Initiate DMA Loop Transfer */
adcTransferConfig.srcAddr = (uint32_t)&ADC0->FIFO;
adcTransferConfig.destAddr = (uint32_t)&g_adc_result[0U];DMA_DRV_ConfigLoopTransfer(0U, &adcTransferConfig);
DMA_DRV_StartChannel(0U); -
const dma_channel_config_t dma_config0 = {
.virtChnConfig=0,
.source=DMA_REQ_ADC0,
.callback=NULL,
.callbackParam=NULL,
};const dma_channel_config_t *const dmaChnConfigArray[NUM_OF_CONFIGURED_DMA_CHANNEL] = {
&dma_config0,
};const dma_user_config_t dmaController_InitConfig = {
.haltOnError = false
};dma_chn_state_t dma_config0_State;
dma_chn_state_t *const dmaChnState[NUM_OF_CONFIGURED_DMA_CHANNEL]={
&dma_config0_State,
};dma_state_t dmaState;
dma_loop_transfer_config_t adcTransferConfigLoopConfig = {
.triggerLoopIterationCount=10,
.srcOffsetEnable=false,
.dstOffsetEnable=true,
.triggerLoopOffset=-16,
.transferLoopChnLinkEnable=false,
.transferLoopChnLinkNumber=0,
.triggerLoopChnLinkEnable=false,
.triggerLoopChnLinkNumber=0,
};dma_transfer_config_t adcTransferConfig = {
.srcAddr=(uint32_t)0,
.destAddr=(uint32_t)0,
.srcOffset=0,
.destOffset=0x02U,
.srcTransferSize=DMA_TRANSFER_SIZE_2B,
.destTransferSize=DMA_TRANSFER_SIZE_2B,
.srcModulo=DMA_MODULO_OFF,
.destModulo=DMA_MODULO_OFF,
.transferLoopByteCount=16,
.srcLastAddrAdjust=0,
.destLastAddrAdjust=-16,
.interruptEnable=false,
.loopTransferConfig=&adcTransferConfigLoopConfig,
}; -
可以开一下 AWDG 的中断,当转换出来的结果为 0xFFF时,进入中断,看一下当前 ADC 的状态。不过怀疑可能是读空值,即当 ADC FIFO 为空时,仍去读取 ADC FIFO 值。
另外可以参考下这个
https://forum.ytmicro.com/topic/444/adc采样漂移或不准问题排查方法
帮助没办法联网的电脑使用YCT
帮助改进和优化YT CONFIG TOOL,有机会抽取YTM32B1ME0 EVB哦...