嵌入式系统应用-ADC-模拟电压采集-肖迎春.ppt
《嵌入式系统应用-ADC-模拟电压采集-肖迎春.ppt》由会员分享,可在线阅读,更多相关《嵌入式系统应用-ADC-模拟电压采集-肖迎春.ppt(38页珍藏版)》请在三一办公上搜索。
1、嵌入式系统应用,肖迎春 Email:Tel:,2,目录,任务1:ADC-模拟电压采集STM32 ADC介绍,3,STM32的A/D转换器,STM32单片机有2个独立的ADC控制器,有18个通道,可测量16个外部信号和2个内部信号源:内部温度传感器和内部参考电压(Bandgap voltage)。ADC 电源要求:2.4V to 3.6 V。ADC 输入范围:VREF-VIN VREF+(VREF+and VREF-available only in LQFP100 package)精度:12位。结果可按左对齐或右对齐的方式存放在16位寄存器中。A/D转换的过程:采用、保持、量化、编程。采样时间
2、越长,转换结果越稳定。采样时间可设置为:1.5个/7.5个/13.5个/28.5个ADC时钟周期。ADC转换时间 采用时间+转换时间转换时间:12.5个时钟周期。,4,STM32的A/D转换器,转换速率:ADC1和ADC2连在APB2总线上(其最高速率72MHz)。CLK控制器为ADC时钟提供一个专用的可编程预分频器,预分频值为:STM32的ADC允许的最高时钟频率为14MHz,若超过会降低精度,因此需要对CLK进行分频。最快转换时间:最高转换速率:,5,STM32的A/D转换器,转换模式:单次/连续/扫描/间断/双重。扫描模式如果没有启动,则启动一次AD转换只会转换第一个通道;扫描模式如果启
3、动,则启动一次AD转换会对所有通道进行转换。如果是单次模式,启动后一次转换完成后不再转换,如果是连续模式,则一次转换完后继续反复转换。STM32的16个外部ADC通道可分为两组:规则的和注入的。每个组可以是这16个通道中的任意一些通道以任意顺序进行的组合。规则组最多有16个通道,通道和转换顺序在ADC规则系列寄存器x(ADC_JSQR)中选择。注入组最多有4个通道。通道和转换顺序在ADC注入系列寄存器(ADC_JSQR)中选择。,6,STM32的A/D转换器,ADC端口:PA0PA7:ADC_IN0ADC_IN7 PB0PB1:ADC_IN8ADC_IN9 PC0PC5:ADC_IN10ADC
4、_IN15输入信号量程:VREF-VREF+(03.3V)本电路板的模拟电压(电位器)连在PC0端口。,7,任务1:ADC模拟电压采集,任务:编程从STM32的ADC采集电位器上的模拟电压,通过串口输出到PC上,串口终端接收显示出来目的:掌握STM32 ADC的应用及库函数的使用步骤:建立自己的项目文件夹建立Keil工程项目,命名为ADC.uvproj,保存到MDK目录下项目中添加main.c、retarget.c和标准外设库STM32StdPeriphLib.lib配置好C/C+头文件路径和调试工具参数将实验板上的跳线J61,J62接到RS232&RS485端,跳线J59,J60接到RS23
5、2端;连接好仿真器和实验板编译、下载程序 打开PC机上的串口终端,选择正确的端口和波特率调整电位R2,观察串口接收窗口的数据 修改代码,将ADC的数值转换为实际电压值,通过串口将结果发回PC,同时在电压值2.5V时蜂鸣器报警;,8,任务1:配置,头文件路径配置:,1、C/C+配置,2、H文件路径,3、添加路径:.App.INC.INCCMSIS_INC,9,任务1:配置,Debug配置:,1、Debug配置,10,任务1:配置,下载工具配置:,1、下载工具配置,2、设置,3、添加下载算法:Stm32F10 x Connectivity Line,11,ADC库函数功能描述,USART标准库函数
6、的说明参考课本p335表C.9在软件开发时,adc标准库函数的参数使用,可以参考头文件stm32f10 x.h、stm32f10 x_adc.h,12,使用STM32 ADC的步骤,调用RCC_APB2PeriphClockCmd()库函数使能对应IO口的时钟RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_ADC1|RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO,ENABLE);调用GPIO_Init()配置IO口的模式/PC0 作为模拟通道10输入引脚 GPIO_InitStructure
7、.GPIO_Pin=GPIO_Pin_0;GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AIN;GPIO_Init(GPIOC,13,使用STM32 ADC的步骤,ADC_Init()初始化,ADC_RegularChannelConfig()设置通道和转化顺序及时间,ADC_Cmd()使能/*ADC1 configuration-*/ADC_InitStructure.ADC_Mode=ADC_Mode_Independent;ADC_InitStructure.ADC_ScanConvMode=ENABLE;ADC_InitStructure.ADC_Con
8、tinuousConvMode=ENABLE;ADC_InitStructure.ADC_ExternalTrigConv=ADC_ExternalTrigConv_None;ADC_InitStructure.ADC_DataAlign=ADC_DataAlign_Right;ADC_InitStructure.ADC_NbrOfChannel=1;ADC_Init(ADC1,14,使用STM32 ADC的步骤,重置校验寄存器,等待重置完成,开始校验,等待校验完成/*Enable ADC1 reset calibaration register*/ADC_ResetCalibration(A
9、DC1);/*Check the end of ADC1 reset calibration register*/while(ADC_GetResetCalibrationStatus(ADC1);/*Start ADC1 calibaration*/ADC_StartCalibration(ADC1);/*Check the end of ADC1 calibration*/while(ADC_GetCalibrationStatus(ADC1);/*Start ADC1 Software Conversion*/ADC_SoftwareStartConvCmd(ADC1,ENABLE);调
10、用ADC_GetConversionValue获取结果AD_value=ADC_GetConversionValue(ADC1);,15,ADC库函数,void ADC_DeInit(ADC_TypeDef*ADCx);void ADC_Init(ADC_TypeDef*ADCx,ADC_InitTypeDef*ADC_InitStruct);void ADC_StructInit(ADC_InitTypeDef*ADC_InitStruct);void ADC_Cmd(ADC_TypeDef*ADCx,FunctionalState NewState);void ADC_DMACmd(ADC
11、_TypeDef*ADCx,FunctionalState NewState);void ADC_ITConfig(ADC_TypeDef*ADCx,uint16_t ADC_IT,FunctionalState NewState);void ADC_ResetCalibration(ADC_TypeDef*ADCx);FlagStatus ADC_GetResetCalibrationStatus(ADC_TypeDef*ADCx);void ADC_StartCalibration(ADC_TypeDef*ADCx);FlagStatus ADC_GetCalibrationStatus(
12、ADC_TypeDef*ADCx);void ADC_SoftwareStartConvCmd(ADC_TypeDef*ADCx,FunctionalState NewState);FlagStatus ADC_GetSoftwareStartConvStatus(ADC_TypeDef*ADCx);void ADC_DiscModeChannelCountConfig(ADC_TypeDef*ADCx,uint8_t Number);void ADC_DiscModeCmd(ADC_TypeDef*ADCx,FunctionalState NewState);,16,ADC库函数,void
13、ADC_RegularChannelConfig(ADC_TypeDef*ADCx,uint8_t ADC_Channel,uint8_t Rank,uint8_t ADC_SampleTime);void ADC_ExternalTrigConvCmd(ADC_TypeDef*ADCx,FunctionalState NewState);uint16_t ADC_GetConversionValue(ADC_TypeDef*ADCx);uint32_t ADC_GetDualModeConversionValue(void);void ADC_AutoInjectedConvCmd(ADC_
14、TypeDef*ADCx,FunctionalState NewState);void ADC_InjectedDiscModeCmd(ADC_TypeDef*ADCx,FunctionalState NewState);void ADC_ExternalTrigInjectedConvConfig(ADC_TypeDef*ADCx,uint32_t ADC_ExternalTrigInjecConv);void ADC_ExternalTrigInjectedConvCmd(ADC_TypeDef*ADCx,FunctionalState NewState);void ADC_Softwar
15、eStartInjectedConvCmd(ADC_TypeDef*ADCx,FunctionalState NewState);FlagStatus ADC_GetSoftwareStartInjectedConvCmdStatus(ADC_TypeDef*ADCx);void ADC_InjectedChannelConfig(ADC_TypeDef*ADCx,uint8_t ADC_Channel,uint8_t Rank,uint8_t ADC_SampleTime);void ADC_InjectedSequencerLengthConfig(ADC_TypeDef*ADCx,uin
16、t8_t Length);,17,ADC库函数,void ADC_SetInjectedOffset(ADC_TypeDef*ADCx,uint8_t ADC_InjectedChannel,uint16_t Offset);uint16_t ADC_GetInjectedConversionValue(ADC_TypeDef*ADCx,uint8_t ADC_InjectedChannel);void ADC_AnalogWatchdogCmd(ADC_TypeDef*ADCx,uint32_t ADC_AnalogWatchdog);void ADC_AnalogWatchdogThres
17、holdsConfig(ADC_TypeDef*ADCx,uint16_t HighThreshold,uint16_t LowThreshold);void ADC_AnalogWatchdogSingleChannelConfig(ADC_TypeDef*ADCx,uint8_t ADC_Channel);void ADC_TempSensorVrefintCmd(FunctionalState NewState);FlagStatus ADC_GetFlagStatus(ADC_TypeDef*ADCx,uint8_t ADC_FLAG);void ADC_ClearFlag(ADC_T
18、ypeDef*ADCx,uint8_t ADC_FLAG);ITStatus ADC_GetITStatus(ADC_TypeDef*ADCx,uint16_t ADC_IT);void ADC_ClearITPendingBit(ADC_TypeDef*ADCx,uint16_t ADC_IT);*函数说明参考 课本 附录C表C.9,p335页,18,STM32的ADC介绍,ADC 转换率达 1 MHz,精度为12位ADC 电源要求:2.4V to 3.6 VADC 输入范围:VREF-VIN VREF+(VREF+and VREF-available only in LQFP100 pac
19、kage)Dual mode(on devices with 2 ADCs):8 conversion mode多达18个通道:16 external channels 2 internal channels:与温度传感器和内部参考电压连接(Bandgap voltage)Channels conversion groups:Up to 16 channels regular groupUp to 4 channels injected groupSingle and continuous conversion modes,19,STM32的ADC介绍,自动从通道 0 到通道 n 进行转换的扫
20、描模式Channel by channel programmable sampling time and conversion orderDiscontinuous mode on regular and injected groupsSelf-calibrationLeft or right Data alignment with inbuilt data coherencyAnalog Watchdog on high and low thresholdsInterrupt generation on:End of ConversionEnd of Injected conversionA
21、nalog watchdogDMA capability(only on ADC1),20,ADC Block Diagram,21,ADC Regular channels group,Programmable number of regular channels:Up to 16 channelsProgrammable sample time and order of each channel in the conversion sequenceConversion started by:Software through start bitExternal trigger generat
22、ed by:Timer1 CC1 Timer1 CC2Timer1 CC3Timer2 CC2 Timer3 TRGOTimer4 CC4EXTI Line11,22,ADC Injected channels group,Programmable number of injected channels:Up to 4 channelsProgrammable sample time and order of each channel in the conversion sequenceConversion started by:JAUTO:automatic injected convers
23、ion after regular channels conversionSoftware through start bitExternal trigger generated by:Timer1 TRGO Timer1 CC4Timer2 TRGOTimer2 CC1 Timer3 CC4Timer4 TRGOEXTI Line15,23,Analog sample time,ADCCLK,up to 14MHz,taken from PCLK2 through a prescaler(Div2,Div4,Div6 and Div8)Three bits programmable samp
24、le time cycles for each channel:1.5 cycles 7.5 cycles13.5 cycles28.5 cycles41.5 cycles55.5 cycles71.5 cycles239.5 cyclesTotal conversion=Sample time+12.5 cycles(fixed time)14MHz and Sample time=1.5cycle total conversion:1s(14 cycles),ADC,ADCCLK,ADC Prescalers:Div2,Div4,Div6 and Div8,PCLK2,55.5 cycle
25、s,7.5 cycles,71.5 cycles,41.5 cycles,13.5 cycles,28.5 cycles,1.5 cycles,239.5 cycles,Sample Time Selection,SMPx2:0,24,ADC conversion modes,Four conversion mode are available:,CHx,Start,Stop,CHx,Start,Stop,.,CHn,CHx,Start,CHx,Start,.,CHn,Single channel single conversion mode,Multi-channels(Scan)singl
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 嵌入式 系统 应用 ADC 模拟 电压 采集 迎春

链接地址:https://www.31ppt.com/p-6437480.html