当前位置:网站首页>STM32 photoresistor sensor & two channel AD acquisition
STM32 photoresistor sensor & two channel AD acquisition
2022-07-01 04:43:00 【Flowers bloom in half】
Photoresistor sensor
Schematic diagram

Tr_AO: Analog output , Turn the collected light into a continuous analog signal from Tr_AO Pin out .
Tr_DO: Adjust the RP7, Comparison with partial voltage of photosensitive resistance , adopt Tr_DO Output 0 or 1.

Code
Photo.c
#include "Photo.h"
uint32_t Get_Adc2(void)
{
uint32_t adc_value;
HAL_ADC_Start(&hadc2);
if(HAL_ADC_PollForConversion(&hadc2,10) == HAL_OK)
{
adc_value = HAL_ADC_GetValue(&hadc2);
}
return adc_value;
}
Photo.h
#ifndef _PHOTO_H_
#define _PHOTO_H_
#include "main.h"
#include "adc.h"
uint32_t Get_Adc2(void);
#endifDisplay the partial pressure value
void Lcd_Proc(void)
{
if(uwTick - lcd_uwTick < 200)
return;
lcd_uwTick = uwTick;
sprintf((char *)lcd_disp_string,"photo_value: %d ",Get_Adc2());
LCD_DisplayStringLine(Line3,lcd_disp_string);
//" R-P:%.2fK ", Get_Adc2() / (4096. - Get_Adc2()) * 10
sprintf((char *)lcd_disp_string," R-P:%.2fK ", Get_Adc2() / (4096. - Get_Adc2()) * 10);
LCD_DisplayStringLine(Line4,lcd_disp_string);
if(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_3) == GPIO_PIN_SET)
{
sprintf((char *)lcd_disp_string," DO: high ");
}
else
{
sprintf((char *)lcd_disp_string," DO: low ");
}
LCD_DisplayStringLine(Line5,lcd_disp_string);
}Two ways AD collection
Different for acquisition AD Different channels of , It's easy , The following is to collect the same AD Different channels of .
Schematic diagram


The previous part is right ADC2 The initialization , The following is the configuration of the channel , But we use the same AD Different channels , And only one channel can be configured separately , So we can get ADC Values in the function , Delete the configuration in this function .

Pay attention to the pin configuration here .
2AD.c
#include "2AD.h"
uint32_t Get_adc1(void)
{
uint32_t adc1;
ADC_ChannelConfTypeDef sConfig = {0};
sConfig.Channel = ADC_CHANNEL_17;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_640CYCLES_5;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
{
Error_Handler();
}
HAL_ADC_Start(&hadc2);
if(HAL_ADC_PollForConversion(&hadc2,10) == HAL_OK)
{
adc1 = HAL_ADC_GetValue(&hadc2);
}
return adc1;
}
uint32_t Get_adc2(void)
{
uint32_t adc2;
ADC_ChannelConfTypeDef sConfig = {0};
sConfig.Channel = ADC_CHANNEL_13;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_640CYCLES_5;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
{
Error_Handler();
}
HAL_ADC_Start(&hadc2);
if(HAL_ADC_PollForConversion(&hadc2,10) == HAL_OK)
{
adc2 = HAL_ADC_GetValue(&hadc2);
}
return adc2;
}
2AD.h
#include "main.h"
#include "adc.h"
uint32_t Get_adc1(void);
uint32_t Get_adc2(void);
Display voltage value function
void Lcd_Proc(void)
{
if(uwTick - lcd_uwTick < 200)
return;
lcd_uwTick = uwTick;
sprintf((char *)lcd_disp_string," RP5_V: %.2fV ",Get_adc1() * 3.3 / 4096);
LCD_DisplayStringLine(Line2,lcd_disp_string);
sprintf((char *)lcd_disp_string," RP6_V: %.2fV ",Get_adc2() * 3.3 / 4096);
LCD_DisplayStringLine(Line3,lcd_disp_string);
}In some cases, the order of these two values will be reversed when reading , Remember in 15 SCM reads two AD A similar situation has occurred when the value is , The solution was to read it twice , Then this one , Appropriate delay can be made , But I don't know why , When I wrote this program myself, I succeeded as soon as I wrote it , There is no problem of location exchange , therefore , There is the problem of position exchange , You can delay reading properly .

边栏推荐
- LeetCode_28(实现 strStr())
- Section 27 remote access virtual private network workflow and experimental demonstration
- One click shell to automatically deploy any version of redis
- C -- array
- This sideline workload is small, 10-15k, free unlimited massage
- 神经网络-非线性激活
- 2022 t elevator repair question bank and simulation test
- Question bank and online simulation examination for special operation certificate of G1 industrial boiler stoker in 2022
- Codeforces Round #771 (Div. 2) ABCD|E
- Odeint et GPU
猜你喜欢

2022.2.7-2.13 AI industry weekly (issue 84): family responsibilities

离线安装wireshark2.6.10

2022 Shanghai safety officer C certificate examination question simulation examination question bank and answers

Cmake selecting compilers and setting compiler options

Dual contractual learning: text classification via label aware data augmentation reading notes

2022危险化学品生产单位安全生产管理人员题库及答案

Daily question - line 10

Offline installation of Wireshark 2.6.10

pytorch 卷积操作

2022 t elevator repair question bank and simulation test
随机推荐
LM小型可编程控制器软件(基于CoDeSys)笔记二十:plc通过驱动器控制步进电机
Shell之分析服务器日志命令集锦
Measurement of quadrature axis and direct axis inductance of three-phase permanent magnet synchronous motor
Applications and features of VR online exhibition
Selenium opens the Chrome browser and the settings page pops up: Microsoft defender antivirus to reset your settings
pytorch 卷积操作
Shell之Unix运维常用命令
Talk about testdeploy
[2020 overview] overview of link prediction based on knowledge map embedding
Odeint et GPU
解决qiankun中子应用外链文件无法获取
Basic usage, principle and details of session
数据加载及预处理
Simple implementation of slf4j
Maixll-Dock 快速上手
The index is invalid
科研狗可能需要的一些工具
Haskell lightweight threads overhead and use on multicores
最长递增子序列及最优解、动物总重量问题
Basic exercise of test questions hexadecimal to decimal