Curious problem when trying to read differential ADC values on Nucleo F303ZE
- April 15, 2021
- 5 replies
- 3918 views
Hello, first time posting so I'm sorry if this is not the right place.
I just got a Nucleo F303ZE board and I'm trying to learn how to use it. The thing is, I have a board with several capacitos connected in series, and I'd like to use the MC to measure their individual voltages.
For this, I have to use several ADCs from the chip in differential mode, but I'm having trouble just measuring one. I can't use single-end mode, as the sum of volages of the supercaps can get up to 48V (18 caps of 2.7V each), but I've tried when they were dischaged and it worked just fine after messing with the sampling time and adding calibration.
The thing is, after setting ADC1 for differential mode, the value I get after measuring one capacitor is of 2155 (1.74V), which is way higher than it's actual charge (0.17V, measured manually).
I thought that maybe I had missplaced the pins, so I swaped them and I got 1937 this time. Funny enough, 2155 - 1937 = 218, which is exactly the 0.17V that I'm expecting when converted, so I know that I can't be too far from the solution.
And here is what i receive through terminal:
And after switching the pins:
Here is an screenshot of my configuration and I also include the main.c code, but the only things that I've included after auto generating are:
int main(void)
{
/* USER CODE BEGIN 1 */
uint16_t raw;
char msg[10];
/* USER CODE END 1 */
if(HAL_ADCEx_Calibration_Start(&hadc1, ADC_DIFFERENTIAL_ENDED)){
Error_Handler();
}
/* USER CODE BEGIN 2 */
if (HAL_ADC_Start(&hadc1) != HAL_OK)
{
/* Start Conversation Error */
Error_Handler();
}
/* USER CODE END 2 */
while (1)
{
//Some LEDs tryouts and serial connection
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET);
HAL_GPIO_WritePin(LD3_GPIO_Port,LD3_Pin,GPIO_PIN_SET);
HAL_GPIO_WritePin(LD3_GPIO_Port,LD3_Pin,GPIO_PIN_RESET);
raw = HAL_ADC_GetValue(&hadc1);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET);
sprintf(msg, "%hu\r\n", raw);
HAL_UART_Transmit(&huart3, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY);
}
So I've been trying several configurations on CubeIDE but to no avail, any one can help me with where could be the problem? I'm pretty new to all of this stuff so I'm sorry if I'm not explaining well.
Right now I'm only trying to measure 1 as I'm just starting, but in the future I'll have to measure all 18 caps at the same time, do you think I'll be able with this board?
Thank you very much.