1731 views|1 replies

1455

Posts

1

Resources
The OP
 

【AT-START-F425 Review】+ A/D Data Acquisition and Display [Copy link]

 

The AT32F425 chip is equipped with a 12-bit 16-channel high-speed ADC with a sampling rate of up to 2Msps.

Combining the serial digital tube with A/D data acquisition can visually view the detection value.

The connection relationship between the serial digital tube and the development board is:

SCL---PC2

SDA---PC3

CS---PC5

The analog signal input channel is ADC_CH5, and the pin it uses is PA5.

The effects of A/D data acquisition and display are shown in Figures 1 to 3 .

Figure 1 Detecting 3.3V voltage

Figure 2 Detecting the suspended state

Figure 3 Detecting GND voltage

The driver program of the serial digital tube is as follows:

void Max7219_Init(void)
{
 gpio_init_type gpio_init_struct;
 crm_periph_clock_enable(CRM_GPIOC_PERIPH_CLOCK, TRUE);
 gpio_default_para_init(&gpio_init_struct);
 gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
 gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
 gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
 gpio_init_struct.gpio_pins = GPIO_PINS_2|GPIO_PINS_3|GPIO_PINS_5;
 gpio_init(GPIOC, &gpio_init_struct);
}
void Write_Max7219_byte(unsigned char DATA)
{
 unsigned char i;
 GPIOC->clr = GPIO_PINS_5;
delay_us(10);
 for(i=8;i>=1;i--)
 {
 GPIOC->clr = GPIO_PINS_2;
 if(DATA&0x80) GPIOC->scr = GPIO_PINS_3;
 else GPIOC->clr = GPIO_PINS_3;
 delay_us(10);
DATA=DATA<<1;
 GPIOC->scr = GPIO_PINS_2;
 delay_us(10);
  }
}
void Write_Max7219(char address,char dat)
{
 GPIOC->clr = GPIO_PINS_5;
 Write_Max7219_byte(address);
 Write_Max7219_byte(dat);
 GPIOC->scr = GPIO_PINS_5;
}
void Init_MAX7219(void)
{
 Write_Max7219(0x09, 0xff);
 Write_Max7219(0x0a, 0x03);
 Write_Max7219(0x0b, 0x07);
 Write_Max7219(0x0c, 0x01);
 Write_Max7219(0x0f, 0x01);
}

The function to set the ADC input pin is:

static void gpio_config(void)
{
 gpio_init_type gpio_initstructure;
 crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
 gpio_default_para_init(&gpio_initstructure);
 gpio_initstructure.gpio_mode = GPIO_MODE_ANALOG;
 gpio_initstructure.gpio_pins = GPIO_PINS_4 | GPIO_PINS_5 | GPIO_PINS_6;
 gpio_init(GPIOA, &gpio_initstructure);
}

The configuration functions of ADC and DMA are:

static void adc_config(void)
{
 adc_base_config_type adc_base_struct;
 crm_periph_clock_enable(CRM_ADC1_PERIPH_CLOCK, TRUE);
 crm_adc_clock_div_set(CRM_ADC_DIV_6);
 nvic_irq_enable(ADC1_IRQn, 0, 0);
 adc_combine_mode_select(ADC_INDEPENDENT_MODE);
 adc_base_default_para_init(&adc_base_struct);
 adc_base_struct.sequence_mode = TRUE;
 adc_base_struct.repeat_mode = FALSE;
 adc_base_struct.data_align = ADC_RIGHT_ALIGNMENT;
 adc_base_struct.ordinary_channel_length = 3;
 adc_base_config(ADC1, &adc_base_struct);
 adc_ordinary_channel_set(ADC1, ADC_CHANNEL_4, 1, ADC_SAMPLETIME_239_5);
 adc_ordinary_channel_set(ADC1, ADC_CHANNEL_5, 2, ADC_SAMPLETIME_239_5);
 adc_ordinary_channel_set(ADC1, ADC_CHANNEL_6, 3, ADC_SAMPLETIME_239_5);
 adc_ordinary_conversion_trigger_set(ADC1, ADC12_ORDINARY_TRIG_SOFTWARE, TRUE);
 adc_dma_mode_enable(ADC1, TRUE);
 adc_voltage_monitor_enable(ADC1, ADC_VMONITOR_SINGLE_ORDINARY);
 adc_voltage_monitor_threshold_value_set(ADC1, 0xBBB, 0xAAA);
 adc_voltage_monitor_single_channel_select(ADC1, ADC_CHANNEL_5);
 adc_interrupt_enable(ADC1, ADC_VMOR_INT, TRUE);
 adc_enable(ADC1, TRUE);
 adc_calibration_init(ADC1);
 while(adc_calibration_init_status_get(ADC1));
 adc_calibration_start(ADC1);
 while(adc_calibration_status_get(ADC1));
}

static void dma_config(void)
{
 dma_init_type dma_init_struct;
 crm_periph_clock_enable(CRM_DMA1_PERIPH_CLOCK, TRUE);
 dma_reset(DMA1_CHANNEL1);
 dma_flexible_config(DMA1, FLEX_CHANNEL1, DMA_FLEXIBLE_ADC1);
 dma_default_para_init(&dma_init_struct);
 dma_init_struct.buffer_size = 3;
 dma_init_struct.direction = DMA_DIR_PERIPHERAL_TO_MEMORY;
 dma_init_struct.memory_base_addr = (uint32_t)adc1_ordinary_valuetab;
 dma_init_struct.memory_data_width = DMA_MEMORY_DATA_WIDTH_HALFWORD;
 dma_init_struct.memory_inc_enable = TRUE;
 dma_init_struct.peripheral_base_addr = (uint32_t)&(ADC1->odt);
 dma_init_struct.peripheral_data_width = DMA_PERIPHERAL_DATA_WIDTH_HALFWORD;
 dma_init_struct.peripheral_inc_enable = FALSE;
 dma_init_struct.priority = DMA_PRIORITY_HIGH;
 dma_init_struct.loop_mode_enable = TRUE;
 dma_init(DMA1_CHANNEL1, &dma_init_struct);
 dma_channel_enable(DMA1_CHANNEL1, TRUE);
}

The ADC interrupt processing function used is:

void ADC1_IRQHandler(void)
{
 if(adc_flag_get(ADC1, ADC_VMOR_FLAG) != RESET)
 {
 adc_flag_clear(ADC1, ADC_VMOR_FLAG);
 vmor_flag_index = 1;
 }
}

The main program to achieve the display effect is:

int main(void)
{
 char n;
 uint16_t m;
 __IO uint32_t index = 0;
 nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
 system_clock_config();
 gpio_config();
 dma_config();
 adc_config();
 Max7219_Init();
 Init_MAX7219();
 delay_sec(1);
 Write_Max7219(0x0f, 0x00);
 Write_Max7219(1, 0x0f);
 Write_Max7219(2, 0x0f);
 Write_Max7219(3, 0x0f);
 Write_Max7219(4, 0x0f);
 Write_Max7219(5,0x0f);
 Write_Max7219(6,0x0f);
 Write_Max7219(7,0x0f);
 Write_Max7219(8,0x0f);
 while(1)
 {
 delay_sec(1);
 if(vmor_flag_index == 1)
 {
 vmor_flag_index = 0;
m=adc1_ordinary_valuetab[1];
  n=m%10;
 Write_Max7219(1,n);
 n=m%100/10;
 Write_Max7219(2,n);
 n=m%1000/100;
 Write_Max7219(3,n);
 n=m/1000;
 Write_Max7219(4,n);
 }
 adc_ordinary_software_trigger_enable(ADC1, TRUE);
 }
}

This post is from Domestic Chip Exchange

Latest reply

A/D data acquisition is generally a must-test item for development boards.   Details Published on 2022-4-28 07:12
 
 

6593

Posts

0

Resources
2
 

A/D data acquisition is generally a must-test item for development boards.

This post is from Domestic Chip Exchange
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

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