当前位置:网站首页>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.
边栏推荐
- 2:第一章:认识JVM规范1:JVM简介;
- CIS benchmark tool Kube bench
- 【原创】程序员团队管理的核心是什么?
- 21.PWM应用编程
- MySQL (2) -- simple query, conditional query
- 2: Chapter 1: understanding JVM specification 1: introduction to JVM;
- Judge whether the binary tree is a complete binary tree
- Naoqi robot summary 26
- CorelDRAW plug-in -- GMS plug-in development -- new project -- macro recording -- VBA editing -- debugging skills -- CDR plug-in (2)
- UVA11294-Wedding(2-SAT)
猜你喜欢
Creative mode 1 - single case mode
数学公式截图识别神器Mathpix无限使用教程
98. 验证二叉搜索树 ●●
Do you regret becoming a programmer?
LabVIEW打开PNG 图像正常而 Photoshop打开得到全黑的图像
Initial experience | purchase and activate typora software
Switching power supply buck circuit CCM and DCM working mode
Hcip course notes-16 VLAN, three-tier architecture, MPLS virtual private line configuration
Go language implementation principle -- map implementation principle
98. Verify the binary search tree ●●
随机推荐
(4)UART应用设计及仿真验证2 —— TX模块设计(无状态机)
Detailed explanation of pointer and array written test of C language
Use of metadata in golang grpc
Summary of binary tree recursive routines
Attacking technology Er - Automation
Development specification: interface unified return value format [resend]
2022.6.20-6.26 AI行业周刊(第103期):新的小生命
Multi sensor fusion of imu/ optical mouse / wheel encoder (nonlinear Kalman filter)
How to insert data into MySQL database- How can I insert data into a MySQL database?
grafana工具界面显示报错influxDB Error
Spire Office 7.5.4 for NET
2:第一章:认识JVM规范1:JVM简介;
开关电源Buck电路CCM及DCM工作模式
Southeast Asia e-commerce guide, how do sellers layout the Southeast Asia market?
(4)UART应用设计及仿真验证2 —— RX模块设计(无状态机)
MySQL (1) -- related concepts, SQL classification, and simple operations
What is the process of building a website
Scala concurrent programming (II) akka
MySQL (2) -- simple query, conditional query
Go语言实现原理——锁实现原理