980 views|2 replies

410

Posts

3

Resources
The OP
 

【CW32L052 Review】 Segment LCD displays ADC sampling voltage value [Copy link]

 

In this article, we will learn about the CW32L052 chip ADC voltage sampling and display the sampled voltage value on the LCD.

1. Hardware Circuit

The peripheral circuits of the hardware part related to ADC include analog power pins AVDD and AVSS, as well as analog signal input pins.

AVDD power connection circuit on the development board, connected to the power supply.

Regarding the ADC input pins, the definition in the manual

2. Procedure

2.1, fun_adc.c

#include "main.h"

void init_adc(void)
{
	ADC_InitTypeDef ADC_InitStruct;

  __RCC_ADC_CLK_ENABLE();

  ADC_InitStruct.ADC_AccEn = DISABLE;
  ADC_InitStruct.ADC_Align = ADC_AlignRight;
  ADC_InitStruct.ADC_ClkDiv = ADC_Clk_Div2;    // ADCCLK=16MHz
  ADC_InitStruct.ADC_InBufEn = DISABLE;
  ADC_InitStruct.ADC_OpMode = ADC_SingleChOneMode;
  ADC_InitStruct.ADC_SampleTime = ADC_SampTime5Clk;
  ADC_InitStruct.ADC_TsEn = DISABLE;
  ADC_InitStruct.ADC_VrefSel = ADC_Vref_VDDA;

  ADC_Init(&ADC_InitStruct);
  ADC_Enable();
	
}

uint16_t adc_readval(uint8_t ch)
{
	CW_ADC->CR1_f.CHMUX = ch;
	ADC_SoftwareStartConvCmd(ENABLE);
	while(CW_ADC->START_f.START);
	return CW_ADC->RESULT0;
}

2.2, fun_adc.h

#ifndef __FUN_ADC_H
#define __FUN_ADC_H

#include "base_types.h"

void init_adc(void);
uint16_t adc_readval(uint8_t ch);
#endif 

2.3, mian.c

int32_t main(void)
{
	uint8_t dp[8];
	uint8_t i=0;
	uint16_t tp=0;
	uint32_t dp1=0;
	uint32_t dp_temp=0;
	GPIO_InitTypeDef GPIO_InitStruct = {0};
	rcc_config();
	init_uart();
	init_led();
	init_adc();
	init_spi_flash();

	InitTick( 48000000 );                  //初始化SysTick
	LCD_Configuration();
	SPI_FLASH_Test();
	dp[0]=disp[0];
	dp[1]=disp[0];
	dp[2]=disp[0];
	dp[3]=disp[0];
	dp[4]=disp[0];
	dp[5]=disp[0];
	dp[6]=disp[0];
	dp[7]=disp[0];
		
	while (1)
	{
		float adv=0.0;
		tp=(adc_readval(1)*33)/4096;
		dp[4]=disp[tp/1000];
		dp[3]=disp[((tp%1000)/100)];
		dp[2]=disp_p[((tp%1000)%100)/10];
		dp[1]=disp[((tp%1000)%100)%10];
		dp[0]=0x4c;
		led2_tog();
		SysTickDelay(100);
		lcd_disp(dp);  
		adv=tp*0.1;
		printf("ADC value = %1.1f \r\n",adv );
	}
}

3. Program running

After downloading the program, run the development board and adjust the serial port output of the sampling voltage potentiometer

Run the video

adc

This post is from Domestic Chip Exchange

Latest reply

Why is the last one only half?   Details Published on 2023-7-24 20:16
 
 

1668

Posts

0

Resources
2
 

Adjust the sampling voltage potentiometer serial port output, the video demonstration is relatively accurate and stable

This post is from Domestic Chip Exchange
 
 
 

7462

Posts

2

Resources
3
 

Why is the last one only half?

This post is from Domestic Chip Exchange
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list