CIU32_L051_M307R/bsp/inc/bsp_adc.h

59 lines
1.7 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/***
* @Author: mbw
* @Date: 2024-09-05 15:04:14
* @LastEditors: mbw && 1600520629@qq.com
* @LastEditTime: 2024-09-14 16:22:29
* @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要采集的通道个数
#define NUM_OF_CHANNEL (1U)
// ADC要采集的次数
#define ADC_TIMES (10U)
#define ADC_BUFFER_SIZE (NUM_OF_CHANNEL * ADC_TIMES)
/***************************12V输入的检测用来实现掉电检测****************************/
#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);
#define VIN_ADC_CHANNEL ADC_CHANNEL_3
typedef enum
{
kVinAdc = 0U,
// kVbgrAdc
} TeAdcIndex;
// 存储采集的数据
extern rt_uint16_t adc_buffer[ADC_BUFFER_SIZE];
#define VIN_THREAD_STACK_SIZE (1024)
#define VIN_THREAD_PRIORITY (10)
#define VIN_THREAD_TIMESLICE (20)
// #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
#define VIN_ADC_HIGH_THRESHOLD (0xFFFU * 7 /8) /* 模拟看门狗监控电压高阈值 2.625v*/
#define VIN_ADC_LOW_THRESHOLD (0xFFFU * 2 /3) /* 模拟看门狗监控电压低阈值 2v*/
float Get_VIN_Voltage(void);
rt_uint16_t Get_VIN_VoltageInt1000x(void);
#endif // !__BSP_ADC_H__