STM32F767AD sampling is seriously inaccurate[Copy link]
I wrote a program for STM32F767AD sampling. I measured it and found that the AD port (PF4) has only 0.1V, but the sampled value is very large, 0x3c8, 0x3cb. The program is as follows: int main(void) { u 8 i; float temp; Cache_Enable(); //Open L1-Cache HAL_Init(); //Initialize HAL library[/backcolor ] Stm32_Clock_Init(432,25,2,9); //Set clock, 216Mhz delay_init(216); //Delay initialization uart_init(115200); //Serial port initialization LED_Init(); //Initialize LED SDRAM_Init(); //Initialize SDRAM MY_ADC_Init(); //Initialize ADC1 channel 5 while(1) { adcx=Get_Adc_Average(ADC_CHANNEL_14,20);//Get the conversion value of channel 5 and average it for 20 times i=8; delay_ms(5); } } The above is the main program. ADC_HandleTypeDef ADC3_Handler; //ADC handle //Initialize ADC //ch: ADC_channels //Channel value 0~16 range: ADC_CHANNEL_0~ADC_CHANNEL_16 void MY_ADC_Init(void) { ADC3_Handler.Instance=ADC3; ADC3_Handler.Init.ClockPrescaler=ADC_CLOCK_SYNC_PCLK_DIV4; //4 frequency division, ADCCLK=PCLK2/4=108/4 =27MHZ ADC3_Handler.Init.Resolution=ADC_RESOLUTION_12B; //12-bit mode ADC3_Handler.Init.DataAlign=ADC_DATAALIGN_RIGHT; //Right alignment ADC3_Handler.Init.ScanConvMode=DISABLE; //Non-scanning mode ADC3_Handler.Init.EOCSelection=DISABLE; //Disable EOC interrupt ADC3_Handler.Init.ContinuousConvMode=DISABLE; //Disable continuous conversion ADC3_Handler.Init.NbrOfConversion=1; //1 conversion in the regular sequence means only converting regular sequence 1 ADC3_Handler.Init.DiscontinuousConvMode=DISABLE; //Disable discontinuous sampling mode ADC3_Handler.Init.NbrOfDiscConversion=0; //The number of discontinuous sampling channels is 0 ADC3_Handler.Init.ExternalTrigConv=ADC_SOFTWARE_START; //Software trigger ADC3_Handler.Init.ExternalTrigConvEdge=ADC_EXTERNALTRIGCONVEDGE_NONE; //Use software trigger ADC3_Handler.Init.DMAContinuousRequests=DISABLE; //Disable DMA request HAL_ADC_Init(&ADC3_Handler); //Initialization } //ADC underlying driver, pin configuration, clock enable //This function will be called by HAL_ADC_Init() //hadc:ADC handle void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) { GPIO_InitTypeDef GPIO_Initure; __HAL_RCC_ADC3_CLK_ENABLE(); //Enable ADC1 clock _HAL_RCC_GPIOF_CLK_ENABLE(); //Enable GPIOA clock GPIO_Initure.Pin=GPIO_PIN_4; //PA5 GPIO_Initure.Mode=GPIO_MODE_ANALOG; //Analog GPIO_Initure.Pull=GPIO_NOPULL; //Without pull-up and pull-down [backcolor=rgb(222, u16 Get_Adc(u32 ch) ADC_ChannelConfTypeDef ADC3_ChanConf; ADC3_ChanConf.Channel=ch; ADC3_ChanConf.Rank=1; 1 sequence ADC3_ChanConf.SamplingTime=ADC_SAMPLETIME_480CYCLES; ADC3_ChanConf.SamplingTime=ADC_SAMPLETIME_480CYCLES; ADC3_ChanConf.Offset=0; HAL_ADC_ConfigChannel(&ADC3_Handler,&ADC3_ChanConf); //Channel configuration HAL_ADC_Start(&ADC3_Handler); //Start ADC HAL_ADC_PollForConversion(&ADC3_Handler,10); //Poll for conversion return (u16)HAL_ADC_GetValue(&ADC3_Handler); //Return the most recent conversion result of the ADC1 rule group } //Get the conversion value of the specified channel, take times, and then average u16 Get_Adc_Average(u32 ch,u8 times) { u32 temp_val=0; u8 t; 251)] for(t=0;t" times;[="" {[="" }[="">
I have another question. The AD schematic is as follows: After connecting the sensor, AD1 and AD3 are both about 0.7V. If only one is connected, such as U5, AD1 is about 0.7V, but the voltage value of U7 is 1.32V. Can an expert tell me what is going on? Thank you!
After connecting the sensor, AD1 and AD3 are both about 0.7V. If only one is connected, such as U5, AD1 is about 0.7V, but the voltage value of U7 is 1.32V. Can an expert tell me what is going on? Thank you!