-
AT32F407多路ADC问题 sos
[i=s] 本帖最后由 zhjb1 于 2024-11-13 17:42 编辑 [/i] [color=#444444][color=rgb(68, 68, 68)][backcolor=rgb(255, 255, 255)][font=Tahoma, "][size=15px][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]用Work_Bench创建了一个AT的工程,在做实验室能遇到一些问题,以后慢慢提问并解决。如果解决了,会将代码放上一起学习。[/size][/font][/backcolor][/size][/font][/backcolor][/color][/color][color=#444444][color=rgb(68, 68, 68)][backcolor=rgb(255, 255, 255)][font=Tahoma, "][size=15px][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]二、多路ADC采样[/size][/font][/backcolor][/size][/font][/backcolor][/color][/color] [color=#444444][color=rgb(68, 68, 68)][backcolor=rgb(255, 255, 255)][font=Tahoma, "][size=15px][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]在AT_WORK_BENCH中设置了ADC1的IN1,IN2,IN3,IN6,IN7,其中IN7连接内部温度传感器。[/size][/font][/backcolor][/size][/font][/backcolor][/color][/color] [color=#444444][color=rgb(68, 68, 68)][backcolor=rgb(255, 255, 255)][font=Tahoma, "][size=15px][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]AWB生成的代码看着挺好也非常漂亮,初始化代码如下:[/size][/font][/backcolor][/size][/font][/backcolor][/color][/color] [backcolor=rgb(255, 255, 255)][backcolor=rgb(242, 249, 253)][font=Tahoma, Microsoft Yahei, Simsun][color=#444444][size=16px]/**[/size] [size=16px] * [url=home.php?mod=space&uid=247401]@brief[/url] init adc1 function.[/size] [size=16px] * @param none[/size] [size=16px] * @retval none[/size] [size=16px] */[/size] [size=16px]void wk_adc1_init(void)[/size] [size=16px]{[/size] [size=16px] /* add user code begin adc1_init 0 */[/size] [size=16px] /* add user code end adc1_init 0 */[/size] [size=16px] gpio_init_type gpio_init_struct;[/size] [size=16px] adc_base_config_type adc_base_struct;[/size] [size=16px] gpio_default_para_init(&gpio_init_struct);[/size] [size=16px] /* add user code begin adc1_init 1 */[/size] [size=16px] /* add user code end adc1_init 1 */[/size] [size=16px] /*gpio--------------------------------------------------------------------*/ [/size] [size=16px] /* configure the IN1 pin */[/size] [size=16px] gpio_init_struct.gpio_mode = GPIO_MODE_ANALOG;[/size] [size=16px] gpio_init_struct.gpio_pins = ADC0_PIN;[/size] [size=16px] gpio_init(ADC0_GPIO_PORT, &gpio_init_struct);[/size] [size=16px] /* configure the IN2 pin */[/size] [size=16px] gpio_init_struct.gpio_mode = GPIO_MODE_ANALOG;[/size] [size=16px] gpio_init_struct.gpio_pins = ADC1_PIN;[/size] [size=16px] gpio_init(ADC1_GPIO_PORT, &gpio_init_struct);[/size] [size=16px] /* configure the IN3 pin */[/size] [size=16px] gpio_init_struct.gpio_mode = GPIO_MODE_ANALOG;[/size] [size=16px] gpio_init_struct.gpio_pins = ADC2_PIN;[/size] [size=16px] gpio_init(ADC2_GPIO_PORT, &gpio_init_struct);[/size] [size=16px] /* configure the IN6 pin */[/size] [size=16px] gpio_init_struct.gpio_mode = GPIO_MODE_ANALOG;[/size] [size=16px] gpio_init_struct.gpio_pins = ADC3_PIN;[/size] [size=16px] gpio_init(ADC3_GPIO_PORT, &gpio_init_struct);[/size] [size=16px] /* configure the IN7 pin */[/size] [size=16px] gpio_init_struct.gpio_mode = GPIO_MODE_ANALOG;[/size] [size=16px] gpio_init_struct.gpio_pins = ADC4_PIN;[/size] [size=16px] gpio_init(ADC4_GPIO_PORT, &gpio_init_struct);[/size] [size=16px] crm_adc_clock_div_set(CRM_ADC_DIV_6);[/size] [size=16px] adc_tempersensor_vintrv_enable(TRUE);[/size] [size=16px] /*adc_common_settings-------------------------------------------------------------*/ [/size] [size=16px] adc_combine_mode_select(ADC_INDEPENDENT_MODE);[/size] [size=16px] /*adc_settings--------------------------------------------------------------------*/ [/size] [size=16px] adc_base_default_para_init(&adc_base_struct);[/size] [size=16px] adc_base_struct.sequence_mode = TRUE;[/size] [size=16px] adc_base_struct.repeat_mode = TRUE;[/size] [size=16px] adc_base_struct.data_align = ADC_RIGHT_ALIGNMENT;[/size] [size=16px] adc_base_struct.ordinary_channel_length = 5;[/size] [size=16px] adc_base_config(ADC1, &adc_base_struct);[/size] [size=16px] /* adc_ordinary_conversionmode-------------------------------------------- */[/size] [size=16px] adc_ordinary_channel_set(ADC1, ADC_CHANNEL_1, 1, ADC_SAMPLETIME_1_5);[/size] [size=16px] adc_ordinary_channel_set(ADC1, ADC_CHANNEL_2, 2, ADC_SAMPLETIME_1_5);[/size] [size=16px] adc_ordinary_channel_set(ADC1, ADC_CHANNEL_3, 3, ADC_SAMPLETIME_1_5);[/size] [size=16px] adc_ordinary_channel_set(ADC1, ADC_CHANNEL_6, 4, ADC_SAMPLETIME_1_5);[/size] [size=16px] adc_ordinary_channel_set(ADC1, ADC_CHANNEL_16, 5, ADC_SAMPLETIME_1_5);[/size] [size=16px] adc_ordinary_conversion_trigger_set(ADC1, ADC12_ORDINARY_TRIG_SOFTWARE, TRUE);[/size] [size=16px] adc_ordinary_part_mode_enable(ADC1, FALSE);[/size] [size=16px] adc_dma_mode_enable(ADC1, TRUE);[/size] [size=16px] /**[/size] [size=16px] * Users need to configure ADC1 interrupt functions according to the actual application.[/size] [size=16px] * 1. Call the below function to enable the corresponding ADC1 interrupt.[/size] [size=16px] * --adc_interrupt_enable(...)[/size] [size=16px] * 2. Add the user's interrupt handler code into the below function in the at32f403a_407_int.c file.[/size] [size=16px] * --void ADC1_2_IRQHandler(void)[/size] [size=16px] */[/size] [size=16px] adc_enable(ADC1, TRUE);[/size] [size=16px] /* adc calibration-------------------------------------------------------- */[/size] [size=16px] adc_calibration_init(ADC1);[/size] [size=16px] while(adc_calibration_init_status_get(ADC1));[/size] [size=16px] adc_calibration_start(ADC1);[/size] [size=16px] while(adc_calibration_status_get(ADC1));[/size] [size=16px] /* add user code begin adc1_init 2 */[/size] [size=16px] /* add user code end adc1_init 2 */[/size] [size=16px]}[/size] [size=16px]初始化之后在main中定时调用下边的ADC函数:[/size] [size=16px]//Test ADCs[/size] [size=16px]void adcTest(void){[/size] [size=16px] int i;[/size] [size=16px] adc_calibration_start(ADC1);//dma_trans_complete_flag = 0;这条语句也不行[/size] [size=16px] adc_ordinary_software_trigger_enable(ADC1, TRUE);[/size] [size=16px] //while(!dma_trans_complete_flag);[/size] [size=16px] while(!adc_calibration_status_get(ADC1));//adc_calibration_status_get(ADC1)[/size] [size=16px] for(i=0;i<5;i++){[/size] [size=16px] adcx[i]=adc_combine_ordinary_conversion_data_get();//adc_preempt_conversion_data_get(ADC1,i);//adc1_ordinary_valuetab[i];//(double)adc1_ordinary_value;[/i][/i][/size][i][i] [size=16px] }[/size] [size=16px]}[/size] [size=16px]在STM例程中获得组数据不用循环赋值,只需要:[/size] [size=16px]HAL_ADC_Start_DMA(&hadc1,(uint32_t*)&ADC_Result,ADC_NUMOFCHANNEL);[/size] [size=16px]而在WB中用那条语句也不通,上述语句倒是显示数据了,前4个通道为固定值1236(等效0~4095),第5个听到位0064稍有变化,在1个bit之间,基本稳定。所有5个通道数值***不变,无论你加电位器与否。[/size] 暂时没有辙了,发帖求助。 声明:用STM代码移植过来可以成功,但希望WB能成功。 先谢谢了 [/i][/i][/color][/font][/backcolor][/backcolor]
606浏览量 0回复量 关注量