当前位置:网站首页>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.
边栏推荐
- Neural structured learning 4 antagonistic learning for image classification
- 带外和带内的区别
- TVS管和ESD管的技术指标和选型指南-嘉立创推荐
- When to use useImperativeHandle, useLayoutEffect, and useDebugValue
- Krypton Factor-紫书第七章暴力求解
- Rasa 3. X learning series -rasa x Community Edition (Free Edition) changes
- Live tiktok shop 2022 latest gameplay card slot overseas live e-commerce new traffic
- Opencvsharp (C openCV) shape detection and recognition (with source code)
- AsyncSocket长连接棒包装问题解决
- 开关电源Buck电路CCM及DCM工作模式
猜你喜欢
Dynamic memory management (malloc/calloc/realloc)
Technical specifications and model selection guidelines for TVs tubes and ESD tubes - recommended by jialichuang
TVS管 与 稳压二极管参数对比
How to design API return code (error code)?
STM32__06—单通道ADC
无刷驱动设计——浅谈MOS驱动电路
并查集实践
Data analysis - Thinking foreshadowing
98. 验证二叉搜索树 ●●
Sum of two numbers, sum of three numbers (sort + double pointer)
随机推荐
Spire.PDF for NET 8.7.2
芯源&立创EDA训练营——无刷电机驱动
Mathematical formula screenshot recognition artifact mathpix unlimited use tutorial
Go language implementation principle -- map implementation principle
Use of shell:for loop
424. The longest repeated character after replacement ●●
How to improve eloquence
MySQL (2) -- simple query, conditional query
[Yu Yue education] NC machining technology reference materials of Shaanxi University of science and technology
VS2010 writes DLL and unit test of dynamic link library, and transfers the correctness of DLL test
Krypton Factor purple book chapter 7 violent solution
21.PWM应用编程
UVA – 11637 Garbage Remembering Exam (组合+可能性)
The maximum happiness of the party
基于脉冲神经网络的物体检测
二叉树递归套路总结
AsyncSocket长连接棒包装问题解决
开关电源Buck电路CCM及DCM工作模式
Xinyuan & Lichuang EDA training camp - brushless motor drive
Creative mode 1 - single case mode