当前位置:网站首页>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.
边栏推荐
- Multi sensor fusion of imu/ optical mouse / wheel encoder (nonlinear Kalman filter)
- Xinyuan & Lichuang EDA training camp - brushless motor drive
- Golang code checking tool
- (4)UART应用设计及仿真验证2 —— RX模块设计(无状态机)
- (4) UART application design and simulation verification 2 - RX module design (stateless machine)
- Design and implementation of secsha system
- Multi camera stereo calibration
- February 13, 2022-4-symmetric binary tree
- Common static methods of math class
- Dynamic memory management (malloc/calloc/realloc)
猜你喜欢

保研笔记二 软件工程与计算卷二(13-16章)

Neural structured learning - Part 2: training with natural graphs

【原创】程序员团队管理的核心是什么?

YML configuration, binding and injection, verification, unit of bean

Go language introduction detailed tutorial (I): go language in the era

Attacking technology Er - Automation

LabVIEW打开PNG 图像正常而 Photoshop打开得到全黑的图像

698. 划分为k个相等的子集 ●●

Do you regret becoming a programmer?

MySQL replace primary key delete primary key add primary key
随机推荐
February 13, 2022 -5- maximum depth of binary tree
Summary of binary tree recursive routines
Multi sensor fusion of imu/ optical mouse / wheel encoder (nonlinear Kalman filter)
Use of shell:for loop
Multi camera stereo calibration
(4) UART application design and simulation verification 2 - RX module design (stateless machine)
Spire.PDF for NET 8.7.2
STM32__06—单通道ADC
二叉树递归套路总结
424. 替换后的最长重复字符 ●●
Rasa 3.x 学习系列-Rasa X 社区版(免费版) 更改
February 13, 2022-4-symmetric binary tree
Object detection based on impulse neural network
asp. Net pop-up layer instance
MySQL delete uniqueness constraint unique
The PNG image is normal when LabVIEW is opened, and the full black image is obtained when Photoshop is opened
(4)UART應用設計及仿真驗證2 —— TX模塊設計(無狀態機)
Comparison between webgl and webgpu [3] - vertex buffer
Code farmers to improve productivity
orgchart. JS organization chart, presenting structural data in an elegant way