Question
How to get the best ADC data?
Posted on July 06, 2015 at 21:56
I am testing/playing with a STM32f207 dev. board. I would like to know what ways are there to get most out of the ADC converter. For instance, is it possible to shut down the rest of CPU when conversion is done. Is there something ARM or ST specific I should know or are there any mistakes I made. The code below is mostly from the CubeMX.
The PC board is of course important and a dev. kit is not optimized for analog signals. Output wanders now between 0 and 3 and there are random high glitches. But some of it comes surely from the PCB. The program below calculates an average of two conversions.#include ''stm32f2xx_hal.h''
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
/* USER CODE BEGIN Includes */
char
plaa[] =
''Hellogffgffgf''
;
char
klaa[20];
/* USER CODE END Includes */
float
kkk,ccc;
int
b,c;
/* Private variables ---------------------------------------------------------*/
ADC_HandleTypeDef hadc1;
UART_HandleTypeDef huart3;
void
SystemClock_Config(
void
);
static
void
MX_GPIO_Init(
void
);
static
void
MX_ADC1_Init(
void
);
static
void
MX_USART3_UART_Init(
void
);
int
main(
void
)
{
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_ADC1_Init();
MX_USART3_UART_Init();
while
(1)
{
/* USER CODE END WHILE */
HAL_ADC_Start(& hadc1);
while
(HAL_OK!= HAL_ADC_PollForConversion(&hadc1, 1000))
{
}
ccc= HAL_ADC_GetValue(&hadc1);
HAL_ADC_Start(& hadc1);
while
(HAL_OK!= HAL_ADC_PollForConversion(&hadc1, 1000))
{
}
ccc= HAL_ADC_GetValue(&hadc1)+ccc;
kkk=ccc/2;
sprintf
(klaa,
''readout %f \n''
, kkk);
c=
sizeof
(klaa);
// strcpy(klaa,b);
HAL_UART_Transmit(&huart3,(uint8_t *) klaa,c,1000);
/* USER CODE BEGIN 3 */
HAL_UART_Receive(&huart3, (uint8_t *)klaa,
sizeof
(klaa), 1000);
HAL_UART_Transmit(&huart3,(uint8_t *) klaa,c,1000);
HAL_Delay(1000);
}
}
Clip
Clip