您好,欢迎访问三七文档
NuMicroCortex-M0ADC议题NuMicroADC转换器的特性ADC功能方块图ADC的3个操作模式用比较模式监控结果ADC中断自校正ADC特性(I)12比特SARADC模拟电压输入范围:0~Vref(Maxto5.0V).操作电压:VADD=3.0V~5.0V;Vref=0V~VADD.48pin/64pin时,Vref与VADD接在一起,没有拉出来输入通道:最多8个single-end模拟输入通道4个differential模拟输入通道.-Vref~+Vref,0~4096最大600KHzSPS转换频率,转换时间小于1.7us.最大16MHzADC操作频率三个操作模式单次模式:某个通道上A/D转换完成一次.单次循环模式:在所有说明的通道上,按照从低编号通道到高编号通道的顺序,A/D转换完成一个循环.连续循环模式:A/D转换连续执行单次循环模式直到软件停止A/D转换.ADC特性(II)一次A/D转换可以这样启动通过写1到ADST寄存器,软件触发外部引脚STADC转换结果放在每个通道的数据寄存器,带有有效和超出指示.differential模式下数据放在ADCHERchannelenable对应的ADDRx寄存器转换结果可以和特定的值比较,当转换结果等于比较寄存器的设定的时候,用户可以选择是否发生中断.通道7支持3个输入源:外部模拟电压输入内部固定的带隙电压1.2V内部温度传感器输出2mV/°C支持自校正功能以减小转换错误.选择ADC时钟源11100100PLL_Fout12M22MADC_S(CLKSEL1[3:2])ADC_EN(APBCLK[28])ADC_CLK÷(ADC_N+1)ADC_N(CLKDIV[23:16])最大ADC时钟频率16MHzADC时钟频率=(ADC时钟源频率)/(ADC_N+1);8-bitADC_NinCLKDIV[23:16]ADC方块图转换结果ADC配置控制通道选择12-bitDAC&CalibrationA/DStatusRegister(ADSTR)AnalogControlLogicsSuccessiveApproximationsRegisterA/DDataRegister0(ADDR0)A/DDataRegister1(ADDR1)A/DDataRegister7(ADDR7):.+-DigatalControlLogics&ADCClockGeneratorA/DControlRegister(ADCR)A/DChannelEnableRegister(ADCHER)A/DCompareRegister(ADCMR)A/DCalibrationRgister(ADCALR)...AIN[0]AIN[1]AIN[7]*8to1AnalogMUXSampleandHoldComparatorPDMA_nDREQcal_finishandadc_finishSAR[1:0]ADINTSTADC(PB.8)AnalogMacroadc_start&adc_clkVREFchsel[2:0]APBBusVALID&OVERRUNADF*AIN[7]sourceisselectedbyPRESEL[1:0]ADC7VBG0001PRESEL[1:0]VTEMPAVSS0001外部触发引脚4选项:falling/rising/high/low参考输入电压ADCPDMA请求ADC中断请求ADC寄存器映射RegisterOffsetR/WDescriptionResetValueADC_BA=0x400E_0000ADDR0ADC_BA+0x00RA/DDataRegister00x0000_0000ADDR1ADC_BA+0x04RA/DDataRegister10x0000_0000ADDR2ADC_BA+0x08RA/DDataRegister20x0000_0000ADDR3ADC_BA+0x0CRA/DDataRegister30x0000_0000ADDR4ADC_BA+0x10RA/DDataRegister40x0000_0000ADDR5ADC_BA+0x14RA/DDataRegister50x0000_0000ADDR6ADC_BA+0x18RA/DDataRegister60x0000_0000ADDR7ADC_BA+0x1CRA/DDataRegister70x0000_0000ADCRADC_BA+0x20R/WA/DControlRegister0x0000_0000ADCHERADC_BA+0x24R/WA/DChannelEnableRegister0x0000_0000ADCMPR0ADC_BA+0x28R/WA/DCompareRegister00x0000_0000ADCMPR1ADC_BA+0x2CR/WA/DCompareRegister10x0000_0000ADSRADC_BA+0x30R/WA/DStatusRegister0x0000_0000ADCALRADC_BA+0x34R/WA/DCalibrationRegister0x0000_0000ADC控制寄存器differential模式下数据放在ADCHERchannelenable对应的ADDRx寄存器ADCChannelEnableRegisterADC输入通道设定ADC输入引脚与GPIO共享ADC输入引脚必须由SW配置成输入类型.(参考GPIOx_PMD寄存器)Single-end输入模式DIFFEN(ADCR[10])=0(缺省模式)通道:Ch0~Ch7Differential输入模式DIFFEN(ADCR[10])=1PairedChannel:Ch0~Ch3单次模式在单次模式,如果软件使能了多于一个通道,最低编号的通道被转换,其它使能的通道被忽略.sampleADSTADF129820ADDRx[11:0]ADDRx[11:0]ADC_CLK单次循环模式3'b0003'b0103'b0113'b111sampleADSTchsel[2:0]SAR[11:0]ADDR0ADDR2ADDR3ADDR7Single-cyclescanonchannel0,2,3and7(ADCHER[7:0]=8'b10001101)R0R2R3R7R0R2R3R7Channel0Channel2Channel3Channel7连续循环模式3'b0003'b0103'b0113'b1113'b0003'b0103'b0113'b1113'b010ADDR7ADDR3ADDR2ADDR0samplechsel[2:0]ADSTContinuousscanonchannel0,2,3,and7(ADCHER[7:0]=8'b10001101)SoftwareclearADSTChannel0Channel2Channel3Channel7Channel0Channel2Channel0Channel2Channel3利用比较模式监控结果两个12比特ADC结果比较器.比较ADC转换的结果和存在CMPD(ADCCMPRx[27:16])中的用户定义的常量当由CMPCH说明的通道转换完成的时候,比较自动触发一次.比较匹配计数(CMPMATCNTinADCCMPRx[11:8])如果条件匹配数量等于(CMPMATCNT+1)CMPF将被置.12-bitComparatorRSLT=CMPDRSLTCMPDCMPCOND(ADCMPRx[2])10CMPFx(ADSR[2:1])A/DanalogmacroChannelAddr.8to1AnalogMUXMatchCounterCMPMATCNT(ADCMPRx[11:8])AIN[0]AIN[7]....CHANNEL(ADSR[6:4])CMPCH(ADCMPRx[5:3])ADDRx[11:0]CMPD(ADCMPRx[27:16])Note:CMPD=ADCMPRx[27:16]RSLT=ADDRx[11:0]ADC中断ThreeinterruptsourcesADF:转换完成CMPF0:被ADC比较器0监控的条件匹配CMPF1:被ADC比较器1监控的条件匹配ADFADIECMPF1CMPIE1ADINTCMPF0CMPIE0自校正自校正由软件触发时机上电后在single-end和differential-end之间切换输入模式以后例子:单次模式ADC操作TosetADCinputmodeTosetandenableADCclockssourceTosetandenableADCoperationmodeTosetADCconversionchannelToenableADC&NVICinterruptTostartconversionWaitADCfinishinterruptYesCheckADCfinishinterruptNo/*----------------------------------------------------------------------------MAINfunction----------------------------------------------------------------------------*/int32_tmain(void){/*Step1.GPIOinitial*///SetinputmodeGPIOA-PMD.PMD1=0;//DisabledigitalinputpathGPIOA-SCH|=0x00020000;//SetADCfunctionSYS-GPAMFP.ADC1=1;/*Step2.EnableandSelectADCclocksource,andthenenableADCmodule*///Select22MhzforADCSYSCLK-CLKSEL1.ADC_S=2;//ADCclocksource=22Mhz/2=11Mhz;SYSCLK-CLKDIV.ADC_N=1;//EnableclocksourceSYSCLK-APBCLK.ADC_EN=1;/*Step3.SelectOperationmode*///EnableADCmoduleADC-ADCR.ADEN=1;//SingleendinputADC-ADCR.DIFF=0;//SinglemodeADC-ADCR.ADMD=0;示例代码(1/2)/*Step4.SelectADCchannel*/ADC-ADCHER.CHEN=0x02;/*Step5.EnableADCinterrupt*///cleartheA/DinterruptflagsforsafeADC-ADSR.ADF=1;ADC-ADCR.ADIE=1;//ToenabletheADCinterrtuptNVIC_EnableIRQ(ADC_IRQn);/*Step6.Conversionstart*/ADC-ADCR.ADST=1;while(1){if(ADC-ADSR.BUSY==0)ADC-ADCR.ADST=1;ADCTemp=ADC-ADSR.CHANNEL;}}示例代码(2/2)驱动示例(1/2)voidAdcSingleModeTest(){uint8_tu8Option;ADC_INPUT_MODEInputMode;uint8_tu8ChannelSelBitwise,u8ChannelNum;uint32_tu32ConversionData;printf(\n==Singlemodetest===\n);/*SettheADCoperationmodeassinglemode*/DrvADC_SetAdcOperationMode(ADC_SINGLE_OP);while(1){printf(Selectinputmode:\n);pri
本文标题:4_ADC
链接地址:https://www.777doc.com/doc-4043977 .html