版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
嵌入式系统应用肖迎春Email:QQ:787522366Tel:1目录任务1:ADC--模拟电压采集STM32ADC介绍2STM32的A/D转换器STM32单片机有2个独立的ADC控制器,有18个通道,可测量16个外部信号和2个内部信号源:内部温度传感器和内部参考电压(Bandgapvoltage)。ADC电源要求:2.4Vto3.6V。ADC输入范围:VREF-≤VIN≤VREF+(VREF+andVREF-availableonlyinLQFP100package)精度:12位。结果可按左对齐或右对齐的方式存放在16位寄存器中。A/D转换的过程:采用、保持、量化、编程。采样时间越长,转换结果越稳定。采样时间可设置为:1.5个/7.5个/13.5个/28.5个ADC时钟周期。ADC转换时间采用时间+转换时间转换时间:12.5个时钟周期。3STM32的A/D转换器转换模式:
单次/连续/扫描/间断/双重。
扫描模式如果没有启动,则启动一次AD转换只会转换第一个通道;扫描模式如果启动,则启动一次AD转换会对所有通道进行转换。如果是单次模式,启动后一次转换完成后不再转换,如果是连续模式,则一次转换完后继续反复转换。 STM32的16个外部ADC通道可分为两组:规则的和注入的。每个组可以是这16个通道中的任意一些通道以任意顺序进行的组合。规则组最多有16个通道,通道和转换顺序在ADC规则系列寄存器x(ADC_JSQR)中选择。注入组最多有4个通道。通道和转换顺序在ADC注入系列寄存器(ADC_JSQR)中选择。5STM32的A/D转换器ADC端口: PA0~PA7:ADC_IN0~ADC_IN7PB0~PB1:ADC_IN8~ADC_IN9 PC0~PC5:ADC_IN10~ADC_IN15输入信号量程:VREF-~VREF+(0~3.3V)本电路板的模拟电压(电位器)连在PC0端口。
6任务1:ADC模拟电压采集任务:编程从STM32的ADC采集电位器上的模拟电压,通过串口输出到PC上,串口终端接收显示出来目的:掌握STM32ADC的应用及库函数的使用步骤:建立自己的项目文件夹建立Keil工程项目,命名为ADC.uvproj,保存到MDK目录下项目中添加main.c、retarget.c和标准外设库STM32StdPeriphLib.lib配置好C/C++头文件路径和调试工具参数将实验板上的跳线J61,J62接到RS232&RS485端,跳线J59,J60接到RS232端;连接好仿真器和实验板编译、下载程序打开PC机上的串口终端,选择正确的端口和波特率调整电位R2,观察串口接收窗口的数据修改代码,将ADC的数值转换为实际电压值,通过串口将结果发回PC,同时在电压值<1.0V时LED闪烁,电压值>2.5V时蜂鸣器报警;7任务1:配置Debug配置:1、Debug配置9任务1:配置下载工具配置:1、下载工具配置2、设置3、添加下载算法:Stm32F10xConnectivityLine10ADC库函数功能描述USART标准库函数的说明参考课本p335表C.9在软件开发时,adc标准库函数的参数使用,可以参考头文件stm32f10x.h、stm32f10x_adc.h11使用STM32ADC的步骤ADC_Init()初始化,ADC_RegularChannelConfig()设置通道和转化顺序及时间,ADC_Cmd()使能 /*ADC1configuration------------------------------------------------------*/ ADC_InitStructure.ADC_Mode=ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode=ENABLE; ADC_InitStructure.ADC_ContinuousConvMode=ENABLE; ADC_InitStructure.ADC_ExternalTrigConv=ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign=ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel=1; ADC_Init(ADC1,&ADC_InitStructure); /*ADC1regularchannel10configuration*/ ADC_RegularChannelConfig(ADC1,ADC_Channel_10,1,ADC_SampleTime_55Cycles5); /*EnableADC1*/ ADC_Cmd(ADC1,ENABLE);
13使用STM32ADC的步骤重置校验寄存器,等待重置完成,开始校验,等待校验完成 /*EnableADC1resetcalibarationregister*/ ADC_ResetCalibration(ADC1); /*ChecktheendofADC1resetcalibrationregister*/ while(ADC_GetResetCalibrationStatus(ADC1)); /*StartADC1calibaration*/ ADC_StartCalibration(ADC1); /*ChecktheendofADC1calibration*/ while(ADC_GetCalibrationStatus(ADC1));
/*StartADC1SoftwareConversion*/ ADC_SoftwareStartConvCmd(ADC1,ENABLE);调用ADC_GetConversionValue获取结果
AD_value=ADC_GetConversionValue(ADC1);14ADC库函数voidADC_DeInit(ADC_TypeDef*ADCx);voidADC_Init(ADC_TypeDef*ADCx,ADC_InitTypeDef*ADC_InitStruct);voidADC_StructInit(ADC_InitTypeDef*ADC_InitStruct);voidADC_Cmd(ADC_TypeDef*ADCx,FunctionalStateNewState);voidADC_DMACmd(ADC_TypeDef*ADCx,FunctionalStateNewState);voidADC_ITConfig(ADC_TypeDef*ADCx,uint16_tADC_IT,FunctionalStateNewState);voidADC_ResetCalibration(ADC_TypeDef*ADCx);FlagStatusADC_GetResetCalibrationStatus(ADC_TypeDef*ADCx);voidADC_StartCalibration(ADC_TypeDef*ADCx);FlagStatusADC_GetCalibrationStatus(ADC_TypeDef*ADCx);voidADC_SoftwareStartConvCmd(ADC_TypeDef*ADCx,FunctionalStateNewState);FlagStatusADC_GetSoftwareStartConvStatus(ADC_TypeDef*ADCx);voidADC_DiscModeChannelCountConfig(ADC_TypeDef*ADCx,uint8_tNumber);voidADC_DiscModeCmd(ADC_TypeDef*ADCx,FunctionalStateNewState);15ADC库函数voidADC_SetInjectedOffset(ADC_TypeDef*ADCx,uint8_tADC_InjectedChannel,uint16_tOffset);uint16_tADC_GetInjectedConversionValue(ADC_TypeDef*ADCx,uint8_tADC_InjectedChannel);voidADC_AnalogWatchdogCmd(ADC_TypeDef*ADCx,uint32_tADC_AnalogWatchdog);voidADC_AnalogWatchdogThresholdsConfig(ADC_TypeDef*ADCx,uint16_tHighThreshold,uint16_tLowThreshold);voidADC_AnalogWatchdogSingleChannelConfig(ADC_TypeDef*ADCx,uint8_tADC_Channel);voidADC_TempSensorVrefintCmd(FunctionalStateNewState);FlagStatusADC_GetFlagStatus(ADC_TypeDef*ADCx,uint8_tADC_FLAG);voidADC_ClearFlag(ADC_TypeDef*ADCx,uint8_tADC_FLAG);ITStatusADC_GetITStatus(ADC_TypeDef*ADCx,uint16_tADC_IT);voidADC_ClearITPendingBit(ADC_TypeDef*ADCx,uint16_tADC_IT);*函数说明参考课本附录C表C.9,p335页17STM32的ADC介绍ADC转换率达1MHz,精度为12位ADC电源要求:2.4Vto3.6VADC输入范围:VREF-≤VIN≤VREF+(VREF+andVREF-availableonlyinLQFP100package)Dualmode(ondeviceswith2ADCs):8conversionmode多达18个通道:
16externalchannels2internalchannels:与温度传感器和内部参考电压连接(Bandgapvoltage)Channelsconversiongroups:Upto16channelsregulargroupUpto4channelsinjectedgroupSingleandcontinuousconversionmodes18STM32的ADC介绍自动从通道0到通道‘n’进行转换的扫描模式ChannelbychannelprogrammablesamplingtimeandconversionorderDiscontinuousmodeonregularandinjectedgroupsSelf-calibrationLeftorrightDataalignmentwithinbuiltdatacoherencyAnalogWatchdogonhighandlowthresholdsInterruptgenerationon:EndofConversionEndofInjectedconversionAnalogwatchdogDMAcapability(onlyonADC1)19ADCRegularchannelsgroupProgrammablenumberofregularchannels:Upto16channelsProgrammablesampletimeandorderofeachchannelintheconversionsequenceConversionstartedby:SoftwarethroughstartbitExternaltriggergeneratedby:Timer1CC1Timer1CC2Timer1CC3Timer2CC2Timer3TRGOTimer4CC4EXTILine1121ADCInjectedchannelsgroupProgrammablenumberofinjectedchannels:Upto4channelsProgrammablesampletimeandorderofeachchannelintheconversionsequenceConversionstartedby:JAUTO:automaticinjectedconversionafterregularchannelsconversionSoftwarethroughstartbitExternaltriggergeneratedby:Timer1TRGOTimer1CC4Timer2TRGOTimer2CC1Timer3CC4Timer4TRGOEXTILine1522AnalogsampletimeADCCLK,upto14MHz,takenfromPCLK2throughaprescaler(Div2,Div4,Div6andDiv8)Threebitsprogrammablesampletimecyclesforeachchannel:1.5cycles7.5cycles13.5cycles28.5cycles41.5cycles55.5cycles71.5cycles239.5cyclesTotalconversion=Sampletime+12.5cycles(fixedtime)@14MHzandSampletime=1.5cycletotalconversion:1µs(14cycles)ADCADCCLKADCPrescalers:Div2,Div4,Div6andDiv8PCLK255.5cycles7.5cycles71.5cycles41.5cycles13.5cycles28.5cycles1.5cycles239.5cyclesSampleTimeSelectionSMPx[2:0]23ADCdiscontinuousconversionmodeSplitchannelsconversionsequenceintosub-sequencesAvailableforbothregularandinjectedgroups:Upto8conversionforregularchannel1conversionforinjectedchannelExample:-Conversionofchannels:0,1,2,4,5,8,9,11,12,13,14and15-DiscontinuousmodeNumberofchannelis3Channel0Channel1Channel2Channel4Channel5Channel8Channel9Channel11Channel12Channel13Channel14Channel151sttrigger2ndtrigger3rdtrigger4thtriggerEndofConversionChannel0Channel1Channel25thtrigger…Note:
Donotusediscontinuousmodeforbothregularandinjectedtogether.Itcanbeusedonlyforonegroupchannel25ADCDataalignmentOnebitdataalignselection:rightorleftForinjectedchannelconversionnegativevalueaftersubtractionoftheoffsetthesignisextendedinrightalignmentSEXTSEXTSEXTSEXTD11D10D9D8D7D6D5D4D3D2D1D0Rightalignment0000D11D10D9D8D7D6D5D4D3D2D1D0SEXT000D11D10D9D8D7D6D5D4D3D2D1D0Leftalignment0000D11D10D9D8D7D6D5D4D3D2D1D0RegulargroupInjectedgroupRegulargroupInjectedgroup26ADCdualmodes(1/9)AvailableindeviceswithtwoADCs:ADC1masterandADC2slaveADC1andADC2triggersaresynchronizedinternallyforregularandinjectedchannelsconversion8ADCdualmodesGPIOPortsTempSensorVREFINTUpto4injectedchannelsUpto16regularchannelsADC_IN0ANALOGMUX…ADC_IN1ADC_IN15ADC1AnalogADC2AnalogDigitalMasterDigitalSlaveExternaleventsynchronizationExternalevent(Regulargroup)Externalevent(Injectedgroup)DataregisterEOC/JEOC…29ADCdualmodes(2/9)
InjectedsimultaneousmodeCH0CH1CH2CH3CH15CH13CH1CH2ConvertsaninjectedchannelgroupTheexternaltriggersource,whichstarttheconversion,comesfromADC1(simultaneoustriggerprovidedtoADC2)AnendofinjectedconversionisgeneratedattheendofallchannelsconversionResultsstoredoninjecteddataregistersofeachADC.Note:
DonotconvertthesamechannelonthetwoADCsADC2ADC1Injectedsimultaneousmodeon4injectedchannelsSamplingConversionTriggerforinjectedchannelsEndofInjectedConversiononADC1andADC230ADCdualmodes(3/9)
RegularsimultaneousmodeCH0CH1CH2CH3CH15CH14CH13CH12ConvertsaregularchannelgroupTheexternaltriggersource,whichstarttheconversion,comesfromADC1(simultaneoustriggerprovidedtoADC2)AnendofconversionisgeneratedattheendofallchannelsconversionResultsstoredonADC1regulardataregister(32bits)Note:
DonotconvertthesamechannelonthetwoADCsADC2ADC1Regularsimultaneousmodeon16regularchannelsSamplingConversionTriggerforregularchannelsEndofConversiononADC1andADC2……CH15CH031ADCdualmodes(4/9)
FastInterleavedmodeCH0CH0Convertsaregularchannelgroup(usuallyonechannel)Theexternaltriggersource,whichstarttheconversion,comesfromADC1:ADC2startsimmediatelyonADC1triggerADC1startsafteradelayof7ADCclockcyclesAnendofconversionisgeneratedattheendofallchannelsconversionResultsstoredonADC1regulardataregister(32bits)ADC2ADC1FastInterleavedmodeon1regularchannelincontinuousconversionmodeSamplingConversionTriggerforregularchannelsEndofConversiononADC17ADCCLKcycles……CH0CH0CH0CH0EndofConversiononADC2Note:-Themaximumsamplingtimeallowedislessthan7ADCclockcycles32ADCdualmodes(5/9)
SlowInterleavedmodeCH0CH0Convertsaregularchannelgroup(onlyonechannel)Theexternaltriggersource,whichstarttheconversion,comesfromADC1:ADC2startsimmediatelyonADC1triggerADC1startsafteradelayof14ADCclockcyclesAnendofconversionisgeneratedattheendofallchannelsconversionResultsstoredonADC1regulardataregister(32bits)AnewADC2startisautomaticallygeneratedafter28ADCclockcyclesNote:-Themaximumsamplingtimeallowedislessthan14ADCclockcycles-ContinuousconversionmodeisnotsupportedADC2ADC1SlowInterleavedmodeon1regularchannelSamplingConversionTriggerforregularchannelEndofConversiononADC114ADCCLKcyclesCH0CH028ADCCLKcyclesEndofConversiononADC133ADCdualmodes(6/9)
AlternateTriggermodeCH0ConvertsaninjectedchannelgroupTheexternaltriggersource,whichstarttheconversion,comesfromADC1(incaseofinjecteddiscontinuousmodeenabled):On1sttrigger,thefirstinjectedgroupchannelinADC1isconvertedOn2ndtrigger,thefirstinjectedgroupchannelinADC2isconvertedOn3rdtrigger,thesecondinjectedgroupchannelinADC1isconverted…AnendofinjectedconversionisgeneratedattheendofallchannelsconversionResultsstoredoninjecteddataregistersofeachADC.ADC1ADC2AlternateTriggermodeon4injectedchannels(injecteddiscontinuousmodeenabled)SamplingConversion2ndTriggerJEOConADC2CH11CH1CH12CH13CH2CH31stTrigger4thTrigger6thTrigger8thTrigger3rdTrigger5thTrigger7thTriggerCH10JEOConADC134ADCdualmodes(7/9)
CombinedRegular/Injectedsimultaneousmode
CH0CH1CH1CH2CH3CH2CH2CH1ConvertsaninjectedandaregularchannelsgroupsTheexternaltriggerssources,whichstarttheconversions,comesfromADC1(simultaneoustriggerprovidedtoADC2):injectedsimultaneousmodecaninterrupttheotheroneAnendofinjectedconversionisgeneratedattheendofallinjectedchannelsconversionandanendofconversionisgeneratedattheendofallregularchannelsResultsofinjectedchannelsstoredoninjecteddataregistersofeachADC,andregularchannelsonADC1dataregister(32bits)Note:
DonotconvertthesamechannelonthetwoADCsADC2ADC1CombinedRegular/Injectedsimultaneousmodeon4regularchannelsand2injectedchannelsSamplingConversionTriggerforregularchannelsEndofConversiononADC1andADC2CH10CH11CH15CH14ADC2ADC1TriggerforinjectedchannelsEndofInjectedConversiononADC1andADC2regularsimultaneousmodeinterruptedbyinjectedsimultaneousoneCH3CH035ADCdualmodes(8/9)
CombinedRegularsimultaneous+AlternateTriggermode
CH0CH1CH1CH3CH3CH2CH2CH0ConvertsaninjectedandregularchannelsgroupsTheexternaltriggerssources,whichstarttheconversions,comesfromADC1(simultaneoustriggerprovidedtoADC2):alternatetriggermodecaninterrupttheotheroneAnendofinjectedconversionisgeneratedattheendofallinjectedchannelsconversionandanendofconversionisgeneratedattheendofallregularchannelsResultsofinjectedchannelsstoredoninjecteddataregistersofeachADC,andregularchannelsonADC1dataregister(32bits)Note:
DonotconvertthesamechannelonthetwoADCsforregularsimultaneousmodeADC1ADC2CombinedRegula
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 四川省建筑工地施工合同效力证明
- 建材行业库存优化策略
- 恒大养老产业招投标流程
- 职务变动团队适应指南
- 乡镇环境美化工作指南
- 合作伙伴合同签订指南
- 环保项目招投标申请表
- 环保设施承包合同
- 办公大楼车辆出入管理准则
- 市政道路标线施工合同
- 医务人员职业暴露预防及处理课件(完整版)
- 期中考试模拟试卷 2024-2025学年人教版数学九年级上册
- CJT 497-2016 城市轨道交通桥梁伸缩装置
- 中外政治思想史-形成性测试二-国开(HB)-参考资料
- 咖啡种植标准化规程
- 上海大众汽车商务礼仪培训PPT课件
- 理论力学习题集含答案
- 驱动压在肺保护性通气策略中的研究进展(全文)
- 公路工程施工安全技术规范
- “碑学”、“帖学”献疑.doc
- 通信综合网管技术规格书doc
评论
0/150
提交评论