当前位置:网站首页>SWM32系列教程5-ADC应用
SWM32系列教程5-ADC应用
2022-07-28 06:11:00 【天外飞仙CUG】

1.ADC功能介绍
SWM32SRET6单片机内置2个12位SAR型ADC,最多支持8通道,1MSPS 转换速率。支持软件触发、定时器触发。该单片机的ADC模块结构框图如下,

该ADC相比于其它单片机内部ADC来说,有两个特点,一个是硬件平均器,一个是8级深度的FIFO。硬件平均器可以减少CPU软件求平均的工作量,8级深度的FIFO也可以减少中断的频率(如果使能中断),两者都提高程序的效率。唯一遗憾的是没有看到DMA部分内容,应该是不支持DMA读取。
2.串口应用
直接来看程序:
void ADCInit(void)
{
ADC_InitStructure ADC_initStruct;
PORT_Init(PORTC, PIN6, PORTC_PIN6_ADC1_IN1, 0); //PC6 => ADC1.CH1
ADC_initStruct.clk_src = ADC_CLKSRC_VCO_DIV64; //注意:ADC1只能使用VCO时钟,不能使用ADC_CLKSRC_HRC
ADC_initStruct.clk_div = 25;
ADC_initStruct.pga_ref = PGA_REF_INTERNAL;
ADC_initStruct.channels = ADC_CH1;
ADC_initStruct.samplAvg = ADC_AVG_SAMPLE16; //16次硬件平均
ADC_initStruct.trig_src = ADC_TRIGSRC_SW; //软件触发
ADC_initStruct.Continue = 1; //连续模式
ADC_initStruct.EOC_IEn = 0;
ADC_initStruct.OVF_IEn = 0;
ADC_initStruct.HFULL_IEn = ADC_CH1; //使能FIFO半满中断
ADC_initStruct.FULL_IEn = 0;
ADC_Init(ADC1, &ADC_initStruct); //配置ADC
ADC_Open(ADC1); //使能ADC
ADC_Start(ADC1);
}首先需要初始化IO口为ADC输入模式。ADC的IO只能是固定的几个,不像UART等数字接口一样可以灵活配置。
其次是ADC功能的配置。首先选择时钟源和通道,这里使能了ADC1的CH1,如果需要多个通道扫描,则几个通道号相与即可:
ADC_initStruct.channels = ADC_CH1| ADC_CH2| ADC_CH3;开启了16次硬件平均,即启动一次转换,硬件自动采样16次并输出平均值。
这里使能了连续转换模式。开启了FIFO半满中断。ADC有多个中断源:
EOC_IEn--转换结束中断
OVF_IEn--FIFO溢出中断
HFULL_IEn—FIFO半满中断
FULL_IEn—FIFO满中断
转换结束中断是每次ADC转换完成后中断一次。由于有FIFO的存在,这里使能了FIFO半满中断,这样ADC采样后自动将数据存在FIFO中,当FIFO半满时中断一次读出全部数据。这样可以减少程序中断的频率。
在中断函数中,需要清除中断标志,读取FIFO中的数据,如果是单次转换模式,还需要重新触发ADC转换。程序如下:
uint16_t adc_buf[100];
uint16_t adc_cnt = 0;
void ADC1_Handler(void)
{
ADC1->IF = (1 << ADC_IF_CH1HFULL_Pos);//
while((ADC1->CH[1].STAT & ADC_STAT_EMPTY_Msk) == 0)//读出FIFO中全部数据
{
adc_buf[adc_cnt] = ADC_Read(ADC1, ADC_CH1);
adc_cnt++;
if(adc_cnt == 100)
adc_cnt = 0;
}
//ADC_Start(ADC1);
}推荐阅读:
欢迎关注公众号"嵌入式技术开发",大家可以后台给我留言沟通交流。如果觉得该公众号对你有所帮助,也欢迎推荐分享给其他人。
边栏推荐
- Merge two sorted linked lists - two questions per day
- (daily question) - the longest substring without repeated characters
- [Google] solve the problem that Google browser does not pop up the account and password save box and cannot save login information
- 数据化管理洞悉零售及电子商务运营——数据化管理介绍
- DNA修饰贵金属纳米颗粒|DNA脱氧核糖核酸修饰金属钯Pd纳米颗粒PdNPS-DNA
- .NET 6.0中使用Identity框架实现JWT身份认证与授权
- The penultimate node in the linked list - Double finger
- 微信小程序隐藏滚动条的方法
- Mysql查看某个表所占内存大小
- Collection | combined with my personal experience, I have summarized these seven EMC related knowledge
猜你喜欢

win系统添加打印机

Digital management insight into retail and e-commerce operations -- Introduction to digital management

EMC's "don't come back until you rectify"

动态内存管理知识点

非关系型数据库之Redis【redis安装】

The first common node of two linked lists -- two questions per day
![[solution] visual full link log tracking - log tracking system](/img/0c/f93c7d31e01257c5dee7d292ac7d84.jpg)
[solution] visual full link log tracking - log tracking system

近红外二区AgzS量子点包裹脱氧核糖核酸DNA|DNA-AgzSQDs(齐岳)

Disassemble Huawei switches and learn Basic EMC operations

How low-end computers learn secrets in depth - using the mistgpu computing platform
随机推荐
EMC rectification ideas
flowable工作流所有业务概念
【jvm优化】线上JVM调优实践
Don't be afraid of ESD static electricity. This article tells you some solutions
How low-end computers learn secrets in depth - using the mistgpu computing platform
2022/7/27 考试总结
通过sed 修改conf文件
非关系型数据库之Redis【redis集群详细搭建】
MHA high availability configuration and failover
【解决方案】可视化全链路日志追踪-日志追踪系统
(每日一题)——最长不含重复字符的子字符串
Which of class A and class B is more stringent in EMC?
DNA modified rhodium RH nanoparticles rhnps DNA (DNA modified noble metal nanoparticles)
EMC中class A和class B哪个更严格?
On deep paging
Isolation level RR, gap lock, unreal reading
华为高级工程师---BGP路由过滤及社团属性
[untitled]
调整数组顺序使奇数位于偶数前面——每日两题
[Google] solve the problem that Google browser does not pop up the account and password save box and cannot save login information