本帖最后由 xihui-122742 于 2015-6-23 16:27 编辑 安:你好! 一、硬件连接: 1. +3.3V 串3个10k电阻到地 取中间电阻电压(1.10V)送AD 得到码数为:2610 2. +5V 串3个10k电阻到地 取中间电阻电压(1.66V)送AD 得到码数为:2915 3. ADC1_IN1->PA0 接信号+ ADC1_IN2->PA1 接信号- 二、问题:为何电压和码数无法对应呢? 三、代码:(cube生成) /** System Clock Configuration */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct; RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_PeriphCLKInitTypeDef PeriphClkInit; RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = 16; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16; HAL_RCC_OscConfig(&RCC_OscInitStruct); RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_HRTIM1|RCC_PERIPHCLK_USART1 |RCC_PERIPHCLK_ADC12; PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1; PeriphClkInit.Adc12ClockSelection = RCC_ADC12PLLCLK_DIV1; PeriphClkInit.Hrtim1ClockSelection = RCC_HRTIM1CLK_PLLCLK; HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit); __SYSCFG_CLK_ENABLE(); } ******************************************************* /* ADC1 init function */ void MX_ADC1_Init(void) { ADC_ChannelConfTypeDef sConfig; /**Common config */ hadc1.Instance = ADC1; hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC; hadc1.Init.Resolution = ADC_RESOLUTION12b; hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE; hadc1.Init.ContinuousConvMode = ENABLE; hadc1.Init.DiscontinuousConvMode = DISABLE; hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc1.Init.NbrOfConversion = 1; hadc1.Init.DMAContinuousRequests = DISABLE; hadc1.Init.EOCSelection = EOC_SINGLE_CONV; hadc1.Init.LowPowerAutoWait = DISABLE; hadc1.Init.Overrun = OVR_DATA_OVERWRITTEN; HAL_ADC_Init(&hadc1); /**Configure Regular Channel */ sConfig.Channel = ADC_CHANNEL_1; sConfig.Rank = 1; sConfig.SingleDiff = ADC_DIFFERENTIAL_ENDED; sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5; sConfig.OffsetNumber = ADC_OFFSET_NONE; sConfig.Offset = 0; HAL_ADC_ConfigChannel(&hadc1, &sConfig); } ******************************************************* HAL_ADC_Start(&hadc1); while (1) { ADC_GetValue=HAL_ADC_GetValue(&hadc1); printf("%d \r\n", ADC_GetValue); } |
STM32F3 硬件I2C 驱动OLED 求助!!
【探索发现STM32 F3系列】之变频调速应用
STM32F303使用定时器触发双ADC常规同步采样模式
STM32的USB host CDC应用
哪位大哥传下STM32F334 Nucleo的工程模板给我下
STM32F1的IAP程序,APP1和APP2两个应用程序交替更新的问题
STM32F334 不能串口下载
关于STM32F334的HRTIM分辨率问题
现金悬赏-STM32F4Cube生成的USB HID应用无法接收数据
STM32F030F4P6待机模式唤醒应用问题
ADC1_IN2->PA1 接信号-
这里说的信号+ -指的是具体哪个?还有参考电压ref是多少?
满码:4096
差分信号输入
1.10V送AD 得到码数为:2610
1.66V送AD 得到码数为:2915
请教码数和电压的换算关系?是不是选择了差分输入则AD自动为双极性?
ADC1_IN2->PA1 接信号-
这里的信号+指的是哪个?信号-指的是哪个?
如果不用差分,这个时候采集到的AD值是多少?他应该是实际电压/REF*4096.
参考电压:3.3V
满码:4096
差分信号输入
2.20-1.10=1.10V送AD 得到码数为:2610
ADC1_IN1->PA0 接+2.20V
ADC1_IN2->PA1 接+1.10V
3.32-1.66=1.66V送AD 得到码数为:2915
ADC1_IN1->PA0 接+3.32V
ADC1_IN2->PA1 接+1.66V
请教码数和电压的换算关系?
是不是选择了差分输入则AD自动为双极性?
In differential input mode, the analog voltage to be converted for channel “i” is the difference
between the external voltage ADC_INi (positive input) and ADC_INi+1 (negative input).
您好~麻烦问一下您说的双极性指的是什么? 我也在用334,遇到楼主的问题了