CIU32_L051_M307R/bsp/inc/bsp_adc.h

59 lines
1.7 KiB
C
Raw Normal View History

2024-09-05 15:30:19 +08:00
/***
* @Author: mbw
* @Date: 2024-09-05 15:04:14
* @LastEditors: mbw && 1600520629@qq.com
* @LastEditTime: 2024-09-20 10:59:22
2024-09-05 15:30:19 +08:00
* @FilePath: \USART1_Interrupt - RT-Thread\bsp\inc\bsp_adc.h
* @Description:
* @
* @Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
*/
#ifndef __BSP_ADC_H__
#define __BSP_ADC_H__
#include "rtthread.h"
// ADC要采集的通道个数
2024-09-14 09:18:45 +08:00
#define NUM_OF_CHANNEL (1U)
// ADC要采集的次数
2024-09-14 09:18:45 +08:00
#define ADC_TIMES (10U)
#define ADC_BUFFER_SIZE (NUM_OF_CHANNEL * ADC_TIMES)
2024-09-05 15:30:19 +08:00
/***************************12V输入的检测用来实现掉电检测****************************/
2024-09-05 15:30:19 +08:00
#define VIN_ADC_GPIO_PORT GPIOA
#define VIN_ADC_GPIO_PIN GPIO_PIN_4
// #define VIN_ADC_GPIO_CLK_ENABLE() std_rcc_gpio_clk_enable(RCC_PERIPH_CLK_GPIOA);
2024-09-05 15:30:19 +08:00
#define VIN_ADC_CHANNEL ADC_CHANNEL_3
2024-09-05 15:30:19 +08:00
typedef enum
{
kVinAdc = 0U,
2024-09-14 09:18:45 +08:00
// kVbgrAdc
} TeAdcIndex;
2024-09-05 15:30:19 +08:00
// 存储采集的数据
extern rt_uint16_t adc_buffer[ADC_BUFFER_SIZE];
2024-09-05 15:30:19 +08:00
#define VIN_THREAD_STACK_SIZE (512)
#define VIN_THREAD_PRIORITY (10)
#define VIN_THREAD_TIMESLICE (20)
2024-09-05 15:30:19 +08:00
#define VIN_VOLTAGE_RATIO (4.19148936F)
// #define VIN_VOLTAGE_RATIO (1)
// 不含输入二极管的压降
// (4.7/19.7) * 13V = 3.1V, 3.1/3.3*4096 = 3723
// #define VIN_ADC_HIGH_THRESHOLD (uint16_t)3847 // 13V
// (4.7/19.7) * 10V = 2.39V, 2.39/3.3*4096 = 2966
// #define VIN_ADC_LOW_THRESHOLD (uint16_t)2966 // 10V
2024-09-05 15:30:19 +08:00
#define VIN_ADC_HIGH_THRESHOLD (0xFFFU * 7 /8) /* 模拟看门狗监控电压高阈值 2.625v*/
#define VIN_ADC_LOW_THRESHOLD (0xFFFU * 2 /3) /* 模拟看门狗监控电压低阈值 2v*/
2024-09-05 15:30:19 +08:00
float Get_VIN_Voltage(void);
2024-09-05 15:30:19 +08:00
rt_uint16_t Get_VIN_VoltageInt1000x(void);
2024-09-05 15:30:19 +08:00
#endif // !__BSP_ADC_H__