int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART2_UART_Init();
MX_TIM2_Init();
MX_TIM3_Init();
MX_ADC1_Init();
/* USER CODE BEGIN 2 */
HAL_UART_Receive_IT(&huart2,(uint8_t *)Uartrec2.RBuf,1);
HAL_TIM_Base_Start_IT(&htim3);
Uartrec2.read_flag =0;
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
if(adc1_tim >=5000)
{
adc1_tim=0;
char uart_buf[300]={0};
HAL_ADC_Start(&hadc1);
uint32_t adc1_val = HAL_ADC_GetValue(&hadc1);
sprintf(uart_buf,"adc is :%6d\n",(const int)adc1_val);
HAL_UART_Transmit_IT(&huart2,(const uint8_t*)&uart_buf[0], 16);
HAL_Delay(100);
}
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
看起来,没有加滤波,ADC的采集还是非常稳定,
lugl4313820 发表于 2024-7-20 06:09 看起来,没有加滤波,ADC的采集还是非常稳定,
是的,可以多次平均。我这里采用很慢(5秒才才一次),多次平均可以加快采样。
本帖最后由 damiaa 于 2024-7-20 12:02 编辑引用: Jacktang 发表于 2024-7-20 07:46 这是高手,^_^
没办法的办法,没找到可调电阻器。