当前位置:网站首页>Swm32 series tutorial 5-adc application
Swm32 series tutorial 5-adc application
2022-07-28 07:54:00 【Tianwaifeixian CUG】

1.ADC Function is introduced
SWM32SRET6 MCU built-in 2 individual 12 position SAR type ADC, Most support 8 passageway ,1MSPS Conversion rate . Support software trigger 、 Timer triggered . The design of the single chip microcomputer ADC The block diagram of module structure is as follows ,

The ADC Compared with other MCU internal ADC Come on , There are two characteristics , One is hardware averager , One is 8 Level depth FIFO. Hardware averagers can reduce CPU Average workload of software ,8 Level depth FIFO It can also reduce the frequency of interrupts ( If enabled, interrupt ), Both improve the efficiency of the program . The only regret is that I didn't see DMA Part content , It should not support DMA Read .
2. Serial port application
Look at the program directly :
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; // Be careful :ADC1 Only use VCO The clock , Out of commission 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 Secondary hardware average
ADC_initStruct.trig_src = ADC_TRIGSRC_SW; // Software triggers
ADC_initStruct.Continue = 1; // Continuous mode
ADC_initStruct.EOC_IEn = 0;
ADC_initStruct.OVF_IEn = 0;
ADC_initStruct.HFULL_IEn = ADC_CH1; // Can make FIFO Half full interrupt
ADC_initStruct.FULL_IEn = 0;
ADC_Init(ADC1, &ADC_initStruct); // To configure ADC
ADC_Open(ADC1); // Can make ADC
ADC_Start(ADC1);
}Initialization required first IO The mouth is ADC The input mode .ADC Of IO It can only be fixed , Unlike UART And other digital interfaces can be flexibly configured .
The second is ADC Configuration of functions . First select the clock source and channel , It's enabled here ADC1 Of CH1, If multiple channel scanning is required , Then several channel numbers can be matched :
ADC_initStruct.channels = ADC_CH1| ADC_CH2| ADC_CH3;Open the 16 Secondary hardware average , That is, start a conversion , Hardware automatic sampling 16 Times and output the average value .
Here the continuous conversion mode is enabled . Open the FIFO Half full interrupt .ADC There are multiple interrupt sources :
EOC_IEn-- End of conversion interrupt
OVF_IEn--FIFO Overflow interrupt
HFULL_IEn—FIFO Half full interrupt
FULL_IEn—FIFO Full interrupt
The end of conversion interrupt is every ADC Interrupt once after the conversion . Because of FIFO The existence of , It's enabled here FIFO Half full interrupt , such ADC After sampling, the data will be stored automatically FIFO in , When FIFO When half full, interrupt reading all data at once . This can reduce the frequency of program interruption .
In interrupt function , You need to clear the interrupt flag , Read FIFO Data in , If it is a single conversion mode , It needs to be triggered again ADC transformation . The procedure is as follows :
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)// read out FIFO All data in
{
adc_buf[adc_cnt] = ADC_Read(ADC1, ADC_CH1);
adc_cnt++;
if(adc_cnt == 100)
adc_cnt = 0;
}
//ADC_Start(ADC1);
}Recommended reading :
several RS485 Introduction to the scheme of isolated communication
SWM32 Series of tutorials 4- Port mapping and serial port application
Welcome to the official account " Development of Embedded Technology ", You can leave a message for me backstage . If you think the official account is helpful to you , Also welcome to recommend and share with others .
边栏推荐
- MySQL view the memory size of a table
- protobuf 基本语法总结
- User mode vs kernel mode, process vs thread
- ESD静电不用怕,本文告诉你一些解决方法
- PCB design skills of EMC
- What is the root cause of EMC's problems?
- After being accidentally dragged into QQ fraud group
- 再次出现用户净流失,大失颜面的中国移动推出超低价套餐争取用户
- 深度学习基础宝典---激活函数、Batch Size、归一化
- MPLS --- 多协议标签交换技术
猜你喜欢

win系统添加打印机

Using identity framework to realize JWT identity authentication and authorization in.Net 6.0
![[dry goods] 32 EMC standard circuits are shared!](/img/51/cff9dd7e033ca2df917307e9fe38ff.jpg)
[dry goods] 32 EMC standard circuits are shared!

整改了七次,花了半个月时间,惨痛的EMC总结

DNA modified noble metal nanoparticles | DNA modified copper nanoparticles cunps-dna | research points

Don't be afraid of ESD static electricity. This article tells you some solutions

DNA modified rhodium RH nanoparticles rhnps DNA (DNA modified noble metal nanoparticles)

Collection | combined with my personal experience, I have summarized these seven EMC related knowledge

Daily question - split equal sum subset
![[Google] solve the problem that Google browser does not pop up the account and password save box and cannot save login information](/img/b3/2592e941f5d8f3505fb9763e8947a6.png)
[Google] solve the problem that Google browser does not pop up the account and password save box and cannot save login information
随机推荐
Using identity framework to realize JWT identity authentication and authorization in.Net 6.0
And is two numbers of S - two questions per day
After being accidentally dragged into QQ fraud group
Flowable workflow all business concepts
Cdn.jsdelivr.net is not available, what should I do
Information system project manager must recite the core examination site (41) risk management plan
Opencv's practical learning of credit card recognition (4)
Retryer of guava
5g commercial third year: driverless "going up the mountain" and "going to the sea"
快速搭建DMHS DM之间双向同步
Reasons why null is not recommended for MySQL fields
What is the root cause of EMC's problems?
Analysis of collector principle
DNA modified osmium OS nanoparticles osnps DNA modified iridium nanoparticles irnps DNA
03 | 项目部署:如何快速部署一个基于laravel框架开发的网站
Discrimination coverage index / index coverage / Samsung index
GD32使用ST的HAL库和GD官方库的一些体会
Tensorflow uses deep learning (II)
【13】加法器:如何像搭乐高一样搭电路(上)?
Niuke MySQL - SQL must know and know