I have a STM32L053-Disco eval board, and I'm building a capacitance meter. For it to work, I have to calculate the charge time on my capacitor. The approach that I'm taking is to set 1 GPIO pin to output and for ADC to read it and then calculate. The issue is my ADC doesn't measuring from zero, when my GPIO pin is reset, the values that I'm getting are around 0.05V and I can't get it to drop to 0.00V. Any ideas why that could be happening? This is my circuit:
And here is some code:
while (1)
{
// Get ADC value
//
HAL_ADC_Start(&hadc);
HAL_ADC_PollForConversion(&hadc, 1000);
HAL_ADCEx_Calibration_Start(&hadc,4096);
raw = HAL_ADC_GetValue(&hadc);
// HAL_COMP_Start(&hcomp1);
real = (raw*3.3)/4096;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
// status == HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET);
if(real >= 0.117*0.632)
{
HAL_ADC_Stop(&hadc);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
time2 = HAL_GetTick();
}
if(real <= 0)
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
time1 = HAL_GetTick();
}
time3 = (time2 - time1)/1000;
c = time3/res;
// Convert to string and print
sprintf(TxBuffer,"%7.3f V\n", real);
HAL_UART_Transmit(&huart1, (uint8_t*)TxBuffer, strlen(TxBuffer), HAL_MAX_DELAY);
}
}
Also I think my ADC for some reason doesn't reset, because here are the values that I get:
When it reaches 62.3% it just stops there and doesn't reset, even if in the code I wrote HAL_ADC_STOP()