当前位置:网站首页>STM32__ 06 - single channel ADC
STM32__ 06 - single channel ADC
2022-07-05 23:33:00 【The God of C language】
One ,ADC( Analog to digital conversion )
STM32 Chip integrated 12 Bit successive approximation type ADC modular , What is successive approximation , Simply put, there is a built-in DAC The module is used to output a voltage for binary comparison with the input voltage , adopt DAC To determine the numerical value of the input voltage . The input voltage range is 0~3.3, Corresponding digital quantity 0~4095. I'm using 103c8t6, Yes 2 individual ADC modular , Respectively ADC1 And ADC2, Every ADC Module has 10 Channels . Next is the following ADC The module is briefly introduced .
I will learn the part of this section , Divide into 3 The modules are
1, Input module
The input pin is for IO Please refer to the following figure , The pin application diagram is from Jiangke University
This picture is very important , It will be used many times later . The configuration of the input module is relatively simple, and it is configured as GPIO_Mode_AIN(GPIO Analog input mode )
2, Connection channel module
This part mainly configures the input channel , The order , Transformation cycle .
It also involves mode selection : Injection mode and rule mode
What we are talking about here is the rule pattern , A simple explanation is to sort the input channels , Then according to certain rules, there is a single conversion , Continuous transformation , Scan conversion , Non scan conversion . Refer to the data manual for specific functions .
3,ADC Converter module ( a key )
In the use of ADC The converter needs to set the prescaler , The prescaler is right 72MHz Divide the internal clock of
Although it can be /2,/4,/6,/8 frequency division , however ADCCLK The biggest one is 14MHz, So you can only use /6,/8 frequency division .
Trigger source can be timer or software .
After the conversion, the value needs to be read from the register , But the register is 16 position , But the value read is 12 position , It needs to be right here 12 Right align the values of bits .
Two , Code section
Conduct ADC Several steps of , Basically follow the above 3 Programming of large modules
1, Turn on RCC, Include ADC And GPIO
2,GPIO initialization , Configured for analog input mode
3, Configure the connection module
4,ADC converter
5, Turn on ADC
6, calibration , Reduce error
Calibration does not require in-depth understanding , Just know how to calibrate .
AD.c
#include "stm32f10x.h" // Device header
void AD_Init(void)
{
// Turn on the clock
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);// Turn on ADC1 The clock
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);// Turn on GPIOA The clock
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AIN;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
ADC_RegularChannelConfig(ADC1,ADC_Channel_0,1,ADC_SampleTime_55Cycles5);// Select the input channel of the rule group
// initialization ADC
ADC_InitTypeDef ADC_InitStructure;
ADC_InitStructure.ADC_Mode=ADC_Mode_Independent;// Select independent working mode
ADC_InitStructure.ADC_DataAlign=ADC_DataAlign_Right;// Data alignment : Right alignment
ADC_InitStructure.ADC_ExternalTrigConv=ADC_ExternalTrigConv_None;// External trigger source selects software trigger
ADC_InitStructure.ADC_ContinuousConvMode=DISABLE;// Continuous conversion mode or single mode
ADC_InitStructure.ADC_ScanConvMode=DISABLE;// Scan mode or non scan mode
ADC_InitStructure.ADC_NbrOfChannel=1;// Number of channels 1~16;
ADC_Init(ADC1,&ADC_InitStructure);
RCC_ADCCLKConfig(RCC_PCLK2_Div6);// To configure ADCCLK 6 frequency division 72/6=12MHz
// Turn on ADC
ADC_Cmd(ADC1,ENABLE);
// calibration
ADC_ResetCalibration(ADC1);// Reset calibration
while(ADC_GetResetCalibrationStatus(ADC1)==SET);// Wait for reset calibration to complete
ADC_StartCalibration(ADC1);// Start calibration
while(ADC_GetCalibrationStatus(ADC1)==SET);// Wait for the calibration to complete
}
uint16_t AD_GetValue(void)
{
ADC_SoftwareStartConvCmd(ADC1,ENABLE);
while(ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC)==RESET);// Rule group or injection group conversion completion flag bit
return ADC_GetConversionValue(ADC1);
}
main.c
#include "stm32f10x.h" // Device header
#include "Delay.h"
#include "LED.h"
#include "Key.h"
#include "Buzzer.h"
#include "OLED.h "
#include "AD.h"
uint16_t ADValue;
float Volatge;
int main()
{
OLED_Init();
AD_Init();
OLED_ShowString(1,1,"ADValue");
OLED_ShowString(2,1,"Volatge:0.00V");
while(1)
{
ADValue = AD_GetValue();
Volatge = (float)ADValue / 1241;
OLED_ShowNum(1,9,ADValue,4);
OLED_ShowNum(2,9,Volatge,1);// Show the part of an integer
OLED_ShowNum(2,11,(uint16_t)(Volatge*100)%100,2);
Delay_ms(100);
}
}
3、 ... and , summary
32 It's a little entry , It's a lot easier to learn . In a few days, we will update the single chip microcomputer of the electronic game MSP430.
边栏推荐
- Attacking technology Er - Automation
- Shell: operator
- idea 连接mysql ,直接贴配置文件的url 比较方便
- Spire Office 7.5.4 for NET
- What is the process of building a website
- TVS管和ESD管的技術指標和選型指南-嘉立創推薦
- orgchart. JS organization chart, presenting structural data in an elegant way
- 14种神笔记方法,只需选择1招,让你的学习和工作效率提高100倍!
- 3: Chapter 1: understanding JVM specification 2: JVM specification, introduction;
- QCombox(重写)+QCompleter(自动补全,自动加载qcombox的下拉选项,设置背景颜色)
猜你喜欢
Spire.PDF for NET 8.7.2
Go语言实现原理——Map实现原理
Go language introduction detailed tutorial (I): go language in the era
20.移植Freetype字体库
698. 划分为k个相等的子集 ●●
Comparison of parameters between TVs tube and zener diode
CorelDRAW plug-in -- GMS plug-in development -- new project -- macro recording -- VBA editing -- debugging skills -- CDR plug-in (2)
Non rigid / flexible point cloud ICP registration
数学公式截图识别神器Mathpix无限使用教程
Do you regret becoming a programmer?
随机推荐
Xinyuan & Lichuang EDA training camp - brushless motor drive
STM32__06—单通道ADC
YML configuration, binding and injection, verification, unit of bean
Spire.PDF for NET 8.7.2
UART Application Design and Simulation Verification 2 - TX Module Design (Stateless machine)
asp. Net pop-up layer instance
VS2010编写动态链接库DLL和单元测试,转让DLL测试的正确性
yate.conf
UVA11294-Wedding(2-SAT)
21.PWM应用编程
TS type declaration
UVA11294-Wedding(2-SAT)
动态规划 之 打家劫舍
3D point cloud slam
Go language introduction detailed tutorial (I): go language in the era
Attacking technology Er - Automation
Southeast Asia e-commerce guide, how do sellers layout the Southeast Asia market?
There are 14 God note taking methods. Just choose one move to improve your learning and work efficiency by 100 times!
Why use weak pointers for delegation- Why use weak pointer for delegation?
C# Linq Demo